mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
WIP: Show full name of network printer types
This commit is contained in:
parent
de9f6f47bd
commit
764f7281c2
4 changed files with 30 additions and 7 deletions
|
@ -1,15 +1,20 @@
|
||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Callable, List, Optional, TYPE_CHECKING
|
from typing import Callable, List, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
|
||||||
|
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from PyQt5.QtCore import QObject
|
from PyQt5.QtCore import QObject
|
||||||
|
|
||||||
|
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
class DiscoveredPrinter(QObject):
|
class DiscoveredPrinter(QObject):
|
||||||
|
|
||||||
def __init__(self, ip_address: str, key: str, name: str, create_callback: Callable[[str], None], machine_type: str,
|
def __init__(self, ip_address: str, key: str, name: str, create_callback: Callable[[str], None], machine_type: str,
|
||||||
|
@ -43,11 +48,19 @@ class DiscoveredPrinter(QObject):
|
||||||
def machine_type(self) -> str:
|
def machine_type(self) -> str:
|
||||||
return self._machine_type
|
return self._machine_type
|
||||||
|
|
||||||
# Machine type string with underscores "_" replaced with spaces " "
|
def setMachineType(self, machine_type: str) -> None:
|
||||||
|
if self._machine_type != machine_type:
|
||||||
|
self._machine_type = machine_type
|
||||||
|
self.machineTypeChanged.emit()
|
||||||
|
|
||||||
|
# Human readable machine type string
|
||||||
@pyqtProperty(str, notify = machineTypeChanged)
|
@pyqtProperty(str, notify = machineTypeChanged)
|
||||||
def machine_type_with_spaces(self) -> str:
|
def readable_machine_type(self) -> str:
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
return CuraApplication.getInstance().getMachineManager().getMachineTypeNameFromId(self._machine_type)
|
readable_type = CuraApplication.getInstance().getMachineManager().getMachineTypeNameFromId(self._machine_type)
|
||||||
|
if not readable_type:
|
||||||
|
readable_type = catalog.i18nc("@label", "Unknown")
|
||||||
|
return readable_type
|
||||||
|
|
||||||
@pyqtProperty(QObject, constant = True)
|
@pyqtProperty(QObject, constant = True)
|
||||||
def device(self):
|
def device(self):
|
||||||
|
|
|
@ -20,11 +20,14 @@ Button
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
|
||||||
property bool selected: checked
|
property bool selected: checked
|
||||||
|
property bool printerTypeLabelAutoFit: false
|
||||||
|
|
||||||
property var outputDevice: null
|
property var outputDevice: null
|
||||||
property var printerTypesList: []
|
property var printerTypesList: []
|
||||||
|
|
||||||
property var updatePrinterTypesFunction: updatePrinterTypesList
|
property var updatePrinterTypesFunction: updatePrinterTypesList
|
||||||
|
// This function converts the printer type string to another string.
|
||||||
|
property var printerTypeLabelConversionFunction: Cura.MachineManager.getAbbreviatedMachineName
|
||||||
|
|
||||||
function updatePrinterTypesList()
|
function updatePrinterTypesList()
|
||||||
{
|
{
|
||||||
|
@ -71,7 +74,8 @@ Button
|
||||||
model: printerTypesList
|
model: printerTypesList
|
||||||
delegate: Cura.PrinterTypeLabel
|
delegate: Cura.PrinterTypeLabel
|
||||||
{
|
{
|
||||||
text: Cura.MachineManager.getAbbreviatedMachineName(modelData)
|
autoFit: printerTypeLabelAutoFit
|
||||||
|
text: printerTypeLabelConversionFunction(modelData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,9 @@ Item
|
||||||
{
|
{
|
||||||
property alias text: printerTypeLabel.text
|
property alias text: printerTypeLabel.text
|
||||||
|
|
||||||
width: UM.Theme.getSize("printer_type_label").width
|
property bool autoFit: false
|
||||||
|
|
||||||
|
width: autoFit ? (printerTypeLabel.width + UM.Theme.getSize("default_margin").width) : UM.Theme.getSize("printer_type_label").width
|
||||||
height: UM.Theme.getSize("printer_type_label").height
|
height: UM.Theme.getSize("printer_type_label").height
|
||||||
|
|
||||||
Rectangle
|
Rectangle
|
||||||
|
|
|
@ -57,11 +57,15 @@ Item
|
||||||
anchors.rightMargin: 10
|
anchors.rightMargin: 10
|
||||||
outputDevice: modelData.device
|
outputDevice: modelData.device
|
||||||
|
|
||||||
|
printerTypeLabelAutoFit: true
|
||||||
|
|
||||||
updatePrinterTypesFunction: updateMachineTypes
|
updatePrinterTypesFunction: updateMachineTypes
|
||||||
|
// show printer type as it is
|
||||||
|
printerTypeLabelConversionFunction: function(value) { return value }
|
||||||
|
|
||||||
function updateMachineTypes()
|
function updateMachineTypes()
|
||||||
{
|
{
|
||||||
printerTypesList = [ modelData.machine_type_with_spaces ]
|
printerTypesList = [ modelData.readable_machine_type ]
|
||||||
}
|
}
|
||||||
|
|
||||||
checkable: false
|
checkable: false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue