Support opening a handler on a collection of widgets
							parent
							
								
									3302d21086
								
							
						
					
					
						commit
						fd73d1eef1
					
				| 
						 | 
					@ -1689,8 +1689,8 @@ async def _async_main(
 | 
				
			||||||
            # start handling search bar kb inputs
 | 
					            # start handling search bar kb inputs
 | 
				
			||||||
            async with (
 | 
					            async with (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                _event.open_handler(
 | 
					                _event.open_handlers(
 | 
				
			||||||
                    search.bar,
 | 
					                    [search.bar],
 | 
				
			||||||
                    event_types={QEvent.KeyPress},
 | 
					                    event_types={QEvent.KeyPress},
 | 
				
			||||||
                    async_handler=_search.handle_keyboard_input,
 | 
					                    async_handler=_search.handle_keyboard_input,
 | 
				
			||||||
                    # let key repeats pass through for search
 | 
					                    # let key repeats pass through for search
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@
 | 
				
			||||||
Qt event proxying and processing using ``trio`` mem chans.
 | 
					Qt event proxying and processing using ``trio`` mem chans.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
from contextlib import asynccontextmanager
 | 
					from contextlib import asynccontextmanager, AsyncExitStack
 | 
				
			||||||
from typing import Callable
 | 
					from typing import Callable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from PyQt5 import QtCore
 | 
					from PyQt5 import QtCore
 | 
				
			||||||
| 
						 | 
					@ -124,9 +124,9 @@ async def open_event_stream(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@asynccontextmanager
 | 
					@asynccontextmanager
 | 
				
			||||||
async def open_handler(
 | 
					async def open_handlers(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    source_widget: QWidget,
 | 
					    source_widgets: list[QWidget],
 | 
				
			||||||
    event_types: set[QEvent],
 | 
					    event_types: set[QEvent],
 | 
				
			||||||
    async_handler: Callable[[QWidget, trio.abc.ReceiveChannel], None],
 | 
					    async_handler: Callable[[QWidget, trio.abc.ReceiveChannel], None],
 | 
				
			||||||
    **kwargs,
 | 
					    **kwargs,
 | 
				
			||||||
| 
						 | 
					@ -135,7 +135,13 @@ async def open_handler(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async with (
 | 
					    async with (
 | 
				
			||||||
        trio.open_nursery() as n,
 | 
					        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
 | 
					        yield
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -273,8 +273,8 @@ class ChartView(ViewBox):
 | 
				
			||||||
    ) -> 'ChartView':
 | 
					    ) -> 'ChartView':
 | 
				
			||||||
        from . import _event
 | 
					        from . import _event
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        async with _event.open_handler(
 | 
					        async with _event.open_handlers(
 | 
				
			||||||
            self,
 | 
					            [self],
 | 
				
			||||||
            event_types={QEvent.KeyPress, QEvent.KeyRelease},
 | 
					            event_types={QEvent.KeyPress, QEvent.KeyRelease},
 | 
				
			||||||
            async_handler=handle_viewmode_inputs,
 | 
					            async_handler=handle_viewmode_inputs,
 | 
				
			||||||
        ):
 | 
					        ):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue