mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
option to set a dark theme for Qt
qdarkstyle is now a new dependency - note that it is only for qt and qt is not strictly a dependency, but it is pure python and relatively small
This commit is contained in:
parent
9a8183f348
commit
ca7e5575bf
4 changed files with 30 additions and 3 deletions
|
@ -7,3 +7,4 @@ protobuf
|
||||||
dnspython
|
dnspython
|
||||||
jsonrpclib-pelix
|
jsonrpclib-pelix
|
||||||
PySocks>=1.6.6
|
PySocks>=1.6.6
|
||||||
|
qdarkstyle<3.0
|
||||||
|
|
|
@ -117,8 +117,22 @@ class ElectrumGui:
|
||||||
self.build_tray_menu()
|
self.build_tray_menu()
|
||||||
self.tray.show()
|
self.tray.show()
|
||||||
self.app.new_window_signal.connect(self.start_new_window)
|
self.app.new_window_signal.connect(self.start_new_window)
|
||||||
|
self.set_dark_theme_if_needed()
|
||||||
run_hook('init_qt', self)
|
run_hook('init_qt', self)
|
||||||
ColorScheme.update_from_widget(QWidget())
|
|
||||||
|
def set_dark_theme_if_needed(self):
|
||||||
|
use_dark_theme = self.config.get('qt_gui_color_theme', 'default') == 'dark'
|
||||||
|
if use_dark_theme:
|
||||||
|
try:
|
||||||
|
import qdarkstyle
|
||||||
|
self.app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
|
||||||
|
except BaseException as e:
|
||||||
|
use_dark_theme = False
|
||||||
|
print_error('Error setting dark theme: {}'.format(e))
|
||||||
|
# Even if we ourselves don't set the dark theme,
|
||||||
|
# the OS/window manager/etc might set *a dark theme*.
|
||||||
|
# Hence, try to choose colors accordingly:
|
||||||
|
ColorScheme.update_from_widget(QWidget(), force_dark=use_dark_theme)
|
||||||
|
|
||||||
def build_tray_menu(self):
|
def build_tray_menu(self):
|
||||||
# Avoid immediate GC of old menu when window closed via its action
|
# Avoid immediate GC of old menu when window closed via its action
|
||||||
|
|
|
@ -2790,6 +2790,18 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
qr_combo.currentIndexChanged.connect(on_video_device)
|
qr_combo.currentIndexChanged.connect(on_video_device)
|
||||||
gui_widgets.append((qr_label, qr_combo))
|
gui_widgets.append((qr_label, qr_combo))
|
||||||
|
|
||||||
|
colortheme_combo = QComboBox()
|
||||||
|
colortheme_combo.addItem(_('Light'), 'default')
|
||||||
|
colortheme_combo.addItem(_('Dark'), 'dark')
|
||||||
|
index = colortheme_combo.findData(self.config.get('qt_gui_color_theme', 'default'))
|
||||||
|
colortheme_combo.setCurrentIndex(index)
|
||||||
|
colortheme_label = QLabel(_('Color theme') + ':')
|
||||||
|
def on_colortheme(x):
|
||||||
|
self.config.set_key('qt_gui_color_theme', colortheme_combo.itemData(x), True)
|
||||||
|
self.need_restart = True
|
||||||
|
colortheme_combo.currentIndexChanged.connect(on_colortheme)
|
||||||
|
gui_widgets.append((colortheme_label, colortheme_combo))
|
||||||
|
|
||||||
usechange_cb = QCheckBox(_('Use change addresses'))
|
usechange_cb = QCheckBox(_('Use change addresses'))
|
||||||
usechange_cb.setChecked(self.wallet.use_change)
|
usechange_cb.setChecked(self.wallet.use_change)
|
||||||
if not self.config.is_modifiable('use_change'): usechange_cb.setEnabled(False)
|
if not self.config.is_modifiable('use_change'): usechange_cb.setEnabled(False)
|
||||||
|
|
|
@ -706,8 +706,8 @@ class ColorScheme:
|
||||||
return brightness < (255*3/2)
|
return brightness < (255*3/2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_from_widget(widget):
|
def update_from_widget(widget, force_dark=False):
|
||||||
if ColorScheme.has_dark_background(widget):
|
if force_dark or ColorScheme.has_dark_background(widget):
|
||||||
ColorScheme.dark_scheme = True
|
ColorScheme.dark_scheme = True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue