Inhibiting duplicate apps in Windows?

Edward K. Ream edream at tds.net
Thu Jun 20 11:51:02 EDT 2002


Hi All,

I have a pure Python app called Leo.  In Windows, I can open Leo by
double-clicking a .leo file.  I would like to do more: if Leo is open
and I double-click a .leo file, I would like the _already open_ copy of
Leo to open the second .leo file, rather than (permanently) opening a
second copy of Leo.

What I would like is for the second copy of Leo to detect that another
copy of leo.py is already running, send a message to the first copy and
then exit. I wonder if anyone knows how this might be done?

The C++ version of Leo works as follows:

1. It inhibits multiple copies of leo.py from running using a mutex.  I
think this part is easy because the Python library supports mutexes. 

2. It sends a message from the second copy of leo.py (the copy that will
shortly close), instructing the first copy of leo.py to open a file. 
This is the part that I'm not sure can be done in pure Python.  I don't
see anything applicable in section 22 (MS Windows Specific Services) of
the Python Library.  The C++ version of Leo does this by doing:

SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)&cds);

where hWnd is a handle to the previously open copy of Leo and cds is a
COPYDATASTRUCT containing the command line used to open the second copy
of Leo.

Perhaps this problem can be solved in Python using processes instead of
messages, and I don't see how.  Are there any demos that might be of
use?  Thanks!

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list