From bb8dcb37b956ce2bacdd42da81712bcd4231f97d Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 18 Feb 2019 16:11:24 +0200 Subject: [PATCH] - fixed a bug in Tool Transform that made the user to not be able to capture the click coordinates with SHIFT + LMB click combo - added the ability to choose an App QStyle out of the offered choices (different for each OS) to be applied at the next app start (Preferences -> General -> Gui Pref -> Style Combobox) - added support for FlatCAM usage with High DPI monitors (4k). It is applied on the next app startup after change in Preferences -> General -> Gui Pref -> HDPI Support Checkbox --- FlatCAM.py | 27 +++++- FlatCAMEditor.py | 165 ++++++++++++++++++++-------------- FlatCAMGUI.py | 54 ++++++++++- README.md | 3 + flatcamTools/ToolTransform.py | 2 +- 5 files changed, 177 insertions(+), 74 deletions(-) diff --git a/FlatCAM.py b/FlatCAM.py index 489af513..b1701a99 100644 --- a/FlatCAM.py +++ b/FlatCAM.py @@ -1,7 +1,8 @@ -import sys +import sys, os from PyQt5 import sip from PyQt5 import QtGui, QtCore, QtWidgets +from PyQt5.QtCore import QSettings, Qt from FlatCAMApp import App from multiprocessing import freeze_support import VisPyPatches @@ -31,7 +32,31 @@ if __name__ == '__main__': debug_trace() VisPyPatches.apply_patches() + # apply High DPI support + settings = QSettings("Open Source", "FlatCAM") + if settings.contains("hdpi"): + hdpi_support = settings.value('hdpi', type=int) + else: + hdpi_support = 0 + + if hdpi_support == 2: + os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" + else: + os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "0" + app = QtWidgets.QApplication(sys.argv) + + # apply style + settings = QSettings("Open Source", "FlatCAM") + if settings.contains("style"): + style = settings.value('style', type=str) + app.setStyle(style) + + if hdpi_support == 2: + app.setAttribute(Qt.AA_EnableHighDpiScaling, True) + else: + app.setAttribute(Qt.AA_EnableHighDpiScaling, False) + fc = App() sys.exit(app.exec_()) diff --git a/FlatCAMEditor.py b/FlatCAMEditor.py index e1161778..e6def4ae 100644 --- a/FlatCAMEditor.py +++ b/FlatCAMEditor.py @@ -1013,17 +1013,20 @@ class TransformEditorTool(FlatCAMTool): self.app.ui.splitter.setSizes([0, 1]) - def on_rotate(self): - try: - value = float(self.rotate_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_rotate(self, sig=None, val=None): + if val: + value = val + else: try: - value = float(self.rotate_entry.get_value().replace(',', '.')) + value = float(self.rotate_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Rotate, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + value = float(self.rotate_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Rotate, " + "use a number.") + return self.app.worker_task.emit({'fcn': self.on_rotate_action, 'params': [value]}) # self.on_rotate_action(value) @@ -1044,20 +1047,23 @@ class TransformEditorTool(FlatCAMTool): return def on_flip_add_coords(self): - val = self.app.defaults["global_point_clipboard_format"] % (self.app.pos[0], self.app.pos[1]) + val = self.app.clipboard.text() self.flip_ref_entry.set_value(val) - def on_skewx(self): - try: - value = float(self.skewx_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_skewx(self, sig=None, val=None): + if val: + value = val + else: try: - value = float(self.skewx_entry.get_value().replace(',', '.')) + value = float(self.skewx_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew X, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + value = float(self.skewx_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew X, " + "use a number.") + return # self.on_skew("X", value) axis = 'X' @@ -1065,17 +1071,20 @@ class TransformEditorTool(FlatCAMTool): 'params': [axis, value]}) return - def on_skewy(self): - try: - value = float(self.skewy_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_skewy(self, sig=None, val=None): + if val: + value = val + else: try: - value = float(self.skewy_entry.get_value().replace(',', '.')) + value = float(self.skewy_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew Y, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + value = float(self.skewy_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew Y, " + "use a number.") + return # self.on_skew("Y", value) axis = 'Y' @@ -1083,17 +1092,20 @@ class TransformEditorTool(FlatCAMTool): 'params': [axis, value]}) return - def on_scalex(self): - try: - xvalue = float(self.scalex_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_scalex(self, sig=None, val=None): + if val: + xvalue = val + else: try: - xvalue = float(self.scalex_entry.get_value().replace(',', '.')) + xvalue = float(self.scalex_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale X, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + xvalue = float(self.scalex_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale X, " + "use a number.") + return # scaling to zero has no sense so we remove it, because scaling with 1 does nothing if xvalue == 0: @@ -1116,18 +1128,21 @@ class TransformEditorTool(FlatCAMTool): return - def on_scaley(self): + def on_scaley(self, sig=None, val=None): xvalue = 1 - try: - yvalue = float(self.scaley_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + if val: + yvalue = val + else: try: - yvalue = float(self.scaley_entry.get_value().replace(',', '.')) + yvalue = float(self.scaley_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale Y, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + yvalue = float(self.scaley_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale Y, " + "use a number.") + return # scaling to zero has no sense so we remove it, because scaling with 1 does nothing if yvalue == 0: @@ -1146,17 +1161,20 @@ class TransformEditorTool(FlatCAMTool): return - def on_offx(self): - try: - value = float(self.offx_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_offx(self, sig=None, val=None): + if val: + value = val + else: try: - value = float(self.offx_entry.get_value().replace(',', '.')) + value = float(self.offx_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset X, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + value = float(self.offx_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset X, " + "use a number.") + return # self.on_offset("X", value) axis = 'X' @@ -1164,17 +1182,20 @@ class TransformEditorTool(FlatCAMTool): 'params': [axis, value]}) return - def on_offy(self): - try: - value = float(self.offy_entry.get_value()) - except ValueError: - # try to convert comma to decimal point. if it's still not working error message and return + def on_offy(self, sig=None, val=None): + if val: + value = val + else: try: - value = float(self.offy_entry.get_value().replace(',', '.')) + value = float(self.offy_entry.get_value()) except ValueError: - self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset Y, " - "use a number.") - return + # try to convert comma to decimal point. if it's still not working error message and return + try: + value = float(self.offy_entry.get_value().replace(',', '.')) + except ValueError: + self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset Y, " + "use a number.") + return # self.on_offset("Y", value) axis = 'Y' @@ -2582,8 +2603,7 @@ class FCPaint(FCShapeTool): self.start_msg = "Create Paint geometry ..." self.origin = (0, 0) - self.paint_tool = PaintOptionsTool(self.app, self.draw_app) - self.paint_tool.run() + self.draw_app.paint_tool.run() class FCTransform(FCShapeTool): @@ -2597,8 +2617,7 @@ class FCTransform(FCShapeTool): self.start_msg = "Shape transformations ..." self.origin = (0, 0) - self.transform_tool = TransformEditorTool(self.app, self.draw_app) - self.transform_tool.run() + self.draw_app.transform_tool.run() class FCRotate(FCShapeTool): @@ -3341,6 +3360,9 @@ class FlatCAMGeoEditor(QtCore.QObject): # if using Paint store here the tool diameter used self.paint_tooldia = None + self.paint_tool = PaintOptionsTool(self.app, self) + self.transform_tool = TransformEditorTool(self.app, self) + def pool_recreated(self, pool): self.shapes.pool = pool self.tool_shape.pool = pool @@ -3656,6 +3678,13 @@ class FlatCAMGeoEditor(QtCore.QObject): self.pos = (x, y) + modifiers = QtWidgets.QApplication.keyboardModifiers() + # If the SHIFT key is pressed when LMB is clicked then the coordinates are copied to clipboard + if modifiers == QtCore.Qt.ShiftModifier: + self.app.clipboard.setText( + self.app.defaults["global_point_clipboard_format"] % (self.pos[0], self.pos[1])) + return + # Selection with left mouse button if self.active_tool is not None and event.button is 1: # Dispatch event to active_tool diff --git a/FlatCAMGUI.py b/FlatCAMGUI.py index 2470995f..bf700869 100644 --- a/FlatCAMGUI.py +++ b/FlatCAMGUI.py @@ -2774,10 +2774,11 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI): self.form_box_child_11.addWidget(self.sel_draw_color_button) self.form_box_child_11.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) - # Theme selection + # Layout selection self.layout_label = QtWidgets.QLabel('Layout:') - self.alt_sf_color_label.setToolTip( - "Select an layout for FlatCAM." + self.layout_label.setToolTip( + "Select an layout for FlatCAM.\n" + "It is applied immediately." ) self.layout_combo = FCComboBox() self.layout_combo.addItem("Choose ...") @@ -2785,11 +2786,37 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI): self.layout_combo.addItem("Compact") self.layout_combo.setCurrentIndex(0) + # Style selection + self.style_label = QtWidgets.QLabel('Style:') + self.style_label.setToolTip( + "Select an style for FlatCAM.\n" + "It will be applied at the next app start." + ) + self.style_combo = FCComboBox() + self.style_combo.addItems(QtWidgets.QStyleFactory.keys()) + # find current style + index = self.style_combo.findText(QtWidgets.qApp.style().objectName(), QtCore.Qt.MatchFixedString) + self.style_combo.setCurrentIndex(index) + self.style_combo.activated[str].connect(self.handle_style) + + # Enable High DPI Support + self.hdpi_label = QtWidgets.QLabel('HDPI Support:') + self.hdpi_label.setToolTip( + "Enable High DPI support for FlatCAM.\n" + "It will be applied at the next app start." + ) + self.hdpi_cb = FCCheckBox() + settings = QSettings("Open Source", "FlatCAM") + if settings.contains("hdpi"): + self.hdpi_cb.set_value(settings.value('hdpi', type=int)) + else: + self.hdpi_cb.set_value(False) + self.hdpi_cb.stateChanged.connect(self.handle_hdpi) + # Just to add empty rows self.spacelabel = QtWidgets.QLabel('') # Add (label - input field) pair to the QFormLayout - self.form_box.addRow(self.spacelabel, self.spacelabel) self.form_box.addRow(self.gridx_label, self.gridx_entry) @@ -2813,10 +2840,29 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI): self.form_box.addRow(self.spacelabel, self.spacelabel) self.form_box.addRow(self.layout_label, self.layout_combo) + self.form_box.addRow(self.style_label, self.style_combo) + self.form_box.addRow(self.hdpi_label, self.hdpi_cb) + # Add the QFormLayout that holds the Application general defaults # to the main layout of this TAB self.layout.addLayout(self.form_box) + def handle_style(self, style): + # set current style + settings = QSettings("Open Source", "FlatCAM") + settings.setValue('style', style) + + # This will write the setting to the platform specific storage. + del settings + + def handle_hdpi(self, state): + # set current style + settings = QSettings("Open Source", "FlatCAM") + settings.setValue('hdpi', state) + + # This will write the setting to the platform specific storage. + del settings + class GeneralAppPrefGroupUI(OptionsGroupUI): def __init__(self, parent=None): diff --git a/README.md b/README.md index c7f9317e..49ae3d6f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ CAD program, and create G-Code for Isolation routing. - added in Geometry Editor a new Tool: Transformation Tool. It still has some bugs, though ... - in Geometry Editor by selecting a shape with a selection shape, that object was added multiple times (one per each selection) to the selected list, which is not intended. Bug fixed. - finished adding Transform Tool in Geometry Editor - everything is working as intended +- fixed a bug in Tool Transform that made the user to not be able to capture the click coordinates with SHIFT + LMB click combo +- added the ability to choose an App QStyle out of the offered choices (different for each OS) to be applied at the next app start (Preferences -> General -> Gui Pref -> Style Combobox) +- added support for FlatCAM usage with High DPI monitors (4k). It is applied on the next app startup after change in Preferences -> General -> Gui Pref -> HDPI Support Checkbox 17.02.2019 diff --git a/flatcamTools/ToolTransform.py b/flatcamTools/ToolTransform.py index 966303d4..60b2d4af 100644 --- a/flatcamTools/ToolTransform.py +++ b/flatcamTools/ToolTransform.py @@ -419,7 +419,7 @@ class ToolTransform(FlatCAMTool): return def on_flip_add_coords(self): - val = self.app.defaults["global_point_clipboard_format"] % (self.app.pos[0], self.app.pos[1]) + val = self.app.clipboard.text() self.flip_ref_entry.set_value(val) def on_skewx(self):