Closed Avasam closed 2 years ago
You either need to use asyncio so that you can write item = await picker.pick_singe_item_async()
or you need to add a callback that will be called when the operation has completed with async_operation.completed = callback
and then call async_operation.get_results()
in the callback. Have a look at the link below for an example.
Ah, that makes sense if completed is supposed to be a callback. It works that way thank you. Maybe I couldn't get await
to work due to a lack of experience with asyncio, but I got it working this way:
def select_graphics_item(autosplit: AutoSplit):
def callback(async_operation: IAsyncOperation[GraphicsCaptureItem], async_status: AsyncStatus):
autosplit.graphics_capture_item = async_operation.get_results()
picker = GraphicsCapturePicker()
initialize_with_window(picker, autosplit.effectiveWinId().__int__())
picker.pick_single_item_async().completed = callback
Thanks for the support. Hopefully this helps anyone else who comes across the same issue :)
Starting with the following snippet of code:
async_operation = await picker.pick_single_item_async()
never gets past the awaitlooking at the object's properties,
status
stays at 0 (STARTED),completed
throws a not implemented error,get_results
throws "OSError(22, 'A method was called at an unexpected time', None, -2147483634, None)", even after the picker is closed.I'm not sure how I'm supposed to get the resulting
GraphicsCaptureItem
fromGraphicsCapturePicker
Sidenote, the return type of
pick_single_item_async
isUnknown
(even though it looks like from the stub file it should be a genericIAsyncOperation[GraphicsCaptureItem]
)