Dear Sirs,
lately I started to work, for the first time, on a new project using the Raspberry Pi 4, Python and wxPython. I have started to create my GUI that will be controlled by a touch screen and some signals generated by some toggle switches and sensors that all are interfaced with my Pi GPIO. I took a look at wxPython API documentations to understand which event I should bind to my handler and I saw that I could use a custom events but I still do not understand how I can create them and link them to my external inputs.
For example : if my GPIO.input(15) is True, I get a change on my GUI (a change of the background colour) and if it is False I get my initial GUI.
Well, you have to understand that your wxPython GUI runs in its own process, forever spinning its main loop. So, if you have other processes doing their own jobs in the meantime, we are basically talking inter-process communication here. Feel free to apply any technique that best suits your case. Have the other process send data over a socket, or use a pipe or… whatever.
From the gui process’ side, all you have to do is to listen to your socket/pipe/whatever from time to time, and retrieve the data. You can set up a wx.Timer and the catch the wx.EVT_TIMER event, if you need regular intervals. Or, you can just catch the irregular wx.EVT_IDLE (browse the docs for wx.IdleEvent), but only if you foresee that the gui will be, in fact, manipulated by an actual user (an IdleEvent won’t work if the gui is left untouched for a while).