Created
February 5, 2021 20:11
-
-
Save SomberNight/f6d3c54cea13b1b400b3d4d7fbf633cb to your computer and use it in GitHub Desktop.
electrum qt gui systray patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py | |
index 00eb5d34ee..31f9dd06c5 100644 | |
--- a/electrum/gui/qt/__init__.py | |
+++ b/electrum/gui/qt/__init__.py | |
@@ -122,16 +122,19 @@ class ElectrumGui(Logger): | |
self.network_updated_signal_obj = QNetworkUpdatedSignalObject() | |
self._num_wizards_in_progress = 0 | |
self._num_wizards_lock = threading.Lock() | |
- # init tray | |
self.dark_icon = self.config.get("dark_icon", False) | |
+ self.tray = None | |
+ self._init_tray() | |
+ self.app.new_window_signal.connect(self.start_new_window) | |
+ self.set_dark_theme_if_needed() | |
+ run_hook('init_qt', self) | |
+ | |
+ def _init_tray(self): | |
self.tray = QSystemTrayIcon(self.tray_icon(), None) | |
self.tray.setToolTip('Electrum') | |
self.tray.activated.connect(self.tray_activated) | |
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) | |
def set_dark_theme_if_needed(self): | |
use_dark_theme = self.config.get('qt_gui_color_theme', 'default') == 'dark' | |
@@ -150,6 +153,8 @@ class ElectrumGui(Logger): | |
ColorScheme.update_from_widget(QWidget(), force_dark=use_dark_theme) | |
def build_tray_menu(self): | |
+ if not self.tray: | |
+ return | |
# Avoid immediate GC of old menu when window closed via its action | |
if self.tray.contextMenu() is None: | |
m = QMenu() | |
@@ -179,6 +184,8 @@ class ElectrumGui(Logger): | |
return read_QIcon('electrum_light_icon.png') | |
def toggle_tray_icon(self): | |
+ if not self.tray: | |
+ return | |
self.dark_icon = not self.dark_icon | |
self.config.set_key("dark_icon", self.dark_icon, True) | |
self.tray.setIcon(self.tray_icon()) | |
@@ -382,7 +389,8 @@ class ElectrumGui(Logger): | |
# clipboard persistence. see http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17328.html | |
event = QtCore.QEvent(QtCore.QEvent.Clipboard) | |
self.app.sendEvent(self.app.clipboard(), event) | |
- self.tray.hide() | |
+ if self.tray: | |
+ self.tray.hide() | |
self.app.aboutToQuit.connect(clean_up) | |
# main loop | |
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py | |
index de2f99916f..b156ecb2d2 100644 | |
--- a/electrum/gui/qt/main_window.py | |
+++ b/electrum/gui/qt/main_window.py | |
@@ -978,7 +978,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): | |
text = _("Not connected") | |
icon = read_QIcon("status_disconnected.png") | |
- self.tray.setToolTip("%s (%s)" % (text, self.wallet.basename())) | |
+ if self.tray: | |
+ self.tray.setToolTip("%s (%s)" % (text, self.wallet.basename())) | |
self.balance_label.setText(text) | |
if self.status_button: | |
self.status_button.setIcon( icon ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment