[pygtk] centralized multiple instances of a pygtk app
Robert Schroll
rschroll at gmail.com
Thu Mar 31 06:07:50 WST 2011
On 03/30/2011 04:58 PM, Giuseppe Penone wrote:
> This makes sense, but I don't see why you need threads to do it. Multiple
>> windows can be controlled by a single thread. If a given document needs an
>> intensive calculation, that can be split into it's own thread, but that
>> seems orthogonal to having multiple documents open.
>>
>
> I cannot do everything in a single thread because, when the user tries to
> open the same document again I should be aware that the document is already
> opened and put the already opened window on top of the screen rather than
> open two instances of the same document.
>
> If you double click on a text file, then just minimize the window and double
> click again upon the same file you will understand the (correct) behavior
> that apps such as gedit have.
>
> So I need a centralized server or something like that,
I'm with you up to here. I'd probably create a controller object that
keeps track of all open windows, receives requests to open documents,
and opens new windows or brings old windows to the front as appropriate.
But I'm sure there are other ways to do it just as well.
> which must be on a separate thread or separate process.
I don't understand why this must be. The controller object (or
whatever) can run just fine in the same thread as all of the windows.
The one example I have handy is Reinteract, which has a window
associated with each "notebook" and only allows each notebook to be
opened once. An object of class "Application" keeps track of all of
these windows. You may wish to consider Application.open_notebook() in
http://git.fishsoup.net/cgit/reinteract/tree/lib/reinteract/application.py
(This may not be the best example, because Reinteract does use
threads. But the windows and the Application object all live in the
main thread.)
Robert
More information about the pygtk
mailing list