getting to the wxapp via window handle...

Hi,

I have written an editor for which I allow only one instance
(using win32api.CreateMutex) to be up and running. So far so good: I can tell if the app is already running and if so, I set the top window of the the already running instance to the foreground and show it, if iconified.

Now, consider the app is up and running, and the user pops up command shell to start the Editor with the name of a file to open. How can I pass that information to the already running app when all I have is the platform's window handle of its top window? IOW, how can I pass control to the running wx app and have it open the file?

Any pointers much appreciated!

(Environment: win XP, 2.4.2.4u, Python 2.3)

···

--
Vincent Wehren <vincent@visualtrans.de>
http://www.visualtrans.de

Vincent Wehren wrote:

Hi,

I have written an editor for which I allow only one instance
(using win32api.CreateMutex) to be up and running. So far so good: I can tell if the app is already running and if so, I set the top window of the the already running instance to the foreground and show it, if iconified.

You can also use wxSingleInstanceChecker to see if the app is already running.

Now, consider the app is up and running, and the user pops up command shell to start the Editor with the name of a file to open. How can I pass that information to the already running app when all I have is the platform's window handle of its top window? IOW, how can I pass control to the running wx app and have it open the file?

You'll need to do some form of higher level IPC. Socket, named pipe, xmlrpc, etc.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

You can also use wxSingleInstanceChecker to see if the app is already
running.

Be very careful with that as it (in the example) only allows one
instance per user.

One of my pet peeves is programs that don't recognize that a
user can be logged in from multiple locations. For example
on Linux I am often running a gui session on the console
as well as via a VNC session. They have nothing to do
with each other. Similarly you can be logged into a Windows
box multiple times over RDP.

Nothing gets more annoying than being told in a session
than app is already running and you must bring it up
when it is displayed in another session. (Or the
web browsers that display links in an existing instance
of the browser displaying somewhere else).

In wx 2.5, you can also include wx.Display(0).GetName()
as part of the mutex name, thereby ensuring that people
like me don't have their peeves tickled :slight_smile:

Roger

Hi all,

I was trying to help someone on this list, and their code kept segfaulting on me. That hasn't happened in a long time with wxPython, so I was quite surprised.

Anyway, I don't use wx.Dialog.Center, but his code did, and that's where the crash is.

Here's how it's used:

  message = 'Button %d is %d wide by %d high' % (bid, bwide, bhigh)

         # MessageDialog(parent, message, caption, flags, wx.Point(x,y)=defpos)
         dlg = wx.MessageDialog(self, message, 'MessageDialog', wx.OK)
         # Center puts dialog in center of screen, not center of window
         dlg.Center()
         dlg.ShowModal()
         dlg.Destroy()

I've enclosed the complete program. click the "grow" button, and all works fine, click the other buttons, and it segfaults on my machine. The only difference is the dlg.Center() call has been commented out in the grow button handler.

Anyone else see this?

Gentoo Linux
Python 2.3.3
wxPython 2.5.1.5 ( compiled by me for GTK2 )

thanks, Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker wrote:

I've enclosed the complete program.

oops. now I have. It was written by Jim Peterson.

-Chris

jim.py (5.96 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker writes:

Anyway, I don't use wx.Dialog.Center, but his code did, and
that's where the crash is.

I filed a bug report on this issue a couple weeks ago. It
happens on GTK2 with any frame where the frame's parent isn't
shown.

···

--
Paul

Paul McNett wrote:

I filed a bug report on this issue a couple weeks ago. It happens on GTK2 with any frame where the frame's parent isn't shown.

cool, except isn't the main frame the parent of the dialog in this case?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker writes:

> I filed a bug report on this issue a couple weeks ago. It
> happens on GTK2 with any frame where the frame's parent
> isn't shown.

cool, except isn't the main frame the parent of the dialog in
this case?

Right, I had it wrong. Now that I'm trying to get it to work, I
can't get any of the Center() functions to not segfault no
matter what I do. CenterOnParent(), CenterOnScreen(), Center()
all cause:

(dMessageBox.py:32251): Gtk-CRITICAL **: file gtkwidget.c: line
4996 (gtk_widget_set_uposition): assertion `GTK_IS_WIDGET
(widget)' failed
Segmentation fault

in my messagebox code, and just a simple:
Segmentation fault

in Jim's code.

···

--
Paul

Paul McNett wrote:

Chris Barker writes:

Anyway, I don't use wx.Dialog.Center, but his code did, and
that's where the crash is.

I filed a bug report on this issue a couple weeks ago. It happens on GTK2 with any frame where the frame's parent isn't shown.

Isn't it just wx.MessageBox?

I think it is because on wxGTK2 a native message box API is used instead of a wx.Dialog, but some (most?) of the inherited methods don't know the difference. It's already on my todo list to investigate that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn writes:

Isn't it just wx.MessageBox?

Yes, just wx.MessageBox. Sorry, it has been a couple weeks and I
can't even remember what I did this morning.

···

--
Paul

Robin Dunn wrote:

I think it is because on wxGTK2 a native message box API is used instead of a wx.Dialog, but some (most?) of the inherited methods don't know the difference. It's already on my todo list to investigate that.

Thanks, Robin.

Is there a list of GTK2 "gotchas" anywhere?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov