Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qss theme from qtum core #106

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions electrum/gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import threading
from typing import Optional, TYPE_CHECKING

from .theme_helper import set_qtum_theme_if_needed

try:
import PyQt5
Expand Down Expand Up @@ -128,48 +129,9 @@ def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins')
self.build_tray_menu()
self.tray.show()
self.app.new_window_signal.connect(self.start_new_window)
self.set_qtum_theme_if_needed()
set_qtum_theme_if_needed(self)
run_hook('init_qt', self)

def set_qtum_theme_if_needed(self):
use_dark_theme = self.config.get('qt_gui_color_theme', 'default') == 'dark'
#Add switcher for Qtum core style themes on electrum
use_qtum_theme1 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_dark'
use_qtum_theme2 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_almost_dark'
use_qtum_theme3 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_light'

if use_dark_theme:
try:
import qdarkstyle
self.app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting dark theme: {repr(e)}')
if use_qtum_theme1:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme1/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
if use_qtum_theme2:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme2/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
if use_qtum_theme3:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme3/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
# Apply any necessary stylesheet patches
patch_qt_stylesheet(use_dark_theme=use_dark_theme)
# 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
if self.tray.contextMenu() is None:
Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qt/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from electrum.i18n import languages
from electrum import qrscanner

from .theme_helper import *
if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig
from .main_window import ElectrumWindow
Expand Down Expand Up @@ -292,7 +292,7 @@ def on_unit(x, nz):
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
set_qtum_theme_if_needed(self)
colortheme_combo.currentIndexChanged.connect(on_colortheme)
gui_widgets.append((colortheme_label, colortheme_combo))

Expand Down
49 changes: 49 additions & 0 deletions electrum/gui/qt/theme_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from PyQt5.QtWidgets import QWidget, QApplication

from electrum.gui.qt.stylesheet_patcher import patch_qt_stylesheet
from electrum.gui.qt.util import ColorScheme

def set_qtum_theme_if_needed(self):
akshaynexus marked this conversation as resolved.
Show resolved Hide resolved
use_dark_theme = self.config.get('qt_gui_color_theme', 'default') == 'dark'
# Add switcher for Qtum core style themes on electrum
use_qtum_theme1 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_dark'
use_qtum_theme2 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_almost_dark'
use_qtum_theme3 = self.config.get('qt_gui_color_theme', 'default') == 'qtum_light'
self.app = QApplication.instance()
if use_dark_theme:
try:
import qdarkstyle
self.app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting dark theme: {repr(e)}')
elif use_qtum_theme1:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme1/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
elif use_qtum_theme2:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme2/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
elif use_qtum_theme3:
try:
self.app.setStyleSheet(open('electrum/gui/qt/styles/theme3/app.css').read())
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Qtum theme: {repr(e)}')
else:
try:
self.app.setStyleSheet('')
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting Light theme: {repr(e)}')
# Apply any necessary stylesheet patches
patch_qt_stylesheet(use_dark_theme=use_dark_theme)
# 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)