Browse Source

plugins: fix labels plugin FIXME re "just enabled plugin"

master
SomberNight 5 years ago
parent
commit
24221f8fca
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/gui/qt/__init__.py
  2. 1
      electrum/gui/qt/main_window.py
  3. 7
      electrum/plugins/cosigner_pool/qt.py
  4. 8
      electrum/plugins/labels/labels.py
  5. 21
      electrum/plugins/labels/qt.py

4
electrum/gui/qt/__init__.py

@ -28,7 +28,7 @@ import signal
import sys
import traceback
import threading
from typing import Optional, TYPE_CHECKING
from typing import Optional, TYPE_CHECKING, List
try:
@ -106,7 +106,7 @@ class ElectrumGui(Logger):
self.config = config
self.daemon = daemon
self.plugins = plugins
self.windows = []
self.windows = [] # type: List[ElectrumWindow]
self.efilter = OpenFileEventFilter(self.windows)
self.app = QElectrumApplication(sys.argv)
self.app.installEventFilter(self.efilter)

1
electrum/gui/qt/main_window.py

@ -2951,6 +2951,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
p = plugins.toggle(name)
cb.setChecked(bool(p))
enable_settings_widget(p, name, i)
# note: all enabled plugins will receive this hook:
run_hook('init_qt', self.gui_object)
for i, descr in enumerate(plugins.descriptions.values()):

7
electrum/plugins/cosigner_pool/qt.py

@ -43,6 +43,7 @@ from electrum.gui.qt.transaction_dialog import show_transaction, TxDialog
from electrum.gui.qt.util import WaitingDialog
if TYPE_CHECKING:
from electrum.gui.qt import ElectrumGui
from electrum.gui.qt.main_window import ElectrumWindow
@ -101,9 +102,13 @@ class Plugin(BasePlugin):
self.obj.cosigner_receive_signal.connect(self.on_receive)
self.keys = [] # type: List[Tuple[str, str, ElectrumWindow]]
self.cosigner_list = [] # type: List[Tuple[ElectrumWindow, str, bytes, str]]
self._init_qt_received = False
@hook
def init_qt(self, gui):
def init_qt(self, gui: 'ElectrumGui'):
if self._init_qt_received: # only need/want the first signal
return
self._init_qt_received = True
for window in gui.windows:
self.on_new_window(window)

8
electrum/plugins/labels/labels.py

@ -3,7 +3,7 @@ import hashlib
import json
import sys
import traceback
from typing import Union
from typing import Union, TYPE_CHECKING
import base64
@ -13,6 +13,9 @@ from electrum.i18n import _
from electrum.util import log_exceptions, ignore_exceptions, make_aiohttp_session
from electrum.network import Network
if TYPE_CHECKING:
from electrum.wallet import Abstract_Wallet
class ErrorConnectingServer(Exception):
def __init__(self, reason: Union[str, Exception] = None):
@ -152,6 +155,9 @@ class LabelsPlugin(BasePlugin):
self.set_nonce(wallet, response["nonce"] + 1)
self.on_pulled(wallet)
def on_pulled(self, wallet: 'Abstract_Wallet') -> None:
raise NotImplementedError()
@ignore_exceptions
@log_exceptions
async def pull_safe_thread(self, wallet, force):

21
electrum/plugins/labels/qt.py

@ -1,6 +1,7 @@
from functools import partial
import traceback
import sys
from typing import TYPE_CHECKING
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtWidgets import (QHBoxLayout, QLabel, QVBoxLayout)
@ -11,6 +12,10 @@ from electrum.gui.qt.util import ThreadedButton, Buttons, EnterButton, WindowMod
from .labels import LabelsPlugin
if TYPE_CHECKING:
from electrum.gui.qt import ElectrumGui
from electrum.gui.qt.main_window import ElectrumWindow
from electrum.wallet import Abstract_Wallet
class QLabelsSignalObject(QObject):
labels_changed_signal = pyqtSignal(object)
@ -21,6 +26,7 @@ class Plugin(LabelsPlugin):
def __init__(self, *args):
LabelsPlugin.__init__(self, *args)
self.obj = QLabelsSignalObject()
self._init_qt_received = False
def requires_settings(self):
return True
@ -63,10 +69,17 @@ class Plugin(LabelsPlugin):
dialog.show_error(_("Error synchronising labels") + f':\n{repr(exc_info[1])}')
@hook
def load_wallet(self, wallet, window):
# FIXME if the user just enabled the plugin, this hook won't be called
# as the wallet is already loaded, and hence the plugin will be in
# a non-functional state for that window
def init_qt(self, gui: 'ElectrumGui'):
if self._init_qt_received: # only need/want the first signal
return
self._init_qt_received = True
# If the user just enabled the plugin, the 'load_wallet' hook would not
# get called for already loaded wallets, hence we call it manually for those:
for window in gui.windows:
self.load_wallet(window.wallet, window)
@hook
def load_wallet(self, wallet: 'Abstract_Wallet', window: 'ElectrumWindow'):
self.obj.labels_changed_signal.connect(window.update_tabs)
self.start_wallet(wallet)

Loading…
Cancel
Save