Browse Source

Working on extracting the prefs UI code from the App class

David Robertson 5 năm trước cách đây
mục cha
commit
72c2dd5f26

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 26 - 981
FlatCAMApp.py


+ 1 - 1
FlatCAMTranslation.py

@@ -207,6 +207,6 @@ def restart_program(app, ask=None):
         if response == bt_yes:
             app.on_file_saveprojectas(use_thread=True, quit_action=True)
 
-    app.save_defaults()
+    app.preferencesUiManager.save_defaults()
     python = sys.executable
     os.execl(python, python, *sys.argv)

+ 68 - 4
defaults.py

@@ -3,12 +3,16 @@ import stat
 import sys
 from copy import deepcopy
 from FlatCAMCommon import LoudDict
-from camlib import to_dict
+from camlib import to_dict, CNCjob, Geometry
 import simplejson
 import logging
 import gettext
 import FlatCAMTranslation as fcTranslate
 import builtins
+
+from flatcamParsers.ParseExcellon import Excellon
+from flatcamParsers.ParseGerber import Gerber
+
 fcTranslate.apply_language('strings')
 if '_' not in builtins.__dict__:
     _ = gettext.gettext
@@ -689,6 +693,30 @@ class FlatCAMDefaults:
         self.current_defaults.update(self.factory_defaults)
         self.old_defaults_found = False
 
+    ##### Pass-through to the defaults LoudDict #####
+    def __len__(self):
+        return self.defaults.__len__()
+
+    def __getitem__(self, item):
+        return self.defaults.__getitem__(item)
+
+    def __setitem__(self, key, value):
+        return self.defaults.__setitem__(key, value)
+
+    def __delitem__(self, key):
+        return self.defaults.__delitem__(key)
+
+    def __iter__(self):
+        return self.defaults.__iter__()
+
+    def set_change_callback(self, callback):
+        self.defaults.set_change_callback(callback)
+
+    def update(self, *args, **kwargs):
+        return self.defaults.update(*args, **kwargs)
+
+    ##### Additional Methods #####
+
     def write(self, filename: str):
         """Saves the defaults to a file on disk"""
         with open(filename, "w") as file:
@@ -703,7 +731,7 @@ class FlatCAMDefaults:
             options = f.read()
             f.close()
         except IOError:
-            self.log.error("Could not load defaults file.")
+            log.error("Could not load defaults file.")
             self.inform.emit('[ERROR] %s' % _("Could not load defaults file."))
             # in case the defaults file can't be loaded, show all toolbars
             self.defaults["global_toolbar_view"] = 511
@@ -762,6 +790,42 @@ class FlatCAMDefaults:
                     migrated[k] = v
         return migrated
 
+    def reset_to_factory_defaults(self):
+        self.defaults.update(self.factory_defaults)
+        self.current_defaults.update(self.factory_defaults)
+        self.old_defaults_found = False
 
-
-
+    def propagate_defaults(self):
+        """
+        This method is used to set default values in classes. It's
+        an alternative to project options but allows the use
+        of values invisible to the user.
+        """
+        log.debug("propagate_defaults()")
+
+        # Which objects to update the given parameters.
+        routes = {
+            "global_zdownrate": CNCjob,
+            "excellon_zeros": Excellon,
+            "excellon_format_upper_in": Excellon,
+            "excellon_format_lower_in": Excellon,
+            "excellon_format_upper_mm": Excellon,
+            "excellon_format_lower_mm": Excellon,
+            "excellon_units": Excellon,
+            "gerber_use_buffer_for_union": Gerber,
+            "geometry_multidepth": Geometry
+        }
+
+        for param in routes:
+            if param in routes[param].defaults:
+                try:
+                    routes[param].defaults[param] = self.defaults[param]
+                except KeyError:
+                    log.error("FlatCAMApp.propagate_defaults() --> ERROR: " + param + " not in defaults.")
+            else:
+                # Try extracting the name:
+                # classname_param here is param in the object
+                if param.find(routes[param].__name__.lower() + "_") == 0:
+                    p = param[len(routes[param].__name__) + 1:]
+                    if p in routes[param].defaults:
+                        routes[param].defaults[p] = self.defaults[param]

+ 1 - 1
flatcamGUI/FlatCAMGUI.py

@@ -2910,7 +2910,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_S:
                     widget_name = self.plot_tab_area.currentWidget().objectName()
                     if widget_name == 'preferences_tab':
-                        self.app.on_save_button(save_to_file=False)
+                        self.app.preferencesUiManager.on_save_button(save_to_file=False)
                         return
 
                     if widget_name == 'database_tab':

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 999 - 4
flatcamGUI/PreferencesUI.py


+ 1 - 1
tclCommands/TclCommandSaveSys.py

@@ -50,4 +50,4 @@ class TclCommandSaveSys(TclCommandSignaled):
         :return: None or exception
         """
 
-        self.app.save_defaults(args)
+        self.app.preferencesUiManager.save_defaults(args)

+ 1 - 2
tclCommands/TclCommandSetSys.py

@@ -83,8 +83,7 @@ class TclCommandSetSys(TclCommand):
                 pass
 
             self.app.defaults[param] = value
-
-            self.app.propagate_defaults(silent=True)
+            self.app.defaults.propagate_defaults()
 
         else:
             self.raise_tcl_error("No such system parameter \"{}\".".format(param))

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác