From 63ced6756d237a00833021625b1f8e2b72f4f554 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 10 Jan 2022 16:37:11 -0600 Subject: [PATCH] translation cleanup fix context for deburr enums deburr translation cleanup enums --- src/Mod/Path/PathScripts/PathDeburr.py | 76 ++++++++++++++++++----- src/Mod/Path/PathScripts/PathDeburrGui.py | 31 ++++++--- 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDeburr.py b/src/Mod/Path/PathScripts/PathDeburr.py index 317ddb5c67..45c92b9676 100644 --- a/src/Mod/Path/PathScripts/PathDeburr.py +++ b/src/Mod/Path/PathScripts/PathDeburr.py @@ -29,7 +29,7 @@ import PathScripts.PathOp as PathOp import PathScripts.PathOpTools as PathOpTools import math -from PySide import QtCore +from PySide.QtCore import QT_TRANSLATE_NOOP # lazily loaded modules from lazy_loader.lazy_loader import LazyLoader @@ -41,13 +41,14 @@ __author__ = "sliptonic (Brad Collette), Schildkroet" __url__ = "http://www.freecadweb.org" __doc__ = "Deburr operation." -PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# PathLog.trackModule(PathLog.thisModule()) +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# Qt translation handling -def translate(context, text, disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate def toolDepthAndOffset(width, extraDepth, tool, printInfo): @@ -122,36 +123,34 @@ class ObjectDeburr(PathEngraveBase.ObjectOp): "App::PropertyDistance", "Width", "Deburr", - QtCore.QT_TRANSLATE_NOOP("PathDeburr", "The desired width of the chamfer"), + QT_TRANSLATE_NOOP("App::Property", "The desired width of the chamfer"), ) obj.addProperty( "App::PropertyDistance", "ExtraDepth", "Deburr", - QtCore.QT_TRANSLATE_NOOP( - "PathDeburr", "The additional depth of the tool path" - ), + QT_TRANSLATE_NOOP("App::Property", "The additional depth of the tool path"), ) obj.addProperty( "App::PropertyEnumeration", "Join", "Deburr", - QtCore.QT_TRANSLATE_NOOP("PathDeburr", "How to join chamfer segments"), + QT_TRANSLATE_NOOP("App::Property", "How to join chamfer segments"), ) - obj.Join = ["Round", "Miter"] + # obj.Join = ["Round", "Miter"] obj.setEditorMode("Join", 2) # hide for now obj.addProperty( "App::PropertyEnumeration", "Direction", "Deburr", - QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Direction of Operation"), + QT_TRANSLATE_NOOP("App::Property", "Direction of Operation"), ) - obj.Direction = ["CW", "CCW"] + # obj.Direction = ["CW", "CCW"] obj.addProperty( "App::PropertyEnumeration", "Side", "Deburr", - QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Side of Operation"), + QT_TRANSLATE_NOOP("App::Property", "Side of Operation"), ) obj.Side = ["Outside", "Inside"] obj.setEditorMode("Side", 2) # Hide property, it's calculated by op @@ -159,11 +158,54 @@ class ObjectDeburr(PathEngraveBase.ObjectOp): "App::PropertyInteger", "EntryPoint", "Deburr", - QtCore.QT_TRANSLATE_NOOP( - "PathDeburr", "Select the segment, there the operations starts" + QT_TRANSLATE_NOOP( + "App::Property", "Select the segment, there the operations starts" ), ) + ENUMS = self.propertyEnumerations() + for n in ENUMS: + setattr(obj, n[0], n[1]) + + @classmethod + def propertyEnumerations(self, dataType="data"): + + """opPropertyEnumerations(dataType="data")... return property enumeration lists of specified dataType. + Args: + dataType = 'data', 'raw', 'translated' + Notes: + 'data' is list of internal string literals used in code + 'raw' is list of (translated_text, data_string) tuples + 'translated' is list of translated string literals + """ + + # Enumeration lists for App::PropertyEnumeration properties + enums = { + "Direction": [ + (translate("Path", "CW"), "CW"), + (translate("Path", "CCW"), "CCW"), + ], # this is the direction that the profile runs + "Join": [ + (translate("PathDeburr", "Round"), "Round"), + (translate("PathDeburr", "Miter"), "Miter"), + ], # this is the direction that the profile runs + } + + if dataType == "raw": + return enums + + data = list() + idx = 0 if dataType == "translated" else 1 + + PathLog.debug(enums) + + for k, v in enumerate(enums): + # data[k] = [tup[idx] for tup in v] + data.append((v, [tup[idx] for tup in enums[v]])) + PathLog.debug(data) + + return data + def opOnDocumentRestored(self, obj): obj.setEditorMode("Join", 2) # hide for now diff --git a/src/Mod/Path/PathScripts/PathDeburrGui.py b/src/Mod/Path/PathScripts/PathDeburrGui.py index df09249afb..ddcce623ee 100644 --- a/src/Mod/Path/PathScripts/PathDeburrGui.py +++ b/src/Mod/Path/PathScripts/PathDeburrGui.py @@ -27,6 +27,7 @@ import PathScripts.PathGui as PathGui import PathScripts.PathLog as PathLog import PathScripts.PathOpGui as PathOpGui from PySide import QtCore, QtGui +from PySide.QtCore import QT_TRANSLATE_NOOP __title__ = "Path Deburr Operation UI" __author__ = "sliptonic (Brad Collette), Schildkroet" @@ -34,12 +35,14 @@ __url__ = "https://www.freecadweb.org" __doc__ = "Deburr operation page controller and command implementation." -PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -# PathLog.trackModule(PathLog.thisModule()) +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) -def translate(context, text, disambig=None): - return QtCore.QCoreApplication.translate(context, text, disambig) +translate = FreeCAD.Qt.translate class TaskPanelBaseGeometryPage(PathOpGui.TaskPanelBaseGeometryPage): @@ -55,8 +58,16 @@ class TaskPanelBaseGeometryPage(PathOpGui.TaskPanelBaseGeometryPage): class TaskPanelOpPage(PathOpGui.TaskPanelPage): """Page controller class for the Deburr operation.""" + _ui_form = ":/panels/PageOpDeburrEdit.ui" + def getForm(self): - return FreeCADGui.PySideUic.loadUi(":/panels/PageOpDeburrEdit.ui") + form = FreeCADGui.PySideUic.loadUi(self._ui_form) + comboToPropertyMap = [("direction", "Direction")] + enumTups = PathDeburr.ObjectDeburr.propertyEnumerations(dataType="raw") + + self.populateCombobox(form, enumTups, comboToPropertyMap) + + return form def initPage(self, obj): self.opImagePath = "{}Mod/Path/Images/Ops/{}".format( @@ -81,8 +92,8 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): elif self.form.joinMiter.isChecked(): obj.Join = "Miter" - if obj.Direction != str(self.form.direction.currentText()): - obj.Direction = str(self.form.direction.currentText()) + if obj.Direction != str(self.form.direction.currentData()): + obj.Direction = str(self.form.direction.currentData()) self.updateToolController(obj, self.form.toolController) self.updateCoolant(obj, self.form.coolantController) @@ -133,9 +144,9 @@ Command = PathOpGui.SetupOperation( PathDeburr.Create, TaskPanelOpPage, "Path_Deburr", - QtCore.QT_TRANSLATE_NOOP("PathDeburr", "Deburr"), - QtCore.QT_TRANSLATE_NOOP( - "PathDeburr", "Creates a Deburr Path along Edges or around Faces" + QT_TRANSLATE_NOOP("Path_Deburr", "Deburr"), + QT_TRANSLATE_NOOP( + "Path_Deburr", "Creates a Deburr Path along Edges or around Faces" ), PathDeburr.SetupProperties, )