Theme option added to match OS appearance. Sets appearance on application launch.

This commit is contained in:
Ali Khalil
2022-04-11 12:13:49 +03:00
parent 3af1b189c5
commit adad500f15
6 changed files with 49 additions and 45 deletions

View File

@@ -73,8 +73,7 @@ class PreferencesUIManager(QtCore.QObject):
"global_tpdf_rmargin": self.ui.general_pref_form.general_app_group.rmargin_entry,
# General GUI Preferences
"global_theme": self.ui.general_pref_form.general_gui_group.theme_radio,
"global_gray_icons": self.ui.general_pref_form.general_gui_group.gray_icons_cb,
"global_appearance": self.ui.general_pref_form.general_gui_group.appearance_radio,
"global_layout": self.ui.general_pref_form.general_gui_group.layout_combo,
"global_hover_shape": self.ui.general_pref_form.general_gui_group.hover_cb,
"global_selection_shape": self.ui.general_pref_form.general_gui_group.selection_cb,
@@ -1064,20 +1063,20 @@ class PreferencesUIManager(QtCore.QObject):
# make sure we update the self.current_defaults dict used to undo changes to self.defaults
self.defaults.current_defaults.update(self.defaults)
# deal with theme change
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
theme = theme_settings.value('theme', type=str)
# deal with appearance change
appearance_settings = QtCore.QSettings("Open Source", "FlatCAM")
if appearance_settings.contains("appearance"):
appearance = appearance_settings.value('appearance', type=str)
else:
theme = 'white'
appearance = None
should_restart = False
theme_new_val = self.ui.general_pref_form.general_gui_group.theme_radio.get_value()
appearance_new_val = self.ui.general_pref_form.general_gui_group.appearance_radio.get_value()
ge = self.defaults["global_graphic_engine"]
ge_val = self.ui.general_pref_form.general_app_group.ge_radio.get_value()
if theme_new_val != theme or ge != ge_val:
if appearance_new_val != appearance or ge != ge_val:
msgbox = FCMessageBox(parent=self.ui)
title = _("Application will restart")
txt = _("Are you sure you want to continue?")
@@ -1094,16 +1093,16 @@ class PreferencesUIManager(QtCore.QObject):
msgbox.exec()
response = msgbox.clickedButton()
if theme_new_val != theme:
if appearance_new_val != appearance:
if response == bt_yes:
theme_settings.setValue('theme', theme_new_val)
appearance_settings.setValue('appearance', appearance_new_val)
# This will write the setting to the platform specific storage.
del theme_settings
del appearance_settings
should_restart = True
else:
self.ui.general_pref_form.general_gui_group.theme_radio.set_value(theme)
self.ui.general_pref_form.general_gui_group.appearance_radio.set_value(appearance)
else:
if response == bt_yes:
self.defaults["global_graphic_engine"] = ge_val

View File

@@ -35,28 +35,25 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
par_frame.setLayout(grid0)
# Theme selection
self.theme_label = FCLabel('%s:' % _('Theme'))
self.theme_label.setToolTip(
self.appearance_label = FCLabel('%s:' % _('Theme'))
self.appearance_label.setToolTip(
_("Select a theme for the application.\n"
"It will theme the plot area.")
)
self.theme_radio = RadioSet([
{"label": _("Light"), "value": "white"},
{"label": _("Dark"), "value": "black"}
self.appearance_radio = RadioSet([
{"label": _("OS Dependent"), "value": "auto"},
{"label": _("Light"), "value": "light"},
{"label": _("Dark"), "value": "dark"}
], compact=True)
grid0.addWidget(self.theme_label, 0, 0)
grid0.addWidget(self.theme_radio, 0, 1)
# Enable Gray Icons
self.gray_icons_cb = FCCheckBox('%s' % _('Use Gray Icons'))
self.gray_icons_cb.setToolTip(
_("Check this box to use a set of icons with\n"
"a lighter (gray) color. To be used when a\n"
"full dark theme is applied.")
self.appearance_radio.setToolTip(
_("OS Dependent: Matches mode from OS\n"
"Light: Light mode\n"
"Dark: Dark mode")
)
grid0.addWidget(self.gray_icons_cb, 2, 0, 1, 3)
grid0.addWidget(self.appearance_label, 0, 0)
grid0.addWidget(self.appearance_radio, 0, 1)
# self.theme_button = FCButton(_("Apply Theme"))
# self.theme_button.setToolTip(