From 7d2fd7c77a932ec41dd8b9ae4d71b335046fd76e Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 18 Apr 2022 11:48:16 +0300 Subject: [PATCH] - added a way to allow patching FCLabel widget colors for certain cases without having to pass them each instance --- CHANGELOG.md | 1 + .../geo_plugins/GeoSimplificationPlugin.py | 2 +- appGUI/GUIElements.py | 34 +++++++++++-------- appGUI/MainGUI.py | 5 +++ .../general/GeneralAPPSetGroupUI.py | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a30daf..d0b2b544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM Evo beta - updated the FCLabel widget - replaced all the FCLabel widgets that have color HTML with the new FCLabel widget that uses parameters for 'color' and weight - minor changes +- added a way to allow patching FCLabel widget colors for certain cases without having to pass them each instance 17.04.2022 diff --git a/appEditors/geo_plugins/GeoSimplificationPlugin.py b/appEditors/geo_plugins/GeoSimplificationPlugin.py index 7fe9938a..d350813e 100644 --- a/appEditors/geo_plugins/GeoSimplificationPlugin.py +++ b/appEditors/geo_plugins/GeoSimplificationPlugin.py @@ -11,7 +11,7 @@ class SimplificationTool(AppTool): Do a shape simplification for the selected geometry. """ - update_ui = pyqtSignal(list, int) + update_ui = pyqtSignal(object, int) def __init__(self, app, draw_app): AppTool.__init__(self, app) diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index ebd129cd..c7b01204 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -155,11 +155,11 @@ class RadioSetCross(QtWidgets.QWidget): self.choices[choice]['radio'].toggled.connect(self.on_toggle) # add to layout - layout.addWidget(self.choices[0]['radio'], 0, 0) # top-left - layout.addWidget(self.choices[1]['radio'], 0, 2) # top-right - layout.addWidget(self.choices[2]['radio'], 2, 0) # bottom-left - layout.addWidget(self.choices[3]['radio'], 2, 2) # bottom-right - layout.addWidget(self.choices[4]['radio'], 1, 1) # center + layout.addWidget(self.choices[0]['radio'], 0, 0) # top-left + layout.addWidget(self.choices[1]['radio'], 0, 2) # top-right + layout.addWidget(self.choices[2]['radio'], 2, 0) # bottom-left + layout.addWidget(self.choices[3]['radio'], 2, 2) # bottom-right + layout.addWidget(self.choices[4]['radio'], 1, 1) # center layout.setContentsMargins(0, 0, 0, 0) @@ -2435,9 +2435,9 @@ class FCPlainTextAreaExtended(QtWidgets.QPlainTextEdit): idx = start.start() # Select the matched text and apply the desired format cursor.setPosition(idx, QtGui.QTextCursor.MoveMode.MoveAnchor) - cursor.movePosition(QtGui.QTextCursor.MoveOperation.EndOfWord, QtGui.QTextCursor.MoveMode.KeepAnchor ,1) + cursor.movePosition(QtGui.QTextCursor.MoveOperation.EndOfWord, QtGui.QTextCursor.MoveMode.KeepAnchor, 1) cursor.mergeCharFormat(fmt) - start = pattern.search(text, idx+1) + start = pattern.search(text, idx + 1) cursor.select(QtGui.QTextCursor.SelectionType.WordUnderCursor) @@ -2624,6 +2624,7 @@ class DialogBoxChoice(QtWidgets.QDialog): if self.moving: self.move(event.globalPosition().toPoint() - self.offset.toPoint()) + class FCInputDialog(QtWidgets.QInputDialog): def __init__(self, parent=None, ok=False, val=None, title=None, text=None, min=None, max=None, decimals=None, init_val=None): @@ -2970,15 +2971,14 @@ class FCLabel(QtWidgets.QLabel): right_clicked = QtCore.pyqtSignal(bool) middle_clicked = QtCore.pyqtSignal(bool) - def __init__(self, title=None, color=None, color_callback=None, bold=None, parent=None): + + def __init__(self, title=None, color=None, bold=None, parent=None): """ :param title: the label's text :type title: str :param color: text color :type color: str - :param color_callback: function to alter the color - :type color_callback: function :param bold: the text weight :type bold: bool :param parent: parent of this widget @@ -2987,8 +2987,8 @@ class FCLabel(QtWidgets.QLabel): super(FCLabel, self).__init__(parent) - if color and color_callback: - color = color_callback(color) + if color: + color = self.patching_text_color(color) if isinstance(title, str): if color and not bold: @@ -3005,6 +3005,9 @@ class FCLabel(QtWidgets.QLabel): self.middle_clicked_state = False self.right_clicked_state = False + def patching_text_color(self, color): + return color + def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: self.clicked_state = not self.clicked_state @@ -5723,19 +5726,20 @@ class FCMessageBox(QtWidgets.QMessageBox): """ Frameless QMessageBox """ + def __init__(self, *args, **kwargs): super(FCMessageBox, self).__init__(*args, **kwargs) self.offset = None self.moving = None self.setWindowFlags(self.windowFlags() | Qt.WindowType.FramelessWindowHint | Qt.WindowType.WindowSystemMenuHint) - # "background-color: palette(base); " + # "background-color: palette(base); " self.setStyleSheet( "QDialog { " "border: 1px solid palette(shadow); " "}" ) - + def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: self.moving = True @@ -5791,7 +5795,7 @@ class FCDate(QtWidgets.QDateEdit): date = self.date() date_formated = date.toString(QtCore.Qt.DateFormat.ISODate) return date_formated - + def message_dialog(title, message, kind="info", parent=None): """ diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 1bd9d30a..56bd706b 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -52,6 +52,9 @@ class MainGUI(QtWidgets.QMainWindow): final_save = QtCore.pyqtSignal(name='saveBeforeExit') # screenChanged = QtCore.pyqtSignal(QtGui.QScreen, QtGui.QScreen) + def theme_safe_color(self, color): + return color + # https://www.w3.org/TR/SVG11/types.html#ColorKeywords def __init__(self, app): super(MainGUI, self).__init__() @@ -60,6 +63,8 @@ class MainGUI(QtWidgets.QMainWindow): self.app = app self.decimals = self.app.decimals + FCLabel.patching_text_color = self.theme_safe_color + # Divine icon pack by Ipapun @ finicons.com # ####################################################################### diff --git a/appGUI/preferences/general/GeneralAPPSetGroupUI.py b/appGUI/preferences/general/GeneralAPPSetGroupUI.py index a307011e..44fd77c4 100644 --- a/appGUI/preferences/general/GeneralAPPSetGroupUI.py +++ b/appGUI/preferences/general/GeneralAPPSetGroupUI.py @@ -408,7 +408,7 @@ class GeneralAPPSetGroupUI(OptionsGroupUI): # ############################################################################################################# # Parameters Frame # ############################################################################################################# - self.par_label = FCLabel('%s' % _('Parameters')) + self.par_label = FCLabel(_('Parameters'), color='blue', bold=True) self.layout.addWidget(self.par_label) par_frame = FCFrame()