diff --git a/FlatCAMApp.py b/FlatCAMApp.py index eeac19f7..f960f2e7 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -963,19 +963,22 @@ class App(QtCore.QObject): lambda: self.on_toggle_units(no_pref=False)) # ##################################### Workspace Setting Signals ########################################### - self.ui.general_defaults_form.general_app_set_group.wk_cb.currentIndexChanged.connect( + + + self.preferencesUiManager.option_dict()["global_workspaceT"].get_field().currentIndexChanged.connect( self.on_workspace_modified) - self.ui.general_defaults_form.general_app_set_group.wk_orientation_radio.activated_custom.connect( + self.preferencesUiManager.option_dict()["global_workspace_orientation"].get_field().activated_custom.connect( self.on_workspace_modified ) + self.preferencesUiManager.option_dict()["global_workspace"].get_field().stateChanged.connect(self.on_workspace) - self.ui.general_defaults_form.general_app_set_group.workspace_cb.stateChanged.connect(self.on_workspace) # ########################################################################################################### # ######################################## GUI SETTINGS SIGNALS ############################################# # ########################################################################################################### self.ui.general_defaults_form.general_app_group.ge_radio.activated_custom.connect(self.on_app_restart) - self.ui.general_defaults_form.general_app_set_group.cursor_radio.activated_custom.connect(self.on_cursor_type) + + self.preferencesUiManager.get_form_field("global_cursor_type").activated_custom.connect(self.on_cursor_type) # ######################################## Tools related signals ############################################ # Film Tool @@ -3563,20 +3566,20 @@ class App(QtCore.QObject): ) stgs.setValue( 'notebook_font_size', - self.ui.general_defaults_form.general_app_set_group.notebook_font_size_spinner.get_value() + self.preferencesUiManager.get_form_field("notebook_font_size").get_value() ) stgs.setValue( 'axis_font_size', - self.ui.general_defaults_form.general_app_set_group.axis_font_size_spinner.get_value() + self.preferencesUiManager.get_form_field("axis_font_size").get_value() ) stgs.setValue( 'textbox_font_size', - self.ui.general_defaults_form.general_app_set_group.textbox_font_size_spinner.get_value() + self.preferencesUiManager.get_form_field("textbox_font_size").get_value() ) stgs.setValue('toolbar_lock', self.ui.lock_action.isChecked()) stgs.setValue( 'machinist', - 1 if self.ui.general_defaults_form.general_app_set_group.machinist_cb.get_value() else 0 + 1 if self.preferencesUiManager.get_form_field("global_machinist_setting").get_value() else 0 ) # This will write the setting to the platform specific storage. @@ -4951,7 +4954,7 @@ class App(QtCore.QObject): self.plotcanvas.draw_workspace(workspace_size=self.defaults['global_workspaceT']) def on_workspace(self): - if self.ui.general_defaults_form.general_app_set_group.workspace_cb.get_value(): + if self.preferencesUiManager.option_dict()["global_workspace"].get_field().get_value(): self.plotcanvas.draw_workspace(workspace_size=self.defaults['global_workspaceT']) else: self.plotcanvas.delete_workspace() @@ -4959,13 +4962,13 @@ class App(QtCore.QObject): # self.save_defaults(silent=True) def on_workspace_toggle(self): - state = False if self.ui.general_defaults_form.general_app_set_group.workspace_cb.get_value() else True + state = False if self.preferencesUiManager.option_dict()["global_workspace"].get_field().get_value() else True try: - self.ui.general_defaults_form.general_app_set_group.workspace_cb.stateChanged.disconnect(self.on_workspace) + self.preferencesUiManager.option_dict()["global_workspace"].get_field().stateChanged.disconnect(self.on_workspace) except TypeError: pass - self.ui.general_defaults_form.general_app_set_group.workspace_cb.set_value(state) - self.ui.general_defaults_form.general_app_set_group.workspace_cb.stateChanged.connect(self.on_workspace) + self.preferencesUiManager.option_dict()["global_workspace"].get_field().set_value(state) + self.preferencesUiManager.option_dict()["global_workspace"].get_field().stateChanged.connect(self.on_workspace) self.on_workspace() def on_cursor_type(self, val): @@ -4977,12 +4980,12 @@ class App(QtCore.QObject): self.app_cursor.enabled = False if val == 'small': - self.ui.general_defaults_form.general_app_set_group.cursor_size_entry.setDisabled(False) - self.ui.general_defaults_form.general_app_set_group.cursor_size_lbl.setDisabled(False) + self.preferencesUiManager.get_form_field("global_cursor_size").setDisabled(False) + #self.ui.general_defaults_form.general_app_set_group.cursor_size_lbl.setDisabled(False) self.app_cursor = self.plotcanvas.new_cursor() else: - self.ui.general_defaults_form.general_app_set_group.cursor_size_entry.setDisabled(True) - self.ui.general_defaults_form.general_app_set_group.cursor_size_lbl.setDisabled(True) + self.preferencesUiManager.get_form_field("global_cursor_size").setDisabled(False) + #self.ui.general_defaults_form.general_app_set_group.cursor_size_lbl.setDisabled(True) self.app_cursor = self.plotcanvas.new_cursor(big=True) if self.ui.grid_snap_btn.isChecked(): diff --git a/flatcamGUI/preferences/OptionUI.py b/flatcamGUI/preferences/OptionUI.py index c7e829b2..bec4247c 100644 --- a/flatcamGUI/preferences/OptionUI.py +++ b/flatcamGUI/preferences/OptionUI.py @@ -1,4 +1,4 @@ -from typing import Union +from typing import Union, Sequence from PyQt5 import QtWidgets from flatcamGUI.GUIElements import RadioSet, FCCheckBox, FCButton, FCComboBox, FCEntry, FCSpinner, FCColorEntry, \ @@ -89,7 +89,7 @@ class CheckboxOptionUI(OptionUI): class ComboboxOptionUI(BasicOptionUI): - def __init__(self, option: str, label_text: str, label_tooltip: str, choices: list): + def __init__(self, option: str, label_text: str, label_tooltip: str, choices: Sequence): self.choices = choices super().__init__(option=option, label_text=label_text, label_tooltip=label_tooltip) @@ -119,6 +119,21 @@ class SliderWithSpinnerOptionUI(BasicOptionUI): return entry +class SpinnerOptionUI(BasicOptionUI): + def __init__(self, option: str, label_text: str, label_tooltip: str, min_value: int, max_value: int, step: int = 1): + self.min_value = min_value + self.max_value = max_value + self.step = step + super().__init__(option=option, label_text=label_text, label_tooltip=label_tooltip) + + def build_entry_widget(self) -> QtWidgets.QWidget: + entry = FCSpinner() + entry.set_range(self.min_value, self.max_value) + entry.set_step(self.step) + entry.setWrapping(True) + return entry + + class DoubleSpinnerOptionUI(BasicOptionUI): def __init__(self, option: str, label_text: str, label_tooltip: str, step: float, decimals: int, min_value=None, max_value=None): self.min_value = min_value diff --git a/flatcamGUI/preferences/PreferencesUIManager.py b/flatcamGUI/preferences/PreferencesUIManager.py index 86fc57fb..3234e251 100644 --- a/flatcamGUI/preferences/PreferencesUIManager.py +++ b/flatcamGUI/preferences/PreferencesUIManager.py @@ -76,29 +76,6 @@ class PreferencesUIManager: "global_tpdf_lmargin": self.ui.general_defaults_form.general_app_group.lmargin_entry, "global_tpdf_rmargin": self.ui.general_defaults_form.general_app_group.rmargin_entry, - # General GUI Settings - "global_gridx": self.ui.general_defaults_form.general_app_set_group.gridx_entry, - "global_gridy": self.ui.general_defaults_form.general_app_set_group.gridy_entry, - "global_snap_max": self.ui.general_defaults_form.general_app_set_group.snap_max_dist_entry, - "global_workspace": self.ui.general_defaults_form.general_app_set_group.workspace_cb, - "global_workspaceT": self.ui.general_defaults_form.general_app_set_group.wk_cb, - "global_workspace_orientation": self.ui.general_defaults_form.general_app_set_group.wk_orientation_radio, - - "global_cursor_type": self.ui.general_defaults_form.general_app_set_group.cursor_radio, - "global_cursor_size": self.ui.general_defaults_form.general_app_set_group.cursor_size_entry, - "global_cursor_width": self.ui.general_defaults_form.general_app_set_group.cursor_width_entry, - "global_cursor_color_enabled": self.ui.general_defaults_form.general_app_set_group.mouse_cursor_color_cb, - "global_cursor_color": self.ui.general_defaults_form.general_app_set_group.mouse_cursor_entry, - "global_pan_button": self.ui.general_defaults_form.general_app_set_group.pan_button_radio, - "global_mselect_key": self.ui.general_defaults_form.general_app_set_group.mselect_radio, - "global_delete_confirmation": self.ui.general_defaults_form.general_app_set_group.delete_conf_cb, - "global_open_style": self.ui.general_defaults_form.general_app_set_group.open_style_cb, - "global_toggle_tooltips": self.ui.general_defaults_form.general_app_set_group.toggle_tooltips_cb, - "global_machinist_setting": self.ui.general_defaults_form.general_app_set_group.machinist_cb, - - "global_bookmarks_limit": self.ui.general_defaults_form.general_app_set_group.bm_limit_spinner, - "global_activity_icon": self.ui.general_defaults_form.general_app_set_group.activity_combo, - # Gerber General "gerber_plot": self.ui.gerber_defaults_form.gerber_gen_group.plot_cb, "gerber_solid": self.ui.gerber_defaults_form.gerber_gen_group.solid_cb, @@ -774,12 +751,7 @@ class PreferencesUIManager: "background-color:%s;" "border-color: dimgray" % str(self.defaults['cncjob_plot_line'])[:7]) - # Init Project Disabled Items color - self.ui.general_defaults_form.general_app_set_group.mouse_cursor_entry.set_value( - self.defaults['global_cursor_color']) - self.ui.general_defaults_form.general_app_set_group.mouse_cursor_button.setStyleSheet( - "background-color:%s;" - "border-color: dimgray" % str(self.defaults['global_cursor_color'])[:7]) + # Init the Annotation CNC Job color self.ui.cncjob_defaults_form.cncjob_adv_opt_group.annotation_fontcolor_entry.set_value( @@ -839,20 +811,20 @@ class PreferencesUIManager: settgs = QSettings("Open Source", "FlatCAM") # save the notebook font size - fsize = self.ui.general_defaults_form.general_app_set_group.notebook_font_size_spinner.get_value() + fsize = self.get_form_field("notebook_font_size").get_value() settgs.setValue('notebook_font_size', fsize) # save the axis font size - g_fsize = self.ui.general_defaults_form.general_app_set_group.axis_font_size_spinner.get_value() + g_fsize = self.get_form_field("axis_font_size").get_value() settgs.setValue('axis_font_size', g_fsize) # save the textbox font size - tb_fsize = self.ui.general_defaults_form.general_app_set_group.textbox_font_size_spinner.get_value() + tb_fsize = self.get_form_field("textbox_font_size").get_value() settgs.setValue('textbox_font_size', tb_fsize) settgs.setValue( 'machinist', - 1 if self.ui.general_defaults_form.general_app_set_group.machinist_cb.get_value() else 0 + 1 if self.get_form_field("global_machinist_setting").get_value() else 0 ) # This will write the setting to the platform specific storage. diff --git a/flatcamGUI/preferences/general/GeneralAPPSetGroupUI.py b/flatcamGUI/preferences/general/GeneralAPPSetGroupUI.py deleted file mode 100644 index 11c7a784..00000000 --- a/flatcamGUI/preferences/general/GeneralAPPSetGroupUI.py +++ /dev/null @@ -1,483 +0,0 @@ -from PyQt5 import QtCore, QtWidgets, QtGui -from PyQt5.QtCore import QSettings - -from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCComboBox, RadioSet, OptionalInputSection, FCSpinner, \ - FCEntry -from flatcamGUI.preferences import settings -from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI - -import gettext -import FlatCAMTranslation as fcTranslate -import builtins - -fcTranslate.apply_language('strings') -if '_' not in builtins.__dict__: - _ = gettext.gettext - -settings = QSettings("Open Source", "FlatCAM") -if settings.contains("machinist"): - machinist_setting = settings.value('machinist', type=int) -else: - machinist_setting = 0 - - -class GeneralAPPSetGroupUI(OptionsGroupUI): - def __init__(self, decimals=4, **kwargs): - super().__init__(**kwargs) - - self.setTitle(str(_("App Settings"))) - self.decimals = decimals - - theme_settings = QtCore.QSettings("Open Source", "FlatCAM") - if theme_settings.contains("theme"): - theme = theme_settings.value('theme', type=str) - else: - theme = 'white' - - if theme == 'white': - self.resource_loc = 'assets/resources' - else: - self.resource_loc = 'assets/resources' - - # Create a grid layout for the Application general settings - grid0 = QtWidgets.QGridLayout() - self.layout.addLayout(grid0) - grid0.setColumnStretch(0, 0) - grid0.setColumnStretch(1, 1) - - # GRID Settings - self.grid_label = QtWidgets.QLabel('%s' % _('Grid Settings')) - grid0.addWidget(self.grid_label, 0, 0, 1, 2) - - # Grid X Entry - self.gridx_label = QtWidgets.QLabel('%s:' % _('X value')) - self.gridx_label.setToolTip( - _("This is the Grid snap value on X axis.") - ) - self.gridx_entry = FCDoubleSpinner() - self.gridx_entry.set_precision(self.decimals) - self.gridx_entry.setSingleStep(0.1) - - grid0.addWidget(self.gridx_label, 1, 0) - grid0.addWidget(self.gridx_entry, 1, 1) - - # Grid Y Entry - self.gridy_label = QtWidgets.QLabel('%s:' % _('Y value')) - self.gridy_label.setToolTip( - _("This is the Grid snap value on Y axis.") - ) - self.gridy_entry = FCDoubleSpinner() - self.gridy_entry.set_precision(self.decimals) - self.gridy_entry.setSingleStep(0.1) - - grid0.addWidget(self.gridy_label, 2, 0) - grid0.addWidget(self.gridy_entry, 2, 1) - - # Snap Max Entry - self.snap_max_label = QtWidgets.QLabel('%s:' % _('Snap Max')) - self.snap_max_label.setToolTip(_("Max. magnet distance")) - self.snap_max_dist_entry = FCDoubleSpinner() - self.snap_max_dist_entry.set_precision(self.decimals) - self.snap_max_dist_entry.setSingleStep(0.1) - - grid0.addWidget(self.snap_max_label, 3, 0) - grid0.addWidget(self.snap_max_dist_entry, 3, 1) - - separator_line = QtWidgets.QFrame() - separator_line.setFrameShape(QtWidgets.QFrame.HLine) - separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid0.addWidget(separator_line, 4, 0, 1, 2) - - # Workspace - self.workspace_label = QtWidgets.QLabel('%s' % _('Workspace Settings')) - grid0.addWidget(self.workspace_label, 5, 0, 1, 2) - - self.workspace_cb = FCCheckBox('%s' % _('Active')) - self.workspace_cb.setToolTip( - _("Draw a delimiting rectangle on canvas.\n" - "The purpose is to illustrate the limits for our work.") - ) - - grid0.addWidget(self.workspace_cb, 6, 0, 1, 2) - - self.workspace_type_lbl = QtWidgets.QLabel('%s:' % _('Size')) - self.workspace_type_lbl.setToolTip( - _("Select the type of rectangle to be used on canvas,\n" - "as valid workspace.") - ) - self.wk_cb = FCComboBox() - - grid0.addWidget(self.workspace_type_lbl, 7, 0) - grid0.addWidget(self.wk_cb, 7, 1) - - self.pagesize = {} - self.pagesize.update( - { - 'A0': (841, 1189), - 'A1': (594, 841), - 'A2': (420, 594), - 'A3': (297, 420), - 'A4': (210, 297), - 'A5': (148, 210), - 'A6': (105, 148), - 'A7': (74, 105), - 'A8': (52, 74), - 'A9': (37, 52), - 'A10': (26, 37), - - 'B0': (1000, 1414), - 'B1': (707, 1000), - 'B2': (500, 707), - 'B3': (353, 500), - 'B4': (250, 353), - 'B5': (176, 250), - 'B6': (125, 176), - 'B7': (88, 125), - 'B8': (62, 88), - 'B9': (44, 62), - 'B10': (31, 44), - - 'C0': (917, 1297), - 'C1': (648, 917), - 'C2': (458, 648), - 'C3': (324, 458), - 'C4': (229, 324), - 'C5': (162, 229), - 'C6': (114, 162), - 'C7': (81, 114), - 'C8': (57, 81), - 'C9': (40, 57), - 'C10': (28, 40), - - # American paper sizes - 'LETTER': (8.5, 11), - 'LEGAL': (8.5, 14), - 'ELEVENSEVENTEEN': (11, 17), - - # From https://en.wikipedia.org/wiki/Paper_size - 'JUNIOR_LEGAL': (5, 8), - 'HALF_LETTER': (5.5, 8), - 'GOV_LETTER': (8, 10.5), - 'GOV_LEGAL': (8.5, 13), - 'LEDGER': (17, 11), - } - ) - - page_size_list = list(self.pagesize.keys()) - - self.wk_cb.addItems(page_size_list) - - # Page orientation - self.wk_orientation_label = QtWidgets.QLabel('%s:' % _("Orientation")) - self.wk_orientation_label.setToolTip(_("Can be:\n" - "- Portrait\n" - "- Landscape")) - - self.wk_orientation_radio = RadioSet([{'label': _('Portrait'), 'value': 'p'}, - {'label': _('Landscape'), 'value': 'l'}, - ], stretch=False) - - self.wks = OptionalInputSection(self.workspace_cb, - [ - self.workspace_type_lbl, - self.wk_cb, - self.wk_orientation_label, - self.wk_orientation_radio - ]) - - grid0.addWidget(self.wk_orientation_label, 8, 0) - grid0.addWidget(self.wk_orientation_radio, 8, 1) - - separator_line = QtWidgets.QFrame() - separator_line.setFrameShape(QtWidgets.QFrame.HLine) - separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid0.addWidget(separator_line, 9, 0, 1, 2) - - # Font Size - self.font_size_label = QtWidgets.QLabel('%s' % _('Font Size')) - grid0.addWidget(self.font_size_label, 10, 0, 1, 2) - - # Notebook Font Size - self.notebook_font_size_label = QtWidgets.QLabel('%s:' % _('Notebook')) - self.notebook_font_size_label.setToolTip( - _("This sets the font size for the elements found in the Notebook.\n" - "The notebook is the collapsible area in the left side of the GUI,\n" - "and include the Project, Selected and Tool tabs.") - ) - - self.notebook_font_size_spinner = FCSpinner() - self.notebook_font_size_spinner.set_range(8, 40) - self.notebook_font_size_spinner.setWrapping(True) - - qsettings = QSettings("Open Source", "FlatCAM") - if qsettings.contains("notebook_font_size"): - self.notebook_font_size_spinner.set_value(qsettings.value('notebook_font_size', type=int)) - else: - self.notebook_font_size_spinner.set_value(12) - - grid0.addWidget(self.notebook_font_size_label, 11, 0) - grid0.addWidget(self.notebook_font_size_spinner, 11, 1) - - # Axis Font Size - self.axis_font_size_label = QtWidgets.QLabel('%s:' % _('Axis')) - self.axis_font_size_label.setToolTip( - _("This sets the font size for canvas axis.") - ) - - self.axis_font_size_spinner = FCSpinner() - self.axis_font_size_spinner.set_range(0, 40) - self.axis_font_size_spinner.setWrapping(True) - - qsettings = QSettings("Open Source", "FlatCAM") - if qsettings.contains("axis_font_size"): - self.axis_font_size_spinner.set_value(qsettings.value('axis_font_size', type=int)) - else: - self.axis_font_size_spinner.set_value(8) - - grid0.addWidget(self.axis_font_size_label, 12, 0) - grid0.addWidget(self.axis_font_size_spinner, 12, 1) - - # TextBox Font Size - self.textbox_font_size_label = QtWidgets.QLabel('%s:' % _('Textbox')) - self.textbox_font_size_label.setToolTip( - _("This sets the font size for the Textbox GUI\n" - "elements that are used in FlatCAM.") - ) - - self.textbox_font_size_spinner = FCSpinner() - self.textbox_font_size_spinner.set_range(8, 40) - self.textbox_font_size_spinner.setWrapping(True) - - qsettings = QSettings("Open Source", "FlatCAM") - if qsettings.contains("textbox_font_size"): - self.textbox_font_size_spinner.set_value(settings.value('textbox_font_size', type=int)) - else: - self.textbox_font_size_spinner.set_value(10) - - grid0.addWidget(self.textbox_font_size_label, 13, 0) - grid0.addWidget(self.textbox_font_size_spinner, 13, 1) - - separator_line = QtWidgets.QFrame() - separator_line.setFrameShape(QtWidgets.QFrame.HLine) - separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid0.addWidget(separator_line, 14, 0, 1, 2) - - # ----------------------------------------------------------- - # -------------- MOUSE SETTINGS ----------------------------- - # ----------------------------------------------------------- - - self.mouse_lbl = QtWidgets.QLabel('%s' % _('Mouse Settings')) - grid0.addWidget(self.mouse_lbl, 21, 0, 1, 2) - - # Mouse Cursor Shape - self.cursor_lbl = QtWidgets.QLabel('%s:' % _('Cursor Shape')) - self.cursor_lbl.setToolTip( - _("Choose a mouse cursor shape.\n" - "- Small -> with a customizable size.\n" - "- Big -> Infinite lines") - ) - - self.cursor_radio = RadioSet([ - {"label": _("Small"), "value": "small"}, - {"label": _("Big"), "value": "big"} - ], orientation='horizontal', stretch=False) - - grid0.addWidget(self.cursor_lbl, 22, 0) - grid0.addWidget(self.cursor_radio, 22, 1) - - # Mouse Cursor Size - self.cursor_size_lbl = QtWidgets.QLabel('%s:' % _('Cursor Size')) - self.cursor_size_lbl.setToolTip( - _("Set the size of the mouse cursor, in pixels.") - ) - - self.cursor_size_entry = FCSpinner() - self.cursor_size_entry.set_range(10, 70) - self.cursor_size_entry.setWrapping(True) - - grid0.addWidget(self.cursor_size_lbl, 23, 0) - grid0.addWidget(self.cursor_size_entry, 23, 1) - - # Cursor Width - self.cursor_width_lbl = QtWidgets.QLabel('%s:' % _('Cursor Width')) - self.cursor_width_lbl.setToolTip( - _("Set the line width of the mouse cursor, in pixels.") - ) - - self.cursor_width_entry = FCSpinner() - self.cursor_width_entry.set_range(1, 10) - self.cursor_width_entry.setWrapping(True) - - grid0.addWidget(self.cursor_width_lbl, 24, 0) - grid0.addWidget(self.cursor_width_entry, 24, 1) - - # Cursor Color Enable - self.mouse_cursor_color_cb = FCCheckBox(label='%s' % _('Cursor Color')) - self.mouse_cursor_color_cb.setToolTip( - _("Check this box to color mouse cursor.") - ) - grid0.addWidget(self.mouse_cursor_color_cb, 25, 0, 1, 2) - - # Cursor Color - self.mouse_color_label = QtWidgets.QLabel('%s:' % _('Cursor Color')) - self.mouse_color_label.setToolTip( - _("Set the color of the mouse cursor.") - ) - self.mouse_cursor_entry = FCEntry() - self.mouse_cursor_button = QtWidgets.QPushButton() - self.mouse_cursor_button.setFixedSize(15, 15) - - self.form_box_child_1 = QtWidgets.QHBoxLayout() - self.form_box_child_1.addWidget(self.mouse_cursor_entry) - self.form_box_child_1.addWidget(self.mouse_cursor_button) - self.form_box_child_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) - - grid0.addWidget(self.mouse_color_label, 26, 0) - grid0.addLayout(self.form_box_child_1, 26, 1) - - self.mois = OptionalInputSection( - self.mouse_cursor_color_cb, - [ - self.mouse_color_label, - self.mouse_cursor_entry, - self.mouse_cursor_button - ] - ) - # Select mouse pan button - self.panbuttonlabel = QtWidgets.QLabel('%s:' % _('Pan Button')) - self.panbuttonlabel.setToolTip( - _("Select the mouse button to use for panning:\n" - "- MMB --> Middle Mouse Button\n" - "- RMB --> Right Mouse Button") - ) - self.pan_button_radio = RadioSet([{'label': _('MMB'), 'value': '3'}, - {'label': _('RMB'), 'value': '2'}]) - - grid0.addWidget(self.panbuttonlabel, 27, 0) - grid0.addWidget(self.pan_button_radio, 27, 1) - - # Multiple Selection Modifier Key - self.mselectlabel = QtWidgets.QLabel('%s:' % _('Multiple Selection')) - self.mselectlabel.setToolTip( - _("Select the key used for multiple selection.") - ) - self.mselect_radio = RadioSet([{'label': _('CTRL'), 'value': 'Control'}, - {'label': _('SHIFT'), 'value': 'Shift'}]) - - grid0.addWidget(self.mselectlabel, 28, 0) - grid0.addWidget(self.mselect_radio, 28, 1) - - separator_line = QtWidgets.QFrame() - separator_line.setFrameShape(QtWidgets.QFrame.HLine) - separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) - grid0.addWidget(separator_line, 29, 0, 1, 2) - - # Delete confirmation - self.delete_conf_cb = FCCheckBox(_('Delete object confirmation')) - self.delete_conf_cb.setToolTip( - _("When checked the application will ask for user confirmation\n" - "whenever the Delete object(s) event is triggered, either by\n" - "menu shortcut or key shortcut.") - ) - grid0.addWidget(self.delete_conf_cb, 30, 0, 1, 2) - - # Open behavior - self.open_style_cb = FCCheckBox('%s' % _('"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.") - ) - - grid0.addWidget(self.open_style_cb, 31, 0, 1, 2) - - # Enable/Disable ToolTips globally - self.toggle_tooltips_cb = FCCheckBox(label=_('Enable ToolTips')) - 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.") - ) - - grid0.addWidget(self.toggle_tooltips_cb, 32, 0, 1, 2) - - # Machinist settings that allow unsafe settings - self.machinist_cb = FCCheckBox(_("Allow Machinist Unsafe Settings")) - self.machinist_cb.setToolTip( - _("If checked, some of the application settings will be allowed\n" - "to have values that are usually unsafe to use.\n" - "Like Z travel negative values or Z Cut positive values.\n" - "It will applied at the next application start.\n" - "<>: Don't change this unless you know what you are doing !!!") - ) - - grid0.addWidget(self.machinist_cb, 33, 0, 1, 2) - - # Bookmarks Limit in the Help Menu - self.bm_limit_spinner = FCSpinner() - self.bm_limit_spinner.set_range(0, 9999) - self.bm_limit_label = QtWidgets.QLabel('%s:' % _('Bookmarks limit')) - self.bm_limit_label.setToolTip( - _("The maximum number of bookmarks that may be installed in the menu.\n" - "The number of bookmarks in the bookmark manager may be greater\n" - "but the menu will hold only so much.") - ) - - grid0.addWidget(self.bm_limit_label, 34, 0) - grid0.addWidget(self.bm_limit_spinner, 34, 1) - - # Activity monitor icon - self.activity_label = QtWidgets.QLabel('%s:' % _("Activity Icon")) - self.activity_label.setToolTip( - _("Select the GIF that show activity when FlatCAM is active.") - ) - self.activity_combo = FCComboBox() - self.activity_combo.addItems(['Ball black', 'Ball green', 'Arrow green', 'Eclipse green']) - - grid0.addWidget(self.activity_label, 35, 0) - grid0.addWidget(self.activity_combo, 35, 1) - - self.layout.addStretch() - - self.mouse_cursor_color_cb.stateChanged.connect(self.on_mouse_cursor_color_enable) - - self.mouse_cursor_entry.editingFinished.connect(self.on_mouse_cursor_entry) - self.mouse_cursor_button.clicked.connect(self.on_mouse_cursor_button) - - def on_mouse_cursor_color_enable(self, val): - if val: - self.app.cursor_color_3D = self.app.defaults["global_cursor_color"] - else: - theme_settings = QtCore.QSettings("Open Source", "FlatCAM") - if theme_settings.contains("theme"): - theme = theme_settings.value('theme', type=str) - else: - theme = 'white' - - if theme == 'white': - self.app.cursor_color_3D = 'black' - else: - self.app.cursor_color_3D = 'gray' - - def on_mouse_cursor_entry(self): - self.app.defaults['global_cursor_color'] = self.mouse_cursor_entry.get_value() - self.mouse_cursor_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_cursor_color'])) - - self.app.cursor_color_3D = self.app.defaults["global_cursor_color"] - - def on_mouse_cursor_button(self): - current_color = QtGui.QColor(self.app.defaults['global_cursor_color']) - - c_dialog = QtWidgets.QColorDialog() - proj_color = c_dialog.getColor(initial=current_color) - - if proj_color.isValid() is False: - return - - self.mouse_cursor_button.setStyleSheet("background-color:%s" % str(proj_color.name())) - - new_val_sel = str(proj_color.name()) - self.mouse_cursor_entry.set_value(new_val_sel) - self.app.defaults['global_cursor_color'] = new_val_sel - - self.app.cursor_color_3D = self.app.defaults["global_cursor_color"] diff --git a/flatcamGUI/preferences/general/GeneralAppSettingsGroupUI.py b/flatcamGUI/preferences/general/GeneralAppSettingsGroupUI.py new file mode 100644 index 00000000..a3cd4f20 --- /dev/null +++ b/flatcamGUI/preferences/general/GeneralAppSettingsGroupUI.py @@ -0,0 +1,301 @@ +from PyQt5 import QtCore, QtGui +from PyQt5.QtCore import QSettings +from flatcamGUI.GUIElements import OptionalInputSection +from flatcamGUI.preferences import settings +from flatcamGUI.preferences.OptionUI import * +from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI, OptionsGroupUI2 + +import gettext +import FlatCAMTranslation as fcTranslate +import builtins +fcTranslate.apply_language('strings') +if '_' not in builtins.__dict__: + _ = gettext.gettext + + +class GeneralAppSettingsGroupUI(OptionsGroupUI2): + def __init__(self, decimals=4, **kwargs): + self.decimals = decimals + self.pagesize = {} + self.pagesize.update( + { + 'A0': (841, 1189), + 'A1': (594, 841), + 'A2': (420, 594), + 'A3': (297, 420), + 'A4': (210, 297), + 'A5': (148, 210), + 'A6': (105, 148), + 'A7': (74, 105), + 'A8': (52, 74), + 'A9': (37, 52), + 'A10': (26, 37), + + 'B0': (1000, 1414), + 'B1': (707, 1000), + 'B2': (500, 707), + 'B3': (353, 500), + 'B4': (250, 353), + 'B5': (176, 250), + 'B6': (125, 176), + 'B7': (88, 125), + 'B8': (62, 88), + 'B9': (44, 62), + 'B10': (31, 44), + + 'C0': (917, 1297), + 'C1': (648, 917), + 'C2': (458, 648), + 'C3': (324, 458), + 'C4': (229, 324), + 'C5': (162, 229), + 'C6': (114, 162), + 'C7': (81, 114), + 'C8': (57, 81), + 'C9': (40, 57), + 'C10': (28, 40), + + # American paper sizes + 'LETTER': (8.5, 11), + 'LEGAL': (8.5, 14), + 'ELEVENSEVENTEEN': (11, 17), + + # From https://en.wikipedia.org/wiki/Paper_size + 'JUNIOR_LEGAL': (5, 8), + 'HALF_LETTER': (5.5, 8), + 'GOV_LETTER': (8, 10.5), + 'GOV_LEGAL': (8.5, 13), + 'LEDGER': (17, 11), + } + ) + super().__init__(**kwargs) + + self.setTitle(str(_("App Settings"))) + + qsettings = QSettings("Open Source", "FlatCAM") + + self.notebook_font_size_field = self.option_dict()["notebook_font_size"].get_field() + if qsettings.contains("notebook_font_size"): + self.notebook_font_size_field.set_value(qsettings.value('notebook_font_size', type=int)) + else: + self.notebook_font_size_field.set_value(12) + + self.axis_font_size_field = self.option_dict()["axis_font_size"].get_field() + if qsettings.contains("axis_font_size"): + self.axis_font_size_field.set_value(qsettings.value('axis_font_size', type=int)) + else: + self.axis_font_size_field.set_value(8) + + self.textbox_font_size_field = self.option_dict()["textbox_font_size"].get_field() + if qsettings.contains("textbox_font_size"): + self.textbox_font_size_field.set_value(settings.value('textbox_font_size', type=int)) + else: + self.textbox_font_size_field.set_value(10) + + self.workspace_enabled_field = self.option_dict()["global_workspace"].get_field() + self.workspace_type_field = self.option_dict()["global_workspaceT"].get_field() + self.workspace_type_label = self.option_dict()["global_workspaceT"].label_widget + self.workspace_orientation_field = self.option_dict()["global_workspace_orientation"].get_field() + self.workspace_orientation_label = self.option_dict()["global_workspace_orientation"].label_widget + self.wks = OptionalInputSection(self.workspace_enabled_field, [self.workspace_type_label, self.workspace_type_field, self.workspace_orientation_label, self.workspace_orientation_field]) + + self.mouse_cursor_color_enabled_field = self.option_dict()["global_cursor_color_enabled"].get_field() + self.mouse_cursor_color_field = self.option_dict()["global_cursor_color"].get_field() + self.mouse_cursor_color_label = self.option_dict()["global_cursor_color"].label_widget + self.mois = OptionalInputSection(self.mouse_cursor_color_enabled_field, [self.mouse_cursor_color_label, self.mouse_cursor_color_field]) + self.mouse_cursor_color_enabled_field.stateChanged.connect(self.on_mouse_cursor_color_enable) + self.mouse_cursor_color_field.entry.editingFinished.connect(self.on_mouse_cursor_entry) + + def build_options(self) -> [OptionUI]: + return [ + HeadingOptionUI(label_text="Grid Settings", label_tooltip=None), + DoubleSpinnerOptionUI( + option="global_gridx", + label_text="X value", + label_tooltip="This is the Grid snap value on X axis.", + step=0.1, + decimals=self.decimals + ), + DoubleSpinnerOptionUI( + option="global_gridy", + label_text='Y value', + label_tooltip="This is the Grid snap value on Y axis.", + step=0.1, + decimals=self.decimals + ), + DoubleSpinnerOptionUI( + option="global_snap_max", + label_text="Snap Max", + label_tooltip="Max. magnet distance", + step=0.1, + decimals=self.decimals + ), + SeparatorOptionUI(), + + HeadingOptionUI(label_text="Workspace Settings", label_tooltip=None), + CheckboxOptionUI( + option="global_workspace", + label_text="Active", + label_tooltip="Draw a delimiting rectangle on canvas.\n" + "The purpose is to illustrate the limits for our work." + ), + ComboboxOptionUI( + option="global_workspaceT", + label_text="Size", + label_tooltip="Select the type of rectangle to be used on canvas,\nas valid workspace.", + choices=list(self.pagesize.keys()) + ), + RadioSetOptionUI( + option="global_workspace_orientation", + label_text="Orientation", + label_tooltip="Can be:\n- Portrait\n- Landscape", + choices=[ + {'label': _('Portrait'), 'value': 'p'}, + {'label': _('Landscape'), 'value': 'l'}, + ] + ), + # FIXME enabling OptionalInputSection ?? + SeparatorOptionUI(), + + HeadingOptionUI(label_text="Font Size", label_tooltip=None), + SpinnerOptionUI( + option="notebook_font_size", #FIXME qsettings + label_text="Notebook", + label_tooltip="This sets the font size for the elements found in the Notebook.\n" + "The notebook is the collapsible area in the left side of the GUI,\n" + "and include the Project, Selected and Tool tabs.", + min_value=8, max_value=40, step=1 + ), + SpinnerOptionUI( + option="axis_font_size", #FIXME qsettings + label_text="Axis", + label_tooltip="This sets the font size for canvas axis.", + min_value=8, max_value=40, step=1 + ), + SpinnerOptionUI( + option="textbox_font_size", #FIXME qsettings, + label_text="Textbox", + label_tooltip="This sets the font size for the Textbox GUI\n" + "elements that are used in FlatCAM.", + min_value=8, max_value=40, step=1 + ), + SeparatorOptionUI(), + + HeadingOptionUI(label_text="Mouse Settings", label_tooltip=None), + RadioSetOptionUI( + option="global_cursor_type", + label_text="Cursor Shape", + label_tooltip="Choose a mouse cursor shape.\n" + "- Small -> with a customizable size.\n" + "- Big -> Infinite lines", + choices=[ + {"label": _("Small"), "value": "small"}, + {"label": _("Big"), "value": "big"} + ] + ), + SpinnerOptionUI( + option="global_cursor_size", + label_text="Cursor Size", + label_tooltip="Set the size of the mouse cursor, in pixels.", + min_value=10, max_value=70, step=1 + ), + SpinnerOptionUI( + option="global_cursor_width", + label_text="Cursor Width", + label_tooltip="Set the line width of the mouse cursor, in pixels.", + min_value=1, max_value=10, step=1 + ), + CheckboxOptionUI( + option="global_cursor_color_enabled", + label_text="Cursor Color", + label_tooltip="Check this box to color mouse cursor." + ), + ColorOptionUI( + option="global_cursor_color", + label_text="Cursor Color", + label_tooltip="Set the color of the mouse cursor." + ), + # FIXME enabling of cursor color + RadioSetOptionUI( + option="global_pan_button", + label_text="Pan Button", + label_tooltip="Select the mouse button to use for panning:\n" + "- MMB --> Middle Mouse Button\n" + "- RMB --> Right Mouse Button", + choices=[{'label': _('MMB'), 'value': '3'}, + {'label': _('RMB'), 'value': '2'}] + ), + RadioSetOptionUI( + option="global_mselect_key", + label_text="Multiple Selection", + label_tooltip="Select the key used for multiple selection.", + choices=[{'label': _('CTRL'), 'value': 'Control'}, + {'label': _('SHIFT'), 'value': 'Shift'}] + ), + SeparatorOptionUI(), + + CheckboxOptionUI( + option="global_delete_confirmation", + label_text="Delete object confirmation", + label_tooltip="When checked the application will ask for user confirmation\n" + "whenever the Delete object(s) event is triggered, either by\n" + "menu shortcut or key shortcut." + ), + CheckboxOptionUI( + option="global_open_style", + label_text='"Open" behavior', + label_tooltip="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." + ), + CheckboxOptionUI( + option="global_toggle_tooltips", + label_text="Enable ToolTips", + label_tooltip="Check this box if you want to have toolTips displayed\n" + "when hovering with mouse over items throughout the App." + ), + CheckboxOptionUI( + option="global_machinist_setting", + label_text="Allow Machinist Unsafe Settings", + label_tooltip="If checked, some of the application settings will be allowed\n" + "to have values that are usually unsafe to use.\n" + "Like Z travel negative values or Z Cut positive values.\n" + "It will applied at the next application start.\n" + "<>: Don't change this unless you know what you are doing !!!" + ), + SpinnerOptionUI( + option="global_bookmarks_limit", + label_text="Bookmarks limit", + label_tooltip="The maximum number of bookmarks that may be installed in the menu.\n" + "The number of bookmarks in the bookmark manager may be greater\n" + "but the menu will hold only so much.", + min_value=0, max_value=9999, step=1 + ), + ComboboxOptionUI( + option="global_activity_icon", + label_text="Activity Icon", + label_tooltip="Select the GIF that show activity when FlatCAM is active.", + choices=['Ball black', 'Ball green', 'Arrow green', 'Eclipse green'] + ) + + ] + + def on_mouse_cursor_color_enable(self, val): + if val: + self.app.cursor_color_3D = self.app.defaults["global_cursor_color"] + else: + theme_settings = QtCore.QSettings("Open Source", "FlatCAM") + if theme_settings.contains("theme"): + theme = theme_settings.value('theme', type=str) + else: + theme = 'white' + + if theme == 'white': + self.app.cursor_color_3D = 'black' + else: + self.app.cursor_color_3D = 'gray' + + def on_mouse_cursor_entry(self): + self.app.defaults['global_cursor_color'] = self.mouse_cursor_color_field.get_value() + self.app.cursor_color_3D = self.app.defaults["global_cursor_color"] diff --git a/flatcamGUI/preferences/general/GeneralGUIPrefGroupUI.py b/flatcamGUI/preferences/general/GeneralGUIPrefGroupUI.py index 668c8780..8b77cce6 100644 --- a/flatcamGUI/preferences/general/GeneralGUIPrefGroupUI.py +++ b/flatcamGUI/preferences/general/GeneralGUIPrefGroupUI.py @@ -51,7 +51,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2): self.alt_sel_alpha_field = self.option_dict()["_global_alt_sel_alpha"].get_field() self.alt_sel_alpha_field.spinner.valueChanged.connect(self.on_alt_sel_alpha_change) - def build_options(self) -> [OptionUI]: return [ RadioSetOptionUI( @@ -132,7 +131,7 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2): option="_global_sel_alpha", label_text="Alpha", label_tooltip="Set the fill transparency for the 'left to right' selection box.", - min=0, max=255, step=1 + min_value=0, max_value=255, step=1 ), SeparatorOptionUI(), @@ -154,7 +153,7 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2): option="_global_alt_sel_alpha", label_text="Alpha", label_tooltip="Set the fill transparency for the 'right to left' selection box.", - min=0, max=255, step=1 + min_value=0, max_value=255, step=1 ), SeparatorOptionUI(), diff --git a/flatcamGUI/preferences/general/GeneralPreferencesUI.py b/flatcamGUI/preferences/general/GeneralPreferencesUI.py index 4e44a473..f504fcf8 100644 --- a/flatcamGUI/preferences/general/GeneralPreferencesUI.py +++ b/flatcamGUI/preferences/general/GeneralPreferencesUI.py @@ -1,7 +1,7 @@ from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI from flatcamGUI.preferences.PreferencesSectionUI import PreferencesSectionUI from flatcamGUI.preferences.general.GeneralAppPrefGroupUI import GeneralAppPrefGroupUI -from flatcamGUI.preferences.general.GeneralAPPSetGroupUI import GeneralAPPSetGroupUI +from flatcamGUI.preferences.general.GeneralAppSettingsGroupUI import GeneralAppSettingsGroupUI from flatcamGUI.preferences.general.GeneralGUIPrefGroupUI import GeneralGUIPrefGroupUI @@ -11,13 +11,13 @@ class GeneralPreferencesUI(PreferencesSectionUI): self.decimals = decimals self.general_gui_group = GeneralGUIPrefGroupUI(decimals=self.decimals) self.general_app_group = GeneralAppPrefGroupUI(decimals=self.decimals) - self.general_app_set_group = GeneralAPPSetGroupUI(decimals=self.decimals) + self.general_app_settings_group = GeneralAppSettingsGroupUI(decimals=self.decimals) super().__init__(**kwargs) def build_groups(self) -> [OptionsGroupUI]: return [ self.general_app_group, self.general_gui_group, - self.general_app_set_group + self.general_app_settings_group ]