- the application now uses only the default values from the app.options dict, the app.defaults dict holds the definitive default values

- fixed some outstanding issues from the PyQt6 port
- PEP8 fixes
- minor fixes
- updated the saving of Preferences to update the self.options too: the `Apply` action will update the self.options but the `Save` action will save the updated preferences to the file on disk
This commit is contained in:
Marius Stanciu
2022-02-18 23:06:58 +02:00
committed by Marius
parent 14d9ea5470
commit 65d8dcc0b2
92 changed files with 1881 additions and 1882 deletions

View File

@@ -16,7 +16,7 @@ if '_' not in builtins.__dict__:
class PreferencesUIManager:
def __init__(self, defaults: FlatCAMDefaults, data_path: str, ui, inform):
def __init__(self, defaults: FlatCAMDefaults, data_path: str, ui, inform, options):
"""
Class that control the Preferences Tab
@@ -24,6 +24,7 @@ class PreferencesUIManager:
:param data_path: a path to the file where all the preferences are stored for persistence
:param ui: reference to the MainGUI class which constructs the UI
:param inform: a pyqtSignal used to display information's in the StatusBar of the GUI
:param options: a dict holding the current defaults loaded in the application
"""
self.defaults = defaults
@@ -1093,15 +1094,20 @@ class PreferencesUIManager:
else:
self.ui.general_pref_form.general_app_group.ge_radio.set_value(ge)
if save_to_file or should_restart is True:
# Re-fresh project options
self.ui.app.on_options_app2project()
# #############################################################################################################
# ############################ Here is done the actual preferences updates ##################################
# #############################################################################################################
# update the `defaults` dict from the Preferences UI form
self.defaults_read_form()
# Apply the `defaults` dict to project options
self.ui.app.options.update(self.defaults)
# #############################################################################################################
if save_to_file or should_restart is True:
self.save_defaults(silent=False)
# load the defaults so they are updated into the app
self.defaults.load(filename=os.path.join(self.data_path,
'current_defaults_%s.FlatConfig' % self.defaults.version),
inform=self.inform)
saved_filename_path = os.path.join(self.data_path, 'current_defaults_%s.FlatConfig' % self.defaults.version)
self.defaults.load(filename=saved_filename_path, inform=self.inform)
settgs = QSettings("Open Source", "FlatCAM")

View File

@@ -63,4 +63,4 @@ class CNCJobAdvOptPrefGroupUI(OptionsGroupUI):
self.annotation_fontcolor_entry.editingFinished.connect(self.on_annotation_fontcolor_entry)
def on_annotation_fontcolor_entry(self):
self.app.defaults['cncjob_annotation_fontcolor'] = self.annotation_fontcolor_entry.get_value()
self.app.options['cncjob_annotation_fontcolor'] = self.annotation_fontcolor_entry.get_value()

View File

@@ -238,28 +238,28 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
# Setting travel colors handlers
# ------------------------------------------------------
def on_tfill_color_entry(self):
self.app.defaults['cncjob_travel_fill'] = self.tfill_color_entry.get_value()[:7] + \
self.app.defaults['cncjob_travel_fill'][7:9]
self.app.options['cncjob_travel_fill'] = self.tfill_color_entry.get_value()[:7] + \
self.app.options['cncjob_travel_fill'][7:9]
def on_tline_color_entry(self):
self.app.defaults['cncjob_travel_line'] = self.tline_color_entry.get_value()[:7] + \
self.app.defaults['cncjob_travel_line'][7:9]
self.app.options['cncjob_travel_line'] = self.tline_color_entry.get_value()[:7] + \
self.app.options['cncjob_travel_line'][7:9]
def on_cncjob_alpha_changed(self, spinner_value):
self.app.defaults['cncjob_travel_fill'] = \
self.app.defaults['cncjob_travel_fill'][:7] + \
self.app.options['cncjob_travel_fill'] = \
self.app.options['cncjob_travel_fill'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
self.app.defaults['cncjob_travel_line'] = \
self.app.defaults['cncjob_travel_line'][:7] + \
self.app.options['cncjob_travel_line'] = \
self.app.options['cncjob_travel_line'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
# ------------------------------------------------------
# Setting plot colors handlers
# ------------------------------------------------------
def on_fill_color_entry(self):
self.app.defaults['cncjob_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.defaults['cncjob_plot_fill'][7:9]
self.app.options['cncjob_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.options['cncjob_plot_fill'][7:9]
def on_line_color_entry(self):
self.app.defaults['cncjob_plot_line'] = self.line_color_entry.get_value()[:7] + \
self.app.defaults['cncjob_plot_line'][7:9]
self.app.options['cncjob_plot_line'] = self.line_color_entry.get_value()[:7] + \
self.app.options['cncjob_plot_line'][7:9]

View File

@@ -366,7 +366,7 @@ class ExcellonGenPrefGroupUI(OptionsGroupUI):
self.update_excellon_cb.stateChanged.connect(self.on_update_exc_export)
# call it once to make sure it is updated at startup
self.on_update_exc_export(state=self.app.defaults["excellon_update"])
self.on_update_exc_export(state=self.app.options["excellon_update"])
self.excellon_optimization_radio.activated_custom.connect(self.optimization_selection)
@@ -388,19 +388,19 @@ class ExcellonGenPrefGroupUI(OptionsGroupUI):
# Setting plot colors handlers
def on_fill_color_entry(self):
self.app.defaults['excellon_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.defaults['excellon_plot_fill'][7:9]
self.app.options['excellon_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.options['excellon_plot_fill'][7:9]
def on_line_color_entry(self):
self.app.defaults['excellon_plot_line'] = self.line_color_entry.get_value()[:7] + \
self.app.defaults['excellon_plot_line'][7:9]
self.app.options['excellon_plot_line'] = self.line_color_entry.get_value()[:7] + \
self.app.options['excellon_plot_line'][7:9]
def on_excellon_alpha_changed(self, spinner_value):
self.app.defaults['excellon_plot_fill'] = \
self.app.defaults['excellon_plot_fill'][:7] + \
self.app.options['excellon_plot_fill'] = \
self.app.options['excellon_plot_fill'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
self.app.defaults['excellon_plot_line'] = \
self.app.defaults['excellon_plot_line'][:7] + \
self.app.options['excellon_plot_line'] = \
self.app.options['excellon_plot_line'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
def on_excellon_defaults_button(self):

View File

@@ -490,7 +490,7 @@ class GeneralAPPSetGroupUI(OptionsGroupUI):
def on_mouse_cursor_color_enable(self, val):
if val:
self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
self.app.cursor_color_3D = self.app.options["global_cursor_color"]
else:
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
@@ -504,9 +504,9 @@ class GeneralAPPSetGroupUI(OptionsGroupUI):
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.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
self.app.options['global_cursor_color'] = self.mouse_cursor_entry.get_value()
self.app.cursor_color_3D = self.app.options["global_cursor_color"]
def on_axis_color_entry(self):
self.app.defaults['global_axis_color'] = self.axis_color_entry.get_value()
self.app.options['global_axis_color'] = self.axis_color_entry.get_value()
self.app.plotcanvas.apply_axis_color()

View File

@@ -286,7 +286,7 @@ class GeneralAppSettingsGroupUI(OptionsGroupUI2):
def on_mouse_cursor_color_enable(self, val):
if val:
self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
self.app.cursor_color_3D = self.app.options["global_cursor_color"]
else:
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
@@ -300,5 +300,5 @@ class GeneralAppSettingsGroupUI(OptionsGroupUI2):
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"]
self.app.options['global_cursor_color'] = self.mouse_cursor_color_field.get_value()
self.app.cursor_color_3D = self.app.options["global_cursor_color"]

View File

@@ -332,11 +332,11 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
# Setting selection colors (left - right) handlers
def on_sf_color_entry(self):
self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][7:9]
self.app.options['global_sel_fill'] = self.app.options['global_sel_fill'][7:9]
def on_sl_color_entry(self):
self.app.defaults['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
self.app.defaults['global_sel_line'][7:9]
self.app.options['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
self.app.options['global_sel_line'][7:9]
def on_left_right_alpha_changed(self, spinner_value):
"""
@@ -349,19 +349,19 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
:rtype:
"""
self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][:7] + \
self.app.options['global_sel_fill'] = self.app.options['global_sel_fill'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
self.app.defaults['global_sel_line'] = self.app.defaults['global_sel_line'][:7] + \
self.app.options['global_sel_line'] = self.app.options['global_sel_line'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
# Setting selection colors (right - left) handlers
def on_alt_sf_color_entry(self):
self.app.defaults['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
self.app.defaults['global_alt_sel_fill'][7:9]
self.app.options['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
self.app.options['global_alt_sel_fill'][7:9]
def on_alt_sl_color_entry(self):
self.app.defaults['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
self.app.defaults['global_alt_sel_line'][7:9]
self.app.options['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
self.app.options['global_alt_sel_line'][7:9]
def on_right_left_alpha_changed(self, spinner_value):
"""
@@ -374,20 +374,20 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
:rtype:
"""
self.app.defaults['global_alt_sel_fill'] = self.app.defaults['global_alt_sel_fill'][:7] + \
self.app.options['global_alt_sel_fill'] = self.app.options['global_alt_sel_fill'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
self.app.defaults['global_alt_sel_line'] = self.app.defaults['global_alt_sel_line'][:7] + \
self.app.options['global_alt_sel_line'] = self.app.options['global_alt_sel_line'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
# Setting Editor colors
def on_draw_color_entry(self):
self.app.defaults['global_draw_color'] = self.draw_color_entry.get_value()
self.app.options['global_draw_color'] = self.draw_color_entry.get_value()
def on_sel_draw_color_entry(self):
self.app.defaults['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
self.app.options['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
def on_proj_color_entry(self):
self.app.defaults['global_proj_item_color'] = self.proj_color_entry.get_value()
self.app.options['global_proj_item_color'] = self.proj_color_entry.get_value()
def on_proj_color_dis_entry(self):
self.app.defaults['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()
self.app.options['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()

View File

@@ -184,7 +184,7 @@ class GeometryGenPrefGroupUI(OptionsGroupUI):
self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
def on_line_color_entry(self):
self.app.defaults['geometry_plot_line'] = self.line_color_entry.get_value()[:7] + 'FF'
self.app.options['geometry_plot_line'] = self.line_color_entry.get_value()[:7] + 'FF'
def optimization_selection(self, val):
if platform.architecture()[0] != '64bit':

View File

@@ -292,8 +292,8 @@ class GerberGenPrefGroupUI(OptionsGroupUI):
:return:
:rtype:
"""
self.app.defaults['gerber_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.defaults['gerber_plot_fill'][7:9]
self.app.options['gerber_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
self.app.options['gerber_plot_fill'][7:9]
def on_gerber_alpha_changed(self, spinner_value):
"""
@@ -303,11 +303,11 @@ class GerberGenPrefGroupUI(OptionsGroupUI):
:return:
:rtype:
"""
self.app.defaults['gerber_plot_fill'] = \
self.app.defaults['gerber_plot_fill'][:7] + \
self.app.options['gerber_plot_fill'] = \
self.app.options['gerber_plot_fill'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
self.app.defaults['gerber_plot_line'] = \
self.app.defaults['gerber_plot_line'][:7] + \
self.app.options['gerber_plot_line'] = \
self.app.options['gerber_plot_line'][:7] + \
(hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
def on_line_color_changed(self):
@@ -316,8 +316,8 @@ class GerberGenPrefGroupUI(OptionsGroupUI):
:return:
:rtype:
"""
self.app.defaults['gerber_plot_line'] = (self.line_color_entry.get_value()[:7] +
self.app.defaults['gerber_plot_line'][7:9])
self.app.options['gerber_plot_line'] = (self.line_color_entry.get_value()[:7] +
self.app.options['gerber_plot_line'][7:9])
def on_colors_clear_clicked(self):
"""
@@ -325,7 +325,7 @@ class GerberGenPrefGroupUI(OptionsGroupUI):
:return:
:rtype:
"""
self.app.defaults["gerber_color_list"].clear()
self.app.options["gerber_color_list"].clear()
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Stored colors for Gerber objects are deleted."))
def on_layers_manager(self):
@@ -348,7 +348,7 @@ class ColorsManager(QtWidgets.QDialog):
self.ok = False
self.color_list = []
self.original_color_list = deepcopy(self.app.defaults["gerber_color_list"])
self.original_color_list = deepcopy(self.app.options["gerber_color_list"])
self.setWindowIcon(QtGui.QIcon(self.app.resource_location + '/set_colors64.png'))
self.setWindowTitle('%s' % _('Color manager'))
@@ -502,8 +502,8 @@ class ColorsManager(QtWidgets.QDialog):
layer_nr = list_len
self.original_color_list.append(
(
self.app.defaults['gerber_plot_line'],
self.app.defaults['gerber_plot_fill'],
self.app.options['gerber_plot_line'],
self.app.options['gerber_plot_fill'],
'%s_%d' % (_("Layer"), layer_nr)
)
)

View File

@@ -186,7 +186,7 @@ class Tools2QRCodePrefGroupUI(OptionsGroupUI):
self.back_color_entry.editingFinished.connect(self.on_qrcode_back_color_entry)
def on_qrcode_fill_color_entry(self):
self.app.defaults['tools_qrcode_fill_color'] = self.fill_color_entry.get_value()
self.app.options['tools_qrcode_fill_color'] = self.fill_color_entry.get_value()
def on_qrcode_back_color_entry(self):
self.app.defaults['tools_qrcode_back_color'] = self.back_color_entry.get_value()
self.app.options['tools_qrcode_back_color'] = self.back_color_entry.get_value()

View File

@@ -375,4 +375,4 @@ class ToolsFilmPrefGroupUI(OptionsGroupUI):
self.film_color_entry.editingFinished.connect(self.on_film_color_entry)
def on_film_color_entry(self):
self.app.defaults['tools_film_color'] = self.film_color_entry.get_value()
self.app.options['tools_film_color'] = self.film_color_entry.get_value()