From 8ccd73b91946406ec88179bcd0fedf701739e346 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 18 May 2019 17:17:37 +0300 Subject: [PATCH] - added a new toggle option in Edit -> Preferences -> General Tab -> App Preferences -> "Open" Behavior. It controls which path is used when opening a new file. If checked the last saved path is used when saving files and the last opened path is used when opening files. If unchecked then the path for the last action (either open or save) is used. --- FlatCAMApp.py | 52 +++++++++++++++++------- FlatCAMObj.py | 16 ++++++-- README.md | 4 ++ camlib.py | 2 +- flatcamGUI/FlatCAMGUI.py | 71 ++++++++++++++++++--------------- flatcamTools/ToolSolderPaste.py | 2 + 6 files changed, 96 insertions(+), 51 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 0534d0a0..85340c8a 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -324,6 +324,8 @@ class App(QtCore.QObject): "global_worker_number": self.ui.general_defaults_form.general_app_group.worker_number_sb, "global_tolerance": self.ui.general_defaults_form.general_app_group.tol_entry, + "global_open_style": self.ui.general_defaults_form.general_app_group.open_style_cb, + "global_compression_level": self.ui.general_defaults_form.general_app_group.compress_combo, "global_save_compressed": self.ui.general_defaults_form.general_app_group.save_type_cb, @@ -604,6 +606,7 @@ class App(QtCore.QObject): "global_toggle_tooltips": True, "global_worker_number": 2, "global_tolerance": 0.01, + "global_open_style": True, "global_compression_level": 3, "global_save_compressed": True, @@ -663,7 +666,7 @@ class App(QtCore.QObject): "global_zdownrate": None, # General GUI Settings - "global_hover": True, + "global_hover": False, "global_selection_shape": True, "global_layout": "compact", # Gerber General @@ -2776,7 +2779,8 @@ class App(QtCore.QObject): except: self.inform.emit(_("[ERROR_NOTCL] Failed to write defaults to file.")) return - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("preferences", filename) self.file_saved.emit("preferences", filename) self.inform.emit("[success] Exported Defaults to %s" % filename) @@ -4398,8 +4402,8 @@ class App(QtCore.QObject): return # Just for adding it to the recent files list. - self.file_opened.emit("cncjob", filename) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("cncjob", filename) self.file_saved.emit("cncjob", filename) self.inform.emit(_("Saved to: %s") % filename) @@ -6070,6 +6074,8 @@ class App(QtCore.QObject): return else: self.export_svg(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("SVG", filename) self.file_saved.emit("SVG", filename) def on_file_exportpng(self): @@ -6099,6 +6105,8 @@ class App(QtCore.QObject): return else: write_png(filename, data) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("png", filename) self.file_saved.emit("png", filename) def on_file_savegerber(self): @@ -6138,6 +6146,8 @@ class App(QtCore.QObject): return else: self.save_source_file(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Gerber", filename) self.file_saved.emit("Gerber", filename) def on_file_saveexcellon(self): @@ -6177,6 +6187,8 @@ class App(QtCore.QObject): return else: self.save_source_file(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Excellon", filename) self.file_saved.emit("Excellon", filename) def on_file_exportexcellon(self): @@ -6216,6 +6228,8 @@ class App(QtCore.QObject): return else: self.export_excellon(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Excellon", filename) self.file_saved.emit("Excellon", filename) def on_file_exportgerber(self): @@ -6255,6 +6269,8 @@ class App(QtCore.QObject): return else: self.export_gerber(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Gerber", filename) self.file_saved.emit("Gerber", filename) def on_file_exportdxf(self): @@ -6306,6 +6322,8 @@ class App(QtCore.QObject): return else: self.export_dxf(name, filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("DXF", filename) self.file_saved.emit("DXF", filename) def on_file_importsvg(self, type_of_obj): @@ -6560,8 +6578,8 @@ class App(QtCore.QObject): else: self.worker_task.emit({'fcn': self.save_project, 'params': [self.project_filename]}) - - self.file_opened.emit("project", self.project_filename) + if self.defaults["global_open_style"] is False: + self.file_opened.emit("project", self.project_filename) self.file_saved.emit("project", self.project_filename) self.should_we_save = False @@ -6606,8 +6624,8 @@ class App(QtCore.QObject): self.save_project(filename, quit) # self.save_project(filename) - self.file_opened.emit("project", filename) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("project", filename) self.file_saved.emit("project", filename) if not make_copy: self.project_filename = filename @@ -6665,7 +6683,8 @@ class App(QtCore.QObject): svgcode = parse_xml_string(svg_elem) with open(filename, 'w') as fp: fp.write(svgcode.toprettyxml()) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("SVG", filename) self.file_saved.emit("SVG", filename) self.inform.emit(_("[success] SVG file exported to %s") % filename) @@ -6770,7 +6789,8 @@ class App(QtCore.QObject): fp.write(doc.toprettyxml()) self.progress.emit(100) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("SVG", filename) self.file_saved.emit("SVG", filename) self.inform.emit(_("[success] SVG file exported to %s") % filename) @@ -6884,7 +6904,8 @@ class App(QtCore.QObject): with open(filename, 'w') as fp: fp.write(doc.toprettyxml()) self.progress.emit(100) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("SVG", filename) self.file_saved.emit("SVG", filename) self.inform.emit(_("[success] SVG file exported to %s") % filename) @@ -7034,7 +7055,8 @@ class App(QtCore.QObject): with open(filename, 'w') as fp: fp.write(exported_excellon) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Excellon", filename) self.file_saved.emit("Excellon", filename) self.inform.emit(_("[success] Excellon file exported to %s") % filename) except Exception as e: @@ -7150,7 +7172,8 @@ class App(QtCore.QObject): with open(filename, 'w') as fp: fp.write(exported_gerber) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("Gerber", filename) self.file_saved.emit("Gerber", filename) self.inform.emit(_("[success] Gerber file exported to %s") % filename) except Exception as e: @@ -7208,7 +7231,8 @@ class App(QtCore.QObject): try: dxf_code = obj.export_dxf() dxf_code.saveas(filename) - + if self.defaults["global_open_style"] is False: + self.file_opened.emit("DXF", filename) self.file_saved.emit("DXF", filename) self.inform.emit(_("[success] DXF file exported to %s") % filename) except: diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 1c4c2441..68aad1d7 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -1096,8 +1096,13 @@ class FlatCAMGerber(FlatCAMObj, Gerber): elif type(g) == Point: pass else: - for el in g: - self.add_shape(shape=el, color=color, + try: + for el in g: + self.add_shape(shape=el, color=color, + face_color=random_color() if self.options['multicolored'] + else face_color, visible=self.options['plot']) + except TypeError: + self.add_shape(shape=g, color=color, face_color=random_color() if self.options['multicolored'] else face_color, visible=self.options['plot']) else: @@ -5550,6 +5555,8 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob): if gc == 'fail': return + if self.app.defaults["global_open_style"] is False: + self.app.file_opened.emit("gcode", filename) self.app.file_saved.emit("gcode", filename) self.app.inform.emit(_("[success] Machine Code file saved to: %s") % filename) @@ -5769,7 +5776,7 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob): # lines = StringIO(self.gcode) lines = StringIO(g) - ## Write + # Write if filename is not None: try: with open(filename, 'w') as f: @@ -5783,7 +5790,8 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob): return elif to_file is False: # Just for adding it to the recent files list. - self.app.file_opened.emit("cncjob", filename) + if self.app.defaults["global_open_style"] is False: + self.app.file_opened.emit("cncjob", filename) self.app.file_saved.emit("cncjob", filename) self.app.inform.emit("[success] Saved to: " + filename) diff --git a/README.md b/README.md index d9d55302..2515e7f9 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing. ================================================= +18.05.2019 + +- added a new toggle option in Edit -> Preferences -> General Tab -> App Preferences -> "Open" Behavior. It controls which path is used when opening a new file. If checked the last saved path is used when saving files and the last opened path is used when opening files. If unchecked then the path for the last action (either open or save) is used. + 17.05.2019 - remade the Tool Cutout to work on panels diff --git a/camlib.py b/camlib.py index b76aa630..aa071909 100644 --- a/camlib.py +++ b/camlib.py @@ -5990,7 +5990,7 @@ class CNCjob(Geometry): if self.dwell is True: self.gcode += self.doformat(p.dwell_code) # Dwell time - ## Iterate over geometry paths getting the nearest each time. + # Iterate over geometry paths getting the nearest each time. log.debug("Starting G-Code...") path_count = 0 current_pt = (0, 0) diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 62505ab8..1222c2d0 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -3336,12 +3336,12 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI): self.workspace_lbl = QtWidgets.QLabel(_('Workspace:')) self.workspace_lbl.setToolTip( _( "Draw a delimiting rectangle on canvas.\n" - "The purpose is to illustrate the limits for our work.") + "The purpose is to illustrate the limits for our work.") ) self.workspace_type_lbl = QtWidgets.QLabel(_('Wk. format:')) self.workspace_type_lbl.setToolTip( _( "Select the type of rectangle to be used on canvas,\n" - "as valid workspace.") + "as valid workspace.") ) self.workspace_cb = FCCheckBox() self.wk_cb = FCComboBox() @@ -3356,8 +3356,8 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI): self.pf_color_label = QtWidgets.QLabel(_('Plot Fill:')) self.pf_color_label.setToolTip( _( "Set the fill color for plotted objects.\n" - "First 6 digits are the color and the last 2\n" - "digits are for alpha (transparency) level.") + "First 6 digits are the color and the last 2\n" + "digits are for alpha (transparency) level.") ) self.pf_color_entry = FCEntry() self.pf_color_button = QtWidgets.QPushButton() @@ -3743,18 +3743,18 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): # Units for FlatCAM self.unitslabel = QtWidgets.QLabel(_('Units:')) self.unitslabel.setToolTip(_("The default value for FlatCAM units.\n" - "Whatever is selected here is set every time\n" - "FLatCAM is started.")) + "Whatever is selected here is set every time\n" + "FLatCAM is started.")) self.units_radio = RadioSet([{'label': 'IN', 'value': 'IN'}, {'label': 'MM', 'value': 'MM'}]) # Application Level for FlatCAM self.app_level_label = QtWidgets.QLabel(_('APP. LEVEL:')) self.app_level_label.setToolTip(_("Choose the default level of usage for FlatCAM.\n" - "BASIC level -> reduced functionality, best for beginner's.\n" - "ADVANCED level -> full functionality.\n\n" - "The choice here will influence the parameters in\n" - "the Selected Tab for all kinds of FlatCAM objects.")) + "BASIC level -> reduced functionality, best for beginner's.\n" + "ADVANCED level -> full functionality.\n\n" + "The choice here will influence the parameters in\n" + "the Selected Tab for all kinds of FlatCAM objects.")) self.app_level_radio = RadioSet([{'label': 'Basic', 'value': 'b'}, {'label': 'Advanced', 'value': 'a'}]) @@ -3776,24 +3776,24 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): self.shell_startup_label = QtWidgets.QLabel(_('Shell at StartUp:')) self.shell_startup_label.setToolTip( _("Check this box if you want the shell to\n" - "start automatically at startup.") + "start automatically at startup.") ) self.shell_startup_cb = FCCheckBox(label='') self.shell_startup_cb.setToolTip( _("Check this box if you want the shell to\n" - "start automatically at startup.") + "start automatically at startup.") ) # Version Check CB self.version_check_label = QtWidgets.QLabel(_('Version Check:')) self.version_check_label.setToolTip( _("Check this box if you want to check\n" - "for a new version automatically at startup.") + "for a new version automatically at startup.") ) self.version_check_cb = FCCheckBox(label='') self.version_check_cb.setToolTip( _("Check this box if you want to check\n" - "for a new version automatically at startup.") + "for a new version automatically at startup.") ) # Send Stats CB @@ -3805,7 +3805,7 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): self.send_stats_cb= FCCheckBox(label='') self.send_stats_cb.setToolTip( _("Check this box if you agree to send anonymous\n" - "stats automatically at startup, to help improve FlatCAM.") + "stats automatically at startup, to help improve FlatCAM.") ) self.ois_version_check = OptionalInputSection(self.version_check_cb, [self.send_stats_cb]) @@ -3813,8 +3813,8 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): # Select mouse pan button self.panbuttonlabel = QtWidgets.QLabel(_('Pan Button:')) self.panbuttonlabel.setToolTip(_("Select the mouse button to use for panning:\n" - "- MMB --> Middle Mouse Button\n" - "- RMB --> Right Mouse Button")) + "- MMB --> Middle Mouse Button\n" + "- RMB --> Right Mouse Button")) self.pan_button_radio = RadioSet([{'label': 'MMB', 'value': '3'}, {'label': 'RMB', 'value': '2'}]) @@ -3822,44 +3822,44 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): self.mselectlabel = QtWidgets.QLabel(_('Multiple Sel:')) self.mselectlabel.setToolTip(_("Select the key used for multiple selection.")) self.mselect_radio = RadioSet([{'label': 'CTRL', 'value': 'Control'}, - {'label': 'SHIFT', 'value': 'Shift'}]) + {'label': 'SHIFT', 'value': 'Shift'}]) # Project at StartUp CB self.project_startup_label = QtWidgets.QLabel(_('Project at StartUp:')) self.project_startup_label.setToolTip( _("Check this box if you want the project/selected/tool tab area to\n" - "to be shown automatically at startup.") + "to be shown automatically at startup.") ) self.project_startup_cb = FCCheckBox(label='') self.project_startup_cb.setToolTip( _("Check this box if you want the project/selected/tool tab area to\n" - "to be shown automatically at startup.") + "to be shown automatically at startup.") ) # Project autohide CB self.project_autohide_label = QtWidgets.QLabel(_('Project AutoHide:')) self.project_autohide_label.setToolTip( _( "Check this box if you want the project/selected/tool tab area to\n" - "hide automatically when there are no objects loaded and\n" - "to show whenever a new object is created.") + "hide automatically when there are no objects loaded and\n" + "to show whenever a new object is created.") ) self.project_autohide_cb = FCCheckBox(label='') self.project_autohide_cb.setToolTip( _("Check this box if you want the project/selected/tool tab area to\n" - "hide automatically when there are no objects loaded and\n" - "to show whenever a new object is created.") + "hide automatically when there are no objects loaded and\n" + "to show whenever a new object is created.") ) # Enable/Disable ToolTips globally self.toggle_tooltips_label = QtWidgets.QLabel(_('Enable ToolTips:')) self.toggle_tooltips_label.setToolTip( _( "Check this box if you want to have toolTips displayed\n" - "when hovering with mouse over items throughout the App.") + "when hovering with mouse over items throughout the App.") ) self.toggle_tooltips_cb = FCCheckBox(label='') self.toggle_tooltips_cb.setToolTip( _( "Check this box if you want to have toolTips displayed\n" - "when hovering with mouse over items throughout the App.") + "when hovering with mouse over items throughout the App.") ) self.worker_number_label = QtWidgets.QLabel(_('Workers number:')) self.worker_number_label.setToolTip( @@ -3928,15 +3928,22 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): # to the main layout of this TAB self.layout.addLayout(self.form_box) - # hlay = QtWidgets.QHBoxLayout() - # self.layout.addLayout(hlay) - # hlay.addStretch() + # Save compressed project CB + self.open_style_cb = FCCheckBox(_('"Open" behavior')) + self.open_style_cb.setToolTip( + _("When checked the path for the last saved file is used when saving files,\n" + "and the path for the last opened file is used when opening files.\n\n" + "When unchecked the path for opening files is the one used last: either the\n" + "path for saving files or the path for opening files.") + ) + # self.advanced_cb.setLayoutDirection(QtCore.Qt.RightToLeft) + self.layout.addWidget(self.open_style_cb) # Save compressed project CB self.save_type_cb = FCCheckBox(_('Save Compressed Project')) self.save_type_cb.setToolTip( _("Whether to save a compressed or uncompressed project.\n" - "When checked it will save a compressed FlatCAM project.") + "When checked it will save a compressed FlatCAM project.") ) # self.advanced_cb.setLayoutDirection(QtCore.Qt.RightToLeft) self.layout.addWidget(self.save_type_cb) @@ -3949,8 +3956,8 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): self.compress_label = QtWidgets.QLabel(_('Compression Level:')) self.compress_label.setToolTip( _("The level of compression used when saving\n" - "a FlatCAM project. Higher value means better compression\n" - "but require more RAM usage and more processing time.") + "a FlatCAM project. Higher value means better compression\n" + "but require more RAM usage and more processing time.") ) # self.advanced_cb.setLayoutDirection(QtCore.Qt.RightToLeft) self.compress_combo.addItems([str(i) for i in range(10)]) diff --git a/flatcamTools/ToolSolderPaste.py b/flatcamTools/ToolSolderPaste.py index 4f7a21e7..61600239 100644 --- a/flatcamTools/ToolSolderPaste.py +++ b/flatcamTools/ToolSolderPaste.py @@ -1390,6 +1390,8 @@ class SolderPaste(FlatCAMTool): self.app.inform.emit(_("[WARNING_NOTCL] No such file or directory")) return + if self.app.defaults["global_open_style"] is False: + self.app.file_opened.emit("gcode", filename) self.app.file_saved.emit("gcode", filename) self.app.inform.emit(_("[success] Solder paste dispenser GCode file saved to: %s") % filename)