Skip to content

Commit

Permalink
Correctly refresh corridor settings when shown
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Aug 10, 2024
1 parent d41772c commit 24493d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
21 changes: 16 additions & 5 deletions src/app/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def __init__(self) -> None:
self.current = AsyncValue(utils.ID_RANDOM)

@abstractmethod
async def display(self, row: int, option: Option, remove_event: trio.Event) -> None:
async def display(
self,
row: int, option: Option, remove_event: trio.Event,
*, task_status: trio.TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
"""Reconfigure this row to display the specified option, then show it.
Once the event triggers, remove the row.
Expand Down Expand Up @@ -446,10 +450,17 @@ def corr_changed(new: corridor.CorridorUI | None) -> bool:
done_event = trio.Event()
opt: Option
row: OptionRowT
for ind, (opt, row) in enumerate(zip(options, self.option_rows, strict=False)):
row.current.value = option_conf.value_for(opt)
nursery.start_soon(row.display, ind, opt, done_event)
option_async_vals.append((opt.id, row.current))
# This nursery exits only once all the option tasks has fully initialised.
async with trio.open_nursery() as start_nursery:
for ind, (opt, row) in enumerate(
zip(options, self.option_rows, strict=False)
):
row.current.value = option_conf.value_for(opt)
start_nursery.start_soon(
nursery.start,
row.display, ind, opt, done_event,
)
option_async_vals.append((opt.id, row.current))

# This task stores results when a config is changed. Not required
# if we don't actually have any options.
Expand Down
6 changes: 5 additions & 1 deletion src/ui_tk/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def __init__(self, parent: ttk.Frame) -> None:
tooltip.add_tooltip(self.label)

@override
async def display(self, row: int, option: Option, remove_event: trio.Event) -> None:
async def display(
self, row: int, option: Option, remove_event: trio.Event,
*, task_status: trio.TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
"""Display the row in the specified position, then remove when the event triggers."""
set_text(self.label, option.name)
tooltip.set_tooltip(self.label, option.desc)
Expand All @@ -126,6 +129,7 @@ async def display(self, row: int, option: Option, remove_event: trio.Event) -> N
self.label.grid(row=row + 1, column=0)
self.combo.grid(row=row + 1, column=1, sticky='ew')
# Wait for the signal that the corridor has been deselected, then remove.
task_status.started()
await remove_event.wait()
self.label.grid_forget()
self.combo.grid_forget()
Expand Down
6 changes: 4 additions & 2 deletions src/ui_wx/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def __init__(self, parent: wx.Panel, sizer: wx.GridSizer) -> None:
self.combo.Bind(wx.EVT_COMBOBOX, self.on_changed)

@override
async def display(self, row: int, option: Option, remove_event: trio.Event) -> None:
async def display(
self, row: int, option: Option, remove_event: trio.Event,
*, task_status: trio.TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
"""Reconfigure this row to display the specified option, then show it.
Once the event triggers, remove the row.
Expand Down Expand Up @@ -361,4 +364,3 @@ def ui_option_create(self) -> OptionRowUI:
@override
def ui_option_refreshed(self) -> None:
self.sizer_right.Layout()
self.pane_right.Update()

0 comments on commit 24493d2

Please sign in to comment.