diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index a162d76a..78aa631b 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -1689,8 +1689,8 @@ async def _async_main( # start handling search bar kb inputs async with ( - _event.open_handler( - search.bar, + _event.open_handlers( + [search.bar], event_types={QEvent.KeyPress}, async_handler=_search.handle_keyboard_input, # let key repeats pass through for search diff --git a/piker/ui/_event.py b/piker/ui/_event.py index a99b3241..769d96cf 100644 --- a/piker/ui/_event.py +++ b/piker/ui/_event.py @@ -18,7 +18,7 @@ Qt event proxying and processing using ``trio`` mem chans. """ -from contextlib import asynccontextmanager +from contextlib import asynccontextmanager, AsyncExitStack from typing import Callable from PyQt5 import QtCore @@ -124,9 +124,9 @@ async def open_event_stream( @asynccontextmanager -async def open_handler( +async def open_handlers( - source_widget: QWidget, + source_widgets: list[QWidget], event_types: set[QEvent], async_handler: Callable[[QWidget, trio.abc.ReceiveChannel], None], **kwargs, @@ -135,7 +135,13 @@ async def open_handler( async with ( trio.open_nursery() as n, - open_event_stream(source_widget, event_types, **kwargs) as event_recv_stream, + AsyncExitStack() as stack, ): - n.start_soon(async_handler, source_widget, event_recv_stream) + for widget in source_widgets: + + event_recv_stream = await stack.enter_async_context( + open_event_stream(widget, event_types, **kwargs) + ) + n.start_soon(async_handler, widget, event_recv_stream) + yield diff --git a/piker/ui/_interaction.py b/piker/ui/_interaction.py index 4e5f8017..a14fcb97 100644 --- a/piker/ui/_interaction.py +++ b/piker/ui/_interaction.py @@ -273,8 +273,8 @@ class ChartView(ViewBox): ) -> 'ChartView': from . import _event - async with _event.open_handler( - self, + async with _event.open_handlers( + [self], event_types={QEvent.KeyPress, QEvent.KeyRelease}, async_handler=handle_viewmode_inputs, ):