From b34865e9c8db72436f1dc2971ef4f17d7288bb19 Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Thu, 28 Mar 2024 11:54:54 +0100 Subject: [PATCH 1/6] Changed setting value to enum value while saving ucp CURA-11783 --- plugins/3MFWriter/SettingExport.py | 7 ++++++- plugins/3MFWriter/SettingSelection.qml | 2 +- plugins/3MFWriter/SettingsExportModel.py | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/3MFWriter/SettingExport.py b/plugins/3MFWriter/SettingExport.py index dca72ddffae..61c7d91b545 100644 --- a/plugins/3MFWriter/SettingExport.py +++ b/plugins/3MFWriter/SettingExport.py @@ -6,11 +6,12 @@ class SettingExport(QObject): - def __init__(self, id, name, value, selectable, show): + def __init__(self, id, name, value, value_name, selectable, show): super().__init__() self.id = id self._name = name self._value = value + self._value_name = value_name self._selected = selectable self._selectable = selectable self._show_in_menu = show @@ -23,6 +24,10 @@ def name(self): def value(self): return self._value + @pyqtProperty(str, constant=True) + def valuename(self): + return str(self._value_name) + selectedChanged = pyqtSignal(bool) def setSelected(self, selected): diff --git a/plugins/3MFWriter/SettingSelection.qml b/plugins/3MFWriter/SettingSelection.qml index 53594153b7f..85c2f636aa5 100644 --- a/plugins/3MFWriter/SettingSelection.qml +++ b/plugins/3MFWriter/SettingSelection.qml @@ -24,7 +24,7 @@ RowLayout UM.Label { - text: modelData.value + text: modelData.valuename } UM.HelpIcon diff --git a/plugins/3MFWriter/SettingsExportModel.py b/plugins/3MFWriter/SettingsExportModel.py index 10b7f8f775b..0251a6c4fa1 100644 --- a/plugins/3MFWriter/SettingsExportModel.py +++ b/plugins/3MFWriter/SettingsExportModel.py @@ -121,6 +121,8 @@ def _exportSettings(settings_stack): label = settings_stack.getProperty(setting_to_export, "label") value = settings_stack.getProperty(setting_to_export, "value") unit = settings_stack.getProperty(setting_to_export, "unit") + options = settings_stack.getProperty(setting_to_export, "options") + value_name = value if options == {} else options[value] setting_type = settings_stack.getProperty(setting_to_export, "type") if setting_type is not None: @@ -131,6 +133,7 @@ def _exportSettings(settings_stack): settings_export.append(SettingExport(setting_to_export, label, value, + value_name, is_exportable or setting_to_export in exportable_settings, show_in_menu)) From cf61a78fbffa080d0cf38721fea189c1b627c2dc Mon Sep 17 00:00:00 2001 From: Saumya Jain Date: Thu, 28 Mar 2024 17:16:42 +0100 Subject: [PATCH 2/6] Added enumname while reading ucp Added a connection in WorkspaceDialog.qml to call function whenever the 'exportedSettingModel' changes. This ensures that any changes in the model will now be reflected in the UI table. Furthermore, an added adjustment in SpecificSettingsModel.py now correctly handles the enum type settings, retrieving the correct value from the options list. CURA-11783 --- plugins/3MFReader/SpecificSettingsModel.py | 4 ++++ plugins/3MFReader/WorkspaceDialog.qml | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/3MFReader/SpecificSettingsModel.py b/plugins/3MFReader/SpecificSettingsModel.py index af203ad759f..275b9c03ac2 100644 --- a/plugins/3MFReader/SpecificSettingsModel.py +++ b/plugins/3MFReader/SpecificSettingsModel.py @@ -33,6 +33,10 @@ def addSettingsFromStack(self, stack, category, settings): if setting_type is not None: # This is not very good looking, but will do for now value = str(SettingDefinition.settingValueToString(setting_type, value)) + " " + str(unit) + if setting_type == "enum": + options = stack.getProperty(setting, "options") + value = options[stack.getProperty(setting, "value")] + else: value = str(value) diff --git a/plugins/3MFReader/WorkspaceDialog.qml b/plugins/3MFReader/WorkspaceDialog.qml index eeb33da4c7b..adb070e8623 100644 --- a/plugins/3MFReader/WorkspaceDialog.qml +++ b/plugins/3MFReader/WorkspaceDialog.qml @@ -216,6 +216,16 @@ UM.Dialog headers: ["category", "label", "value"] rows: manager.exportedSettingModelItems } + + Connections + { + target: manager + function onExportedSettingModelChanged() + { + tableModel.clear() + tableModel.rows = manager.exportedSettingModelItems + } + } } } From b2c0767165b978746472583a9b39aa07bd93b66f Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 29 Mar 2024 11:52:09 +0100 Subject: [PATCH 3/6] Add translations to enum values CURA-11783 --- plugins/3MFReader/SpecificSettingsModel.py | 12 ++++++++---- plugins/3MFWriter/SettingsExportModel.py | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/3MFReader/SpecificSettingsModel.py b/plugins/3MFReader/SpecificSettingsModel.py index 275b9c03ac2..09efb453ed3 100644 --- a/plugins/3MFReader/SpecificSettingsModel.py +++ b/plugins/3MFReader/SpecificSettingsModel.py @@ -3,6 +3,7 @@ from PyQt6.QtCore import Qt, pyqtSignal +from UM import i18nCatalog from UM.Logger import Logger from UM.Settings.SettingDefinition import SettingDefinition from UM.Qt.ListModel import ListModel @@ -19,7 +20,7 @@ def __init__(self, parent = None): self.addRoleName(self.LabelRole, "label") self.addRoleName(self.ValueRole, "value") - self._i18n_catalog = None + self._i18n_catalog = i18nCatalog("cura") self._update() modelChanged = pyqtSignal() @@ -32,11 +33,14 @@ def addSettingsFromStack(self, stack, category, settings): setting_type = stack.getProperty(setting, "type") if setting_type is not None: # This is not very good looking, but will do for now - value = str(SettingDefinition.settingValueToString(setting_type, value)) + " " + str(unit) + value = str(SettingDefinition.settingValueToString(setting_type, value)) + if unit: + value += " " + str(unit) if setting_type == "enum": options = stack.getProperty(setting, "options") - value = options[stack.getProperty(setting, "value")] - + msgctxt = f"{str(setting)} option {str(value)}" + msgid = options[stack.getProperty(setting, "value")] + value = self._i18n_catalog.i18nc(msgctxt, msgid) else: value = str(value) diff --git a/plugins/3MFWriter/SettingsExportModel.py b/plugins/3MFWriter/SettingsExportModel.py index 0251a6c4fa1..e8e3e4a0dad 100644 --- a/plugins/3MFWriter/SettingsExportModel.py +++ b/plugins/3MFWriter/SettingsExportModel.py @@ -6,6 +6,7 @@ from PyQt6.QtCore import QObject, pyqtProperty +from UM import i18nCatalog from UM.Settings.SettingDefinition import SettingDefinition from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.SettingFunction import SettingFunction @@ -109,6 +110,7 @@ def settingsGroups(self) -> List[SettingsExportGroup]: @staticmethod def _exportSettings(settings_stack): + i18n_catalog = i18nCatalog("cura") user_settings_container = settings_stack.userChanges user_keys = user_settings_container.getAllKeys() exportable_settings = SettingsExportModel.EXPORTABLE_SETTINGS @@ -122,7 +124,9 @@ def _exportSettings(settings_stack): value = settings_stack.getProperty(setting_to_export, "value") unit = settings_stack.getProperty(setting_to_export, "unit") options = settings_stack.getProperty(setting_to_export, "options") - value_name = value if options == {} else options[value] + msgctxt = f"{setting_to_export} option {value}" + msgid = options.get(value, "") + value_name = i18n_catalog.i18nc(msgctxt, msgid) setting_type = settings_stack.getProperty(setting_to_export, "type") if setting_type is not None: From b2fea2c1b5d61110fe171c0946710f8a473c72da Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 29 Mar 2024 12:52:31 +0100 Subject: [PATCH 4/6] Point to correct catalog CURA-11783 --- plugins/3MFReader/SpecificSettingsModel.py | 4 ++-- plugins/3MFWriter/SettingsExportModel.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/3MFReader/SpecificSettingsModel.py b/plugins/3MFReader/SpecificSettingsModel.py index 09efb453ed3..b8c7ce0a96c 100644 --- a/plugins/3MFReader/SpecificSettingsModel.py +++ b/plugins/3MFReader/SpecificSettingsModel.py @@ -20,7 +20,7 @@ def __init__(self, parent = None): self.addRoleName(self.LabelRole, "label") self.addRoleName(self.ValueRole, "value") - self._i18n_catalog = i18nCatalog("cura") + self._settings_catalog = i18nCatalog("fdmprinter.def.json") self._update() modelChanged = pyqtSignal() @@ -40,7 +40,7 @@ def addSettingsFromStack(self, stack, category, settings): options = stack.getProperty(setting, "options") msgctxt = f"{str(setting)} option {str(value)}" msgid = options[stack.getProperty(setting, "value")] - value = self._i18n_catalog.i18nc(msgctxt, msgid) + value = self._settings_catalog.i18nc(msgctxt, msgid) else: value = str(value) diff --git a/plugins/3MFWriter/SettingsExportModel.py b/plugins/3MFWriter/SettingsExportModel.py index e8e3e4a0dad..b4442de196f 100644 --- a/plugins/3MFWriter/SettingsExportModel.py +++ b/plugins/3MFWriter/SettingsExportModel.py @@ -110,7 +110,7 @@ def settingsGroups(self) -> List[SettingsExportGroup]: @staticmethod def _exportSettings(settings_stack): - i18n_catalog = i18nCatalog("cura") + settings_catalog = i18nCatalog("fdmprinter.def.json") user_settings_container = settings_stack.userChanges user_keys = user_settings_container.getAllKeys() exportable_settings = SettingsExportModel.EXPORTABLE_SETTINGS @@ -126,7 +126,7 @@ def _exportSettings(settings_stack): options = settings_stack.getProperty(setting_to_export, "options") msgctxt = f"{setting_to_export} option {value}" msgid = options.get(value, "") - value_name = i18n_catalog.i18nc(msgctxt, msgid) + value_name = settings_catalog.i18nc(msgctxt, msgid) setting_type = settings_stack.getProperty(setting_to_export, "type") if setting_type is not None: From 0d01f7523e79d0fe2bb7bd643c11a5978b8aab49 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 29 Mar 2024 13:04:56 +0100 Subject: [PATCH 5/6] Also translate label CURA-11783 --- plugins/3MFReader/SpecificSettingsModel.py | 12 ++++++++---- plugins/3MFWriter/SettingsExportModel.py | 10 ++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/3MFReader/SpecificSettingsModel.py b/plugins/3MFReader/SpecificSettingsModel.py index b8c7ce0a96c..1b1319d3915 100644 --- a/plugins/3MFReader/SpecificSettingsModel.py +++ b/plugins/3MFReader/SpecificSettingsModel.py @@ -38,15 +38,19 @@ def addSettingsFromStack(self, stack, category, settings): value += " " + str(unit) if setting_type == "enum": options = stack.getProperty(setting, "options") - msgctxt = f"{str(setting)} option {str(value)}" - msgid = options[stack.getProperty(setting, "value")] - value = self._settings_catalog.i18nc(msgctxt, msgid) + value_msgctxt = f"{str(setting)} option {str(value)}" + value_msgid = options[stack.getProperty(setting, "value")] + value = self._settings_catalog.i18nc(value_msgctxt, value_msgid) else: value = str(value) + label_msgctxt = f"{str(setting)} label" + label_msgid = stack.getProperty(setting, "label") + label = self._settings_catalog.i18nc(label_msgctxt, label_msgid) + self.appendItem({ "category": category, - "label": stack.getProperty(setting, "label"), + "label": label, "value": value }) self.modelChanged.emit() diff --git a/plugins/3MFWriter/SettingsExportModel.py b/plugins/3MFWriter/SettingsExportModel.py index b4442de196f..b0bb54a6a25 100644 --- a/plugins/3MFWriter/SettingsExportModel.py +++ b/plugins/3MFWriter/SettingsExportModel.py @@ -120,13 +120,15 @@ def _exportSettings(settings_stack): for setting_to_export in user_keys: show_in_menu = setting_to_export not in SettingsExportModel.PER_MODEL_EXPORTABLE_SETTINGS_KEYS - label = settings_stack.getProperty(setting_to_export, "label") + label_msgtxt = settings_stack.getProperty(setting_to_export, "label") + label_msgid = f"{str(setting_to_export)} label" + label = settings_catalog.i18nc(label_msgtxt, label_msgid) value = settings_stack.getProperty(setting_to_export, "value") unit = settings_stack.getProperty(setting_to_export, "unit") options = settings_stack.getProperty(setting_to_export, "options") - msgctxt = f"{setting_to_export} option {value}" - msgid = options.get(value, "") - value_name = settings_catalog.i18nc(msgctxt, msgid) + value_msgctxt = f"{setting_to_export} option {value}" + value_msgid = options.get(value, "") + value_name = settings_catalog.i18nc(value_msgctxt, value_msgid) setting_type = settings_stack.getProperty(setting_to_export, "type") if setting_type is not None: From 5301233322408e8d0435221b08cbfc8a94586ff1 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 29 Mar 2024 14:13:06 +0100 Subject: [PATCH 6/6] Fix label in save ucp CURA-11783 --- plugins/3MFWriter/SettingsExportModel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/3MFWriter/SettingsExportModel.py b/plugins/3MFWriter/SettingsExportModel.py index b0bb54a6a25..0ee8885adaf 100644 --- a/plugins/3MFWriter/SettingsExportModel.py +++ b/plugins/3MFWriter/SettingsExportModel.py @@ -120,13 +120,13 @@ def _exportSettings(settings_stack): for setting_to_export in user_keys: show_in_menu = setting_to_export not in SettingsExportModel.PER_MODEL_EXPORTABLE_SETTINGS_KEYS - label_msgtxt = settings_stack.getProperty(setting_to_export, "label") - label_msgid = f"{str(setting_to_export)} label" + label_msgtxt = f"{str(setting_to_export)} label" + label_msgid = settings_stack.getProperty(setting_to_export, "label") label = settings_catalog.i18nc(label_msgtxt, label_msgid) value = settings_stack.getProperty(setting_to_export, "value") unit = settings_stack.getProperty(setting_to_export, "unit") options = settings_stack.getProperty(setting_to_export, "options") - value_msgctxt = f"{setting_to_export} option {value}" + value_msgctxt = f"{str(setting_to_export)} option {str(value)}" value_msgid = options.get(value, "") value_name = settings_catalog.i18nc(value_msgctxt, value_msgid)