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

View File

@@ -35,28 +35,25 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
par_frame.setLayout(grid0) par_frame.setLayout(grid0)
# Theme selection # Theme selection
self.theme_label = FCLabel('%s:' % _('Theme')) self.appearance_label = FCLabel('%s:' % _('Theme'))
self.theme_label.setToolTip( self.appearance_label.setToolTip(
_("Select a theme for the application.\n" _("Select a theme for the application.\n"
"It will theme the plot area.") "It will theme the plot area.")
) )
self.theme_radio = RadioSet([ self.appearance_radio = RadioSet([
{"label": _("Light"), "value": "white"}, {"label": _("OS Dependent"), "value": "auto"},
{"label": _("Dark"), "value": "black"} {"label": _("Light"), "value": "light"},
{"label": _("Dark"), "value": "dark"}
], compact=True) ], compact=True)
self.appearance_radio.setToolTip(
grid0.addWidget(self.theme_label, 0, 0) _("OS Dependent: Matches mode from OS\n"
grid0.addWidget(self.theme_radio, 0, 1) "Light: Light mode\n"
"Dark: Dark mode")
# 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.")
) )
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 = FCButton(_("Apply Theme"))
# self.theme_button.setToolTip( # self.theme_button.setToolTip(

View File

@@ -108,6 +108,8 @@ import gettext
import appTranslation as fcTranslate import appTranslation as fcTranslate
import builtins import builtins
import darkdetect
if sys.platform == 'win32': if sys.platform == 'win32':
import winreg import winreg
@@ -610,6 +612,20 @@ class App(QtCore.QObject):
# self.preferencesUiManager.show_preferences_gui() # self.preferencesUiManager.show_preferences_gui()
# Set global_theme based on appearance
if self.options["global_appearance"] == 'auto':
if darkdetect.isDark():
theme = 'black'
else:
theme = 'white'
else:
if self.options["global_appearance"] == 'dark':
theme = 'black'
else:
theme = 'white'
self.options["global_theme"] = theme
self.app_units = self.options["units"] self.app_units = self.options["units"]
self.default_units = self.defaults["units"] self.default_units = self.defaults["units"]
@@ -618,16 +634,12 @@ class App(QtCore.QObject):
else: else:
self.decimals = int(self.options['decimals_inch']) self.decimals = int(self.options['decimals_inch'])
if self.options["global_gray_icons"] is False: if self.options["global_theme"] == 'white':
self.resource_location = 'assets/resources' self.resource_location = 'assets/resources'
self.qapp.setStyleSheet(qdarktheme.load_stylesheet('light'))
else: else:
self.resource_location = 'assets/resources/dark_resources' self.resource_location = 'assets/resources/dark_resources'
qdarksheet.STYLE_SHEET = style_sheet.D_STYLE_SHEET
# #############################################################################################################
# ######################################### DARK THEME ########################################################
# #############################################################################################################
if self.options["global_gray_icons"] is True:
qdarksheet.STYLE_SHEET = style_sheet.D_STYLE_SHEET # patching so I can do my own changes to the theme
self.qapp.setStyleSheet(qdarktheme.load_stylesheet()) self.qapp.setStyleSheet(qdarktheme.load_stylesheet())
# ########################################################################################################### # ###########################################################################################################
@@ -1021,10 +1033,7 @@ class App(QtCore.QObject):
self.FC_dark_blue = '#0000ffbf' self.FC_dark_blue = '#0000ffbf'
theme_settings = QtCore.QSettings("Open Source", "FlatCAM") theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"): theme_settings.setValue("theme", self.options["global_theme"])
theme = theme_settings.value('theme', type=str)
else:
theme = 'white'
if self.options["global_cursor_color_enabled"]: if self.options["global_cursor_color_enabled"]:
self.cursor_color_3D = self.options["global_cursor_color"] self.cursor_color_3D = self.options["global_cursor_color"]
@@ -8625,7 +8634,7 @@ class App(QtCore.QObject):
root = d_properties_tw.invisibleRootItem() root = d_properties_tw.invisibleRootItem()
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
p_color = QtGui.QColor("#000000") if self.options['global_gray_icons'] is False else QtGui.QColor("#FFFFFF") p_color = QtGui.QColor("#000000") if self.options['global_theme'] == 'white' else QtGui.QColor("#FFFFFF")
# main Items categories # main Items categories
general_cat = d_properties_tw.addParent(root, _('General'), expanded=True, color=p_color, font=font) general_cat = d_properties_tw.addParent(root, _('General'), expanded=True, color=p_color, font=font)

View File

@@ -536,7 +536,7 @@ class FlatCAMObj(QtCore.QObject):
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
p_color = QtGui.QColor("#000000") if self.app.options['global_gray_icons'] is False \ p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] == 'white' \
else QtGui.QColor("#FFFFFF") else QtGui.QColor("#FFFFFF")
# main Items categories # main Items categories

View File

@@ -158,7 +158,7 @@ class ObjectReport(AppTool):
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
p_color = QtGui.QColor("#000000") if self.app.options['global_gray_icons'] is False \ p_color = QtGui.QColor("#000000") if self.app.options['global_theme'] == 'white' \
else QtGui.QColor("#FFFFFF") else QtGui.QColor("#FFFFFF")
# main Items categories # main Items categories

View File

@@ -112,8 +112,7 @@ class AppDefaults:
"global_tpdf_rmargin": 20.0, "global_tpdf_rmargin": 20.0,
# General GUI Preferences # General GUI Preferences
"global_theme": 'white', "global_appearance": 'auto',
"global_gray_icons": False,
"global_layout": "compact", "global_layout": "compact",
"global_hover_shape": False, "global_hover_shape": False,