Skip to content
Advertisement

Trio + PyQT5 in one program?

How can I use trio in conjunction with PyQT5? The thing is that my program has interface written using PyQT5, and now I need to run eventloop trio, to work with the network, because I use trio WebSocket to connect to the server. I read that I should use trio.lowlevel.start_guest_run for this purpose. But in the documentation it says that in addition to the trio function I must pass run_sync_soon_threadsafe and done_callback as arguments. The documentation gives an example with asyncio and says that I have to define similar functions for my event_loop, in my case for PyQT. Unfortunately my knowledge is not enough to do it myself. I wrote a very simple application using PyQT and put in the body of the class an asynchronous function that if it works correctly should change the inscription on the timer every second. In addition you can enter text in the input box and by pressing the button this text will be displayed at the bottom. I did not run the asynchronous function, as that is my question. At best, I expect the answer to my question to be a modified program in which the asynchronous function and the PyQT5 components run in the same thread using trio. Thank you for your reply.

JavaScript

Advertisement

Answer

I have to admit that I haven’t been keeping up on maintenance on QTrio, but it does mix Qt with Trio. https://qtrio.readthedocs.io/en/stable/ Depending what route you want to go you could either use it as a whole library, or you could just pick out the pieces you want.

https://github.com/altendky/qtrio/blob/43c7ff24c0be2f7a3df86eef3c6cc5dae2f7ffd3/qtrio/_core.py#L649-L657

JavaScript

https://github.com/altendky/qtrio/blob/43c7ff24c0be2f7a3df86eef3c6cc5dae2f7ffd3/qtrio/_core.py#L672-L683

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement