Fix system tray icon for multiple wallets
QT doesn't permit dynamic menus for QSystemTrayIcon for some reason so we need to rebuild it each time the window set changes. Add a close and hide/show submenu for each wallet. Double click hides / shows all the wallets.
This commit is contained in:
parent
c3fb7fdb1d
commit
0fa48b926c
|
@ -75,36 +75,51 @@ class ElectrumGui:
|
||||||
self.app.installEventFilter(self.efilter)
|
self.app.installEventFilter(self.efilter)
|
||||||
self.timer = Timer()
|
self.timer = Timer()
|
||||||
|
|
||||||
|
# init tray
|
||||||
|
self.dark_icon = self.config.get("dark_icon", False)
|
||||||
|
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.connect(self.app, QtCore.SIGNAL('new_window'), self.start_new_window)
|
self.app.connect(self.app, QtCore.SIGNAL('new_window'), self.start_new_window)
|
||||||
|
|
||||||
|
|
||||||
def build_tray_menu(self):
|
def build_tray_menu(self):
|
||||||
|
# Avoid immediate GC of old menu when window closed via its action
|
||||||
|
self.old_menu = self.tray.contextMenu()
|
||||||
m = QMenu()
|
m = QMenu()
|
||||||
m.addAction(_("Show/Hide"), self.show_or_hide)
|
for window in self.windows:
|
||||||
|
submenu = m.addMenu(window.wallet.basename())
|
||||||
|
submenu.addAction(_("Show/Hide"), window.show_or_hide)
|
||||||
|
submenu.addAction(_("Close"), window.close)
|
||||||
m.addAction(_("Dark/Light"), self.toggle_tray_icon)
|
m.addAction(_("Dark/Light"), self.toggle_tray_icon)
|
||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
m.addAction(_("Exit Electrum"), self.close)
|
m.addAction(_("Exit Electrum"), self.close)
|
||||||
self.tray.setContextMenu(m)
|
self.tray.setContextMenu(m)
|
||||||
|
|
||||||
|
def tray_icon(self):
|
||||||
|
if self.dark_icon:
|
||||||
|
return QIcon(':icons/electrum_dark_icon.png')
|
||||||
|
else:
|
||||||
|
return QIcon(':icons/electrum_light_icon.png')
|
||||||
|
|
||||||
def toggle_tray_icon(self):
|
def toggle_tray_icon(self):
|
||||||
self.dark_icon = not self.dark_icon
|
self.dark_icon = not self.dark_icon
|
||||||
self.config.set_key("dark_icon", self.dark_icon, True)
|
self.config.set_key("dark_icon", self.dark_icon, True)
|
||||||
icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png')
|
self.tray.setIcon(self.tray_icon())
|
||||||
self.tray.setIcon(icon)
|
|
||||||
|
|
||||||
def show_or_hide(self):
|
|
||||||
self.tray_activated(QSystemTrayIcon.DoubleClick)
|
|
||||||
|
|
||||||
def tray_activated(self, reason):
|
def tray_activated(self, reason):
|
||||||
if reason == QSystemTrayIcon.DoubleClick:
|
if reason == QSystemTrayIcon.DoubleClick:
|
||||||
if self.current_window.isMinimized() or self.current_window.isHidden():
|
if all([w.is_hidden() for w in self.windows]):
|
||||||
self.current_window.show()
|
for w in self.windows:
|
||||||
self.current_window.raise_()
|
w.bring_to_top()
|
||||||
else:
|
else:
|
||||||
self.current_window.hide()
|
for w in self.windows:
|
||||||
|
w.hide()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.current_window.close()
|
for window in self.windows:
|
||||||
|
window.close()
|
||||||
|
|
||||||
def new_window(self, config):
|
def new_window(self, config):
|
||||||
self.app.emit(SIGNAL('new_window'), config)
|
self.app.emit(SIGNAL('new_window'), config)
|
||||||
|
@ -117,9 +132,7 @@ class ElectrumGui:
|
||||||
path = config.get_wallet_path()
|
path = config.get_wallet_path()
|
||||||
for w in self.windows:
|
for w in self.windows:
|
||||||
if w.config.get_wallet_path() == path:
|
if w.config.get_wallet_path() == path:
|
||||||
# Un-minimize the window and raise it
|
w.bring_to_top()
|
||||||
w.setWindowState(w.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
|
||||||
w.activateWindow()
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
w = ElectrumWindow(config, self.network, self)
|
w = ElectrumWindow(config, self.network, self)
|
||||||
|
@ -127,12 +140,16 @@ class ElectrumGui:
|
||||||
w.load_wallet_file(path)
|
w.load_wallet_file(path)
|
||||||
w.show()
|
w.show()
|
||||||
self.windows.append(w)
|
self.windows.append(w)
|
||||||
|
self.build_tray_menu()
|
||||||
|
|
||||||
url = config.get('url')
|
url = config.get('url')
|
||||||
if url:
|
if url:
|
||||||
w.pay_to_URI(url)
|
w.pay_to_URI(url)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
def close_window(self, window):
|
||||||
|
self.windows.remove(window)
|
||||||
|
self.build_tray_menu()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
@ -142,15 +159,6 @@ class ElectrumGui:
|
||||||
if os.path.exists(last_wallet):
|
if os.path.exists(last_wallet):
|
||||||
self.config.cmdline_options['default_wallet_path'] = last_wallet
|
self.config.cmdline_options['default_wallet_path'] = last_wallet
|
||||||
|
|
||||||
# init tray
|
|
||||||
self.dark_icon = self.config.get("dark_icon", False)
|
|
||||||
icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png')
|
|
||||||
self.tray = QSystemTrayIcon(icon, None)
|
|
||||||
self.tray.setToolTip('Electrum')
|
|
||||||
self.tray.activated.connect(self.tray_activated)
|
|
||||||
self.build_tray_menu()
|
|
||||||
self.tray.show()
|
|
||||||
|
|
||||||
# main window
|
# main window
|
||||||
self.current_window = self.main_window = self.start_new_window(self.config)
|
self.current_window = self.main_window = self.start_new_window(self.config)
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,18 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.require_fee_update = False
|
self.require_fee_update = False
|
||||||
self.tx_notifications = []
|
self.tx_notifications = []
|
||||||
|
|
||||||
|
def is_hidden(self):
|
||||||
|
return self.isMinimized() or self.isHidden()
|
||||||
|
|
||||||
|
def show_or_hide(self):
|
||||||
|
if self.is_hidden():
|
||||||
|
self.bring_to_top()
|
||||||
|
else:
|
||||||
|
self.hide()
|
||||||
|
|
||||||
|
def bring_to_top(self):
|
||||||
|
self.show()
|
||||||
|
self.raise_()
|
||||||
|
|
||||||
def register_callback(self, name, method):
|
def register_callback(self, name, method):
|
||||||
""" run callback in the qt thread """
|
""" run callback in the qt thread """
|
||||||
|
@ -554,7 +566,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
QMainWindow.close(self)
|
QMainWindow.close(self)
|
||||||
self.close_wallet()
|
self.close_wallet()
|
||||||
run_hook('close_main_window')
|
run_hook('close_main_window')
|
||||||
self.gui_object.windows.remove(self)
|
self.gui_object.close_window(self)
|
||||||
|
|
||||||
def connect_slots(self, sender):
|
def connect_slots(self, sender):
|
||||||
self.connect(sender, QtCore.SIGNAL('timersignal'), self.timer_actions)
|
self.connect(sender, QtCore.SIGNAL('timersignal'), self.timer_actions)
|
||||||
|
|
Loading…
Reference in New Issue