Closed s-m-e closed 3 years ago
You simply need to use the "already_running" option and do not start your loop. I use qasync in FreeCAD like this: https://github.com/OpenCollaborationPlatform/CollaborativeFC/blob/master/InitGui.py#L35
@ickby Thanks a lot for the pointer. This looks really promising!
Do I correctly assume that Qasync
(upper case "Q"), which refers to this file in the FreeCAD plugin, can in fact be "substituted" with qasync
(lower case "q"), which is this Python package?
I am still trying to wrap my head around how I would trigger an async coroutine by e.g. clicking a button in the user interface. I guess all I have to do is to deploy my tasks by using task = asyncio.create_task( ... )
. The coroutine could then trigger a Qt signal/event when it is done whatever it is supposed to do, so I can react to it and grab the result. Is there anything more I should think about / consider?
Yes, both versions are exactly the same, I just needed to ensure the async functionality without the user to install stuff, hence I copied it into my plugin.
Your general idea is correct. Just create a task, it will then run on the next qt idle loop. Note that for button presses etc. the most comfortable way is to use qasyncs asyncslot decorator. It works exactly as the normal pyqt or pside slot decorator, but does spawn the async task for you. With this you can connect async slots to normal signals in Qt.
Another note: to process results on finish you do not need to create own signals etc. You can access the UI directly from your coroutine. That works as coroutines are async, but not parallel. When your coroutine is running, no other code is executed. Hence no bad race conditions etc.
From: sme @.> Sent: Friday, April 30, 2021 5:54:45 PM To: CabbageDevelopment/qasync @.> Cc: Stefan Tröger @.>; Mention @.> Subject: Re: [CabbageDevelopment/qasync] Usage inside C++ Qt application with Python support? (#33)
@ickbyhttps://github.com/ickby Thanks a lot for the pointer. This looks really promising!
Do I correctly assume that Qasync (upper case "Q"), which refers to this filehttps://github.com/OpenCollaborationPlatform/CollaborativeFC/blob/master/Qasync/__init__.py in the FreeCAD plugin, can in fact be "substituted" with qasync (lower case "q"), which is this Python package?
I am still trying to wrap my head around how I would trigger an async coroutine by e.g. clicking a button in the user interface. I guess all I have to do is to deploy my tasks by using task = asyncio.create_task( ... ). The coroutine could then trigger a Qt signal/event when it is done whatever it is supposed to do, so I can react to it and grab the result. Is there anything more I should think about / consider?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/CabbageDevelopment/qasync/issues/33#issuecomment-830262036, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACVCPM5Y3QS62EZRKW3QWDTLLVGLANCNFSM42OOPMEQ.
Is it possible to use this library inside a C++ Qt GUI application with Python integration (without blocking the GUI)? All examples that I can find assume that I am writing a "pure" Python app.
Examples: QGIS and FreeCAD. QGIS for instance exposes a lot of its API via SIP and "integrates" PyQt5.