Who's to blame?

kyosohma at gmail.com kyosohma at gmail.com
Fri Jan 4 15:12:22 CET 2008


On Jan 4, 3:35 am, Nicola Musatti <nicola.musa... at gmail.com> wrote:
> Hallo, Mike.
> First of all, thanks to both you and Rob for your answers. I now see
> that the wxPython group would have been a better place to post to, all
> the more so given the tight connection between the wxPython and
> wxWidgets projects, of which at first I wasn't aware.
>
> On Jan 3, 8:19 pm, kyoso... at gmail.com wrote:
> [...]
>
>
>
> > I've never created a modal dialog like this. Instead, I follow the
> > wxPython in Action book examples (most of the time), which would do a
> > yes/no dialog like this:
>
> > <code>
>
> > dlg = wx.MessageDialog(None, 'Some Message', 'A Message Box',
> > wx.YES_NO | wx.QUESTION)
> > retCode = dlg.ShowModal()
> > if retCode == wx.ID_YES:
> >    # do something
> >    print 'yes'
> > else:
> >    # do something else
> >    print 'no'
> > dlg.Destroy()
>
> > </code>
>
> Actually my example started out as something like
>
> if wx.MessageBox(message="Some message", caption="Some caption",
>         style=wx.YES|wx.NO) == wx.YES:
>     pass
>
> I had to change it because the actual message can become very long, so
> I assembled a dialog with a scrollable text field. Maybe I'm expecting
> to much of wxStdDialogButtonSizer, but I still feel that given that
> both your method and mine above work straight away, it should provide
> the same behaviour with Yes/No buttons as with OK/Cancel ones.
>
> Cheers,
> Nicola Musatti

Nicola,

I have sub-classed wx.Dialog to do my own custom modal dialogs as
well. You can use sizers and put whatever widgets you want onto it
that way. Just make sure that when you create the Yes/No buttons, you
give them the wx.ID_YES or wx.ID_NO ids, rather than -1 or wx.ID_ANY.

yesBtn = wx.Button(parent, wx.ID_YES, 'Yes')
noBtn  = wx.Button(parent, wx.ID_NO, 'No')

Mike



More information about the Python-list mailing list