Skip to content

Commit

Permalink
Add open_help argument for async wizard.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brow71189 committed Aug 20, 2024
1 parent 1078bca commit 38d2484
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions nion/experimental/Wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ async def run(self) -> int:


class AsyncWizardUIHandler(Declarative.Handler):
def __init__(self, api: API, ui_view: Declarative.UIDescription, wizard_steps: typing.Sequence[AsyncWizardStep], event_loop: typing.Optional[asyncio.AbstractEventLoop] = None) -> None:
def __init__(self,
api: API,
ui_view: Declarative.UIDescription,
wizard_steps: typing.Sequence[AsyncWizardStep], *,
event_loop: typing.Optional[asyncio.AbstractEventLoop] = None,
open_help: typing.Callable[[], None] | None = None) -> None:
super().__init__()
self.__event_loop = event_loop or asyncio.get_event_loop()
self.__wizard_steps = wizard_steps
Expand All @@ -128,6 +133,7 @@ def __init__(self, api: API, ui_view: Declarative.UIDescription, wizard_steps: t
self.__run_step_button_enabled = True
self.instructions_background_default_color = '#f0f0f0'
self.instructions_background_action_color = 'peachpuff'
self.__open_help = open_help
self.__create_requirement_properties()

@staticmethod
Expand Down Expand Up @@ -352,6 +358,10 @@ def close(self) -> None:
self.on_closed()
super().close()

def open_help(self, widget: Declarative.UIWidget) -> None:
if self.__open_help is not None:
self.__open_help()

def __set_up_ui_for_pre_wizard_step(self) -> None:
def listen_fn(listen_to: set[str], fire: set[str], name: str) -> None:
if name in listen_to:
Expand All @@ -376,7 +386,7 @@ def __set_up_ui_for_post_wizard_step(self) -> None:
if self.current_step_index < len(self.__wizard_steps) - 1:
self.continue_enabled = True
self.cancel_button_visible = False
self.skip_button_visible = True
self.skip_button_visible = not self.current_step.canceled
self.status_text = 'Done. Use the buttons below to restart the current or continue with the next step.'
else:
self.continue_enabled = False
Expand Down Expand Up @@ -690,11 +700,11 @@ def get_ui_handler(self, api_broker: PlugInManager.APIBroker, wizard_steps: typi
ui_view = self.__create_ui_view(ui, wizard_steps, title)
return WizardUIHandler(api, ui_view, wizard_steps)

def get_ui_handler_v2(self, api_broker: PlugInManager.APIBroker, wizard_steps: typing.Sequence[AsyncWizardStep], title: str) -> AsyncWizardUIHandler:
def get_ui_handler_v2(self, api_broker: PlugInManager.APIBroker, wizard_steps: typing.Sequence[AsyncWizardStep], title: str, *, open_help: typing.Callable[[], None] | None = None) -> AsyncWizardUIHandler:
api = api_broker.get_api('~1.0')
ui = api_broker.get_ui('~1.0')
ui_view = self.__create_ui_view_v2(ui, wizard_steps, title)
return AsyncWizardUIHandler(api, ui_view, wizard_steps)
ui_view = self.__create_ui_view_v2(ui, wizard_steps, title, open_help is not None)
return AsyncWizardUIHandler(api, ui_view, wizard_steps, open_help=open_help)

def __create_ui_view(self, ui: Declarative.DeclarativeUI, wizard_steps: typing.Sequence[WizardStep], title: str) -> Declarative.UIDescription:
steps = [ui.create_radio_button(text=' ', value=step.step_index, group_value='@binding(current_step)', enabled=False) for step in wizard_steps]
Expand Down Expand Up @@ -729,11 +739,14 @@ def __generate_requirements_ui(self, ui: Declarative.DeclarativeUI, wizard_step:
requirements.append(ui.create_row(ui.create_push_button(text='Run step', on_clicked='run_step_clicked', enabled='@binding(run_step_button_enabled)'), ui.create_stretch(), margin=5, spacing=5))
return ui.create_column(*requirements)

def __create_ui_view_v2(self, ui: Declarative.DeclarativeUI, wizard_steps: typing.Sequence[AsyncWizardStep], title: str) -> Declarative.UIDescription:
def __create_ui_view_v2(self, ui: Declarative.DeclarativeUI, wizard_steps: typing.Sequence[AsyncWizardStep], title: str, has_help: bool) -> Declarative.UIDescription:
steps = [ui.create_radio_button(text=' ', value=step.step_index, group_value='@binding(current_step_index)', enabled=False) for step in wizard_steps]
steps.insert(0, ui.create_stretch())
steps.append(ui.create_stretch())
step_row = ui.create_row(ui.create_push_button(text='\u2630', on_clicked='show_menu_clicked', size_policy_horizontal='minimum', size_policy_vertical='minimum', background_color='#f0f0f0', border_color='#f0f0f0', font='bold', style='minimal'), *steps, margin=5)
step_row = ui.create_row(ui.create_push_button(text='\u2630', on_clicked='show_menu_clicked', size_policy_horizontal='minimum', size_policy_vertical='minimum', background_color='#f0f0f0', border_color='#f0f0f0', font='bold', style='minimal'),
*steps,
ui.create_push_button(text='\u2754', on_clicked='open_help', visible=has_help, size_policy_horizontal='minimum', size_policy_vertical='minimum', background_color='#f0f0f0', border_color='#f0f0f0', font='bold', style='minimal'),
margin=5)
title_row = ui.create_row(ui.create_label(text='@binding(current_step_title)', font='bold'), spacing=5, margin=5)
description_row = ui.create_row(ui.create_label(text='@binding(current_step_description)'), spacing=5, margin=5)
requirements = [self.__generate_requirements_ui(ui, wizard_step) for wizard_step in wizard_steps]
Expand Down

0 comments on commit 38d2484

Please sign in to comment.