gui: add BaseElectrumGui base class for guis
This commit is contained in:
@@ -441,7 +441,7 @@ class PayServer(Logger):
|
||||
class Daemon(Logger):
|
||||
|
||||
network: Optional[Network]
|
||||
gui_object: Optional[Union['gui.qt.ElectrumGui', 'gui.kivy.ElectrumGui']]
|
||||
gui_object: Optional['gui.BaseElectrumGui']
|
||||
|
||||
@profiler
|
||||
def __init__(self, config: SimpleConfig, fd=None, *, listen_jsonrpc=True):
|
||||
@@ -614,7 +614,7 @@ class Daemon(Logger):
|
||||
self.logger.info(f'launching GUI: {gui_name}')
|
||||
try:
|
||||
gui = __import__('electrum.gui.' + gui_name, fromlist=['electrum'])
|
||||
self.gui_object = gui.ElectrumGui(config, self, plugins)
|
||||
self.gui_object = gui.ElectrumGui(config=config, daemon=self, plugins=plugins)
|
||||
if not self._stop_entered:
|
||||
self.gui_object.main()
|
||||
else:
|
||||
|
||||
@@ -9,3 +9,22 @@ from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from . import qt
|
||||
from . import kivy
|
||||
from electrum.simple_config import SimpleConfig
|
||||
from electrum.daemon import Daemon
|
||||
from electrum.plugin import Plugins
|
||||
|
||||
|
||||
class BaseElectrumGui:
|
||||
def __init__(self, *, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
self.config = config
|
||||
self.daemon = daemon
|
||||
self.plugins = plugins
|
||||
|
||||
def main(self) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
def stop(self) -> None:
|
||||
"""Stops the GUI.
|
||||
This method must be thread-safe.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -44,6 +44,7 @@ except ImportError:
|
||||
kivy.require('1.8.0')
|
||||
|
||||
from electrum.logging import Logger
|
||||
from electrum.gui import BaseElectrumGui
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from electrum.simple_config import SimpleConfig
|
||||
@@ -51,25 +52,20 @@ if TYPE_CHECKING:
|
||||
from electrum.plugin import Plugins
|
||||
|
||||
|
||||
class ElectrumGui(BaseElectrumGui, Logger):
|
||||
|
||||
|
||||
class ElectrumGui(Logger):
|
||||
|
||||
def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
def __init__(self, *, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
||||
Logger.__init__(self)
|
||||
self.logger.debug('ElectrumGUI: initialising')
|
||||
self.daemon = daemon
|
||||
self.network = daemon.network
|
||||
self.config = config
|
||||
self.plugins = plugins
|
||||
|
||||
def main(self):
|
||||
from .main_window import ElectrumWindow
|
||||
w = ElectrumWindow(config=self.config,
|
||||
network=self.network,
|
||||
plugins = self.plugins,
|
||||
gui_object=self)
|
||||
w = ElectrumWindow(
|
||||
config=self.config,
|
||||
network=self.network,
|
||||
plugins=self.plugins,
|
||||
gui_object=self,
|
||||
)
|
||||
w.run()
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
@@ -50,6 +50,7 @@ from electrum.util import (UserCancelled, profiler, send_exception_to_crash_repo
|
||||
from electrum.wallet import Wallet, Abstract_Wallet
|
||||
from electrum.wallet_db import WalletDB
|
||||
from electrum.logging import Logger
|
||||
from electrum.gui import BaseElectrumGui
|
||||
|
||||
from .installwizard import InstallWizard, WalletAlreadyOpenInMemory
|
||||
from .util import get_default_language, read_QIcon, ColorScheme, custom_message_box, MessageBoxMixin
|
||||
@@ -88,15 +89,16 @@ class QNetworkUpdatedSignalObject(QObject):
|
||||
network_updated_signal = pyqtSignal(str, object)
|
||||
|
||||
|
||||
class ElectrumGui(Logger):
|
||||
class ElectrumGui(BaseElectrumGui, Logger):
|
||||
|
||||
network_dialog: Optional['NetworkDialog']
|
||||
lightning_dialog: Optional['LightningDialog']
|
||||
watchtower_dialog: Optional['WatchtowerDialog']
|
||||
|
||||
@profiler
|
||||
def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
def __init__(self, *, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
set_language(config.get('language', get_default_language()))
|
||||
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
||||
Logger.__init__(self)
|
||||
self.logger.info(f"Qt GUI starting up... Qt={QtCore.QT_VERSION_STR}, PyQt={QtCore.PYQT_VERSION_STR}")
|
||||
# Uncomment this call to verify objects are being properly
|
||||
@@ -109,9 +111,6 @@ class ElectrumGui(Logger):
|
||||
if hasattr(QGuiApplication, 'setDesktopFileName'):
|
||||
QGuiApplication.setDesktopFileName('electrum.desktop')
|
||||
self.gui_thread = threading.current_thread()
|
||||
self.config = config
|
||||
self.daemon = daemon
|
||||
self.plugins = plugins
|
||||
self.windows = [] # type: List[ElectrumWindow]
|
||||
self.efilter = OpenFileEventFilter(self.windows)
|
||||
self.app = QElectrumApplication(sys.argv)
|
||||
@@ -430,8 +429,5 @@ class ElectrumGui(Logger):
|
||||
# on some platforms the exec_ call may not return, so use _cleanup_before_exit
|
||||
|
||||
def stop(self):
|
||||
"""Stops the GUI.
|
||||
This method is thread-safe.
|
||||
"""
|
||||
self.logger.info('closing GUI')
|
||||
self.app.quit_signal.emit()
|
||||
|
||||
@@ -3,6 +3,7 @@ import getpass
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from electrum.gui import BaseElectrumGui
|
||||
from electrum import util
|
||||
from electrum import WalletStorage, Wallet
|
||||
from electrum.wallet_db import WalletDB
|
||||
@@ -17,10 +18,10 @@ _ = lambda x:x # i18n
|
||||
# written by rofl0r, with some bits stolen from the text gui (ncurses)
|
||||
|
||||
|
||||
class ElectrumGui:
|
||||
class ElectrumGui(BaseElectrumGui):
|
||||
|
||||
def __init__(self, config, daemon, plugins):
|
||||
self.config = config
|
||||
def __init__(self, *, config, daemon, plugins):
|
||||
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
||||
self.network = daemon.network
|
||||
storage = WalletStorage(config.get_wallet_path())
|
||||
if not storage.file_exists:
|
||||
|
||||
@@ -9,6 +9,7 @@ import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import electrum
|
||||
from electrum.gui import BaseElectrumGui
|
||||
from electrum import util
|
||||
from electrum.util import format_satoshis
|
||||
from electrum.bitcoin import is_address, COIN
|
||||
@@ -28,11 +29,10 @@ if TYPE_CHECKING:
|
||||
_ = lambda x:x # i18n
|
||||
|
||||
|
||||
class ElectrumGui:
|
||||
class ElectrumGui(BaseElectrumGui):
|
||||
|
||||
def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
|
||||
self.config = config
|
||||
def __init__(self, *, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
|
||||
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
||||
self.network = daemon.network
|
||||
storage = WalletStorage(config.get_wallet_path())
|
||||
if not storage.file_exists():
|
||||
@@ -342,9 +342,6 @@ class ElectrumGui:
|
||||
curses.echo()
|
||||
curses.endwin()
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def do_clear(self):
|
||||
self.str_amount = ''
|
||||
self.str_recipient = ''
|
||||
|
||||
Reference in New Issue
Block a user