Theme option added to match OS appearance. Sets appearance on application launch.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
33
appMain.py
33
appMain.py
@@ -108,6 +108,8 @@ import gettext
|
||||
import appTranslation as fcTranslate
|
||||
import builtins
|
||||
|
||||
import darkdetect
|
||||
|
||||
if sys.platform == 'win32':
|
||||
import winreg
|
||||
|
||||
@@ -610,6 +612,20 @@ class App(QtCore.QObject):
|
||||
|
||||
# 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.default_units = self.defaults["units"]
|
||||
|
||||
@@ -618,16 +634,12 @@ class App(QtCore.QObject):
|
||||
else:
|
||||
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.qapp.setStyleSheet(qdarktheme.load_stylesheet('light'))
|
||||
else:
|
||||
self.resource_location = 'assets/resources/dark_resources'
|
||||
|
||||
# #############################################################################################################
|
||||
# ######################################### 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
|
||||
qdarksheet.STYLE_SHEET = style_sheet.D_STYLE_SHEET
|
||||
self.qapp.setStyleSheet(qdarktheme.load_stylesheet())
|
||||
|
||||
# ###########################################################################################################
|
||||
@@ -1021,10 +1033,7 @@ class App(QtCore.QObject):
|
||||
self.FC_dark_blue = '#0000ffbf'
|
||||
|
||||
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
|
||||
if theme_settings.contains("theme"):
|
||||
theme = theme_settings.value('theme', type=str)
|
||||
else:
|
||||
theme = 'white'
|
||||
theme_settings.setValue("theme", self.options["global_theme"])
|
||||
|
||||
if self.options["global_cursor_color_enabled"]:
|
||||
self.cursor_color_3D = self.options["global_cursor_color"]
|
||||
@@ -8625,7 +8634,7 @@ class App(QtCore.QObject):
|
||||
root = d_properties_tw.invisibleRootItem()
|
||||
font = QtGui.QFont()
|
||||
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
|
||||
general_cat = d_properties_tw.addParent(root, _('General'), expanded=True, color=p_color, font=font)
|
||||
|
||||
@@ -536,7 +536,7 @@ class FlatCAMObj(QtCore.QObject):
|
||||
font = QtGui.QFont()
|
||||
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")
|
||||
|
||||
# main Items categories
|
||||
|
||||
@@ -158,7 +158,7 @@ class ObjectReport(AppTool):
|
||||
font = QtGui.QFont()
|
||||
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")
|
||||
|
||||
# main Items categories
|
||||
|
||||
@@ -112,8 +112,7 @@ class AppDefaults:
|
||||
"global_tpdf_rmargin": 20.0,
|
||||
|
||||
# General GUI Preferences
|
||||
"global_theme": 'white',
|
||||
"global_gray_icons": False,
|
||||
"global_appearance": 'auto',
|
||||
|
||||
"global_layout": "compact",
|
||||
"global_hover_shape": False,
|
||||
|
||||
Reference in New Issue
Block a user