Browse Source

WIP: Show full name of network printer types

Lipu Fei 6 years ago
parent
commit
764f7281c2

+ 17 - 4
cura/Machines/Models/DiscoveredPrintersModel.py

@@ -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 PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
 
+from UM.i18n import i18nCatalog
 from UM.Logger import Logger
 
 if TYPE_CHECKING:
     from PyQt5.QtCore import QObject
 
 
+catalog = i18nCatalog("cura")
+
+
 class DiscoveredPrinter(QObject):
 
     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:
         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)
-    def machine_type_with_spaces(self) -> str:
+    def readable_machine_type(self) -> str:
         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)
     def device(self):

+ 5 - 1
resources/qml/PrinterSelector/MachineSelectorButton.qml

@@ -20,11 +20,14 @@ Button
     hoverEnabled: true
 
     property bool selected: checked
+    property bool printerTypeLabelAutoFit: false
 
     property var outputDevice: null
     property var printerTypesList: []
 
     property var updatePrinterTypesFunction: updatePrinterTypesList
+    // This function converts the printer type string to another string.
+    property var printerTypeLabelConversionFunction: Cura.MachineManager.getAbbreviatedMachineName
 
     function updatePrinterTypesList()
     {
@@ -71,7 +74,8 @@ Button
                 model: printerTypesList
                 delegate: Cura.PrinterTypeLabel
                 {
-                    text: Cura.MachineManager.getAbbreviatedMachineName(modelData)
+                    autoFit: printerTypeLabelAutoFit
+                    text: printerTypeLabelConversionFunction(modelData)
                 }
             }
         }

+ 3 - 1
resources/qml/PrinterTypeLabel.qml

@@ -12,7 +12,9 @@ Item
 {
     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
 
     Rectangle

+ 5 - 1
resources/qml/WelcomePages/AddNetworkPrinterScrollView.qml

@@ -57,11 +57,15 @@ Item
                 anchors.rightMargin: 10
                 outputDevice: modelData.device
 
+                printerTypeLabelAutoFit: true
+
                 updatePrinterTypesFunction: updateMachineTypes
+                // show printer type as it is
+                printerTypeLabelConversionFunction: function(value) { return value }
 
                 function updateMachineTypes()
                 {
-                    printerTypesList = [ modelData.machine_type_with_spaces ]
+                    printerTypesList = [ modelData.readable_machine_type ]
                 }
 
                 checkable: false