Who's to blame?

Rob Williscroft rtw at freenet.co.uk
Thu Jan 3 11:48:24 EST 2008


Nicola Musatti wrote in news:92dfc2fc-0677-43c0-b34f-4f240fa40205
@e4g2000hsg.googlegroups.com in comp.lang.python:

Note there is a wxpython mailinglist/newsgroup:

    	news:gmane.comp.python.wxpython

[snip]
> problem lies in the fact that apparently ShowModal() does not return
> when either the Yes or the No buttons are pressed. Curiously, if you
> change the Yes and No buttons with the OK and Cancel ones that are
> currently commented everything works as expected.

This is because the wx.Dialog class has handlers for the wxID_OK
and wxID_CANCEL button identifiers, IIRC in windows the MS supplied
dialog procedure behaves this way.

> 
> As the sbs_test_xrc.py file below is automatically generated by
> wxPython 2.8.6.1's XRCed tool from a XRC file which in turn is
> generated by wxFormBuilder (http://wxformbuilder.org/), I really cant
> figure out to whom I should report this problem, assuming I'm not
> missing some obvious mistake of mine, that is.

> class MainFrame(sbs_test_xrc.xrcMainFrame):
>     def __init__(self, parent):
>         sbs_test_xrc.xrcMainFrame.__init__(self, parent)
>         self.button.Bind(wx.EVT_BUTTON, self.OnButton)

First you can make the dialog a member, you are showing and hiding it
so there is no need to create a new one every time OnButton is fired.

          self.dialog = sbs_test_xrc.xrcDialog(self)

          # now replace the defaults of ID_OK and ID_CANCEL
          #
          self.dialog.SetAffirmativeId( wxID_YES )
          self.dialog.SetEscapeId( wxID_NO )

Alternativly you could derive from xrcDialog as you are with
xrcMainFrame and do the above in the derived classes __init__.

>     def OnButton(self, event=None):
>         d = sbs_test_xrc.xrcDialog(self)
> ##        if d.ShowModal() == wx.ID_OK:
>         if d.ShowModal() == wx.ID_YES:
>             self.Close()
> 

http://www.wxpython.org/docs/api/wx.Dialog-class.html

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list