Jelajahi Sumber

Move the code for setting layout out from GeneralGUIPrefGroupUI into FlatCAMGUI

David Robertson 5 tahun lalu
induk
melakukan
c2c4375893

+ 6 - 7
FlatCAMApp.py

@@ -560,13 +560,11 @@ class App(QtCore.QObject):
 
 
         if self.defaults["first_run"] is True:
         if self.defaults["first_run"] is True:
 
 
-            # ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'COMPACT'
+            # ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'minimal'
             initial_lay = 'minimal'
             initial_lay = 'minimal'
-            self.ui.general_defaults_form.general_gui_group.on_layout(lay=initial_lay)
-
-            # Set the combobox in Preferences to the current layout
-            idx = self.ui.general_defaults_form.general_gui_group.layout_field.findText(initial_lay)
-            self.ui.general_defaults_form.general_gui_group.layout_field.setCurrentIndex(idx)
+            layout_field = self.preferencesUiManager.get_form_field("layout")
+            layout_field.setCurrentIndex(layout_field.findText(initial_lay))
+            self.ui.set_layout(initial_lay)
 
 
             # after the first run, this object should be False
             # after the first run, this object should be False
             self.defaults["first_run"] = False
             self.defaults["first_run"] = False
@@ -10206,7 +10204,8 @@ class App(QtCore.QObject):
 
 
         self.log.debug("version_check()")
         self.log.debug("version_check()")
 
 
-        if self.ui.general_defaults_form.general_app_group.send_stats_cb.get_value() is True:
+
+        if self.defaults["global_send_stats"] is True:
             full_url = "%s?s=%s&v=%s&os=%s&%s" % (
             full_url = "%s?s=%s&v=%s&os=%s&%s" % (
                 App.version_url,
                 App.version_url,
                 str(self.defaults['global_serial']),
                 str(self.defaults['global_serial']),

+ 147 - 0
flatcamGUI/FlatCAMGUI.py

@@ -4252,6 +4252,153 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
             self.final_save.emit()
             self.final_save.emit()
         event.ignore()
         event.ignore()
 
 
+    def set_layout(self, layout: str):
+        """
+        Set the toolbars layout (location)
+
+        :param index:
+        :param lay:     Type of layout to be set on the toolbard
+        :return:        None
+        """
+
+        self.app.defaults.report_usage("on_layout()")
+
+        lay_settings = QSettings("Open Source", "FlatCAM")
+        lay_settings.setValue('layout', layout)
+        # This will write the setting to the platform specific storage.
+        del lay_settings
+
+        # first remove the toolbars:
+        try:
+            self.removeToolBar(self.app.ui.toolbarfile)
+            self.removeToolBar(self.app.ui.toolbargeo)
+            self.removeToolBar(self.app.ui.toolbarview)
+            self.removeToolBar(self.app.ui.toolbarshell)
+            self.removeToolBar(self.app.ui.toolbartools)
+            self.removeToolBar(self.app.ui.exc_edit_toolbar)
+            self.removeToolBar(self.app.ui.geo_edit_toolbar)
+            self.removeToolBar(self.app.ui.grb_edit_toolbar)
+            self.removeToolBar(self.app.ui.snap_toolbar)
+            self.removeToolBar(self.app.ui.toolbarshell)
+        except Exception:
+            pass
+
+        if layout == 'compact':
+            # ## TOOLBAR INSTALLATION # ##
+            self.toolbarfile = QtWidgets.QToolBar('File Toolbar')
+            self.toolbarfile.setObjectName('File_TB')
+            self.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
+
+            self.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
+            self.toolbargeo.setObjectName('Edit_TB')
+            self.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
+
+            self.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
+            self.toolbarshell.setObjectName('Shell_TB')
+            self.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
+
+            self.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
+            self.toolbartools.setObjectName('Tools_TB')
+            self.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
+
+            self.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
+            # self.geo_edit_toolbar.setVisible(False)
+            self.geo_edit_toolbar.setObjectName('GeoEditor_TB')
+            self.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
+
+            self.toolbarview = QtWidgets.QToolBar('View Toolbar')
+            self.toolbarview.setObjectName('View_TB')
+            self.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
+
+            self.addToolBarBreak(area=Qt.RightToolBarArea)
+
+            self.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
+            # self.grb_edit_toolbar.setVisible(False)
+            self.grb_edit_toolbar.setObjectName('GrbEditor_TB')
+            self.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
+
+            self.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
+            self.exc_edit_toolbar.setObjectName('ExcEditor_TB')
+            self.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
+
+            self.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
+            self.snap_toolbar.setObjectName('Snap_TB')
+            self.snap_toolbar.setMaximumHeight(30)
+            self.splitter_left.addWidget(self.app.ui.snap_toolbar)
+
+            self.corner_snap_btn.setVisible(True)
+            self.snap_magnet.setVisible(True)
+        else:
+            # ## TOOLBAR INSTALLATION # ##
+            self.toolbarfile = QtWidgets.QToolBar('File Toolbar')
+            self.toolbarfile.setObjectName('File_TB')
+            self.addToolBar(self.app.ui.toolbarfile)
+
+            self.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
+            self.toolbargeo.setObjectName('Edit_TB')
+            self.addToolBar(self.app.ui.toolbargeo)
+
+            self.toolbarview = QtWidgets.QToolBar('View Toolbar')
+            self.toolbarview.setObjectName('View_TB')
+            self.addToolBar(self.app.ui.toolbarview)
+
+            self.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
+            self.toolbarshell.setObjectName('Shell_TB')
+            self.addToolBar(self.app.ui.toolbarshell)
+
+            self.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
+            self.toolbartools.setObjectName('Tools_TB')
+            self.addToolBar(self.app.ui.toolbartools)
+
+            self.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
+            # self.exc_edit_toolbar.setVisible(False)
+            self.exc_edit_toolbar.setObjectName('ExcEditor_TB')
+            self.addToolBar(self.app.ui.exc_edit_toolbar)
+
+            self.addToolBarBreak()
+
+            self.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
+            # self.geo_edit_toolbar.setVisible(False)
+            self.geo_edit_toolbar.setObjectName('GeoEditor_TB')
+            self.addToolBar(self.app.ui.geo_edit_toolbar)
+
+            self.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
+            # self.grb_edit_toolbar.setVisible(False)
+            self.grb_edit_toolbar.setObjectName('GrbEditor_TB')
+            self.addToolBar(self.app.ui.grb_edit_toolbar)
+
+            self.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
+            self.snap_toolbar.setObjectName('Snap_TB')
+            # self.snap_toolbar.setMaximumHeight(30)
+            self.addToolBar(self.app.ui.snap_toolbar)
+
+            self.corner_snap_btn.setVisible(False)
+            self.snap_magnet.setVisible(False)
+
+        if layout == 'minimal':
+            self.toolbarview.setVisible(False)
+            self.toolbarshell.setVisible(False)
+            self.snap_toolbar.setVisible(False)
+            self.geo_edit_toolbar.setVisible(False)
+            self.grb_edit_toolbar.setVisible(False)
+            self.exc_edit_toolbar.setVisible(False)
+            self.lock_toolbar(lock=True)
+
+        # add all the actions to the toolbars
+        self.populate_toolbars()
+
+        # reconnect all the signals to the toolbar actions
+        self.app.connect_toolbar_signals()
+
+        self.grid_snap_btn.setChecked(True)
+        self.on_grid_snap_triggered(state=True)
+
+        self.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
+        self.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
+        self.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
+        self.grid_gap_link_cb.setChecked(True)
+
+
 
 
 class FlatCAMActivityView(QtWidgets.QWidget):
 class FlatCAMActivityView(QtWidgets.QWidget):
     """
     """

+ 1 - 1
flatcamGUI/preferences/general/GeneralAppPrefGroupUI.py

@@ -115,7 +115,7 @@ class GeneralAppPrefGroupUI(OptionsGroupUI2):
                 option="global_language",
                 option="global_language",
                 label_text="Language",
                 label_text="Language",
                 label_tooltip="Set the language used throughout FlatCAM.",
                 label_tooltip="Set the language used throughout FlatCAM.",
-                choices=[] # FIXME: choices should be added here instead of in App
+                choices=[]  # FIXME: choices should be added here instead of in App
             ),
             ),
             FullWidthButtonOptionUI(
             FullWidthButtonOptionUI(
                 option="__apply_language_button",
                 option="__apply_language_button",

+ 1 - 147
flatcamGUI/preferences/general/GeneralGUIPrefGroupUI.py

@@ -205,8 +205,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
         line = self._modify_color_alpha(color=self.alt_sel_line_field.get_value(), alpha=alpha)
         line = self._modify_color_alpha(color=self.alt_sel_line_field.get_value(), alpha=alpha)
         self.alt_sel_line_field.set_value(line)
         self.alt_sel_line_field.set_value(line)
 
 
-
-
     def _modify_color_alpha(self, color: str, alpha: int):
     def _modify_color_alpha(self, color: str, alpha: int):
         color_without_alpha = color[:7]
         color_without_alpha = color[:7]
         if alpha > 255:
         if alpha > 255:
@@ -219,7 +217,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
                 hexalpha = "0" + hexalpha
                 hexalpha = "0" + hexalpha
             return color_without_alpha + hexalpha
             return color_without_alpha + hexalpha
 
 
-
     def on_theme_change(self):
     def on_theme_change(self):
         # FIXME: this should be moved out to a view model
         # FIXME: this should be moved out to a view model
         val = self.theme_field.get_value()
         val = self.theme_field.get_value()
@@ -232,156 +229,13 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
         self.app.on_app_restart()
         self.app.on_app_restart()
 
 
     def on_layout(self, index=None, lay=None):
     def on_layout(self, index=None, lay=None):
-        # FIXME: this should be moved out somewhere else
-        """
-        Set the toolbars layout (location)
-
-        :param index:
-        :param lay:     Type of layout to be set on the toolbard
-        :return:        None
-        """
-
-        self.app.defaults.report_usage("on_layout()")
         if lay:
         if lay:
             current_layout = lay
             current_layout = lay
         else:
         else:
             current_layout = self.layout_field.get_value()
             current_layout = self.layout_field.get_value()
+        self.app.ui.set_layout(current_layout)
 
 
-        lay_settings = QSettings("Open Source", "FlatCAM")
-        lay_settings.setValue('layout', current_layout)
-
-        # This will write the setting to the platform specific storage.
-        del lay_settings
-
-        # first remove the toolbars:
-        try:
-            self.app.ui.removeToolBar(self.app.ui.toolbarfile)
-            self.app.ui.removeToolBar(self.app.ui.toolbargeo)
-            self.app.ui.removeToolBar(self.app.ui.toolbarview)
-            self.app.ui.removeToolBar(self.app.ui.toolbarshell)
-            self.app.ui.removeToolBar(self.app.ui.toolbartools)
-            self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
-            self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
-            self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
-            self.app.ui.removeToolBar(self.app.ui.snap_toolbar)
-            self.app.ui.removeToolBar(self.app.ui.toolbarshell)
-        except Exception:
-            pass
-
-        if current_layout == 'compact':
-            # ## TOOLBAR INSTALLATION # ##
-            self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
-            self.app.ui.toolbarfile.setObjectName('File_TB')
-            self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
-
-            self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
-            self.app.ui.toolbargeo.setObjectName('Edit_TB')
-            self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
-
-            self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
-            self.app.ui.toolbarshell.setObjectName('Shell_TB')
-            self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
-
-            self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
-            self.app.ui.toolbartools.setObjectName('Tools_TB')
-            self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
-
-            self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
-            # self.app.ui.geo_edit_toolbar.setVisible(False)
-            self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
-            self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
-
-            self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
-            self.app.ui.toolbarview.setObjectName('View_TB')
-            self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
-
-            self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
-
-            self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
-            # self.app.ui.grb_edit_toolbar.setVisible(False)
-            self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
-            self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
-
-            self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
-            self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
-            self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
-
-            self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
-            self.app.ui.snap_toolbar.setObjectName('Snap_TB')
-            self.app.ui.snap_toolbar.setMaximumHeight(30)
-            self.app.ui.splitter_left.addWidget(self.app.ui.snap_toolbar)
-
-            self.app.ui.corner_snap_btn.setVisible(True)
-            self.app.ui.snap_magnet.setVisible(True)
-        else:
-            # ## TOOLBAR INSTALLATION # ##
-            self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
-            self.app.ui.toolbarfile.setObjectName('File_TB')
-            self.app.ui.addToolBar(self.app.ui.toolbarfile)
-
-            self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
-            self.app.ui.toolbargeo.setObjectName('Edit_TB')
-            self.app.ui.addToolBar(self.app.ui.toolbargeo)
-
-            self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
-            self.app.ui.toolbarview.setObjectName('View_TB')
-            self.app.ui.addToolBar(self.app.ui.toolbarview)
-
-            self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
-            self.app.ui.toolbarshell.setObjectName('Shell_TB')
-            self.app.ui.addToolBar(self.app.ui.toolbarshell)
-
-            self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
-            self.app.ui.toolbartools.setObjectName('Tools_TB')
-            self.app.ui.addToolBar(self.app.ui.toolbartools)
-
-            self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
-            # self.app.ui.exc_edit_toolbar.setVisible(False)
-            self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
-            self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
-
-            self.app.ui.addToolBarBreak()
-
-            self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
-            # self.app.ui.geo_edit_toolbar.setVisible(False)
-            self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
-            self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
-
-            self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
-            # self.app.ui.grb_edit_toolbar.setVisible(False)
-            self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
-            self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
-
-            self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
-            self.app.ui.snap_toolbar.setObjectName('Snap_TB')
-            # self.app.ui.snap_toolbar.setMaximumHeight(30)
-            self.app.ui.addToolBar(self.app.ui.snap_toolbar)
-
-            self.app.ui.corner_snap_btn.setVisible(False)
-            self.app.ui.snap_magnet.setVisible(False)
-
-        if current_layout == 'minimal':
-            self.app.ui.toolbarview.setVisible(False)
-            self.app.ui.toolbarshell.setVisible(False)
-            self.app.ui.snap_toolbar.setVisible(False)
-            self.app.ui.geo_edit_toolbar.setVisible(False)
-            self.app.ui.grb_edit_toolbar.setVisible(False)
-            self.app.ui.exc_edit_toolbar.setVisible(False)
-            self.app.ui.lock_toolbar(lock=True)
-
-        # add all the actions to the toolbars
-        self.app.ui.populate_toolbars()
-
-        # reconnect all the signals to the toolbar actions
-        self.app.connect_toolbar_signals()
-
-        self.app.ui.grid_snap_btn.setChecked(True)
-        self.app.ui.on_grid_snap_triggered(state=True)
 
 
-        self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
-        self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
-        self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
-        self.app.ui.grid_gap_link_cb.setChecked(True)
 
 
     @staticmethod
     @staticmethod
     def handle_style(style):
     def handle_style(style):

+ 4 - 5
flatcamGUI/preferences/general/GeneralPreferencesUI.py

@@ -8,15 +8,14 @@ from flatcamGUI.preferences.general.GeneralGUIPrefGroupUI import GeneralGUIPrefG
 class GeneralPreferencesUI(PreferencesSectionUI):
 class GeneralPreferencesUI(PreferencesSectionUI):
 
 
     def __init__(self, decimals, **kwargs):
     def __init__(self, decimals, **kwargs):
-        self.general_app_group = GeneralAppPrefGroupUI(decimals=decimals)
-        self.general_gui_group = GeneralGUIPrefGroupUI(decimals=decimals)
-        self.general_app_settings_group = GeneralAppSettingsGroupUI(decimals=decimals)
+        self.decimals = decimals
+        self.general_gui_group = GeneralGUIPrefGroupUI(decimals=self.decimals)
         super().__init__(**kwargs)
         super().__init__(**kwargs)
 
 
     def build_groups(self) -> [OptionsGroupUI]:
     def build_groups(self) -> [OptionsGroupUI]:
         return [
         return [
-            self.general_app_group,
+            GeneralAppPrefGroupUI(decimals=self.decimals),
             self.general_gui_group,
             self.general_gui_group,
-            self.general_app_settings_group
+            GeneralAppSettingsGroupUI(decimals=self.decimals)
         ]
         ]