From dd9aaf325bc8ba57f000c807bbf5c285eb6ffa66 Mon Sep 17 00:00:00 2001 From: hasecilu Date: Mon, 29 Jan 2024 13:35:44 -0600 Subject: [PATCH 1/4] Improve code, fix lint warnings - Add some docstrings - Remove extra colon/spaces sed -i 's/[[:space:]]*$//' InitGui.py - Use "not in" notation - Split long lines --- InitGui.py | 488 ++++++++++++++++++++++++++++------------------------- 1 file changed, 261 insertions(+), 227 deletions(-) diff --git a/InitGui.py b/InitGui.py index 85fa31c..1ce5a88 100644 --- a/InitGui.py +++ b/InitGui.py @@ -29,7 +29,7 @@ # # 1.3.4 # Move globals settings on a new tab -# Added setting for show or not the QuickMenu +# Added setting for show or not the QuickMenu # Added checkbox in parameters for Contextual activation # Set default theme (Legacy) on a new installation # Update stylesheets for #styleButtonMenu::menu-indicator (setting for QuickMenu) @@ -52,6 +52,8 @@ PIE_MENU_VERSION = "1.3.6" def pieMenuStart(): + """Main function that starts the Pie Menu.""" + import os import math import operator import platform @@ -61,12 +63,14 @@ def pieMenuStart(): from PySide import QtGui import PieMenuLocator as locator from PySide2.QtGui import QKeyEvent, QFontMetrics - from PySide.QtWidgets import QApplication, QLineEdit, QWidget, QAction, QPushButton, QLabel, QVBoxLayout, QHBoxLayout, QDoubleSpinBox, QCheckBox, QMessageBox, QShortcut, QListWidgetItem, QListWidget, QComboBox + from PySide.QtWidgets import QApplication, QLineEdit, QWidget, QAction, \ + QPushButton, QLabel, QVBoxLayout, QHBoxLayout, QDoubleSpinBox, QCheckBox, \ + QMessageBox, QShortcut, QListWidgetItem, QListWidget, QComboBox from PySide2.QtGui import QKeySequence from PySide2.QtCore import Qt # global variables - + path = locator.path() respath = path + "/Resources/icons/" respath = respath.replace("\\", "/") @@ -81,19 +85,19 @@ def pieMenuStart(): shortcutKey = "" globalShortcutKey = "TAB" shortcutList =[] - + paramPath = "User parameter:BaseApp/PieMenu" paramIndexPath= "User parameter:BaseApp/PieMenu/Index" paramGet = App.ParamGet(paramPath) paramIndexGet = App.ParamGet(paramIndexPath) - - ## workkaround to avoid ghosting : we find wbs already loaded, + + ## HACK: workaround to avoid ghosting : we find wbs already loaded, ## so as not to reload them again in the function 'updateCommands' global loadedWorkbenches paramLoadedWb = "User parameter:BaseApp/Preferences/General" paramWb = App.ParamGet(paramLoadedWb) loadedWorkbenches = paramWb.GetString("BackgroundAutoloadModules") - loadedWorkbenches = loadedWorkbenches.split(",") + loadedWorkbenches = loadedWorkbenches.split(",") def getStyle(): theme = paramGet.GetString("Theme") if theme == "": @@ -103,9 +107,9 @@ def getStyle(): styleCurrentTheme = f.read() styleCurrentTheme = styleCurrentTheme.replace("pieMenuQss:", stylepath) return styleCurrentTheme - + styleCurrentTheme = getStyle() - + def setGlobalShortcutKey(globalShortcutKey): """ Set shortcut in user parameters """ paramGet.SetString("GlobalShortcutKey", globalShortcutKey) @@ -114,26 +118,27 @@ def getGlobalShortcutKey(): """Get global shortcut key from user parameters.""" globalShortcutKey = paramGet.GetString("GlobalShortcutKey") return globalShortcutKey - + globalShortcutKey = getGlobalShortcutKey() - + def getIndexList(): + """Get current pieMenus using available index.""" indexList = paramIndexGet.GetString("IndexList") if indexList: indexList = list(map(int, indexList.split(".,."))) else: indexList = [] return indexList - - + + def getShortcutKey(): - """Get shortcut key from user parameters.""" + """Get shortcut key from user parameters.""" global shortcutKey try: selectedPieName = cBox.currentText() except: selectedPieName = '' - + indexList = getIndexList() for i in indexList: try: @@ -144,17 +149,17 @@ def getShortcutKey(): param = paramIndexGet.GetGroup(str(i)) shortcutKey = param.GetString("ShortcutKey") return shortcutKey - + def getShortcutList(): - global globalShortcutKey """Get keyboard shortcut and namePie from user parameters""" + global globalShortcutKey for shortcut in mw.findChildren(QShortcut): if shortcut.activated is not None: shortcut.activated.disconnect() shortcut.setParent(None) shortcut.deleteLater() shortcutList =[] - + indexList = getIndexList() for i in indexList: param = paramIndexGet.GetGroup(str(i)) @@ -167,10 +172,11 @@ def getShortcutList(): namePie, shortcutKey = result.split(" => ") shortcut = QShortcut(QKeySequence(shortcutKey), mw) namePie = namePie.split("PieMenu_")[1] - shortcut.activated.connect(lambda keyValue=namePie: PieMenuInstance.showAtMouse(keyValue=keyValue, notKeyTriggered=False)) + shortcut.activated.connect(lambda keyValue=namePie: \ + PieMenuInstance.showAtMouse(keyValue=keyValue, notKeyTriggered=False)) shortcut.setEnabled(True) return shortcutList - + def setShortcutKey(shortcutKey): """ set shortcut in parameter """ indexList = getIndexList() @@ -218,8 +224,8 @@ def addMenu(): addMenu() mw.workbenchActivated.connect(addMenu) - - + + iconMenu = respath + "PieMenuQuickMenu.svg" iconUp = respath + "PieMenuUp.svg" iconDown = respath + "PieMenuDown.svg" @@ -231,23 +237,25 @@ def addMenu(): iconRemoveCommand = respath + "PieMenuRemoveCommand.svg" iconBackspace = respath + "PieMenuBackspace.svg" iconInfo = respath + "PieMenuInfo.svg" - + def radiusSize(buttonSize): - """ Return radius size """ + """Calculates border radius for QToolButton based on the given buttonSize.""" radius = str(math.trunc(buttonSize / 2)) return "QToolButton {border-radius: " + radius + "px}" def iconSize(buttonSize): + """Calculates the size of an icon based on the given buttonSize.""" icon = buttonSize / 3 * 2 return icon - + def closeButton(buttonSize=32): + """Style the close button.""" icon = iconSize(buttonSize) radius = radiusSize(buttonSize) button = QtGui.QToolButton() button.setObjectName("styleMenuClose") - button.setProperty("ButtonX", 0) - button.setProperty("ButtonY", 0) + button.setProperty("ButtonX", 0) # +, right + button.setProperty("ButtonY", 0) # +, down button.setGeometry(0, 0, buttonSize, buttonSize) button.setIconSize(QtCore.QSize(icon, icon)) # button.setIcon(QtGui.QIcon(iconClose)) @@ -263,12 +271,12 @@ def onButton(): ### Begin QuickMenu Def ### def quickMenu(buttonSize=20): - """ Build QuickMenu """ + """Build and style the QuickMenu button.""" mw = Gui.getMainWindow() - + icon = iconSize(buttonSize) radius = radiusSize(buttonSize) - + menu = QtGui.QMenu(mw) menu.setObjectName("styleQuickMenu") menu.setStyleSheet(styleCurrentTheme) @@ -276,8 +284,8 @@ def quickMenu(buttonSize=20): button = QtGui.QToolButton() button.setObjectName("styleButtonMenu") button.setMenu(menu) - button.setProperty("ButtonX", 0) - button.setProperty("ButtonY", 32) + button.setProperty("ButtonX", 0) # +, right + button.setProperty("ButtonY", 32) # +, down button.setGeometry(0, 0, buttonSize, buttonSize) button.setStyleSheet(styleCurrentTheme + radius) button.setIconSize(QtCore.QSize(icon, icon)) @@ -336,7 +344,7 @@ def quickMenu(buttonSize=20): def setChecked(): - """ Get states of Hover and Context modes""" + """Get states of Hover and Context modes.""" if paramGet.GetString("TriggerMode") == "Hover": actionHover.setChecked(True) else: @@ -459,7 +467,8 @@ def onMenuToolBar(): pass if len(commands) != 0: menu = QtGui.QMenu(i.windowTitle()) - menu.aboutToShow.connect(lambda sender=menu: onMenuToolbarGroup(sender)) + menu.aboutToShow.connect(lambda sender=menu: \ + onMenuToolbarGroup(sender)) menuToolBar.addMenu(menu) else: pass @@ -478,7 +487,7 @@ def isActualPie(text): else: idMenu = entry if idMenu == text: - return True; + return True return False @@ -531,8 +540,8 @@ def onPrefButton(): """Handle the preferences button event.""" PieMenuInstance.hide() onControl() - - + + prefButton.clicked.connect(onPrefButton) menu.addMenu(menuMode) menu.addAction(actionContext) @@ -542,7 +551,7 @@ def onPrefButton(): menu.addSeparator() menu.addAction(prefButtonWidgetAction) - return button + return button ### END QuickMenu Def ### @@ -555,7 +564,7 @@ def __init__(self, parent=None): self.hoverTimer.setSingleShot(True) self.hoverTimer.timeout.connect(self.onHoverTimeout) self.enterEventConnected = False - self.isMouseOver = False + self.isMouseOver = False self.leaveEvent = self.onLeaveEvent def onHoverTimeout(self): @@ -577,16 +586,16 @@ def onHoverTimeout(self): pass def onLeaveEvent(self, event): - self.isMouseOver = False + self.isMouseOver = False def enterEvent(self, event): hoverDelay = paramGet.GetInt("HoverDelay") if not self.enterEventConnected: self.hoverTimer.start(hoverDelay) self.enterEventConnected = True - self.hoverTimer.stop() + self.hoverTimer.stop() self.hoverTimer.start(hoverDelay) - self.isMouseOver = True + self.isMouseOver = True def mouseReleaseEvent(self, event): if self.isMouseOver and self.defaultAction().isEnabled(): @@ -611,16 +620,16 @@ class PieMenu(QWidget): event_filter_installed = False offset_x = 0 offset_y = 0 - + def __init__(self, parent=mw): super().__init__() self.double_spinbox = None - + if not PieMenu.event_filter_installed: app = QtGui.QGuiApplication.instance() or QtGui.QApplication([]) app.installEventFilter(self) PieMenu.event_filter_installed = True - + self.radius = 100 self.buttons = [] self.buttonSize = 32 @@ -628,20 +637,21 @@ def __init__(self, parent=mw): self.menuSize = 0 self.menu.setObjectName("styleContainer") self.menu.setStyleSheet(styleCurrentTheme) - self.menu.setWindowFlags(self.menu.windowFlags() | QtCore.Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint) + self.menu.setWindowFlags(self.menu.windowFlags() | + QtCore.Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint) self.menu.setAttribute(QtCore.Qt.WA_TranslucentBackground) if compositingManager: pass else: - self.menu.setAttribute(QtCore.Qt.WA_PaintOnScreen) - self.setFocus() + self.menu.setAttribute(QtCore.Qt.WA_PaintOnScreen) + self.setFocus() def validation(self): docName = App.ActiveDocument.Name Gui.getDocument(docName).resetEdit() App.ActiveDocument.recompute() PieMenuInstance.hide() - + def cancel(self): docName = App.ActiveDocument.Name App.closeActiveTransaction(True) @@ -661,7 +671,7 @@ def validButton(self, buttonSize=38): # button.setIcon(QtGui.QIcon(iconValid)) # button.setStyleSheet(styleCurrentTheme) return button - + def cancelButton(self, buttonSize=38): icon = iconSize(buttonSize) button = QtGui.QToolButton() @@ -673,7 +683,7 @@ def cancelButton(self, buttonSize=38): # button.setIcon(QtGui.QIcon(iconCancel)) # button.setStyleSheet(styleCurrentTheme) return button - + def doubleSpinbox(self, buttonSize=32, step=1.0): button = QtGui.QDoubleSpinBox() button.setDecimals(3) @@ -688,13 +698,13 @@ def doubleSpinbox(self, buttonSize=32, step=1.0): return button def setupSpinBox(self): - self.double_spinbox = self.doubleSpinbox(step=1.0) + self.double_spinbox = self.doubleSpinbox(step=1.0) self.double_spinbox.valueChanged.connect(self.spin_interactif) - + self.double_spinbox.setVisible(True) self.buttons.append(self.double_spinbox) - - + + def eventFilter(self, obj, event): """ Handle key and wheel event """ if event.type() == QtCore.QEvent.KeyPress: @@ -702,15 +712,15 @@ def eventFilter(self, obj, event): if key == QtCore.Qt.Key_Enter or key == QtCore.Qt.Key_Return: try: if self.double_spinbox.isVisible(): - self.validation() + self.validation() except: None - + elif event.type() == QtCore.QEvent.Wheel: """ Press CTRL + rotate Wheel = X10, Press SHIFT + rotate Wheel = X0.1, Press CTRL+SHIFT + rotate Wheel= X0.01 """ modifiers = event.modifiers() if modifiers & QtCore.Qt.ControlModifier and modifiers & QtCore.Qt.ShiftModifier: - step = 0.001 # weird behavior, you have to set 0.001 to modify the hundredths... + step = 0.001 # NOTE: weird behavior, you have to set 0.001 to modify the hundredths... elif modifiers & QtCore.Qt.ShiftModifier: step = 0.1 else: @@ -733,7 +743,7 @@ def add_commands(self, commands, context=False, keyValue=None): wbName = wb.name() except: module = None - + for i in self.buttons: i.deleteLater() self.buttons = [] @@ -752,15 +762,15 @@ def add_commands(self, commands, context=False, keyValue=None): buttonSize = valueButton self.offset_x = 0 self.offset_y = 0 - # "Pie", "RainbowUp", "RainbowDown", "UpDown", "TableTop", "TableDown", "LeftRight" + # "Pie", "RainbowUp", "RainbowDown", "UpDown", "TableTop", "TableDown", "LeftRight" shape = getShape(keyValue) num_per_row = getNumColumn(keyValue) - + if paramGet.GetBool("ToolBar"): valueRadius = 100 valueButton = 32 shape = "Pie" - + if valueRadius: self.radius = valueRadius else: @@ -772,7 +782,7 @@ def add_commands(self, commands, context=False, keyValue=None): if num_per_row == 0: num_per_row = 1 - + if shape == "Pie": if commandNumber == 1: angle = 0 @@ -782,7 +792,7 @@ def add_commands(self, commands, context=False, keyValue=None): buttonRadius = math.sin(angle / 2) * self.radius buttonSize = math.trunc(2 * buttonRadius / math.sqrt(2)) angleStart = 3 * math.pi / 2 - angle - + elif shape == "RainbowUp": if commandNumber == 1: angle = 0 @@ -792,7 +802,7 @@ def add_commands(self, commands, context=False, keyValue=None): buttonRadius = math.sin(angle / 2) * self.radius buttonSize = math.trunc(2 * buttonRadius / math.sqrt(2)) angleStart = 3 * math.pi / 2 - (angle*(commandNumber+1))/2 - + elif shape == "RainbowDown": if commandNumber == 1: angle = 0 @@ -802,18 +812,18 @@ def add_commands(self, commands, context=False, keyValue=None): buttonRadius = math.sin(angle / 2) * self.radius buttonSize = math.trunc(2 * buttonRadius / math.sqrt(2)) angleStart = math.pi / 2 - (angle*(commandNumber+1))/2 - + else: angle = 2 * math.pi / commandNumber angleStart = 3 * math.pi / 2 - angle - + if buttonSize > self.buttonSize: buttonSize = self.buttonSize else: pass radius = radiusSize(buttonSize) icon = iconSize(buttonSize) - + if windowShadow: pass else: @@ -826,17 +836,17 @@ def add_commands(self, commands, context=False, keyValue=None): self.menu.setMinimumHeight(self.menuSize) displayCommandName = False - if shape == "Pie": + if shape == "Pie": try: # get displayCommandName to display or not command name only for Pie shape displayCommandName = getdisplayCommandName(keyValue) except: None - + num = 1 for i in commands: if (Gui.ActiveDocument.getInEdit() is None) or (module == 'SketcherGui'): """ show PieMenu in Edit Feature and in Sketcher """ - + button = HoverButton() button.setParent(self.menu) button.setObjectName("pieMenu") @@ -847,15 +857,18 @@ def add_commands(self, commands, context=False, keyValue=None): button.setGeometry(0, 0, buttonSize, buttonSize) - if displayCommandName and shape == "Pie": # modify style for display command name (only with Pie shape) + # modify style for display command name (only with Pie shape) + if displayCommandName and shape == "Pie": button.setIcon(QtGui.QIcon()) # set padding and font size dependind on icon size font_size = round(icon/2) - padding = "QToolButton#pieMenu {padding-left: " + str(icon) + "px; font-size: " + str(font_size) + "px;}" + padding = "QToolButton#pieMenu {padding-left: " + str(icon) \ + + "px; font-size: " + str(font_size) + "px;}" button.setStyleSheet(styleCurrentTheme + radius + padding) # get lenght of the string - text_length = QFontMetrics(button.font()).horizontalAdvance(commands[commands.index(i)].text()) - + text_length = QFontMetrics(button.font()).horizontalAdvance( + commands[commands.index(i)].text()) + button.setGeometry(buttonSize, 0, 2* buttonSize + text_length, buttonSize) # layout for icon and command string layout = QtGui.QHBoxLayout(button) @@ -872,41 +885,41 @@ def add_commands(self, commands, context=False, keyValue=None): num_of_line = math.ceil(commandNumber/num_per_row) offset = num_of_line * buttonSize X = ((num-1) % num_per_row) * buttonSize - Y = self.radius + ((num-1) // num_per_row) * buttonSize + Y = self.radius + ((num-1) // num_per_row) * buttonSize button.setProperty("ButtonX", X - ((num_per_row-1) * buttonSize) / 2) button.setProperty("ButtonY", -Y ) - + elif shape == "TableDown": ### Table Down ### num_of_line = math.ceil(commandNumber/num_per_row) X = ((num-1) % num_per_row) * buttonSize - Y = - buttonSize -self.radius -((num-1) // num_per_row) * buttonSize + Y = - buttonSize -self.radius -((num-1) // num_per_row) * buttonSize button.setProperty("ButtonX", X - ((num_per_row-1) * buttonSize) / 2) button.setProperty("ButtonY", -Y ) - + elif shape == "UpDown": ### Table Up and Down ### num_per_row = math.ceil(commandNumber/2) X = ((num -1) % num_per_row) * buttonSize if ((num-1) < (num_per_row)) : offset = 0 - else : + else : offset = 2*self.radius - Y = (self.radius - offset ) - + Y = (self.radius - offset ) + button.setProperty("ButtonX", X - ((num_per_row - 1) * buttonSize) / 2) button.setProperty("ButtonY", -Y) - + elif shape == "LeftRight": ### Table Up and Down ### num_per_row = math.ceil(commandNumber/2) Y = ((num -1) % num_per_row) * buttonSize if ((num-1) < (num_per_row)) : offset = 0 - else : + else : offset = 2*self.radius - X = (self.radius - offset ) - + X = (self.radius - offset ) + button.setProperty("ButtonX", -X) button.setProperty("ButtonY", Y - ((num_per_row - 1) * buttonSize) / 2) else : @@ -919,8 +932,8 @@ def add_commands(self, commands, context=False, keyValue=None): self.buttons.append(button) else: None - num = num + 1 - + num = num + 1 + buttonQuickMenu = quickMenu() buttonQuickMenu.setParent(self.menu) if checkboxQuickMenu.checkState(): @@ -928,7 +941,7 @@ def add_commands(self, commands, context=False, keyValue=None): self.buttons.append(buttonQuickMenu) else: buttonQuickMenu.hide() - + if (Gui.ActiveDocument.getInEdit() == None): buttonClose = closeButton() buttonClose.setParent(self.menu) @@ -939,7 +952,7 @@ def add_commands(self, commands, context=False, keyValue=None): # buttonValid.setParent(self.menu) # buttonValid.clicked.connect(self.validation) # self.buttons.append(buttonValid) - + # buttonCancel = self.cancelButton() # buttonCancel.setParent(self.menu) # buttonCancel.clicked.connect(self.cancel) @@ -953,27 +966,27 @@ def add_commands(self, commands, context=False, keyValue=None): buttonValid.setParent(self.menu) buttonValid.clicked.connect(self.validation) self.buttons.append(buttonValid) - + buttonCancel = self.cancelButton() buttonCancel.setStyleSheet(styleCurrentTheme) buttonCancel.setParent(self.menu) buttonCancel.clicked.connect(self.cancel) self.buttons.append(buttonCancel) - + self.offset_x = 28 self.offset_y = 0 - if (module != None and module != 'SketcherGui' and wbName == 'PartDesignWorkbench'): + if (module != None and module != 'SketcherGui' and wbName == 'PartDesignWorkbench'): """ Show Spinbox in Edit Feature in Part Design WB only """ fonctionActive = g.Object featureName = g.Object.Name - + double_spinbox = self.doubleSpinbox() double_spinbox.setParent(self.menu) double_spinbox.valueChanged.connect(self.spin_interactif) self.buttons.append(double_spinbox) double_spinbox.setVisible(True) self.double_spinbox = double_spinbox - + if (str(fonctionActive) == ''): self.double_spinbox.setValue(g.Object.Radius) elif (str(fonctionActive) == ''): @@ -990,14 +1003,14 @@ def add_commands(self, commands, context=False, keyValue=None): self.buttons.remove(double_spinbox) else: self.buttons.remove(double_spinbox) - + self.double_spinbox.setFocus() self.double_spinbox.selectAll() self.offset_x = 10 self.offset_y = 28 except : None - + if compositingManager: pass else: @@ -1014,7 +1027,7 @@ def showAtMouse(self, keyValue=None, notKeyTriggered=False): nonlocal contextPhase global lastPosX global lastPosY - + enableContext = paramGet.GetBool("EnableContext") if contextPhase: @@ -1084,16 +1097,19 @@ def showAtMouse(self, keyValue=None, notKeyTriggered=False): lastPosY = pos.y() for i in self.buttons: - i.move(i.property("ButtonX") + (self.menuSize - i.size().width()) / 2 + self.offset_x, - i.property("ButtonY") + (self.menuSize - i.size().height()) / 2 + self.offset_y) - + i.move(i.property("ButtonX") + + (self.menuSize - i.size().width()) / 2 + self.offset_x, + i.property("ButtonY") + + (self.menuSize - i.size().height()) / 2 + self.offset_y) + i.setVisible(True) - self.menu.popup(QtCore.QPoint(pos.x() - self.menuSize / 2, pos.y() - self.menuSize / 2)) + self.menu.popup(QtCore.QPoint(pos.x() - self.menuSize / 2, pos.y() + - self.menuSize / 2)) def spin_interactif(self): - docName = App.ActiveDocument.Name + docName = App.ActiveDocument.Name g = Gui.ActiveDocument.getInEdit() fonctionActive = g.Object featureName = g.Object.Name @@ -1117,7 +1133,7 @@ def spin_interactif(self): self.double_spinbox.setVisible(False) self.double_spinbox.removeEventFilter(self) App.ActiveDocument.recompute() - + sign = { "<": operator.lt, "<=": operator.le, @@ -1126,7 +1142,7 @@ def spin_interactif(self): ">": operator.gt, ">=": operator.ge, } - + def contextList(): contextAll.clear() @@ -1233,7 +1249,7 @@ def listTopo(): updateCommands(context=True) PieMenuInstance.hide() selectionTriggered = True - #PieMenuInstance.showAtMouse(notKeyTriggered=True) + #PieMenuInstance.showAtMouse(notKeyTriggered=True) else: pass @@ -1304,7 +1320,7 @@ def getActionData(action, actions, commands, workbenches): commands.append(command) workbench = extractWorkbench(command) if workbenches is not None: - if not workbench in workbenches: + if workbench not in workbenches: workbenches.append(workbench) def getGuiToolButtonData(idToolBar, actions, commands, workbenches): @@ -1314,7 +1330,7 @@ def getGuiToolButtonData(idToolBar, actions, commands, workbenches): for widgets in action.associatedWidgets(): if widgets.windowTitle() == idToolBar: getActionData(action, actions, commands, workbenches) - + def actualizeWorkbenchActions(actions, toolList, actionMap): for i in toolList: @@ -1322,7 +1338,7 @@ def actualizeWorkbenchActions(actions, toolList, actionMap): if i == "": pass elif i in actionMap: - if not actionMap[i] in actions: + if actionMap[i] not in actions: actions.append(actionMap[i]) else: cmd_parts = i.split("_") @@ -1337,7 +1353,7 @@ def actualizeWorkbenchActions(actions, toolList, actionMap): # Sheet Metal workbench if cmd_parts[0][:2] == "SM": cmd_parts[0] = cmd_parts[0][:2] - # Assembly4 workbench + # Assembly4 workbench if cmd_parts[0][:4] == "Asm4": cmd_parts[0] = "Assembly4" cmdWb = cmd_parts[0] + "Workbench" @@ -1373,7 +1389,7 @@ def updateCommands(keyValue=None, context=False): # Sheet Metal workbench if i[:2] == "SM": i = i[:2] - # Assembly4 workbench + # Assembly4 workbench if i == "Asm4": i = "Assembly4" if (i + "Workbench") not in loadedWorkbenches: @@ -1383,7 +1399,7 @@ def updateCommands(keyValue=None, context=False): None loadedWorkbenches.append(i + "Workbench") Gui.activateWorkbench(lastWorkbench.__class__.__name__) - + else: pass actions = [] @@ -1397,10 +1413,10 @@ def updateCommands(keyValue=None, context=False): module = g.Module except: module = None - if (module == "SketcherGui"): + if (module == "SketcherGui"): """ In Sketcher WB we load the Sketcher PieMenu """ text = 'Sketcher' - else : + else : if context: try: text = paramGet.GetString("ContextPie").decode("UTF-8") @@ -1413,7 +1429,7 @@ def updateCommands(keyValue=None, context=False): text = paramGet.GetString("CurrentPie") else: text = keyValue - + toolList = None for i in indexList: @@ -1442,11 +1458,19 @@ def updateCommands(keyValue=None, context=False): else: pass Gui.activateWorkbench(lastWorkbench.__class__.__name__) - + PieMenuInstance.add_commands(actions, context, text) def getGroup(mode=0): + """ + Obtain the parameter group. + When: + mode = 0: read from comboBox at GUI + mode = 1: read from CurrentPie parameter + mode = 2: read from ContextPie parameter + If it doesn't exists return default PieMenu group + """ indexList = getIndexList() try: docName = App.ActiveDocument.Name @@ -1454,10 +1478,10 @@ def getGroup(mode=0): module = g.Module except: module = None - - if (module != None and module == 'SketcherGui'): + + if (module != None and module == 'SketcherGui'): text = 'Sketcher' - else : + else : if mode == 2: try: text = paramGet.GetString("ContextPie").decode("UTF-8") @@ -1472,6 +1496,8 @@ def getGroup(mode=0): text = cBox.currentText() group = None + # Iterate over the available groups on indexList + # to find the group stored on `text` var for i in indexList: a = str(i) try: @@ -1484,8 +1510,10 @@ def getGroup(mode=0): else: pass if group: + # group was found, good pass else: + # return the default PieMenu group if 0 in indexList: group = paramIndexGet.GetGroup("0") else: @@ -1525,7 +1553,7 @@ def getTheme(): comboBoxTheme.setMinimumWidth(120) getTheme() - + def buttonList(): group = getGroup() toolList = group.GetString("ToolList") @@ -1597,7 +1625,7 @@ def cBoxUpdate(): except AttributeError: pieList.append(paramIndexGet.GetString(a)) duplicates = [] - for i in pieList: + for i in pieList: if i == currentPie: pass else: @@ -1611,12 +1639,14 @@ def cBoxUpdate(): cBox.insertItem(0, i) cBox.blockSignals(False) onPieChange() - + infoShortcut = QLabel() def getAssignedShortcut(): - shortcutsAssigned = [f"{act.whatsThis()} => {act.shortcut().toString()}" for act in Gui.getMainWindow().findChildren(QtGui.QAction) if not act.shortcut().isEmpty() and act.whatsThis()] - shortcutList = getShortcutList() + shortcutsAssigned = [f"{act.whatsThis()} => {act.shortcut().toString()}" \ + for act in Gui.getMainWindow().findChildren(QtGui.QAction) \ + if not act.shortcut().isEmpty() and act.whatsThis()] + shortcutList = getShortcutList() shortcutsAssigned.extend(shortcutList) return shortcutsAssigned @@ -1654,7 +1684,7 @@ def keyPressEvent(self, event): elif modifier_text: if key_text and modifier_text: - + shortcut_text = f"{modifier_text}+{key_text}" self.setText(shortcut_text) @@ -1672,7 +1702,7 @@ def keyPressEvent(self, event): self.setText(key_text) else: super().keyPressEvent(event) - + currentShortcut = self.text() shortcutsAssigned = getAssignedShortcut() compareAndDisplayWarning(shortcutsAssigned, currentShortcut) @@ -1685,28 +1715,29 @@ def get_modifier_text(self, modifiers): Qt.MetaModifier: 'META', Qt.Key_Tab: 'TAB' } - modifier_text = '+'.join([modifier_names[modifier] for modifier in modifier_names if modifiers & modifier]) + modifier_text = '+'.join([modifier_names[modifier] \ + for modifier in modifier_names if modifiers & modifier]) return modifier_text - + shortcutLineEdit = CustomLineEdit() shortcutLineEdit.setText(shortcutKey) - + globalShortcutLineEdit = CustomLineEdit() globalShortcutLineEdit.setText(globalShortcutKey) globalShortcutLineEdit.setToolTip("For TAB press CTRL+TAB") - + labelShortcut = QLabel() labelShortcut.setAlignment(QtCore.Qt.AlignRight) labelGlobalShortcut = QLabel() labelGlobalShortcut.setAlignment(QtCore.Qt.AlignRight) - + separatorPieMenu = QtGui.QFrame() separatorPieMenu.setObjectName("separatorPieMenu") separatorPieMenu.setFrameShape(QtGui.QFrame.HLine) separatorPieMenu.setFrameShadow(QtGui.QFrame.Sunken) separatorPieMenu.setStyleSheet(styleCurrentTheme) - + separatorSettings = QtGui.QFrame() separatorSettings.setObjectName("separatorSettings") separatorSettings.setFrameShape(QtGui.QFrame.HLine) @@ -1863,7 +1894,7 @@ def onButtonRemovePieMenu(): except TypeError: paramGet.SetString("CurrentPie", currentPie) if pie == contextPie: - paramGet.RemString("ContextPie") + paramGet.RemString("ContextPie") else: pass @@ -1882,8 +1913,8 @@ def onButtonRemovePieMenu(): buttonRenamePieMenu.setIcon(QtGui.QIcon(iconRename)) buttonRenamePieMenu.setMinimumHeight(30) buttonRenamePieMenu.setMinimumWidth(30) - - + + def onButtonRenamePieMenu(): text, ok = inputTextDialog("Rename menu") if not ok: @@ -1915,8 +1946,8 @@ def onButtonRenamePieMenu(): cBoxUpdate() - buttonRenamePieMenu.clicked.connect(onButtonRenamePieMenu) - + buttonRenamePieMenu.clicked.connect(onButtonRenamePieMenu) + buttonCopyPieMenu = QtGui.QToolButton() buttonCopyPieMenu.setToolTip("Copy current pie menu") buttonCopyPieMenu.setIcon(QtGui.QIcon(iconCopy)) @@ -1930,7 +1961,7 @@ def getCurrentMenuIndex(currentMenuName): a = str(i) indexName = paramIndexGet.GetString(a) if indexName == currentMenuName: - return a; + return a return "-1" @@ -1964,7 +1995,7 @@ def copyContextParams(grpOrg, grpCopy): grpCntCopy.SetString("ObjectSign", objSgnOrg) grpCntCopy.SetInt("ObjectValue", objValOrg) - + def onButtonCopyPieMenu(): text, ok = inputTextDialog("Copy menu") if not ok: @@ -2014,7 +2045,7 @@ def onButtonCopyPieMenu(): paramIndexGet.SetString(indexCopy, text) cBoxUpdate() - + buttonCopyPieMenu.clicked.connect(onButtonCopyPieMenu) labelRadius = QtGui.QLabel("Pie size:") @@ -2022,22 +2053,22 @@ def onButtonCopyPieMenu(): spinRadius = QtGui.QSpinBox() spinRadius.setMaximum(9999) spinRadius.setMinimumWidth(160) - - + + labelHoverDelay = QtGui.QLabel("Hover delay (ms):") labelHoverDelay.setAlignment(QtCore.Qt.AlignRight) spinHoverDelay = QtGui.QSpinBox() spinHoverDelay.setMaximum(999) spinHoverDelay.setMinimumWidth(90) - + labelShape = QtGui.QLabel("Shape:") labelShape.setAlignment(QtCore.Qt.AlignRight) - + labeldisplayCommandName = QtGui.QLabel("Show command names:") labeldisplayCommandName.setAlignment(QtCore.Qt.AlignRight) - + spinNumColumn = QtGui.QSpinBox() - + def setShape(): group = getGroup(mode=0) comboShape.blockSignals(True) @@ -2045,8 +2076,8 @@ def setShape(): group.SetString("Shape", shape) comboShape.blockSignals(False) onShape(shape) - - + + def onShape(shape): if shape in ["TableTop", "TableDown"]: spinNumColumn.setEnabled(True) @@ -2056,7 +2087,7 @@ def onShape(shape): spinNumColumn.setEnabled(False) labelNumColumn.setVisible(False) spinNumColumn.setVisible(False) - + if shape == "Pie": labeldisplayCommandName.setVisible(True) cboxDisplayCommandName.setVisible(True) @@ -2088,7 +2119,8 @@ def getShape(keyValue=None): comboShape.blockSignals(True) comboShape.clear() - available_shape = [ "Pie", "RainbowUp", "RainbowDown", "UpDown", "TableTop", "TableDown", "LeftRight" ] + available_shape = [ "Pie", "RainbowUp", "RainbowDown", "UpDown", "TableTop",\ + "TableDown", "LeftRight" ] comboShape.addItems(available_shape) index = comboShape.findText(shape) if index != -1: @@ -2096,8 +2128,8 @@ def getShape(keyValue=None): comboShape.blockSignals(False) return shape - - + + def getdisplayCommandName(keyValue): indexList = getIndexList() displayCommandName = False @@ -2112,7 +2144,7 @@ def getdisplayCommandName(keyValue): displayCommandName = param.GetBool("DisplayCommand") cboxDisplayCommandName.setChecked(displayCommandName) return displayCommandName - + def setdisplayCommandName(state): indexList = getIndexList() for i in indexList: @@ -2124,28 +2156,28 @@ def setdisplayCommandName(state): if pieName == cBox.currentText(): param = paramIndexGet.GetGroup(str(i)) param.SetBool("DisplayCommand", state) - + comboShape = QComboBox() comboShape.setMinimumWidth(160) comboShape.currentIndexChanged.connect(setShape) - + labelNumColumn= QtGui.QLabel("Number of columns:") labelNumColumn.setAlignment(QtCore.Qt.AlignRight) spinNumColumn.setMaximum(12) spinNumColumn.setMinimumWidth(120) - + cboxDisplayCommandName = QCheckBox() cboxDisplayCommandName.setCheckable(True) - + cboxDisplayCommandName.stateChanged.connect(lambda state: setdisplayCommandName(state)) - + def onNumColumn(): group = getGroup() value = spinNumColumn.value() group.SetInt("NumColumn", value) spinNumColumn.valueChanged.connect(onNumColumn) - + def getNumColumn(keyValue=None): group = getGroup() num_of_column = 1 @@ -2165,7 +2197,7 @@ def getNumColumn(keyValue=None): param = paramIndexGet.GetGroup(str(i)) num_of_column = param.GetInt("NumColumn") return num_of_column - + def onSpinHoverDelay(): value = spinHoverDelay.value() @@ -2186,8 +2218,8 @@ def onSpinRadius(): spinButton = QtGui.QSpinBox() spinButton.setMaximum(999) spinButton.setMinimumWidth(160) - - + + def onSpinButton(): group = getGroup() value = spinButton.value() @@ -2204,9 +2236,9 @@ def onSpinButton(): .Qt.ScrollBarAlwaysOff) toolListLayout = QVBoxLayout() - + searchLayout = QHBoxLayout() - + searchLineEdit = QLineEdit() searchLineEdit.setPlaceholderText("Search") searchResultLabel = QLabel() @@ -2215,17 +2247,17 @@ def onSpinButton(): clearButton.setMaximumWidth(40) clearButton.setIcon(QtGui.QIcon.fromTheme(iconBackspace)) clearButton.clicked.connect(searchLineEdit.clear) - + searchLayout.addWidget(searchLineEdit) searchLayout.addWidget(clearButton) - + toolListLayout.addLayout(searchLayout) - toolListLayout.addWidget(toolListWidget) - + toolListLayout.addWidget(toolListWidget) + widgetContainer = QWidget() widgetContainer.setLayout(toolListLayout) widgetContainer.setMinimumHeight(380) - + def setShowQuickMenu(state): if state == Qt.Checked: paramGet.SetBool("ShowQuickMenu", True) @@ -2235,25 +2267,25 @@ def setShowQuickMenu(state): def getShowQuickMenu(): showQuickMenu = paramGet.GetBool("ShowQuickMenu") return showQuickMenu - - + + checkboxQuickMenu = QCheckBox() checkboxQuickMenu.setCheckable(True) checkboxQuickMenu.setChecked(getShowQuickMenu()) - - + + def setContext(state): if state == Qt.Checked: paramGet.SetBool("EnableContext", True) else: paramGet.SetBool("EnableContext", False) - + checkboxGlobalContext = QCheckBox() checkboxGlobalContext.setCheckable(True) enableContext = paramGet.GetBool("EnableContext") checkboxGlobalContext.setChecked(enableContext) - + checkboxGlobalContext.stateChanged.connect(lambda state: setContext(state)) @@ -2268,7 +2300,7 @@ def toolList(): item.setIcon(actionMapAll[i].icon()) item.setCheckState(QtCore.Qt.CheckState(0)) item.setData(QtCore.Qt.UserRole, actionMapAll[i].objectName()) - + toolListOn = None indexList = getIndexList() for i in indexList: @@ -2363,7 +2395,7 @@ def onToolListWidget(): def searchInToolList(search_text): search_text = search_text.lower() toolListWidget.clear() - + text = cBox.currentText() actionMapAll = getGuiActionMapAll() toolListWidget.blockSignals(True) @@ -2538,7 +2570,7 @@ def onSpinBox(): groupContext.SetInt(TopoValue, value) contextList() spinBox.valueChanged.connect(onSpinBox) - + return spinBox @@ -2578,8 +2610,8 @@ def onCheckContext(): resetButton.setEnabled(False) groupContext.SetBool("Enabled", 0) contextList() - - + + checkContext.stateChanged.connect(onCheckContext) contextTable = QtGui.QTableWidget(4, 3) @@ -2633,6 +2665,7 @@ def setDefaults(): group = getGroup() groupContext = group.GetGroup("Context") vertexSign = groupContext.GetString("VertexSign") + # Make sure vertexSign has a valid value if vertexSign in sign: pass else: @@ -2745,7 +2778,7 @@ def setDefaults(): valueButton = 32 group.SetInt("Button", valueButton) spinButton.setValue(valueButton) - + valueHoverDelay = paramGet.GetInt("HoverDelay") if valueHoverDelay: pass @@ -2753,7 +2786,7 @@ def setDefaults(): valueHoverDelay = 100 paramGet.SetInt("HoverDelay", valueHoverDelay) spinHoverDelay.setValue(valueHoverDelay) - + contextList() @@ -2766,23 +2799,23 @@ def setDefaultPie(restore=False): "Std_ViewIsometric", "Std_ViewLeft", "Std_ViewScreenShot"] - + defaultToolsPartDesign = ["PartDesign_NewSketch", "PartDesign_Pad", "PartDesign_Pocket", "PartDesign_Chamfer", "PartDesign_Fillet"] - + defaultToolsSketcher =["Sketcher_CreatePolyline", "Sketcher_CompCreateCircle", "Sketcher_CreateRectangle", "Sketcher_ToggleConstruction"] - + indexList = getIndexList() if 0 in indexList: if restore: group = paramIndexGet.GetGroup("0") - group.SetString("ToolList", ".,.".join(defaultTools)) + group.SetString("ToolList", ".,.".join(defaultTools)) else: pass else: @@ -2805,21 +2838,21 @@ def setDefaultPie(restore=False): group.SetInt("Radius", 80) group.SetInt("Button", 32) group.SetString("Shape", "Pie") - + paramIndexGet.SetString("1", "PartDesign") group = paramIndexGet.GetGroup("1") group.SetString("ToolList", ".,.".join(defaultToolsPartDesign)) group.SetInt("Radius", 80) group.SetInt("Button", 32) group.SetString("Shape", "Pie") - + paramIndexGet.SetString("2", "Sketcher") group = paramIndexGet.GetGroup("2") group.SetString("ToolList", ".,.".join(defaultToolsSketcher)) group.SetInt("Radius", 80) group.SetInt("Button", 32) group.SetString("Shape", "Pie") - + paramGet.SetBool("ToolBar", False) paramGet.RemString("ToolBar") paramGet.SetString("CurrentPie", "View") @@ -2834,17 +2867,18 @@ def setDefaultPie(restore=False): # group.SetInt("Radius", 80) # group.SetInt("Button", 32) - + def onControl(): + """Initializes the preferences dialog.""" # getTheme() - + shape = getShape(cBox.currentText()) onShape(shape) - + global pieMenuDialog global shortcutKey global globalShortcutKey - + for i in mw.findChildren(QtGui.QDialog): if i.objectName() == "PieMenuPreferences": i.deleteLater() @@ -2873,7 +2907,7 @@ def onControl(): layoutRadius = QtGui.QHBoxLayout() layoutRadius.addLayout(layoutRadiusLeft, 1) layoutRadius.addLayout(layoutRadiusRight, 1) - + layoutButtonLeft = QtGui.QHBoxLayout() layoutButtonLeft.addStretch(1) layoutButtonLeft.addWidget(labelButton) @@ -2902,22 +2936,22 @@ def updateShortcutKey(newShortcut): shortcutKey = newShortcut setShortcutKey(shortcutKey) labelShortcut.setText('New shortcut assigned: ' + shortcutKey) - + getShortcutList() - + getShortcutKey() - + labelShortcut.setText('Current shortcut: ' + shortcutKey) - + layoutShortcut = QtGui.QHBoxLayout() layoutShortcut.addWidget(labelShortcut) layoutShortcut.addStretch(1) layoutShortcut.addWidget(shortcutLineEdit) - + assignShortcutButton = QtGui.QPushButton("Assign") layoutShortcut.addWidget(assignShortcutButton) assignShortcutButton.clicked.connect(lambda: updateShortcutKey(shortcutLineEdit.text())) - + layoutShapeLeft = QtGui.QHBoxLayout() layoutShapeLeft.addStretch(1) layoutShapeLeft.addWidget(labelShape) @@ -2927,7 +2961,7 @@ def updateShortcutKey(newShortcut): layoutShape = QtGui.QHBoxLayout() layoutShape.addLayout(layoutShapeLeft, 1) layoutShape.addLayout(layoutShapeRight, 1) - + layoutColumnLeft = QtGui.QHBoxLayout() layoutColumnLeft.addStretch(1) layoutColumnLeft.addWidget(labelNumColumn) @@ -2937,7 +2971,7 @@ def updateShortcutKey(newShortcut): layoutColumn = QtGui.QHBoxLayout() layoutColumn.addLayout(layoutColumnLeft, 1) layoutColumn.addLayout(layoutColumnRight, 1) - + layoutDisplayCommandNameLeft = QtGui.QHBoxLayout() layoutDisplayCommandNameLeft.addStretch(1) layoutDisplayCommandNameLeft.addWidget(labeldisplayCommandName) @@ -2947,15 +2981,15 @@ def updateShortcutKey(newShortcut): layoutDisplayCommandName = QtGui.QHBoxLayout() layoutDisplayCommandName.addLayout(layoutDisplayCommandNameLeft, 1) layoutDisplayCommandName.addLayout(layoutDisplayCommandNameRight, 1) - + layoutInfoShortcut = QtGui.QHBoxLayout() layoutInfoShortcut.addWidget(infoShortcut) layoutInfoShortcut.addStretch(1) infoShortcut.setText('') - + labelShowQuickMenu = QLabel("Show QuickMenu:") labelShowQuickMenu.setAlignment(QtCore.Qt.AlignRight) - + layoutShowQuickMenuLeft = QtGui.QHBoxLayout() layoutShowQuickMenuLeft.addStretch(1) layoutShowQuickMenuLeft.addWidget(labelShowQuickMenu) @@ -2965,9 +2999,9 @@ def updateShortcutKey(newShortcut): layoutShowQuickMenu = QtGui.QHBoxLayout() layoutShowQuickMenu.addLayout(layoutShowQuickMenuLeft, 1) layoutShowQuickMenu.addLayout(layoutShowQuickMenuRight, 1) - + checkboxQuickMenu.stateChanged.connect(lambda state: setShowQuickMenu(state)) - + labelTheme = QLabel("Theme style:") labelTheme.setMinimumWidth(160) labelTheme.setAlignment(QtCore.Qt.AlignRight) @@ -2990,7 +3024,7 @@ def updateShortcutKey(newShortcut): radioButtonHover = QtGui.QRadioButton("Hover") radioButtonPress.setChecked(paramGet.GetString("TriggerMode") == "Press") radioButtonHover.setChecked(paramGet.GetString("TriggerMode") == "Hover") - + radioButtonPress.toggled.connect(lambda checked, data="Press": paramGet.SetString("TriggerMode", data)) radioButtonHover.toggled.connect(lambda checked, data="Hover": paramGet.SetString("TriggerMode", data)) @@ -3001,7 +3035,7 @@ def updateShortcutKey(newShortcut): layoutActionHoverButton = QtGui.QVBoxLayout() layoutActionHoverButton.addWidget(radioButtonPress) layoutActionHoverButton.addWidget(radioButtonHover) - + layoutTriggerButtonLeft = QtGui.QHBoxLayout() layoutTriggerButtonLeft.addStretch(1) layoutTriggerButtonLeft.addWidget(labelTriggerButton) @@ -3022,20 +3056,20 @@ def updateShortcutKey(newShortcut): layoutHoverDelay.addLayout(layoutHoverDelayLeft, 1) layoutHoverDelay.addLayout(layoutHoverDelayRight, 1) - - + + def close_dialog(): pieMenuDialog.accept() - + def updateGlobalShortcutKey(newShortcut): global globalShortcutKey touches_speciales = {'CTRL', 'ALT', 'SHIFT', 'META', 'TAB'} - + if not newShortcut: globalShortcutKey = newShortcut setGlobalShortcutKey(globalShortcutKey) labelGlobalShortcut.setText('Shortcut deleted ! No shortcut assigned ' + globalShortcutKey) - + else: parties = set(newShortcut.replace(',', '+').split('+')) for partie in parties: @@ -3058,7 +3092,7 @@ def updateGlobalShortcutKey(newShortcut): assignGlobalShortcutButton = QtGui.QPushButton("Assign") layoutGlobalShortcut.addWidget(assignGlobalShortcutButton) assignGlobalShortcutButton.clicked.connect(lambda: updateGlobalShortcutKey(globalShortcutLineEdit.text())) - + pieMenuTabLayout.insertLayout(0, layoutAddRemove) pieMenuTabLayout.insertSpacing(1, 12) pieMenuTabLayout.insertLayout(2, layoutRadius) @@ -3071,18 +3105,18 @@ def updateGlobalShortcutKey(newShortcut): pieMenuTabLayout.insertLayout(9, layoutShortcut) pieMenuTabLayout.addStretch(0) - + contextTab = QtGui.QWidget() contextTabLayout = QtGui.QVBoxLayout() contextTab.setLayout(contextTabLayout) - + settingsTab = QtGui.QWidget() settingsTabLayout = QtGui.QVBoxLayout() settingsTab.setLayout(settingsTabLayout) - + labelGlobalContext = QLabel("Global context:") labelGlobalContext.setAlignment(QtCore.Qt.AlignRight) - + layoutGlobalContextLeft = QtGui.QHBoxLayout() layoutGlobalContextLeft.addStretch(1) layoutGlobalContextLeft.addWidget(labelGlobalContext) @@ -3092,7 +3126,7 @@ def updateGlobalShortcutKey(newShortcut): layoutGlobalContext = QtGui.QHBoxLayout() layoutGlobalContext.addLayout(layoutGlobalContextLeft, 1) layoutGlobalContext.addLayout(layoutGlobalContextRight, 1) - + layoutCheckContextLeft = QtGui.QHBoxLayout() layoutCheckContextLeft.addStretch(1) layoutCheckContextLeft.addWidget(labelContext) @@ -3102,7 +3136,7 @@ def updateGlobalShortcutKey(newShortcut): layoutCheckContext = QtGui.QHBoxLayout() layoutCheckContext.addLayout(layoutCheckContextLeft, 1) layoutCheckContext.addLayout(layoutCheckContextRight, 1) - + settingsTabLayout.insertLayout(1, layoutTheme) settingsTabLayout.insertLayout(2, layoutShowQuickMenu) settingsTabLayout.insertLayout(3, layoutTriggerButton) @@ -3125,7 +3159,7 @@ def updateGlobalShortcutKey(newShortcut): tabs.addTab(widgetContainer, "Tools") tabs.addTab(contextTab, "Context") tabs.addTab(settingsTab, "Global settings") - + pieButtons = QtGui.QWidget() pieButtonsLayout = QtGui.QVBoxLayout() pieButtons.setLayout(pieButtonsLayout) @@ -3174,7 +3208,7 @@ def infoPopup():

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

""" res = QtGui.QMessageBox.question(None,"Help",msg,QtGui.QMessageBox.Ok) - + info_button = QtGui.QPushButton() info_button.setMaximumWidth(80) info_button.setIcon(QtGui.QIcon.fromTheme(iconInfo)) @@ -3183,20 +3217,20 @@ def infoPopup(): close_button = QtGui.QPushButton("Close", pieMenuDialog) close_button.setMaximumWidth(120) close_button.clicked.connect(close_dialog) - + # Create a horizontal layout for the buttons button_row_layout = QtGui.QHBoxLayout() button_row_layout.addWidget(info_button) button_row_layout.addStretch(1) button_row_layout.addWidget(close_button, 0, alignment=QtCore.Qt.AlignCenter) button_row_layout.addStretch(1) - + button_layout = QtGui.QVBoxLayout() button_layout.addLayout(layoutInfoShortcut) - + button_layout.addLayout(button_row_layout) - + pieMenuDialogLayout.addWidget(preferencesWidget) pieMenuDialogLayout.addLayout(button_layout) From b2812112f667b19acfe3f5676aead3012de68b21 Mon Sep 17 00:00:00 2001 From: hasecilu Date: Mon, 29 Jan 2024 15:33:33 -0600 Subject: [PATCH 2/4] Add translation support - Add bash script to include marked strings on translation files (*.ts) - TranslateUtils to define translate() placeholder function - Spanish (es-ES and es-AR) translations added --- InitGui.py | 124 +++++---- Resources/translation/PieMenu_es-AR.qm | Bin 0 -> 5006 bytes Resources/translation/PieMenu_es-AR.ts | 293 ++++++++++++++++++++ Resources/translation/PieMenu_es-ES.qm | Bin 0 -> 5006 bytes Resources/translation/PieMenu_es-ES.ts | 293 ++++++++++++++++++++ Resources/translation/update_translation.sh | 105 +++++++ TranslateUtils.py | 37 +++ 7 files changed, 800 insertions(+), 52 deletions(-) create mode 100644 Resources/translation/PieMenu_es-AR.qm create mode 100644 Resources/translation/PieMenu_es-AR.ts create mode 100644 Resources/translation/PieMenu_es-ES.qm create mode 100644 Resources/translation/PieMenu_es-ES.ts create mode 100755 Resources/translation/update_translation.sh create mode 100644 TranslateUtils.py diff --git a/InitGui.py b/InitGui.py index 1ce5a88..32f54ea 100644 --- a/InitGui.py +++ b/InitGui.py @@ -68,6 +68,7 @@ def pieMenuStart(): QMessageBox, QShortcut, QListWidgetItem, QListWidget, QComboBox from PySide2.QtGui import QKeySequence from PySide2.QtCore import Qt + from TranslateUtils import translate # global variables @@ -76,6 +77,12 @@ def pieMenuStart(): respath = respath.replace("\\", "/") stylepath = path + "/Resources/Stylesheets/" stylepath = stylepath.replace("\\", "/") + transpath = path + "/Resources/translation/" + transpath = transpath.replace("\\", "/") + + # Add translations path + Gui.addLanguagePath(transpath) + Gui.updateLocale() selectionTriggered = False contextPhase = False @@ -198,7 +205,7 @@ def remObsoleteParams(): def accessoriesMenu(): """Add pie menu preferences to accessories menu.""" pref = QtGui.QAction(mw) - pref.setText("Pie menu") + pref.setText(translate("AccesoriesMenu", "Pie menu settings")) pref.setObjectName("PieMenu") pref.triggered.connect(onControl) try: @@ -295,18 +302,18 @@ def quickMenu(buttonSize=20): .ToolButtonPopupMode.InstantPopup) menuMode = QtGui.QMenu() - menuMode.setTitle("Trigger") + menuMode.setTitle(translate("QuickMenu", "Trigger")) modeGroup = QtGui.QActionGroup(menuMode) modeGroup.setExclusive(True) actionPress = QtGui.QAction(modeGroup) - actionPress.setText("Press") + actionPress.setText(translate("QuickMenu", "Press")) actionPress.setData("Press") actionPress.setCheckable(True) actionHover = QtGui.QAction(modeGroup) - actionHover.setText("Hover") + actionHover.setText(translate("QuickMenu", "Hover")) actionHover.setData("Hover") actionHover.setCheckable(True) @@ -314,18 +321,18 @@ def quickMenu(buttonSize=20): menuMode.addAction(actionHover) actionContext = QtGui.QAction(menu) - actionContext.setText("Context") + actionContext.setText(translate("QuickMenu", "Context")) actionContext.setCheckable(True) menuPieMenu = QtGui.QMenu() - menuPieMenu.setTitle("PieMenu") + menuPieMenu.setTitle(translate("QuickMenu", "PieMenu")) pieGroup = QtGui.QActionGroup(menu) pieGroup.setExclusive(True) menuToolBar = QtGui.QMenu() menuToolBar.setObjectName("styleQuickMenuItem") - menuToolBar.setTitle("ToolBar") + menuToolBar.setTitle(translate("QuickMenu", "ToolBar")) menuToolBar.setStyleSheet(styleCurrentTheme) toolbarGroup = QtGui.QMenu() @@ -334,7 +341,7 @@ def quickMenu(buttonSize=20): toolbarGroupOps.setExclusive(True) prefAction = QtGui.QAction(menu) - prefAction.setIconText("Preferences") + prefAction.setIconText(translate("QuickMenu", "Preferences")) prefButton = QtGui.QToolButton() prefButton.setDefaultAction(prefAction) @@ -1725,7 +1732,7 @@ def get_modifier_text(self, modifiers): globalShortcutLineEdit = CustomLineEdit() globalShortcutLineEdit.setText(globalShortcutKey) - globalShortcutLineEdit.setToolTip("For TAB press CTRL+TAB") + globalShortcutLineEdit.setToolTip(translate("GlobalSettingsTab", "For TAB press CTRL+TAB")) labelShortcut = QLabel() labelShortcut.setAlignment(QtCore.Qt.AlignRight) @@ -1754,8 +1761,9 @@ def onPieChange(): getShortcutList() shortcutLineEdit.setText(shortcutKey) globalShortcutLineEdit.setText(globalShortcutKey) - labelShortcut.setText('Current shortcut: ' + shortcutKey) - labelGlobalShortcut.setText('Global shortcut: ' + globalShortcutKey) + labelShortcut.setText(translate("PieMenuTab", "Current shortcut: ") + shortcutKey) + labelGlobalShortcut.setText(translate("GlobalSettingsTab", "Global shortcut: ") \ + + globalShortcutKey) getdisplayCommandName(cBox.currentText()) shape = getShape(cBox.currentText()) onShape(shape) @@ -1766,7 +1774,7 @@ def onPieChange(): buttonAddPieMenu = QtGui.QToolButton() buttonAddPieMenu.setIcon(QtGui.QIcon(iconAdd)) - buttonAddPieMenu.setToolTip("Add new pie menu") + buttonAddPieMenu.setToolTip(translate("PieMenuTab", "Add new pie menu")) buttonAddPieMenu.setMinimumHeight(30) buttonAddPieMenu.setMinimumWidth(30) @@ -1849,7 +1857,7 @@ def onButtonAddPieMenu(): buttonRemovePieMenu = QtGui.QToolButton() buttonRemovePieMenu.setIcon(QtGui.QIcon(iconRemove)) - buttonRemovePieMenu.setToolTip("Remove current pie menu") + buttonRemovePieMenu.setToolTip(translate("PieMenuTab", "Remove current pie menu")) buttonRemovePieMenu.setMinimumHeight(30) buttonRemovePieMenu.setMinimumWidth(30) @@ -1909,7 +1917,7 @@ def onButtonRemovePieMenu(): buttonRemovePieMenu.clicked.connect(onButtonRemovePieMenu) buttonRenamePieMenu = QtGui.QToolButton() - buttonRenamePieMenu.setToolTip("Rename current pie menu") + buttonRenamePieMenu.setToolTip(translate("PieMenuTab", "Rename current pie menu")) buttonRenamePieMenu.setIcon(QtGui.QIcon(iconRename)) buttonRenamePieMenu.setMinimumHeight(30) buttonRenamePieMenu.setMinimumWidth(30) @@ -1949,7 +1957,7 @@ def onButtonRenamePieMenu(): buttonRenamePieMenu.clicked.connect(onButtonRenamePieMenu) buttonCopyPieMenu = QtGui.QToolButton() - buttonCopyPieMenu.setToolTip("Copy current pie menu") + buttonCopyPieMenu.setToolTip(translate("PieMenuTab", "Copy current pie menu")) buttonCopyPieMenu.setIcon(QtGui.QIcon(iconCopy)) buttonCopyPieMenu.setMinimumHeight(30) buttonCopyPieMenu.setMinimumWidth(30) @@ -2048,23 +2056,23 @@ def onButtonCopyPieMenu(): buttonCopyPieMenu.clicked.connect(onButtonCopyPieMenu) - labelRadius = QtGui.QLabel("Pie size:") + labelRadius = QtGui.QLabel(translate("PieMenuTab", "Pie size:")) labelRadius.setAlignment(QtCore.Qt.AlignRight) spinRadius = QtGui.QSpinBox() spinRadius.setMaximum(9999) spinRadius.setMinimumWidth(160) - labelHoverDelay = QtGui.QLabel("Hover delay (ms):") + labelHoverDelay = QtGui.QLabel(translate("GlobalSettingsTab", "Hover delay (ms):")) labelHoverDelay.setAlignment(QtCore.Qt.AlignRight) spinHoverDelay = QtGui.QSpinBox() spinHoverDelay.setMaximum(999) spinHoverDelay.setMinimumWidth(90) - labelShape = QtGui.QLabel("Shape:") + labelShape = QtGui.QLabel(translate("PieMenuTab", "Shape:")) labelShape.setAlignment(QtCore.Qt.AlignRight) - labeldisplayCommandName = QtGui.QLabel("Show command names:") + labeldisplayCommandName = QtGui.QLabel(translate("PieMenuTab", "Show command names:")) labeldisplayCommandName.setAlignment(QtCore.Qt.AlignRight) spinNumColumn = QtGui.QSpinBox() @@ -2213,7 +2221,7 @@ def onSpinRadius(): spinRadius.valueChanged.connect(onSpinRadius) - labelButton = QtGui.QLabel("Button size:") + labelButton = QtGui.QLabel(translate("PieMenuTab", "Button size:")) labelButton.setAlignment(QtCore.Qt.AlignRight) spinButton = QtGui.QSpinBox() spinButton.setMaximum(999) @@ -2240,10 +2248,11 @@ def onSpinButton(): searchLayout = QHBoxLayout() searchLineEdit = QLineEdit() - searchLineEdit.setPlaceholderText("Search") + searchLineEdit.setPlaceholderText(translate("ToolsTab", "Search")) searchResultLabel = QLabel() clearButton = QtGui.QToolButton() + clearButton.setToolTip(translate("ToolsTab", "Clear search")) clearButton.setMaximumWidth(40) clearButton.setIcon(QtGui.QIcon.fromTheme(iconBackspace)) clearButton.clicked.connect(searchLineEdit.clear) @@ -2453,7 +2462,7 @@ def buttonList2ToolList(buttonListWidget): buttonUp = QtGui.QToolButton() buttonUp.setIcon(QtGui.QIcon(iconUp)) - buttonUp.setToolTip("Move selected command up") + buttonUp.setToolTip(translate("Commands", "Move selected command up")) buttonUp.setMinimumHeight(30) buttonUp.setMinimumWidth(30) @@ -2471,7 +2480,7 @@ def onButtonUp(): buttonDown = QtGui.QToolButton() buttonDown.setIcon(QtGui.QIcon(iconDown)) - buttonDown.setToolTip("Move selected command down") + buttonDown.setToolTip(translate("Commands", "Move selected command down")) buttonDown.setMinimumHeight(30) buttonDown.setMinimumWidth(30) @@ -2489,7 +2498,7 @@ def onButtonDown(): buttonRemoveCommand = QtGui.QToolButton() buttonRemoveCommand.setIcon(QtGui.QIcon(iconRemoveCommand)) - buttonRemoveCommand.setToolTip("Remove selected command") + buttonRemoveCommand.setToolTip(translate("Commands", "Remove selected command")) buttonRemoveCommand.setMinimumHeight(30) buttonRemoveCommand.setMinimumWidth(30) @@ -2507,23 +2516,23 @@ def onButtonRemoveCommand(): buttonRemoveCommand.clicked.connect(onButtonRemoveCommand) vertexItem = QtGui.QTableWidgetItem() - vertexItem.setText("Vertex") - vertexItem.setToolTip("Set desired operator and vertex number") + vertexItem.setText(translate("ContextTab", "Vertex")) + vertexItem.setToolTip(translate("ContextTab", "Set desired operator and vertex number")) vertexItem.setFlags(QtCore.Qt.ItemIsEnabled) edgeItem = QtGui.QTableWidgetItem() - edgeItem.setText("Edge") - edgeItem.setToolTip("Set desired operator and edge number") + edgeItem.setText(translate("ContextTab", "Edge")) + edgeItem.setToolTip(translate("ContextTab", "Set desired operator and edge number")) edgeItem.setFlags(QtCore.Qt.ItemIsEnabled) faceItem = QtGui.QTableWidgetItem() - faceItem.setText("Face") - faceItem.setToolTip("Set desired operator and face number") + faceItem.setText(translate("ContextTab", "Face")) + faceItem.setToolTip(translate("ContextTab", "Set desired operator and face number")) faceItem.setFlags(QtCore.Qt.ItemIsEnabled) objectItem = QtGui.QTableWidgetItem() - objectItem.setText("Object") - objectItem.setToolTip("Set desired operator and object number") + objectItem.setText(translate("ContextTab", "Object")) + objectItem.setToolTip(translate("ContextTab", "Set desired operator and object number")) objectItem.setFlags(QtCore.Qt.ItemIsEnabled) @@ -2579,7 +2588,7 @@ def onSpinBox(): faceSpin = spinBox("FaceValue") objectSpin = spinBox("ObjectValue") - labelContext = QtGui.QLabel("Enable") + labelContext = QtGui.QLabel(translate("ContextTab", "Enable")) checkContext = QtGui.QCheckBox() @@ -2931,7 +2940,8 @@ def updateShortcutKey(newShortcut): parties = set(newShortcut.replace(',', '+').split('+')) for partie in parties: if partie not in touches_speciales and len(partie) > 1: - labelShortcut.setText('Invalid shortcut! Current shortcut: ' + shortcutKey) + labelShortcut.setText( + translate("PieMenuTab", "Invalid shortcut! Current shortcut: ") + shortcutKey) else : shortcutKey = newShortcut setShortcutKey(shortcutKey) @@ -2941,14 +2951,14 @@ def updateShortcutKey(newShortcut): getShortcutKey() - labelShortcut.setText('Current shortcut: ' + shortcutKey) + labelShortcut.setText(translate("PieMenuTab", "Current shortcut: ") + shortcutKey) layoutShortcut = QtGui.QHBoxLayout() layoutShortcut.addWidget(labelShortcut) layoutShortcut.addStretch(1) layoutShortcut.addWidget(shortcutLineEdit) - assignShortcutButton = QtGui.QPushButton("Assign") + assignShortcutButton = QtGui.QPushButton(translate("GlobalSettingsTab", "Assign")) layoutShortcut.addWidget(assignShortcutButton) assignShortcutButton.clicked.connect(lambda: updateShortcutKey(shortcutLineEdit.text())) @@ -2987,7 +2997,7 @@ def updateShortcutKey(newShortcut): layoutInfoShortcut.addStretch(1) infoShortcut.setText('') - labelShowQuickMenu = QLabel("Show QuickMenu:") + labelShowQuickMenu = QLabel(translate("GlobalSettingsTab", "Show QuickMenu:")) labelShowQuickMenu.setAlignment(QtCore.Qt.AlignRight) layoutShowQuickMenuLeft = QtGui.QHBoxLayout() @@ -3002,7 +3012,7 @@ def updateShortcutKey(newShortcut): checkboxQuickMenu.stateChanged.connect(lambda state: setShowQuickMenu(state)) - labelTheme = QLabel("Theme style:") + labelTheme = QLabel(translate("GlobalSettingsTab", "Theme style:")) labelTheme.setMinimumWidth(160) labelTheme.setAlignment(QtCore.Qt.AlignRight) @@ -3017,11 +3027,11 @@ def updateShortcutKey(newShortcut): layoutTheme.addLayout(layoutThemeRight, 1) comboBoxTheme.currentIndexChanged.connect(setTheme) - labelTriggerButton = QLabel("Trigger mode:") + labelTriggerButton = QLabel(translate("GlobalSettingsTab", "Trigger mode:")) labelTriggerButton.setAlignment(QtCore.Qt.AlignRight) - radioButtonPress = QtGui.QRadioButton("Press") - radioButtonHover = QtGui.QRadioButton("Hover") + radioButtonPress = QtGui.QRadioButton(translate("GlobalSettingsTab", "Press")) + radioButtonHover = QtGui.QRadioButton(translate("GlobalSettingsTab", "Hover")) radioButtonPress.setChecked(paramGet.GetString("TriggerMode") == "Press") radioButtonHover.setChecked(paramGet.GetString("TriggerMode") == "Hover") @@ -3068,28 +3078,36 @@ def updateGlobalShortcutKey(newShortcut): if not newShortcut: globalShortcutKey = newShortcut setGlobalShortcutKey(globalShortcutKey) - labelGlobalShortcut.setText('Shortcut deleted ! No shortcut assigned ' + globalShortcutKey) + labelGlobalShortcut.setText(translate("GlobalSettingsTab", \ + "Shortcut deleted ! No shortcut assigned ")\ + + globalShortcutKey) else: parties = set(newShortcut.replace(',', '+').split('+')) for partie in parties: if partie not in touches_speciales and len(partie) > 1: - labelGlobalShortcut.setText('Invalid shortcut ! Current global shortcut : ' + globalShortcutKey) + labelGlobalShortcut.setText(translate("GlobalSettingsTab", \ + "Invalid shortcut ! Current global shortcut : ") \ + + globalShortcutKey) else : globalShortcutKey = newShortcut setGlobalShortcutKey(globalShortcutKey) - labelGlobalShortcut.setText('New global shortcut assigned: ' + globalShortcutKey) + labelGlobalShortcut.setText(translate("GlobalSettingsTab", \ + "New global shortcut assigned: ") \ + + globalShortcutKey) actionKey.setShortcut(QtGui.QKeySequence(globalShortcutKey)) getGlobalShortcutKey() - labelGlobalShortcut.setText('Global shortcut : ' + globalShortcutKey) + labelGlobalShortcut.setText(translate("GlobalSettingsTab",\ + "Global shortcut : ") + globalShortcutKey) layoutGlobalShortcut = QtGui.QHBoxLayout() layoutGlobalShortcut.addWidget(labelGlobalShortcut) layoutGlobalShortcut.addStretch(1) layoutGlobalShortcut.addWidget(globalShortcutLineEdit) - assignGlobalShortcutButton = QtGui.QPushButton("Assign") + assignGlobalShortcutButton = QtGui.QPushButton(translate("PieMenuTab", \ + "Assign")) layoutGlobalShortcut.addWidget(assignGlobalShortcutButton) assignGlobalShortcutButton.clicked.connect(lambda: updateGlobalShortcutKey(globalShortcutLineEdit.text())) @@ -3114,7 +3132,7 @@ def updateGlobalShortcutKey(newShortcut): settingsTabLayout = QtGui.QVBoxLayout() settingsTab.setLayout(settingsTabLayout) - labelGlobalContext = QLabel("Global context:") + labelGlobalContext = QLabel(translate("GlobalSettingsTab", "Global context:")) labelGlobalContext.setAlignment(QtCore.Qt.AlignRight) layoutGlobalContextLeft = QtGui.QHBoxLayout() @@ -3155,10 +3173,10 @@ def updateGlobalShortcutKey(newShortcut): contextTabLayout.insertLayout(2, resetLayout) contextTabLayout.addStretch(1) - tabs.addTab(pieMenuTab, "PieMenu") - tabs.addTab(widgetContainer, "Tools") - tabs.addTab(contextTab, "Context") - tabs.addTab(settingsTab, "Global settings") + tabs.addTab(pieMenuTab, translate("PieMenuTab", "PieMenu")) + tabs.addTab(widgetContainer, translate("ToolsTab", "Tools")) + tabs.addTab(contextTab, translate("ContextTab", "Context")) + tabs.addTab(settingsTab, translate("GlobalSettingsTab", "Global settings")) pieButtons = QtGui.QWidget() pieButtonsLayout = QtGui.QVBoxLayout() @@ -3210,11 +3228,13 @@ def infoPopup(): res = QtGui.QMessageBox.question(None,"Help",msg,QtGui.QMessageBox.Ok) info_button = QtGui.QPushButton() + info_button.setToolTip(translate("MainWindow", "About")) info_button.setMaximumWidth(80) info_button.setIcon(QtGui.QIcon.fromTheme(iconInfo)) info_button.clicked.connect(infoPopup) - close_button = QtGui.QPushButton("Close", pieMenuDialog) + close_button = QtGui.QPushButton(translate("MainWindow", "Close"), \ + pieMenuDialog) close_button.setMaximumWidth(120) close_button.clicked.connect(close_dialog) diff --git a/Resources/translation/PieMenu_es-AR.qm b/Resources/translation/PieMenu_es-AR.qm new file mode 100644 index 0000000000000000000000000000000000000000..6bb1903ffdc2ef45740e9494f1c370c6c6f53e96 GIT binary patch literal 5006 zcmcIoTWB0r82*#)ZZ5m-CQ)nAQcfh6v_-6Fi-uZB)>bV|Qj@hRf;zi%vYB*uW}TVc znEE7$wjv0MA}ZEuy`jGOAQrLIisJ2|;+^#Npr{WbK3P!w{xiF?vyYG1;;TdymCoIxQ)5IOuTkXPuZTK3De}>i7-wno zTY@O|C*AneF{1cZ+OZk$<1S4WjuLgf;Ek!*>9$8-BI+@`u`fe+&Rj**{{YP#{*Wkf zf5#gy9>MolI*v@U`#XsuAH)vi{>J>(`vifQ0I)GOb78-DuC8&ht4ru#Ti-~RYxi;rXcI{y0ICCCx+6PsXn@{+{* z&KHSRScxmX#@Kl*@x&M36Qz0+i$_;r{`tujdj$MAp4@-nQs7&eO1uHwT_;mFKZx&` zS((Rk@7B~$XLRVjEA`jI7vuR?14bU^8ACKmb5tgWT$1=NNXIB>7a17GahX)^W>GO* z{kse)iqb3#N4lxSzL2u`T8#&w<;343o_?QUF57{Q8RU+Tk|FZ=}vnu90g(G ze}Q1b0E2<}AXYU8Q7$coFhbj4rvcjyW#fPFg|F_SDOqf0^-^tplvcjvNZyBd*8SF% zwoF&v=kl7~>U~DbDmNvN0c;{?K;6j5Ha#z!O&_3}RA3Bc7?zOjLyc`SwQQm3vTk6* z)S!m#TCVBT1Wm%Er4C4rJhI0ni za&7_dytyWwMXY!>XQ{Un7Yd} z7jkiHm^1Kw8<^+TqgIpfu5Ia2OU1nn*tv7+(+d5J1aOf8Ig);+w}xAhHg;MYxJlaG zRAg+oTG=dXlGvgS5ac})@lnJ^9mmKk>g&I;U}d!eyr^iowz;nck*jTobk0D^7{(Ip z;SJysFOz*5-=;v>8@xHb{FU30)tS*TQL?4uh;(LZ=LS47#1{Hk7Sp*;L6DxuHsp|N z7)N~BDGx9>Trtx~TcP0^6%+|mmIw`2rxr+8!yC+AC@*1*Bz%DbRg})GWxKhuD@H^c zpv#k41te-R+lst^rj_$JWEI>MIGjGb=uM~$ifCF`xfyX~9_1YH3am$JPC#fGGdMzm zhCzM~tqVk{Unv096|@C0Ty)m8i_=az*x*#Ic@;Vh;f7K^2o>U)iS76h|qLe4MIs;ONl z^|smvuoHv(t|5%Ocz?A?tQ{fGa=_|c1%qVYPN*PqWeXbdhkEjj^>b%`{P^KuzJ z7P#u^T=lyzt#4GRXcXhu3oh7?Dbl8SVmn5FX1wxsQ~;Q2uc?BF8u*Sbtfjq z%C2jf!ZG%GJ`9T*Qni9pB%C?{D)0@uFm06X=- zoj}H)uehytC}pIM;-hd*E$^Jx@9mwl#Rvh(e zMxp}a*w2|060p2d7g{uo-jsQOGoj|{S)V5P0L@5H#{6vS%2-xmOjGSoNLZ3?2vU1s ziAU^BKnwK0TvF?NltmeH=w3y#dO&X?U67iMUm-L*H_MW`8HiIO)dURT-&53K%-0;7 eZZUlo&eL2#*zSOpfu=U9#5XG12eq9Y9sd9wk2D7W literal 0 HcmV?d00001 diff --git a/Resources/translation/PieMenu_es-AR.ts b/Resources/translation/PieMenu_es-AR.ts new file mode 100644 index 0000000..15f4a72 --- /dev/null +++ b/Resources/translation/PieMenu_es-AR.ts @@ -0,0 +1,293 @@ + + + + + AccesoriesMenu + + + Pie menu settings + Ajustes de PieMenu + + + + Commands + + + Move selected command up + Mover comando seleccionado hacia arriba + + + + Move selected command down + Mover comando seleccionado hacia abajo + + + + Remove selected command + Eliminar comando seleccionado + + + + ContextTab + + + Vertex + Vértice + + + + Set desired operator and vertex number + Establecer el operador deseado y el número de vértice + + + + Edge + Arista + + + + Set desired operator and edge number + Establecer el operador deseado y el número de arista + + + + Face + Cara + + + + Set desired operator and face number + Establecer el operador deseado y el número de cara + + + + Object + Objeto + + + + Set desired operator and object number + Establecer el operador deseado y el número de objeto + + + + Enable + Habilitar + + + + Context + Contexto + + + + GlobalSettingsTab + + + For TAB press CTRL+TAB + Para TAB presione CTRL+TAB + + + + Global shortcut: + Atajo global: + + + + Hover delay (ms): + Retardo de sobrevuelo (ms): + + + + Assign + Asignar + + + + Show QuickMenu: + Mostrar menú rápido: + + + + Theme style: + Estilo de tema: + + + + Trigger mode: + Modo de disparo: + + + + Press + Presionar + + + + Hover + Sobrevolar + + + + Shortcut deleted ! No shortcut assigned + ¡Atajo eliminado! No se asignó atajo + + + + Invalid shortcut ! Current global shortcut : + ¡Atajo inválido! Atajo global actual: + + + + New global shortcut assigned: + Nuevo atajo global asignado: + + + + Global shortcut : + Atajo global: + + + + Global context: + Contexto global: + + + + Global settings + Ajustes globales + + + + MainWindow + + + About + Acerca de + + + + Close + Cerrar + + + + PieMenuTab + + + Current shortcut: + Atajo actual: + + + + Add new pie menu + Agregar un nuevo menú + + + + Remove current pie menu + Eliminar menú actual + + + + Rename current pie menu + Renombrar menú actual + + + + Copy current pie menu + Copiar menú actual + + + + Pie size: + Tamaño de menú: + + + + Shape: + Forma: + + + + Show command names: + Mostrar nombres de comandos: + + + + Button size: + Tamaño de botón: + + + + Invalid shortcut! Current shortcut: + ¡Atajo inválido! Atajo actual: + + + + Assign + Asignar + + + + PieMenu + PieMenu + + + + QuickMenu + + + Trigger + Disparo + + + + Press + Presionar + + + + Hover + Sobrevolar + + + + Context + Contexto + + + + PieMenu + PieMenu + + + + ToolBar + Barra de herramienta + + + + Preferences + Preferencias + + + + ToolsTab + + + Search + Buscar + + + + Clear search + Limpiar búsqueda + + + + Tools + Herramientas + + + diff --git a/Resources/translation/PieMenu_es-ES.qm b/Resources/translation/PieMenu_es-ES.qm new file mode 100644 index 0000000000000000000000000000000000000000..97a99eb8487c82a8bc703ada98d3a38a366411b3 GIT binary patch literal 5006 zcmcIoTWl0n82(#!x0hXZp(qk0h zzUk zw<4#;?ggF)A{UopOpZl<{pNSbT@qdJ_7Yg|OZ4gZVSL{k-M{M%$k`Zu`=vdY_fz!D zn_okY9X+?ZnJDr_>_GN!%zr9&b9t0#>NRgnU2fSqv=h$8kG;v=2krsBnW@B4;BL8;TKgitW9H~~ zJh!h%UAwA7@3W~}FVDvFbpu8o=Na>j_^Yc6XAHcSm_ zSfyoaPEAlh{5=9Af+ocJGb4z4El9)gvO*FvIVE2gxiE!DrBTx3#xuwp=Lua zt`BnvzHb2Y_IlK+5#9xLJ!+}AHvl_wTYWl8zaar!q(GLWpXv4Cj!GLltpVI5ZK^3U zwn?q5l{HChQ3nWe9*OuUV%?5o`6kuYU~&|r0{gLDqO!R&?d62?fv7uZoo=?q)8n=QGbOEdsF zIhkcZq9U`Q$UA62Igdj&in~0A(}x#bgUXR1>tqXaU16J)S7$p0)PX&=HThNFb>d80O&z;VJN=_rXlG~|y zqR*=OvSL-Egzr=>7S~>`uUuQXdU6#Nc)9|r@gg7C_RzXrJW(>T+qhS3lumQYyw06Q zwH!0Ea4T6AnHU_F1$2e(SY9@gCluJ=F3Oth)xjw`L!D4$j5r}LKMHAJELi=ZV39TNXNFPGqB zfvcL%WxxBvfu)sFU^yZzL_X0a-XH3l%Zro$`Stm^JIKAP3_b+XQZuBDt2wX&lV`!7f{c}@WZ1u^=PtYpJwnJPI8yMD#wbSw830zhM$L&((JTU$& z>jW}>hT^u$p_Gw2ijTrMHMw(In@^I8G$z{!gqBSv@S!EM%9UzJkrdOpcOb8}S#i{> zA&Cl%V?Sq3NWkPuU1(7!dQ;{B&V-7qhkcsl12iK+8S}HPWze$nJ(_BNLc)^tc#zry zOFUw)0a~E{<&s+EqYTQJL(eIa)dPAH>Aciz{0gDj* + + + + AccesoriesMenu + + + Pie menu settings + Ajustes de PieMenu + + + + Commands + + + Move selected command up + Mover comando seleccionado hacia arriba + + + + Move selected command down + Mover comando seleccionado hacia abajo + + + + Remove selected command + Eliminar comando seleccionado + + + + ContextTab + + + Vertex + Vértice + + + + Set desired operator and vertex number + Establecer el operador deseado y el número de vértice + + + + Edge + Arista + + + + Set desired operator and edge number + Establecer el operador deseado y el número de arista + + + + Face + Cara + + + + Set desired operator and face number + Establecer el operador deseado y el número de cara + + + + Object + Objeto + + + + Set desired operator and object number + Establecer el operador deseado y el número de objeto + + + + Enable + Habilitar + + + + Context + Contexto + + + + GlobalSettingsTab + + + For TAB press CTRL+TAB + Para TAB presione CTRL+TAB + + + + Global shortcut: + Atajo global: + + + + Hover delay (ms): + Retardo de sobrevuelo (ms): + + + + Assign + Asignar + + + + Show QuickMenu: + Mostrar menú rápido: + + + + Theme style: + Estilo de tema: + + + + Trigger mode: + Modo de disparo: + + + + Press + Presionar + + + + Hover + Sobrevolar + + + + Shortcut deleted ! No shortcut assigned + ¡Atajo eliminado! No se asignó atajo + + + + Invalid shortcut ! Current global shortcut : + ¡Atajo inválido! Atajo global actual: + + + + New global shortcut assigned: + Nuevo atajo global asignado: + + + + Global shortcut : + Atajo global: + + + + Global context: + Contexto global: + + + + Global settings + Ajustes globales + + + + MainWindow + + + About + Acerca de + + + + Close + Cerrar + + + + PieMenuTab + + + Current shortcut: + Atajo actual: + + + + Add new pie menu + Agregar un nuevo menú + + + + Remove current pie menu + Eliminar menú actual + + + + Rename current pie menu + Renombrar menú actual + + + + Copy current pie menu + Copiar menú actual + + + + Pie size: + Tamaño de menú: + + + + Shape: + Forma: + + + + Show command names: + Mostrar nombres de comandos: + + + + Button size: + Tamaño de botón: + + + + Invalid shortcut! Current shortcut: + ¡Atajo inválido! Atajo actual: + + + + Assign + Asignar + + + + PieMenu + PieMenu + + + + QuickMenu + + + Trigger + Disparo + + + + Press + Presionar + + + + Hover + Sobrevolar + + + + Context + Contexto + + + + PieMenu + PieMenu + + + + ToolBar + Barra de herramienta + + + + Preferences + Preferencias + + + + ToolsTab + + + Search + Buscar + + + + Clear search + Limpiar búsqueda + + + + Tools + Herramientas + + + diff --git a/Resources/translation/update_translation.sh b/Resources/translation/update_translation.sh new file mode 100755 index 0000000..43797ca --- /dev/null +++ b/Resources/translation/update_translation.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +# -------------------------------------------------------------------------------------------------- +# +# Update translation files +# +# Supported locales on FreeCAD <2024-01-20, FreeCADGui.supportedLocales(), total=40>: +# {'English': 'en', 'Afrikaans': 'af', 'Arabic': 'ar', 'Basque': 'eu', 'Belarusian': 'be', +# 'Bulgarian': 'bg', 'Catalan': 'ca', 'Chinese Simplified': 'zh-CN', +# 'Chinese Traditional': 'zh-TW', 'Croatian': 'hr', 'Czech': 'cs', 'Dutch': 'nl', +# 'Filipino': 'fil', 'Finnish': 'fi', 'French': 'fr', 'Galician': 'gl', 'Georgian': 'ka', +# 'German': 'de', 'Greek': 'el', 'Hungarian': 'hu', 'Indonesian': 'id', 'Italian': 'it', +# 'Japanese': 'ja', 'Kabyle': 'kab', 'Korean': 'ko', 'Lithuanian': 'lt', 'Norwegian': 'no', +# 'Polish': 'pl', 'Portuguese': 'pt-PT', 'Portuguese, Brazilian': 'pt-BR', 'Romanian': 'ro', +# 'Russian': 'ru', 'Serbian': 'sr', 'Serbian, Latin': 'sr-CS', 'Slovak': 'sk', +# 'Slovenian': 'sl', 'Spanish': 'es-ES', 'Spanish, Argentina': 'es-AR', 'Swedish': 'sv-SE', +# 'Turkish': 'tr', 'Ukrainian': 'uk', 'Valencian': 'val-ES', 'Vietnamese': 'vi'} +# +# NOTE: WORKFLOW +# 0. Install Qt tools +# Debian-based (e.g., Ubuntu): $ sudo apt-get install qttools5-dev-tools pyqt5-dev-tools +# Fedora-based: $ sudo dnf install qt5-linguist qt5-devel +# Arch-based: $ sudo pacman -S qt5-tools python-pyqt5 +# 1. Make the script executable +# $ chmod +x update_translation.sh +# 2. Execute the script passing the locale code as first parameter +# The script has to be executed within the `resources/translations` directory +# Only update the files you're translating! +# $ ./update_translation.sh es-ES +# 3. Do the translation via Qt Linguist and use `File>Release` +# 4. If releasing with the script execute the script passing the locale code +# as first parameter and use '-r' flag next +# $ ./update_translation.sh es-ES -r +# +# -------------------------------------------------------------------------------------------------- + +supported_locales=( + "en" "af" "ar" "eu" "be" "bg" "ca" "zh-CN" "zh-TW" "hr" + "cs" "nl" "fil" "fi" "fr" "gl" "ka" "de" "el" "hu" + "id" "it" "ja" "kab" "ko" "lt" "no" "pl" "pt-PT" "pt-BR" + "ro" "ru" "sr" "es-ES" "es-AR" "sv-SE" "tr" "uk" "val-ES" "vi" +) + +is_locale_supported() { + local locale="$1" + for supported_locale in "${supported_locales[@]}"; do + if [[ "$supported_locale" == "$locale" ]]; then + return 0 + fi + done + return 1 +} + +get_strings() { + # Get translatable strings from ../../*.py Python files + pylupdate5 ../../*.py -ts pyfiles.ts -verbose +} + +delete_files() { + # Delete files that are no longer needed + rm pyfiles.ts + rm -f ${WB}.ts +} + +add_new_locale() { + echo -e "\033[1;33m\n\t<<< Creating '${WB}_${LOCALE}.ts' file >>>\n\033[m" + get_strings + # Join strings from Qt Designer and Python files + lconvert -source-language en -target-language $LOCALE \ + -i pyfiles.ts -o ${WB}_${LOCALE}.ts +} + +update_locale() { + echo -e "\033[1;32m\n\t<<< Updating '${WB}_${LOCALE}.ts' file >>>\n\033[m" + get_strings + # Join newly created file with older file ( -no-obsolete) + lconvert -source-language en -target-language $LOCALE \ + -i pyfiles.ts ${WB}_${LOCALE}.ts -o ${WB}_${LOCALE}.ts -no-obsolete +} + +release_translation() { + # Release translation (creation of *.qm file from *.ts file) + lrelease ${WB}_${LOCALE}.ts +} + +# Main function ------------------------------------------------------------------------------------ + +WB="PieMenu" +LOCALE="$1" + +if is_locale_supported "$LOCALE"; then + if [ "$2" == "-r" ]; then + release_translation + else + if [ ! -f "${WB}_${LOCALE}.ts" ]; then + add_new_locale + else + update_locale + fi + delete_files + fi +else + echo "Verify your language code. Case sensitive." + echo "If it's correct ask a maintainer to add support for your language on FreeCAD." +fi diff --git a/TranslateUtils.py b/TranslateUtils.py new file mode 100644 index 0000000..fc91518 --- /dev/null +++ b/TranslateUtils.py @@ -0,0 +1,37 @@ +# -*- coding: utf8 -*- + +#*************************************************************************** +#* * +#* Copyright (c) 2020 kbwbe * +#* * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* This program is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with this program; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#*************************************************************************** + +import FreeCAD + + +if FreeCAD.GuiUp: + from PySide.QtCore import QT_TRANSLATE_NOOP + from DraftGui import translate +else: + def QT_TRANSLATE_NOOP(context, text): + return text + + def translate(context, text): + return text From 7eb222a0a8d162ba3031dc6daf8a4a0f08aa0311 Mon Sep 17 00:00:00 2001 From: hasecilu Date: Mon, 29 Jan 2024 16:06:16 -0600 Subject: [PATCH 3/4] Add `.gitignore` file --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ From 21ec466ccdc3adc53119ed573fb75fb0afe82d75 Mon Sep 17 00:00:00 2001 From: hasecilu Date: Mon, 29 Jan 2024 16:07:29 -0600 Subject: [PATCH 4/4] Move changelog to markdown file --- CHANGELOG.md | 24 ++++++++++++++++++++++++ InitGui.py | 22 ---------------------- 2 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7bdb30b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ +# CHANGELOG + +### 1.3.4 + +- Move globals settings on a new tab +- Added setting for show or not the QuickMenu +- Added checkbox in parameters for Contextual activation +- Set default theme (Legacy) on a new installation +- Update stylesheets for #styleButtonMenu::menu-indicator (setting for QuickMenu) + +### 1.3.5 + +- Factorization and clean some code +- Added differents shapes for PieMenus +- Added possibility to display the command name in the menu (only Pie shape) +- Added a button with information about developers and licence (Pgilfernandez) + +### 1.3.6 + +- Update layout of PieMenu Preferences for better readability (Pgilfernandez) +- Fix some typos (Pgilfernandez) +- Added some styles for QLabel command name (Pgilfernandez) +- Added "LeftRight" shape +- Fix problem with ghosting when reload workbenches diff --git a/InitGui.py b/InitGui.py index 32f54ea..c54dd3d 100644 --- a/InitGui.py +++ b/InitGui.py @@ -25,28 +25,6 @@ # http://forum.freecadweb.org/ # http://www.freecadweb.org/wiki/index.php?title=Code_snippets -# Changelog : -# -# 1.3.4 -# Move globals settings on a new tab -# Added setting for show or not the QuickMenu -# Added checkbox in parameters for Contextual activation -# Set default theme (Legacy) on a new installation -# Update stylesheets for #styleButtonMenu::menu-indicator (setting for QuickMenu) -# -# 1.3.5 -# Factorization and clean some code -# Added differents shapes for PieMenus -# Added possibility to display the command name in the menu (only Pie shape) -# Added a button with information about developers and licence (Pgilfernandez) -# -# 1.3.6 -# Update layout of PieMenu Preferences for better readability (Pgilfernandez) -# Fix some typos (Pgilfernandez) -# Added some styles for QLabel command name (Pgilfernandez) -# Added "LeftRight" shape -# Fix problem with ghosting when reload workbenches - global PIE_MENU_VERSION PIE_MENU_VERSION = "1.3.6"