[PyQt] Working with sub-windows

Barry Scott barry at barrys-emacs.org
Mon Jan 22 19:04:44 GMT 2018



> On 19 Jan 2018, at 09:30, Alain Muls <alain.muls at gmail.com> wrote:
> 
> Hi All
> 
> I am working on a pyqt script that next to a mainwindow opens several separate sub windows. A worker script is running in a separate thread and sends signals which connect to different slots. These slots can be located in sub-windows which are not necessarily created at the instance the signal-slot connection is made.
> 
> A problem arises for which I would get a correct solution (I circumvent them for now):
> 
> to avoid a problem with the signal-slot connection I do a test on the sub-window, which I initialize to None at startup, before connecting, doing
> 
> if subWindow is not None:
>     connect signal to slot
> 
> If I open the window I create the connection from the MainWindow, but here I have to check whether the worker script is already active (done by opening a file) for which I also perform an init to None and a similar check.
> 
> Now I wonder what happens when I close the sub-window, will its value ecome None again ?
> Also, from whatever side I try to create the connection, I perform a check on something else being 'None' and I think this is not the correct approach.

I think this is what you have.

A main window that is always visible.
1 or more background tasks that are outputting something.
Other windows that come and go that show the output of the background tasks.

What I would do is feed the output of the background tasks into a buffer that is used as the basis of what will be drawn.
When the user requests a window to show the background task do the following:
1. Create the Window
2. set a pointer to the background task buffer from which to draw the windows contents
3. connect all the signals you need. Probable including a buffer changed signal.

If the user closes the window undo the above.

Barry


> 
> Tx for your help
> Alain
> 
> -- 
> 
> <logorma-transparent-scaled.png>	
> Alain Muls
> Professor
> Department CISS
> Royal Military Academy
> p:	+32 244 13936
> a:	Renaissance Avenue 30
>  	B1000 Brussels (Belgium)
> w:	www.rma.ac.be/ciss/en/ <http://www.rma.ac.be/ciss/en/>  e: alain.muls at rma.ac.be <mailto:alain.muls at rma.ac.be>_______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180122/cd32583f/attachment.html>


More information about the PyQt mailing list