Merge branch 'Beta' into preferences-refactoring

This commit is contained in:
David Robertson
2020-05-09 15:07:30 +01:00
16 changed files with 455 additions and 251 deletions

View File

@@ -714,7 +714,40 @@ class PreferencesUIManager:
# make sure we update the self.current_defaults dict used to undo changes to self.defaults
self.defaults.current_defaults.update(self.defaults)
if save_to_file:
# deal with theme change
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
theme = theme_settings.value('theme', type=str)
else:
theme = 'white'
should_restart = False
val = self.get_form_field("global_theme").get_value()
if val != theme:
msgbox = QtWidgets.QMessageBox()
msgbox.setText(_("Are you sure you want to continue?"))
msgbox.setWindowTitle(_("Application restart"))
msgbox.setWindowIcon(QtGui.QIcon(self.ui.app.resource_location + '/warning.png'))
bt_yes = msgbox.addButton(_('Yes'), QtWidgets.QMessageBox.YesRole)
msgbox.addButton(_('Cancel'), QtWidgets.QMessageBox.NoRole)
msgbox.setDefaultButton(bt_yes)
msgbox.exec_()
response = msgbox.clickedButton()
if response == bt_yes:
theme_settings.setValue('theme', val)
# This will write the setting to the platform specific storage.
del theme_settings
should_restart = True
else:
self.ui.general_defaults_form.general_gui_group.theme_radio.set_value(theme)
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.FlatConfig'))
@@ -752,6 +785,9 @@ class PreferencesUIManager:
self.ui.plot_tab_area.closeTab(idx)
break
if should_restart is True:
self.ui.app.on_app_restart()
def on_pref_close_button(self):
# Preferences saved, update flag
self.preferences_changed_flag = False

View File

@@ -25,8 +25,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
self.layout_field.activated.connect(self.on_layout)
self.theme_field = self.option_dict()["global_theme"].get_field()
self.theme_apply_button = self.option_dict()["__button_apply_theme"].get_field()
self.theme_apply_button.clicked.connect(self.on_theme_change)
self.style_field = self.option_dict()["style"].get_field()
current_style_index = self.style_field.findText(QtWidgets.qApp.style().objectName(), QtCore.Qt.MatchFixedString)
@@ -58,13 +56,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
label_text="Use Gray Icons",
label_tooltip="Check this box to use a set of icons with\na lighter (gray) color. To be used when a\nfull dark theme is applied."
),
FullWidthButtonOptionUI(
option="__button_apply_theme",
label_text="Apply Theme",
label_tooltip="Select a theme for FlatCAM.\n"
"It will theme the plot area.\n"
"The application will restart after change."
),
SeparatorOptionUI(),
ComboboxOptionUI(
@@ -181,24 +172,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
),
]
def on_theme_change(self):
# FIXME: this should be moved out to a view model
val = self.theme_field.get_value()
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
theme = theme_settings.value('theme', type=str)
else:
theme = 'white'
if val != theme:
theme_settings.setValue("theme", val)
# This will write the setting to the platform specific storage.
del theme_settings
self.app.on_app_restart()
def on_layout(self, index=None, lay=None):
if lay:
current_layout = lay

View File

@@ -1,7 +1,7 @@
from PyQt5 import QtWidgets
from PyQt5.QtCore import QSettings
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, EvalEntry2
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCEntry
from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
import gettext
@@ -191,7 +191,7 @@ class ToolsTransformPrefGroupUI(OptionsGroupUI):
"The 'x' in (x, y) will be used when using Flip on X and\n"
"the 'y' in (x, y) will be used when using Flip on Y and")
)
self.flip_ref_entry = EvalEntry2("(0, 0)")
self.flip_ref_entry = FCEntry()
grid0.addWidget(self.flip_ref_label, 14, 0, 1, 2)
grid0.addWidget(self.flip_ref_entry, 15, 0, 1, 2)