Esempio n. 1
0
    def __init__(self, config, daemon, plugins):
        super(__class__, self).__init__()  # QtCore.QObject init
        assert __class__.instance is None, "ElectrumGui is a singleton, yet an instance appears to already exist! FIXME!"
        __class__.instance = self

        self.config = config
        self.daemon = daemon
        self.plugins = plugins
        self.windows = []

        self._setup_do_in_main_thread_handler()

        # Uncomment this call to verify objects are being properly
        # GC-ed when windows are closed
        #if daemon.network:
        #    from electroncash.util import DebugMem
        #    from electroncash.wallet import Abstract_Wallet
        #    from electroncash.verifier import SPV
        #    from electroncash.synchronizer import Synchronizer
        #    daemon.network.add_jobs([DebugMem([Abstract_Wallet, SPV, Synchronizer,
        #                                       ElectrumWindow], interval=5)])

        self.app = QtWidgets.QApplication.instance()

        self._load_fonts(
        )  # this needs to be done very early, before the font engine loads fonts.. out of paranoia
        self._exit_if_required_pyqt_is_missing(
        )  # This may immediately exit the app if missing required PyQt5 modules, so it should also be done early.
        self.new_version_available = None
        self._set_icon()
        self.app.installEventFilter(self)
        self.timer = QtCore.QTimer(self)
        self.timer.setSingleShot(False)
        self.timer.setInterval(500)  #msec
        self.gc_timer = QtCore.QTimer(self)
        self.gc_timer.setSingleShot(True)
        self.gc_timer.timeout.connect(ElectrumGui.gc)
        self.gc_timer.setInterval(500)  #msec
        self.nd = None
        self._last_active_window = None  # we remember the last activated ElectrumWindow as a Weak.ref
        Address.set_address_format(self.get_config_addr_format())
        # Dark Theme -- ideally set this before any widgets are created.
        self.set_dark_theme_if_needed()
        # /
        # Wallet Password Cache
        # wallet -> (password, QTimer) map for some plugins (like CashShuffle)
        # that need wallet passwords to operate, and we don't want to prompt
        # for pw twice right after the InstallWizard runs (see #106).
        # Entries in this map are deleted after 10 seconds by the QTimer (which
        # also deletes itself)
        self._wallet_password_cache = Weak.KeyDictionary()
        # /
        self.update_checker = UpdateChecker()
        self.update_checker_timer = QtCore.QTimer(self)
        self.update_checker_timer.timeout.connect(self.on_auto_update_timeout)
        self.update_checker_timer.setSingleShot(False)
        self.update_checker.got_new_version.connect(self.on_new_version)
        # init tray
        self.dark_icon = self.config.get("dark_icon", False)
        self.tray = QtWidgets.QSystemTrayIcon(self.tray_icon(), self)
        self.tray.setToolTip(f'{PROJECT_NAME}')
        self.tray.activated.connect(self.tray_activated)
        self.build_tray_menu()
        self.tray.show()
        self.new_window_signal.connect(self.start_new_window)
        if self.has_auto_update_check():
            self._start_auto_update_timer(first_run=True)
        self.app.focusChanged.connect(
            self.on_focus_change)  # track last window the user interacted with
        self.shutdown_signal.connect(self.close, QtCore.Qt.QueuedConnection)
        run_hook('init_qt', self)
        # We did this once already in the set_dark_theme call, but we do this
        # again here just in case some plugin modified the color scheme.
        ColorScheme.update_from_widget(QtWidgets.QWidget())

        self._check_and_warn_qt_version()
Esempio n. 2
0
 def set_address_format(self, fmt):
     """Specify which address format to use."""
     self.config.set_key('address_format', fmt)
     Address.set_address_format(fmt)
     self.addr_fmt_changed.emit()