cleaner way to write this?

Steve Holden steve at holdenweb.com
Thu Oct 26 01:00:22 CEST 2006


John Salerno wrote:
> Paul Rubin wrote:
> 
> 
>>Oh, I see.  You really want something like repeat...while, which Python
>>doesn't have.  Anyway I start to prefer something like (untested):
>>
>>     def create_db_name(self):
>>         try:
>>            while True:
>>               dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',
>>                                       'Create New Database')
>>               if dlg.ShowModal() != wx.ID_OK:
>>                   return None
>>               db_name = dlg.GetValue()
>>               if db_name:
>>                   return db_name
>>               pop_up_error_dialog("please enter a value or press cancel")
>>         finally:
>>            dlg.Destroy()
> 
> 
> Interesting. Some variation of this might suit me, but I think one other 
> problem I'm having is that the ShowModal() method returns whenever a 
> button is pressed, so even if OK is pressed with an empty string in the 
> box, the dialog disappears and returns an "OK" value. I'll have to check 
> in the wxpython group on how to handle this one, I think.

I suspect you need to use a validator so the user can't click OK until 
they've put a value int eh text entry item.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list