Plugins: pass wallet to settings_dialog
Also, remove settings_widget method. The widget should always be a button. nwc: is_initialized -> initialized
This commit is contained in:
@@ -294,9 +294,9 @@ class ElectrumGui(BaseElectrumGui, Logger):
|
||||
self.lightning_dialog = LightningDialog(self)
|
||||
self.lightning_dialog.bring_to_top()
|
||||
|
||||
def show_plugins_dialog(self):
|
||||
def show_plugins_dialog(self, wallet=None):
|
||||
from .plugins_dialog import PluginsDialog
|
||||
d = PluginsDialog(self)
|
||||
d = PluginsDialog(self, wallet)
|
||||
d.exec()
|
||||
|
||||
def show_network_dialog(self, proxy_tab=False):
|
||||
|
||||
@@ -759,7 +759,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
tools_menu.addAction(_("Electrum preferences"), self.settings_dialog)
|
||||
|
||||
tools_menu.addAction(_("&Network"), self.gui_object.show_network_dialog).setEnabled(bool(self.network))
|
||||
tools_menu.addAction(_("&Plugins"), self.gui_object.show_plugins_dialog)
|
||||
tools_menu.addAction(_("&Plugins"), partial(self.gui_object.show_plugins_dialog, self.wallet))
|
||||
tools_menu.addSeparator()
|
||||
tools_menu.addAction(_("&Sign/verify message"), self.sign_verify_message)
|
||||
tools_menu.addAction(_("&Encrypt/decrypt message"), self.encrypt_message)
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from functools import partial
|
||||
import shutil
|
||||
import os
|
||||
|
||||
from PyQt6.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton, QWidget, QScrollArea, QFormLayout
|
||||
from PyQt6.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton, QWidget, QScrollArea, QFormLayout, QFileDialog
|
||||
|
||||
from electrum.i18n import _
|
||||
from electrum.plugin import run_hook
|
||||
|
||||
from .util import WindowModalDialog, Buttons, CloseButton, WWLabel, insert_spaces, MessageBoxMixin
|
||||
from .util import WindowModalDialog, Buttons, CloseButton, WWLabel, insert_spaces, MessageBoxMixin, EnterButton
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import ElectrumGui
|
||||
from electrum_cc import ECPrivkey
|
||||
from electrum.wallet import Abstract_Wallet
|
||||
|
||||
|
||||
class PluginDialog(WindowModalDialog):
|
||||
@@ -56,9 +59,11 @@ class PluginDialog(WindowModalDialog):
|
||||
close_button.setText(_('Close'))
|
||||
buttons = [toggle_button, close_button]
|
||||
# add settings widget
|
||||
if p and p.requires_settings() and p.is_enabled():
|
||||
widget = p.settings_widget(self)
|
||||
buttons.insert(0, widget)
|
||||
if p and p.requires_settings() and p.is_enabled() and self.window.wallet is not None:
|
||||
button = EnterButton(
|
||||
_('Settings'),
|
||||
partial(p.settings_dialog, self, self.window.wallet))
|
||||
buttons.insert(0, button)
|
||||
vbox.addLayout(Buttons(*buttons))
|
||||
|
||||
def do_toggle(self, toggle_button, name):
|
||||
@@ -115,11 +120,12 @@ class PluginStatusButton(QPushButton):
|
||||
|
||||
class PluginsDialog(WindowModalDialog, MessageBoxMixin):
|
||||
|
||||
def __init__(self, gui_object: 'ElectrumGui'):
|
||||
def __init__(self, gui_object: 'ElectrumGui', wallet: Optional['Abstract_Wallet']):
|
||||
WindowModalDialog.__init__(self, None, _('Electrum Plugins'))
|
||||
self.gui_object = gui_object
|
||||
self.config = gui_object.config
|
||||
self.plugins = gui_object.plugins
|
||||
self.wallet = wallet
|
||||
vbox = QVBoxLayout(self)
|
||||
scroll = QScrollArea()
|
||||
scroll.setEnabled(True)
|
||||
@@ -216,8 +222,6 @@ class PluginsDialog(WindowModalDialog, MessageBoxMixin):
|
||||
os.unlink(path)
|
||||
|
||||
def add_plugin_dialog(self):
|
||||
from PyQt6.QtWidgets import QFileDialog
|
||||
import shutil, os
|
||||
pubkey, salt = self.plugins.get_pubkey_bytes()
|
||||
if not pubkey:
|
||||
self.init_plugins_password()
|
||||
|
||||
@@ -48,10 +48,7 @@ class Plugin(BasePlugin):
|
||||
def requires_settings(self):
|
||||
return True
|
||||
|
||||
def settings_widget(self, window):
|
||||
return EnterButton(_('Settings'), partial(self.settings_dialog, window))
|
||||
|
||||
def settings_dialog(self, window):
|
||||
def settings_dialog(self, window, wallet):
|
||||
d = WindowModalDialog(window, _("Audio Modem Settings"))
|
||||
|
||||
layout = QGridLayout(d)
|
||||
|
||||
@@ -31,12 +31,7 @@ class Plugin(LabelsPlugin):
|
||||
def requires_settings(self):
|
||||
return True
|
||||
|
||||
def settings_widget(self, window: WindowModalDialog):
|
||||
return EnterButton(_('Settings'),
|
||||
partial(self.settings_dialog, window))
|
||||
|
||||
def settings_dialog(self, window: WindowModalDialog):
|
||||
wallet = window.parent().wallet
|
||||
def settings_dialog(self, window: WindowModalDialog, wallet: 'Abstract_Wallet'):
|
||||
if not wallet.get_fingerprint():
|
||||
window.show_error(_("{} plugin does not support this type of wallet.")
|
||||
.format("Label Sync"))
|
||||
|
||||
@@ -44,7 +44,7 @@ class NWCServerPlugin(BasePlugin):
|
||||
def start_plugin(self, wallet: 'Abstract_Wallet'):
|
||||
if not wallet.has_lightning():
|
||||
return
|
||||
if self.is_initialized:
|
||||
if self.initialized:
|
||||
# this might be called for several wallets. only use one.
|
||||
return
|
||||
storage = self.get_plugin_storage(wallet)
|
||||
|
||||
@@ -38,11 +38,12 @@ class Plugin(NWCServerPlugin):
|
||||
def requires_settings(self):
|
||||
return True
|
||||
|
||||
def settings_widget(self, window: WindowModalDialog):
|
||||
return EnterButton(_('Setup'),
|
||||
partial(self.settings_dialog, window))
|
||||
def settings_dialog(self, window: WindowModalDialog, wallet: 'Abstract_Wallet'):
|
||||
if not wallet.has_lightning():
|
||||
window.show_error(_("{} plugin requires a lightning enabled wallet. Setup lightning first.")
|
||||
.format("NWC"))
|
||||
return
|
||||
|
||||
def settings_dialog(self, window: WindowModalDialog):
|
||||
d = WindowModalDialog(window, _("Nostr Wallet Connect"))
|
||||
main_layout = QVBoxLayout(d)
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ class Plugin(RevealerPlugin):
|
||||
def requires_settings(self):
|
||||
return True
|
||||
|
||||
def settings_widget(self, window):
|
||||
return EnterButton(_('Printer Calibration'), partial(self.calibration_dialog, window))
|
||||
def settings_dialog(self, window, wallet):
|
||||
return self.calibration_dialog(window)
|
||||
|
||||
def password_dialog(self, msg=None, parent=None):
|
||||
from electrum.gui.qt.password_dialog import PasswordDialog
|
||||
|
||||
Reference in New Issue
Block a user