@@ -60,9 +60,9 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
|
||||
|
||||
def qr_input(self):
|
||||
from electrum import qrscanner
|
||||
main_window = get_parent_main_window(self)
|
||||
assert main_window
|
||||
config = main_window.config
|
||||
window_or_wizard = get_parent_main_window(self, allow_wizard=True)
|
||||
assert window_or_wizard
|
||||
config = window_or_wizard.config
|
||||
try:
|
||||
data = qrscanner.scan_barcode(config.get_video_device())
|
||||
except BaseException as e:
|
||||
|
||||
@@ -30,6 +30,7 @@ from electrum.invoices import PR_UNPAID, PR_PAID, PR_EXPIRED, PR_INFLIGHT, PR_UN
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .main_window import ElectrumWindow
|
||||
from .installwizard import InstallWizard
|
||||
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
@@ -945,19 +946,23 @@ def export_meta_gui(electrum_window, title, exporter):
|
||||
.format(title, str(filename)))
|
||||
|
||||
|
||||
def get_parent_main_window(widget):
|
||||
def get_parent_main_window(
|
||||
widget, *, allow_wizard: bool = False,
|
||||
) -> Union[None, 'ElectrumWindow', 'InstallWizard']:
|
||||
"""Returns a reference to the ElectrumWindow this widget belongs to."""
|
||||
from .main_window import ElectrumWindow
|
||||
from .transaction_dialog import TxDialog
|
||||
from .installwizard import InstallWizard
|
||||
for _ in range(100):
|
||||
if widget is None:
|
||||
return None
|
||||
if isinstance(widget, ElectrumWindow):
|
||||
return widget
|
||||
elif isinstance(widget, TxDialog):
|
||||
if isinstance(widget, TxDialog):
|
||||
return widget.main_window
|
||||
else:
|
||||
widget = widget.parentWidget()
|
||||
if isinstance(widget, InstallWizard) and allow_wizard:
|
||||
return widget
|
||||
widget = widget.parentWidget()
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user