mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
wizard: allow kwargs in run()
This commit is contained in:
parent
0ac2ca8ed3
commit
b076f5294f
1 changed files with 7 additions and 6 deletions
|
@ -28,7 +28,7 @@ import sys
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
import traceback
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import List, TYPE_CHECKING, Tuple, NamedTuple, Any
|
from typing import List, TYPE_CHECKING, Tuple, NamedTuple, Any, Dict
|
||||||
|
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from . import keystore
|
from . import keystore
|
||||||
|
@ -61,6 +61,7 @@ class GoBack(Exception): pass
|
||||||
class WizardStackItem(NamedTuple):
|
class WizardStackItem(NamedTuple):
|
||||||
action: Any
|
action: Any
|
||||||
args: Any
|
args: Any
|
||||||
|
kwargs: Dict[str, Any]
|
||||||
storage_data: dict
|
storage_data: dict
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,21 +82,21 @@ class BaseWizard(object):
|
||||||
def set_icon(self, icon):
|
def set_icon(self, icon):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, *args):
|
def run(self, *args, **kwargs):
|
||||||
action = args[0]
|
action = args[0]
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
storage_data = copy.deepcopy(self.data)
|
storage_data = copy.deepcopy(self.data)
|
||||||
self._stack.append(WizardStackItem(action, args, storage_data))
|
self._stack.append(WizardStackItem(action, args, kwargs, storage_data))
|
||||||
if not action:
|
if not action:
|
||||||
return
|
return
|
||||||
if type(action) is tuple:
|
if type(action) is tuple:
|
||||||
self.plugin, action = action
|
self.plugin, action = action
|
||||||
if self.plugin and hasattr(self.plugin, action):
|
if self.plugin and hasattr(self.plugin, action):
|
||||||
f = getattr(self.plugin, action)
|
f = getattr(self.plugin, action)
|
||||||
f(self, *args)
|
f(self, *args, **kwargs)
|
||||||
elif hasattr(self, action):
|
elif hasattr(self, action):
|
||||||
f = getattr(self, action)
|
f = getattr(self, action)
|
||||||
f(*args)
|
f(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise Exception("unknown action", action)
|
raise Exception("unknown action", action)
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ class BaseWizard(object):
|
||||||
# FIXME only self.storage is properly restored
|
# FIXME only self.storage is properly restored
|
||||||
self.data = copy.deepcopy(stack_item.storage_data)
|
self.data = copy.deepcopy(stack_item.storage_data)
|
||||||
# rerun 'previous' frame
|
# rerun 'previous' frame
|
||||||
self.run(stack_item.action, *stack_item.args)
|
self.run(stack_item.action, *stack_item.args, **stack_item.kwargs)
|
||||||
|
|
||||||
def reset_stack(self):
|
def reset_stack(self):
|
||||||
self._stack = []
|
self._stack = []
|
||||||
|
|
Loading…
Add table
Reference in a new issue