Open running processes

D

DeRRudi

Hi all,

I have a programm. In this program i've made the restriction that only
one instance can run at the time. (done with mutex).
Now i'd like it to open the running (make visible) instance when
someone want's to open it a second time.
Does anybody know how to do this? I hope you all understand what i
mean. My English isn't to good...

Greetz Rudi
 
D

DeRRudi

It is a wxWindow app. It is a kind of datamanager. it is possible to
minimize it to the systray.

hmm.. i've thought of an solution using memorymapping. see if it
works.. don't know if it is the 'best' or 'safest' way.. but ok.

Greetz.

ps. I'm always willing to learn! :D
 
D

DeRRudi

Well it doesnt work yet, but its gonna! ;)
i've tested it with a little app. There is my main app (called it
server) wich contains a thread. This thread listens to a mm (memory
mapping) when an other program sets a flag
(finished_producing_event.set() ) it just calls self.iconize(false)

I'm not sure what pieces of code i have to post here.. posting all of
it makes it too large i believe :)

From server:


ID_MESSAGECH = wxNewId()

def EVT_RESULT(win, func):
win.Connect(-1, -1, ID_MESSAGECH, func)

class ResultEvent(wxPyEvent):

def __init__(self):
wxPyEvent.__init__(self)
self.SetEventType(ID_MESSAGECH)

class listener(Thread):
def __init__(self, frame):
Thread.__init__(self)
self.frame = frame
self.setDaemon(1)

self.stopped = False

#shared_memory = mmap.mmap (0, common.SHARED_MEMORY_SIZE,
common.SHARED_MEMORY_NAME)
#ready_to_consume_event = events.Win32Event
(common.READY_TO_CONSUME)
#finished_producing_event = events.Win32Event
(common.FINISHED_PRODUCING)

def run(self):
while not self.stopped:
try:
finished_producing_event.wait()
wxPostEvent(self.frame,ResultEvent(None))
except Exception,e:
print "Error: " , e

def stop(self):
self.stopped = True



within the frame:
[code:1:080343f1b1]
listen = listener(self)
listen.start()

EVT_RESULT(self, self.OnChange)

def OnChange(self, event):
shared_memory.seek(0)
tekstding = shared_memory.readline()
if(tekstding.strip() ==
"maximize"):
self.Iconize(False)
self.Show(False)
elif(tekstding.strip() ==
"minimize"):
self.Iconize(True)
self.Show(True)
self.panel.tekst.SetValue(tekstding)
[/code:1:080343f1b1]

Hope you can see now how it works! Greetz
 
D

DeRRudi

Well i want a external app to maximize and minimize my app.
And later on i want the external one to send some data. Thought this
would be the most easy (and fast) way!

Greetz
 
D

DeRRudi

Tim Goldenwrote:
Rudi. I, at least, am reading this via the mailing list, not
via Usenet nor via Google. This means that if you don't put
any kind of context in what you post, I have to guess at what
you're responding to. (All I see is the exact text you typed,
nothing else).

Assuming that you're answering my question: why use mmap and
not just two events? I understand what your overall plan is,
and it looks like you have a way to solve it. It just seemed
that you might be able to achieve the same thing with two
events: one for maximize and one for minimize. Why would
this be better? Well, only because it seems to me slightly simpler
than one event and a separate mmap mechanism. But I've never
done what you're doing, so I may well be completely wrong.

TJG

Hi Tim,

I'm sorry did not realize it!
U are right! (i believe) at first i put in the minimize for testing.
I'm only using the maximize.
But it seemed handy to do it this way and beeing abled to send over
data from an other programm. That's what i want to use the mmap for.
Or am i missing something. because i'm not really seeing what your
point is. Because it is a complete different process what is calling
the maximize (or minimize) i can't just create an event and call it
(or can i?)

Greetz
 
D

DeRRudi

Tim Goldenwrote:
If you wanted to send over arbitrary data from another application,
then this is certainly a way to do it. (Another way might be to use a
Windows pipe, for example). My point was only that if you are signalling
an event as a wake-up call plus an atom of extra information saying
"max" or "min", and you weren't considering any expansion of this
vocabulary to include other commands, then two distinct events might
be simpler, one signalling "maximize", the other "minimize".

Please don't take this as any criticism of your work: there's no one
right design decision here; I was merely curious as to the reasons
behind yours.

TJG

Thanx for thinking with me! It really helps to have some other
opinions! It might look simpeler to make two distinct events. But
reading out the mm is really easy to do. So i didn't make more events
for maximizing and minimizing. But further on i'm gonna use it. I
think by now i have all the thing's i need to solute my problems.
Thnx

Rudi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top