mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 15:31:31 +00:00
move tray logic to ElectrumGui object. fixes #468
This commit is contained in:
parent
1662a9e9c5
commit
5bbdcdf73d
2 changed files with 94 additions and 79 deletions
|
@ -70,10 +70,84 @@ class ElectrumGui:
|
||||||
if app is None:
|
if app is None:
|
||||||
self.app = QApplication(sys.argv)
|
self.app = QApplication(sys.argv)
|
||||||
self.app.installEventFilter(self.efilter)
|
self.app.installEventFilter(self.efilter)
|
||||||
|
|
||||||
init_plugins(self)
|
init_plugins(self)
|
||||||
|
|
||||||
|
|
||||||
|
def build_tray_menu(self):
|
||||||
|
m = QMenu()
|
||||||
|
m.addAction(_("Show/Hide"), self.show_or_hide)
|
||||||
|
m.addAction(_("Dark/Light"), self.toggle_tray_icon)
|
||||||
|
m.addSeparator()
|
||||||
|
m.addAction(_("Exit Electrum"), self.close)
|
||||||
|
self.tray.setContextMenu(m)
|
||||||
|
|
||||||
|
def toggle_tray_icon(self):
|
||||||
|
self.dark_icon = not self.dark_icon
|
||||||
|
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(icon)
|
||||||
|
|
||||||
|
def show_or_hide(self):
|
||||||
|
self.tray_activated(QSystemTrayIcon.DoubleClick)
|
||||||
|
|
||||||
|
def tray_activated(self, reason):
|
||||||
|
if reason == QSystemTrayIcon.DoubleClick:
|
||||||
|
if self.current_window.isMinimized() or self.current_window.isHidden():
|
||||||
|
self.current_window.show()
|
||||||
|
self.current_window.raise_()
|
||||||
|
else:
|
||||||
|
self.current_window.hide()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.current_window.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def go_full(self):
|
||||||
|
self.config.set_key('lite_mode', False, True)
|
||||||
|
self.lite_window.hide()
|
||||||
|
self.main_window.show()
|
||||||
|
self.main_window.raise_()
|
||||||
|
self.current_window = self.main_window
|
||||||
|
|
||||||
|
def go_lite(self):
|
||||||
|
self.config.set_key('lite_mode', True, True)
|
||||||
|
self.main_window.hide()
|
||||||
|
self.lite_window.show()
|
||||||
|
self.lite_window.raise_()
|
||||||
|
self.current_window = self.lite_window
|
||||||
|
|
||||||
|
|
||||||
|
def init_lite(self):
|
||||||
|
import lite_window
|
||||||
|
if not self.check_qt_version():
|
||||||
|
if self.config.get('lite_mode') is True:
|
||||||
|
msg = "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nChanging your config to use the 'Classic' GUI"
|
||||||
|
QMessageBox.warning(None, "Could not start Lite GUI.", msg)
|
||||||
|
self.config.set_key('lite_mode', False, True)
|
||||||
|
sys.exit(0)
|
||||||
|
self.lite_window = None
|
||||||
|
self.main_window.show()
|
||||||
|
self.main_window.raise_()
|
||||||
|
return
|
||||||
|
|
||||||
|
actuator = lite_window.MiniActuator(self.main_window)
|
||||||
|
actuator.load_theme()
|
||||||
|
self.lite_window = lite_window.MiniWindow(actuator, self.go_full, self.config)
|
||||||
|
driver = lite_window.MiniDriver(self.main_window, self.lite_window)
|
||||||
|
|
||||||
|
if self.config.get('lite_mode') is True:
|
||||||
|
self.go_lite()
|
||||||
|
else:
|
||||||
|
self.go_full()
|
||||||
|
|
||||||
|
|
||||||
|
def check_qt_version(self):
|
||||||
|
qtVersion = qVersion()
|
||||||
|
return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(self, url):
|
def main(self, url):
|
||||||
|
|
||||||
storage = WalletStorage(self.config)
|
storage = WalletStorage(self.config)
|
||||||
|
@ -95,7 +169,22 @@ class ElectrumGui:
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
wallet.start_threads(self.network)
|
wallet.start_threads(self.network)
|
||||||
|
|
||||||
self.main_window = w = ElectrumWindow(self.config, self.network)
|
|
||||||
|
# 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
|
||||||
|
self.main_window = w = ElectrumWindow(self.config, self.network, self)
|
||||||
|
self.current_window = self.main_window
|
||||||
|
|
||||||
|
#lite window
|
||||||
|
self.init_lite()
|
||||||
|
|
||||||
# plugins that need to change the GUI do it here
|
# plugins that need to change the GUI do it here
|
||||||
run_hook('init')
|
run_hook('init')
|
||||||
|
|
|
@ -100,47 +100,19 @@ default_column_widths = { "history":[40,140,350,140], "contacts":[350,330], "rec
|
||||||
|
|
||||||
class ElectrumWindow(QMainWindow):
|
class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
def build_tray_menu(self):
|
|
||||||
m = QMenu()
|
|
||||||
m.addAction(_("Show/Hide"), self.show_or_hide)
|
|
||||||
m.addAction(_("Dark/Light"), self.toggle_tray_icon)
|
|
||||||
m.addSeparator()
|
|
||||||
m.addAction(_("Exit Electrum"), self.close)
|
|
||||||
self.tray.setContextMenu(m)
|
|
||||||
|
|
||||||
def toggle_tray_icon(self):
|
|
||||||
self.dark_icon = not self.dark_icon
|
|
||||||
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(icon)
|
|
||||||
|
|
||||||
def show_or_hide(self):
|
def __init__(self, config, network, gui_object):
|
||||||
self.tray_activated(QSystemTrayIcon.DoubleClick)
|
|
||||||
|
|
||||||
def tray_activated(self, reason):
|
|
||||||
if reason == QSystemTrayIcon.DoubleClick:
|
|
||||||
if self.isMinimized() or self.isHidden():
|
|
||||||
self.show()
|
|
||||||
self.raise_()
|
|
||||||
else:
|
|
||||||
self.hide()
|
|
||||||
|
|
||||||
def __init__(self, config, network):
|
|
||||||
QMainWindow.__init__(self)
|
QMainWindow.__init__(self)
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
|
self.tray = gui_object.tray
|
||||||
|
self.go_lite = gui_object.go_lite
|
||||||
|
|
||||||
self._close_electrum = False
|
self._close_electrum = False
|
||||||
self.lite = None
|
self.lite = None
|
||||||
|
|
||||||
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, self)
|
|
||||||
self.tray.setToolTip('Electrum')
|
|
||||||
self.tray.activated.connect(self.tray_activated)
|
|
||||||
self.build_tray_menu()
|
|
||||||
self.tray.show()
|
|
||||||
|
|
||||||
self.create_status_bar()
|
self.create_status_bar()
|
||||||
self.need_update = threading.Event()
|
self.need_update = threading.Event()
|
||||||
|
@ -199,52 +171,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.console.showMessage(self.network.banner)
|
self.console.showMessage(self.network.banner)
|
||||||
|
|
||||||
self.wallet = None
|
self.wallet = None
|
||||||
self.init_lite()
|
|
||||||
|
|
||||||
|
|
||||||
def go_full(self):
|
|
||||||
self.config.set_key('lite_mode', False, True)
|
|
||||||
self.mini.hide()
|
|
||||||
self.show()
|
|
||||||
self.raise_()
|
|
||||||
|
|
||||||
def go_lite(self):
|
|
||||||
self.config.set_key('lite_mode', True, True)
|
|
||||||
self.hide()
|
|
||||||
self.mini.show()
|
|
||||||
self.mini.raise_()
|
|
||||||
|
|
||||||
|
|
||||||
def init_lite(self):
|
|
||||||
import lite_window
|
|
||||||
if not self.check_qt_version():
|
|
||||||
if self.config.get('lite_mode') is True:
|
|
||||||
msg = "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nChanging your config to use the 'Classic' GUI"
|
|
||||||
QMessageBox.warning(None, "Could not start Lite GUI.", msg)
|
|
||||||
self.config.set_key('lite_mode', False, True)
|
|
||||||
sys.exit(0)
|
|
||||||
self.mini = None
|
|
||||||
self.show()
|
|
||||||
self.raise_()
|
|
||||||
return
|
|
||||||
|
|
||||||
actuator = lite_window.MiniActuator(self)
|
|
||||||
|
|
||||||
actuator.load_theme()
|
|
||||||
|
|
||||||
self.mini = lite_window.MiniWindow(actuator, self.go_full, self.config)
|
|
||||||
|
|
||||||
driver = lite_window.MiniDriver(self, self.mini)
|
|
||||||
|
|
||||||
if self.config.get('lite_mode') is True:
|
|
||||||
self.go_lite()
|
|
||||||
else:
|
|
||||||
self.go_full()
|
|
||||||
|
|
||||||
|
|
||||||
def check_qt_version(self):
|
|
||||||
qtVersion = qVersion()
|
|
||||||
return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
|
|
||||||
|
|
||||||
|
|
||||||
def update_account_selector(self):
|
def update_account_selector(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue