avoid multiple instance of the same application

Alessandro Crugnola *sephiroth* alessandro at sephiroth.it
Tue Nov 25 22:17:58 CET 2003


Hi, i've created a wxpython app, a text editor, and then I've created the .exe file and make in myOS the file associtation to this
application.
The problem is that when an instance of the application is already opened and i double click on a file, my system open another
instance of the same file.

So, the question.. how to avoid this and open the clicked file in the previos opened application?

I've founded this piece of code on the net, this just to prevent multiple instance to be opened, but now the problem is how to tell
to the first app "open" that file..


if wxPlatform == '__WXMSW__':
    # [ 838561 ] open file opens a new SEPY instance
    import win32event, win32api, win32gui, win32con

    myMutex = win32event.CreateMutex(None,-1,'sepy_mutex')
    if win32event.WaitForSingleObject(myMutex, 0) == 0:
        app = App(0)
        app.MainLoop()
    else:
        exeName = win32api.GetModuleFileName(0)
        sepyWindow = win32gui.FindWindow(0,exeName)
        if not(win32gui.IsWindowVisible(sepyWindow)):
            win32gui.PostMessage(sepyWindow, win32con.WM_USER, 0, 0)
            win32gui.SetForegroundWindow(sepyWindow)
        if len(sys.argv) > 1:
            # here call opennewfile... ??
        sys.exit()
else:
    app = App(0)
    app.MainLoop()

-- 

Alessandro Crugnola [sephiroth]
Flash | PHP Developer
http://www.sephiroth.it

Team Macromedia Volunteer for Flash
http://www.macromedia.com/go/team

Flash-php mailing list
http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe






More information about the Python-list mailing list