A MessageBox / MessageDialog that I can Destroy() from an external thread

179 views
Skip to first unread message

Basj

unread,
Feb 11, 2014, 3:59:05 PM2/11/14
to wxpytho...@googlegroups.com
Hello,
I'm creating a dialog box "waiting" for an external trigger, before closing/destroying itself.

When using :
    waitingdlg = wx.MessageDialog( ... )
    waitingdlg.ShowModal()

I notice that I cannot destroy it from an external thread with waitingdlg.Destroy(). Why ?

If so, it seems that I should redo all with a wx.Dialog : information icon, white background on the upper part of the dialog, grey background on the lower part of the dialog, main text, main buttons, bind buttons, etc.  Moreover this will break the native look of the OS on some platforms...

I would really like to keep a standard wx.MessageDialog  (standard OS look), but I also need to be able to destroy it from an external thread.

Any idea about this? 

Best regards J

Werner

unread,
Feb 12, 2014, 3:00:45 AM2/12/14
to wxpytho...@googlegroups.com
On 11/02/2014 21:59, Basj wrote:
> Hello,
> I'm creating a dialog box "waiting" for an external trigger, before
> closing/destroying itself.
>
> When using :
> waitingdlg = wx.MessageDialog( ... )
> waitingdlg.ShowModal()
>
> I notice that I cannot destroy it from an external thread with
> waitingdlg.Destroy(). Why ?
>
> If so, it seems that I should redo all with a wx.Dialog : information
> icon, white background on the upper part of the dialog, grey
> background on the lower part of the dialog, main text, main buttons,
> bind buttons, etc. Moreover this will break the native look of the OS
> on some platforms...
>
> I would really like to keep a standard wx.MessageDialog (standard OS
> look), but I also need to be able to destroy it from an external thread.
>
> Any idea about this?
Not using threads but from what I read here you need to use
wx.CallAfter, see e.g.:
http://wiki.wxpython.org/CallAfter

Werner

Nouvelle Collection

unread,
Feb 12, 2014, 3:53:07 AM2/12/14
to wxpytho...@googlegroups.com
Hi Werner, I already tried with wx.CallAfter but it seems that wx.MessageDialog doesn't respond to Destroy().

According to http://wxpython-users.1045709.n5.nabble.com/Destroy-a-wx-MessageDialog-after-a-given-amount-of-time-td2852005.html, the answer seems to be :

> Robin Dunn :
> The wx.MessageDialog is not a real wx.Dialog, it's just a convenience
> wrapper around a native API function.  As such it does not implement
> most of the wx.Dialog API.

> To do what you want you'll need to either create your own message dialog
> class or use something like wx.lib.agw.genericmessagedialog.

--

A last question : Robin, do you think it would be possible to add handling of Destroy() to the *standard* wx.MessageDialog  (to be sure to keep the native OS look) ?  Or would it be technically difficult ?

Best regards, J





Werner

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Tim Roberts

unread,
Feb 12, 2014, 1:04:38 PM2/12/14
to wxpytho...@googlegroups.com
Basj wrote:
> Hello,
> I'm creating a dialog box "waiting" for an external trigger, before
> closing/destroying itself.
>
> When using :
> waitingdlg = wx.MessageDialog( ... )
> waitingdlg.ShowModal()
>
> I notice that I cannot destroy it from an external thread with
> waitingdlg.Destroy(). Why ?

This is an operating system limitation. Even from C++, there is no
(documented) method of forcing a modal message box to close.

(If you can get the window handle, you can send it a WM_CLOSE message,
but that's icky and system-dependent.)


> If so, it seems that I should redo all with a wx.Dialog : information
> icon, white background on the upper part of the dialog, grey
> background on the lower part of the dialog, main text, main buttons,
> bind buttons, etc. Moreover this will break the native look of the OS
> on some platforms...

Yes, but that's OK, because you are breaking the native BEHAVIOR as well.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Nouvelle Collection

unread,
Feb 13, 2014, 3:10:16 AM2/13/14
to wxpytho...@googlegroups.com
Hello Tim,
 
This is an operating system limitation.  Even from C++, there is no
(documented) method of forcing a modal message box to close.

(If you can get the window handle, you can send it a WM_CLOSE message,
but that's icky and system-dependent.)
 
Ok thank you, now I know the reason.

 
> If so, it seems that I should redo all with a wx.Dialog : information
> icon, white background on the upper part of the dialog, grey
> background on the lower part of the dialog, main text, main buttons,
> bind buttons, etc.  Moreover this will break the native look of the OS
> on some platforms...

Yes, but that's OK, because you are breaking the native BEHAVIOR as well.

True indeed !

J

Robin Dunn

unread,
Feb 15, 2014, 8:29:48 PM2/15/14
to wxpytho...@googlegroups.com
Nouvelle Collection wrote:
> Hi Werner, I already tried with wx.CallAfter but it seems that
> wx.MessageDialog doesn't respond to Destroy().
>
> According to
> http://wxpython-users.1045709.n5.nabble.com/Destroy-a-wx-MessageDialog-after-a-given-amount-of-time-td2852005.html,
> the answer seems to be :
>
> > Robin Dunn :
> > The wx.MessageDialog is not a real wx.Dialog, it's just a convenience
> > wrapper around a native API function. As such it does not implement
> > most of the wx.Dialog API.
>
> > To do what you want you'll need to either create your own message dialog
> > class or use something like wx.lib.agw.genericmessagedialog.
>
> --
>
> A last question : Robin, do you think it would be possible to add
> handling of Destroy() to the *standard* wx.MessageDialog (to be sure to
> keep the native OS look) ?

No, but even if it was possible Destroy is not what you want to be using
for this anyway. You should use EndModal for modal dialogs (and this
will work with generic wx.Dialogs). EndModal does just what it says it
does, end the modality and cause ShowModal to return, and the advantage
is that the dialog still exists so the code that called ShowModal can
read values from it, and then it will call Destroy from there like usual.

--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages