[pygtk] Tow instance of the same pyGTK application in a the same process

Mystilleef mystilleef at gmail.com
Thu Jan 25 10:00:54 WST 2007


On 1/24/07, Cyril Giraudon <cyril.giraudon at free.fr> wrote:
> Hi,
>
> I have a PyGTK application which works fine (scientific visualization
> application based on matplotlib).
>  > python myGTKApp.py
> And some beautiful curves appear.
>
> Now I 'd like to launch several instance of this application from a
> process with threads.
> All instances share nothing at all but the master thread can communicate
> with them (simple requests).
>
> What are the prerequisites for the PyGTK application ?
> What is the easier method to instantiate this app from a process ?
>
> I forget, It's on Windows XP :-(
>
> Thanks a lot,
>
> Cyril.

Multiple instances of your application can share the same mainloop. All
you need to do is design an "InstanceManager" class that creates new
instances of your application. "InstanceManager" runs on the mainloop.
"InstanceManager" should have functions to create and keep track of all
instances of your application, perhaps stored in a list. When there are
no more instances of your application in the list, just quit the
mainloop. There is no threading needed. Of course each instance of
your application will have a reference to "InstanceManager" and the
methods (e.g. new_window, get_instances, focus_window, etc) it exposes.
Thus, "InstanceManager" becomes a mediator, and you can use it to
communicate with other instances, through the methods it exposes. I've
used this pattern successfully in one of projects.


More information about the pygtk mailing list