electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 0546fa73dfc012a925a27b0134132fa7b07e05b8
parent 9a8183f348f5b4b56efe8f27b24c7baf7c46e207
Author: ThomasV <thomasv@electrum.org>
Date:   Mon, 25 Jun 2018 17:10:46 +0200

Merge pull request #4461 from SomberNight/dark_theme

option to set a dark theme for Qt
Diffstat:
Mcontrib/requirements/requirements.txt | 1+
Mgui/qt/__init__.py | 16+++++++++++++++-
Mgui/qt/main_window.py | 12++++++++++++
Mgui/qt/util.py | 4++--
4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/contrib/requirements/requirements.txt b/contrib/requirements/requirements.txt @@ -7,3 +7,4 @@ protobuf dnspython jsonrpclib-pelix PySocks>=1.6.6 +qdarkstyle<3.0 diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -117,8 +117,22 @@ class ElectrumGui: self.build_tray_menu() self.tray.show() self.app.new_window_signal.connect(self.start_new_window) + self.set_dark_theme_if_needed() 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): # Avoid immediate GC of old menu when window closed via its action diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -2790,6 +2790,18 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): qr_combo.currentIndexChanged.connect(on_video_device) 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.setChecked(self.wallet.use_change) if not self.config.is_modifiable('use_change'): usechange_cb.setEnabled(False) diff --git a/gui/qt/util.py b/gui/qt/util.py @@ -706,8 +706,8 @@ class ColorScheme: return brightness < (255*3/2) @staticmethod - def update_from_widget(widget): - if ColorScheme.has_dark_background(widget): + def update_from_widget(widget, force_dark=False): + if force_dark or ColorScheme.has_dark_background(widget): ColorScheme.dark_scheme = True