> so far I've allowed a single instance only for simplicity but now I would
> like to introduce the opportunity to open more instances
> of different documents, but avoid to open twice the same document for
> mistake and instead put the running window to toplevel
> in case there's already an instance of that document opened.

If I understand the problem correctly, you can easily do this using
D-Bus. (If you're on GTK+ 3, GtkApplication makes it even easier; see
its example code [1]. I assume you're on GTK+ 2, which doesn't have
this.)

[1] http://library.gnome.org/devel/gtk/unstable/GtkApplication.html

To do this with D-Bus, in pseudocode:

On app run:
    Try to reserve a service address ("bus name", in D-Bus terminology)
    If succeeded:
        Act as service provider, open windows when requested, etc.
        // This is your main app process, the only one that ever lives
        // for more than 1 second. Thus, it contains your GUI code as
        // well as the D-Bus service.
    else:
        Send "open file" message to the existing service through D-Bus
        Die

On receiving "open file" message: // In main app
    If file is already open:
        Bring up the window
    else:
        Open file

-- 
Johannes
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to