commit 3d54011c5d53c405ad22ace08e038bf3ec327e91
parent 901dda089802797639166ce937e020b6a18c382b
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 4 Oct 2017 18:17:38 +0200
Merge pull request #2983 from bauerj/dark
Adjust colors if dark color scheme is used
Diffstat:
10 files changed, 60 insertions(+), 26 deletions(-)
diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py
@@ -110,6 +110,7 @@ class ElectrumGui:
self.tray.show()
self.app.new_window_signal.connect(self.start_new_window)
run_hook('init_qt', self)
+ ColorScheme.update_from_widget(QWidget())
def build_tray_menu(self):
# Avoid immediate GC of old menu when window closed via its action
diff --git a/gui/qt/address_dialog.py b/gui/qt/address_dialog.py
@@ -57,7 +57,8 @@ class AddressDialog(WindowModalDialog):
vbox.addWidget(QLabel(_("Address:")))
self.addr_e = ButtonsLineEdit(self.address)
self.addr_e.addCopyButton(self.app)
- self.addr_e.addButton(":icons/qrcode.png", self.show_qr, _("Show QR Code"))
+ icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png"
+ self.addr_e.addButton(icon, self.show_qr, _("Show QR Code"))
self.addr_e.setReadOnly(True)
vbox.addWidget(self.addr_e)
diff --git a/gui/qt/address_list.py b/gui/qt/address_list.py
@@ -95,9 +95,9 @@ class AddressList(MyTreeWidget):
address_item.setData(0, Qt.UserRole, address)
address_item.setData(0, Qt.UserRole+1, True) # label can be edited
if self.wallet.is_frozen(address):
- address_item.setBackground(0, QColor('lightblue'))
+ address_item.setBackground(0, ColorScheme.BLUE.as_color(True))
if self.wallet.is_beyond_limit(address, is_change):
- address_item.setBackground(0, QColor('red'))
+ address_item.setBackground(0, ColorScheme.RED.as_color(True))
if is_used:
if not used_flag:
seq_item.insertChild(0, used_item)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -640,7 +640,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def edit_changed(edit):
if edit.follows:
return
- edit.setStyleSheet(BLACK_FG)
+ edit.setStyleSheet(ColorScheme.DEFAULT.as_stylesheet())
fiat_e.is_last_edited = (edit == fiat_e)
amount = edit.get_amount()
rate = self.fx.exchange_rate() if self.fx else None
@@ -655,7 +655,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
if edit is fiat_e:
btc_e.follows = True
btc_e.setAmount(int(amount / Decimal(rate) * COIN))
- btc_e.setStyleSheet(BLUE_FG)
+ btc_e.setStyleSheet(ColorScheme.BLUE.as_stylesheet())
btc_e.follows = False
if fee_e:
window.update_fee()
@@ -663,7 +663,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
fiat_e.follows = True
fiat_e.setText(self.fx.ccy_amount_str(
amount * Decimal(rate) / COIN, False))
- fiat_e.setStyleSheet(BLUE_FG)
+ fiat_e.setStyleSheet(ColorScheme.BLUE.as_stylesheet())
fiat_e.follows = False
btc_e.follows = False
@@ -1111,22 +1111,22 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def entry_changed():
text = ""
if self.not_enough_funds:
- amt_color, fee_color = RED_FG, RED_FG
+ amt_color, fee_color = ColorScheme.RED, ColorScheme.RED
text = _( "Not enough funds" )
c, u, x = self.wallet.get_frozen_balance()
if c+u+x:
text += ' (' + self.format_amount(c+u+x).strip() + ' ' + self.base_unit() + ' ' +_("are frozen") + ')'
elif self.fee_e.isModified():
- amt_color, fee_color = BLACK_FG, BLACK_FG
+ amt_color, fee_color = ColorScheme.DEFAULT, ColorScheme.DEFAULT
elif self.amount_e.isModified():
- amt_color, fee_color = BLACK_FG, BLUE_FG
+ amt_color, fee_color = ColorScheme.DEFAULT, ColorScheme.BLUE
else:
- amt_color, fee_color = BLUE_FG, BLUE_FG
+ amt_color, fee_color = ColorScheme.BLUE, ColorScheme.BLUE
self.statusBar().showMessage(text)
- self.amount_e.setStyleSheet(amt_color)
- self.fee_e.setStyleSheet(fee_color)
+ self.amount_e.setStyleSheet(amt_color.as_stylesheet())
+ self.fee_e.setStyleSheet(fee_color.as_stylesheet())
self.amount_e.textChanged.connect(entry_changed)
self.fee_e.textChanged.connect(entry_changed)
@@ -2311,7 +2311,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
return keystore.get_private_keys(text)
f = lambda: button.setEnabled(get_address() is not None and get_pk() is not None)
- on_address = lambda text: address_e.setStyleSheet(BLACK_FG if get_address() else RED_FG)
+ on_address = lambda text: address_e.setStyleSheet((ColorScheme.DEFAULT if get_address() else ColorScheme.RED).as_stylesheet())
keys_e.textChanged.connect(f)
address_e.textChanged.connect(f)
address_e.textChanged.connect(on_address)
@@ -2474,9 +2474,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
return
if self.alias_info:
alias_addr, alias_name, validated = self.alias_info
- alias_e.setStyleSheet(GREEN_BG if validated else RED_BG)
+ alias_e.setStyleSheet((ColorScheme.GREEN if validated else ColorScheme.RED).as_stylesheet(True))
else:
- alias_e.setStyleSheet(RED_BG)
+ alias_e.setStyleSheet(ColorScheme.RED.as_stylesheet(True))
def on_alias_edit():
alias_e.setStyleSheet("")
alias = str(alias_e.text())
@@ -2505,7 +2505,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
SSL_error = None
SSL_id_label = HelpLabel(_('SSL certificate') + ':', msg)
SSL_id_e = QLineEdit(SSL_identity)
- SSL_id_e.setStyleSheet(RED_BG if SSL_error else GREEN_BG if SSL_identity else '')
+ SSL_id_e.setStyleSheet((ColorScheme.RED if SSL_error else ColorScheme.GREEN).as_stylesheet(True) if SSL_identity else '')
if SSL_error:
SSL_id_e.setToolTip(SSL_error)
SSL_id_e.setReadOnly(True)
diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py
@@ -73,10 +73,10 @@ class PayToEdit(ScanQRTextEdit):
button.setHidden(b)
def setGreen(self):
- self.setStyleSheet(util.GREEN_BG)
+ self.setStyleSheet(util.ColorScheme.GREEN.as_stylesheet(True))
def setExpired(self):
- self.setStyleSheet(util.RED_BG)
+ self.setStyleSheet(util.ColorScheme.RED.as_stylesheet(True))
def parse_address_and_amount(self, line):
x, y = line.split(',')
diff --git a/gui/qt/qrtextedit.py b/gui/qt/qrtextedit.py
@@ -10,7 +10,7 @@ from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QFileDialog
-from .util import ButtonsTextEdit, MessageBoxMixin
+from .util import ButtonsTextEdit, MessageBoxMixin, ColorScheme
class ShowQRTextEdit(ButtonsTextEdit):
@@ -42,7 +42,8 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
ButtonsTextEdit.__init__(self, text)
self.setReadOnly(0)
self.addButton(":icons/file.png", self.file_input, _("Read file"))
- self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
+ icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png"
+ self.addButton(icon, self.qr_input, _("Read QR code"))
run_hook('scan_text_edit', self)
def file_input(self):
diff --git a/gui/qt/util.py b/gui/qt/util.py
@@ -26,11 +26,6 @@ elif platform.system() == 'Darwin':
else:
MONOSPACE_FONT = 'monospace'
-GREEN_BG = "QWidget {background-color:#80ff80;}"
-RED_BG = "QWidget {background-color:#ffcccc;}"
-RED_FG = "QWidget {color:red;}"
-BLUE_FG = "QWidget {color:blue;}"
-BLACK_FG = "QWidget {color:black;}"
dialogs = []
@@ -602,6 +597,41 @@ class TaskThread(QThread):
self.tasks.put(None)
+class ColorSchemeItem:
+ def __init__(self, fg_color, bg_color):
+ self.colors = (fg_color, bg_color)
+
+ def _get_color(self, background):
+ return self.colors[(int(background) + int(ColorScheme.dark_scheme)) % 2]
+
+ def as_stylesheet(self, background=False):
+ css_prefix = "background-" if background else ""
+ color = self._get_color(background)
+ return "QWidget {{ {}color:{}; }}".format(css_prefix, color)
+
+ def as_color(self, background=False):
+ color = self._get_color(background)
+ return QColor(color)
+
+
+class ColorScheme:
+ dark_scheme = False
+
+ GREEN = ColorSchemeItem("#117c11", "#8af296")
+ RED = ColorSchemeItem("#7c1111", "#f18c8c")
+ BLUE = ColorSchemeItem("#123b7c", "#8cb3f2")
+ DEFAULT = ColorSchemeItem("black", "white")
+
+ @staticmethod
+ def has_dark_background(widget):
+ brightness = sum(widget.palette().color(QPalette.Background).getRgb()[0:3])
+ return brightness < (255*3/2)
+
+ @staticmethod
+ def update_from_widget(widget):
+ if ColorScheme.has_dark_background(widget):
+ ColorScheme.dark_scheme = True
+
if __name__ == "__main__":
app = QApplication([])
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))
diff --git a/gui/qt/utxo_list.py b/gui/qt/utxo_list.py
@@ -53,7 +53,7 @@ class UTXOList(MyTreeWidget):
utxo_item.setFont(4, QFont(MONOSPACE_FONT))
utxo_item.setData(0, Qt.UserRole, name)
if self.wallet.is_frozen(address):
- utxo_item.setBackground(0, QColor('lightblue'))
+ utxo_item.setBackground(0, ColorScheme.BLUE.as_color(True))
self.addChild(utxo_item)
def create_menu(self, position):
diff --git a/icons.qrc b/icons.qrc
@@ -23,6 +23,7 @@
<file>icons/microphone.png</file>
<file>icons/network.png</file>
<file>icons/qrcode.png</file>
+ <file>icons/qrcode_white.png</file>
<file>icons/preferences.png</file>
<file>icons/seed.png</file>
<file>icons/status_connected.png</file>
diff --git a/icons/qrcode_white.png b/icons/qrcode_white.png
Binary files differ.