Modal Dialog Button Return Code

Mark Erbaugh wrote:

···

On Mon, 2008-06-30 at 10:26 -0400, Mike Rooney wrote:

Mark Erbaugh wrote:

Is there a way to associate a code with a button, so that when the
button is clicked on a modal dialog the ShowModal() method will return
with that value. I see that the Dialog class as SetAffirmativeId() and
SetEscapeId() which can be used for YES and NO/CANCEL buttons, but is
there a way to add a third button? I know I can bind an event handler
to the third button, but is there a simpler way?

Are you subclassing a dialog? In that case a nice way to do this can be to make a method on the dialog such as GetReturnValue which gives what you want, and call it after you ShowModal(). A second method is to just tack whatever you want onto the dialog for access later, such as myDialog.returnVal = 5, and then after ShowModal() you can just read myDialog.returnVal.

Wouldn't both of these options still require an event handler for the
third button? Or am I missing something? Right now I have an event
handler for the third button

def onThirdButton(self,evt):
    self.EndModal(<desired result>)

Yes, this is the correct way to set the integer return value of ShowModal. Mike was suggesting how to make other dialog data available to the caller of the dialog.

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