Closed PySimpleGUI closed 1 year ago
Hello my friend,
I hope you are fine! Here there were bad moments but now the situation is going better. At first instance I could reply you that there is not a specific function that gets called before a client connection. But maybe we can find out a solution. Can you please explain me what you want to do exactly? Why you need this? A specific use case can help to invent a solution.
Have a wonderful day,
Davide
Il giorno sab 26 giu 2021 alle ore 01:12 PySimpleGUI < @.***> ha scritto:
Long time no questions from me so things are going great!
I have a question about the startup protocol.
My assumption, that I now believe is incorrect, is that the main() member function will be called once the start() operation has completed.
In the MyApp class, I'm signaling that the startup has completed when the member function main is called. It appears that this function is called only after a connection on the port is made.
Is there an option or another function I can use that will tell me that Remi is ready to have widgets added? It's been a long time since I have made any changes to PySiMPLEGUIWeb, so I may not be looking at the code correctly.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dddomodossola/remi/issues/455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACTNK5JVTRR37IIGOPTBGLTUUEOBANCNFSM47KWOQ6Q .
Hi both,
Hopefully, it may help if I explain where this came from :) I raised this as a question to Mike on the PySimpleGUI project here - https://github.com/PySimpleGUI/PySimpleGUI/issues/4451
This is for a project of mine running on a Raspberry Pi. It has a local PySimpleGUI interface on a SPI-connected screen, but also hosts most of the same interface on a web page (hence the use of PySimpleGUIWeb for commonality). However, the web page will only occasionally be connected to, and usually only during the middle of running and not at start-up. So, I create both the local interface and the webpage at start-up. But the call to create the web page window blocks and does not return until a browser is connected, which is where Mike's question on when 'main' is called comes from. At the moment, I have spawned a temporary thread which waits for this to complete when a connection is made, and then update a flag I use elsewhere to know the web page is "active" but if there is a way for the web page to be active even without a browser connected, then I can dispense with that extra layer of checks.
Either way, both PySimpleGUI and remi underneath it have proved to be very impressive code and I thank you for all your efforts!
Nick
Hello @nrobbert ,
To be sure to correctly understand your question, let me rephrase the situation:
You have an application that needs to do some work (spi communication with devices and so on) regardless if GUI interfaces are shown. So you need to start some activities before to run the gui threads.
If so, you need to start a separate thread to be run before the gui initialization, then share the thread with the gui. I think you already done this, and this is the correct solution. I only have a doubt: why you need a flag to get aware that a user connected to the gui?
Kind Regards,
Davide
Hi Davide,
Thanks for looking at this!
Yes, I have a main loop accessing SPI devices, serial devices etc and performing the main task of the application. There is a local GUI which is checked regularly for button presses, but also updated regularly with latest information. The web GUI is also checked regularly for presses, but is also updated regularly with latest information. I have tried reading both GUIs once per main loop (with minimal timeouts if no button press). The web gui read returns on timeout as expected if there is a browser connected. But, if no-one has connected a browser, then the read (with timeout) does not return, and any attempt to update the content of the webpage also fails. So, the flag is to avoid me trying to read or update the web gui without a user, because it will block.
Does that help explain at all?
Thanks
Nick
Thank you very much Nick for jumping into and driving the whole thing forward. I really appreciate the time and effort you've been putting in to help.
@nrobbert Excuse me for the delay.
So, I think that you should not update directly the gui. The external thread that handles connections (spi and so on) should create and update a shared data structure. The GUIs, will update its own widgets when ready, just by reading the shared data structure. This way, the external thread is not blocked, and will constantly feed information to the shared structure. On the other side, each GUIs will fetch data from the shared structure asyncronously.
Please let me know if you need clarifications.
Kind Regards.
Hi Davide,
Many thanks for looking in to this. I was heading in the same direction as you, to run them in separate threads/processes and share the data and events between them. That way, the GUIs can sit idle when they are not actively updating or being used.
Thanks again to both of you for the support! It is much appreciated.
Nick
Long time no questions from me so things are going great!
I have a question about the startup protocol.
My assumption, that I now believe is incorrect, is that the
main()
member function will be called once thestart()
operation has completed.In the MyApp class, I'm signaling that the startup has completed when the member function
main
is called. It appears that this function is called only after a connection on the port is made.Is there an option or another function I can use that will tell me that Remi is ready to have widgets added? It's been a long time since I have made any changes to PySiMPLEGUIWeb, so I may not be looking at the code correctly.