1
0

refactor qt.util.ChoiceWidget: introduce ChoiceItem

This commit is contained in:
SomberNight
2025-05-06 17:47:11 +00:00
parent ef49bb2109
commit ba3783f998
18 changed files with 153 additions and 116 deletions

View File

@@ -30,7 +30,7 @@ from electrum.plugin import (BasePlugin, hook, Device, DeviceMgr,
assert_runs_in_hwd_thread, runs_in_hwd_thread)
from electrum.i18n import _
from electrum.bitcoin import is_address, opcodes
from electrum.util import versiontuple, UserFacingException
from electrum.util import versiontuple, UserFacingException, ChoiceItem
from electrum.transaction import TxOutput, PartialTransaction
from electrum.bip32 import BIP32Node
from electrum.storage import get_derivation_used_for_hw_device_encryption
@@ -316,7 +316,8 @@ class HardwareHandlerBase:
def update_status(self, paired: bool) -> None:
pass
def query_choice(self, msg: str, labels: Sequence[str]) -> Optional[int]:
def query_choice(self, msg: str, choices: Sequence[ChoiceItem]) -> Optional[Any]:
"""Returns ChoiceItem.key (for selected item), or None if the user cancels the dialog."""
raise NotImplementedError()
def yes_no_question(self, msg: str) -> bool:

View File

@@ -41,7 +41,7 @@ from electrum.gui.qt.util import read_QIcon_from_bytes
from electrum.i18n import _
from electrum.logging import Logger
from electrum.util import UserCancelled, UserFacingException
from electrum.util import UserCancelled, UserFacingException, ChoiceItem
from electrum.plugin import hook, DeviceUnpairableError
from .plugin import OutdatedHwFirmwareException, HW_PluginBase, HardwareHandlerBase
@@ -98,9 +98,9 @@ class QtHandlerBase(HardwareHandlerBase, QObject, Logger):
icon = read_QIcon_from_bytes(icon_bytes)
button.setIcon(icon)
def query_choice(self, msg: str, labels: Sequence[Tuple]):
def query_choice(self, msg: str, choices: Sequence[ChoiceItem]):
self.done.clear()
self.query_signal.emit(msg, labels)
self.query_signal.emit(msg, choices)
self.done.wait()
return self.choice
@@ -197,9 +197,9 @@ class QtHandlerBase(HardwareHandlerBase, QObject, Logger):
self.dialog.accept()
self.dialog = None
def win_query_choice(self, msg: str, labels: Sequence[Tuple]):
def win_query_choice(self, msg: str, choices: Sequence[ChoiceItem]):
try:
self.choice = self.win.query_choice(msg, labels)
self.choice = self.win.query_choice(msg, choices)
except UserCancelled:
self.choice = None
self.done.set()