Paul Rubin wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
>>> But if the user doesn't enter any text, I don't want the method to
>>> return at all (even None).
>> John, please re-read the FineManual(tm). None is the default return
>> value of a function - even if there's no return stateme
Steve Holden wrote:
> 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.
wow, didn't think of that. that might end up being simpler than anything
else i've considered! :)
--
http://mail.python.org/mailman/listinfo/python-list
"John Salerno" <[EMAIL PROTECTED]> wrote:
8<-
>
> LOL. Guess I'm doing things right, then? ;)
>
you can NEVER be sure
- Hendrik
--
http://mail.python.org/mailman/listinfo/python-list
Roy Smith <[EMAIL PROTECTED]> writes:
> Isn't this the kind of thing that the new-fangled "with" statement is
> supposed to solve?
1) that would require rewriting the wx.TextEntryDialog to have an
exit method.
2) It's not necessarily always the case that you want to destroy the
dialog when the f
In article <[EMAIL PROTECTED]>,
Ben Finney <[EMAIL PROTECTED]> wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
>
> > if dlg.ShowModal() == wx.ID_OK:
> > db_name = dlg.GetValue()
> > dlg.Destroy()
> > return db_name
> > else:
> >
Farshid Lashkari <[EMAIL PROTECTED]> writes:
> Paul Rubin wrote:
> > I like
> >
> > if dlg.ShowModal() == wx.ID_OK:
> > db_name = dlg.GetValue()
> > else:
> > db_name = None
> > dlg.Destroy()
> > return db_name
> >
> > better than
> >
> > db_name = None
> >
John Salerno <[EMAIL PROTECTED]> writes:
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> dlg.Destroy()
> return db_name
> else:
> dlg.Destroy()
> return
It's for reasons like this that I prefer to ha
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.TextEn
Paul Rubin wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
>
>> if dlg.ShowModal() == wx.ID_OK:
>> db_name = dlg.GetValue()
>> dlg.Destroy()
>> return db_name
>> else:
>> dlg.Destroy()
>> return
>
>
> I like
>
> i
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> > But if the user doesn't enter any text, I don't want the method to
> > return at all (even None).
>
> John, please re-read the FineManual(tm). None is the default return
> value of a function - even if there's no return statement.
Correct, but i
John Salerno a écrit :
> Paul Rubin wrote:
>
>> John Salerno <[EMAIL PROTECTED]> writes:
>>
>>> I just need some advice for how to structure
>>> the check of the empty string.
>>
>>
>> How about
>>
>> return db_name or None
>>
>> since the empty string taken as a boolean is False.
>
>
> But
Paul Rubin wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
>> Interesting idea to use try/finally to ensure that dlg.Destroy() runs
>> even with a return earlier in the method.
>
> Note that the code is wrong, the dialog should either be created
> outside the while loop, or destroyed inside it.
How about this?
def create_db_name(self):
dlg = wx.TextEntryDialog(self.frame, 'Enter a
database name:',
'Create New
Database')
db_name = None #or db_name = ""
if dlg.ShowModal() == wx.ID_OK:
db_name = dlg.GetValue()
John Salerno <[EMAIL PROTECTED]> writes:
> Interesting idea to use try/finally to ensure that dlg.Destroy() runs
> even with a return earlier in the method.
Note that the code is wrong, the dialog should either be created
outside the while loop, or destroyed inside it. I don't know wx so
I'm not
Paul Rubin wrote:
>> but given that try/except and try/finally used to be separate
>> blocks,
>
> That old separation was just an artifact of how the parser was
> originally written, I believe.
$ more Misc/HISTORY
New features in 0.9.6:
- stricter try stmt syntax: cannot mix except and
John Salerno <[EMAIL PROTECTED]> writes:
> Interesting idea to use try/finally to ensure that dlg.Destroy() runs
> even with a return earlier in the method. Would this be considered
> appropriate use though, or would it be misusing try/finally? I thought
> the point of a try block was for when you
Paul Rubin wrote:
> 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:
>
Neil Cerutti wrote:
> This completes our C version [of a csv reading library]. It
> handles arbitrarily large inputs and does something sensible
> even with perverse data. The price is that it is more than four
> times as long as the first prototype and some of the code is
> intricate. S
On 2006-10-25, John Salerno <[EMAIL PROTECTED]> wrote:
> Paul Rubin wrote:
>
>> Right. The above handles that case, I believe.
>
> Oh, you're right! It's amazing how this went from a simple,
> two-line method to a big mess of error-checking. :)
>From Kernighan & Pike, _The Practice of Programmin
Paul Rubin wrote:
> Right. The above handles that case, I believe.
Oh, you're right! It's amazing how this went from a simple, two-line
method to a big mess of error-checking. :)
--
http://mail.python.org/mailman/listinfo/python-list
John Salerno <[EMAIL PROTECTED]> writes:
> > def create_db_name(self):
> > try:
> > while True:
> >dlg = wx.TextEntryDialog(self.frame, 'Enter a database
> > name:',
> >'Create New Database')
> >if dl
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, 'Ente
John Salerno <[EMAIL PROTECTED]> writes:
> But if the user doesn't enter any text, I don't want the method to
> return at all (even None). I need an error dialog to pop up and tell
> him to enter a value (or press Cancel).
Oh, I see. You really want something like repeat...while, which Python
doe
Paul Rubin wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
>> I just need some advice for how to structure
>> the check of the empty string.
>
> How about
>
> return db_name or None
>
> since the empty string taken as a boolean is False.
But if the user doesn't enter any text, I don't wan
John Salerno <[EMAIL PROTECTED]> writes:
> I just need some advice for how to structure
> the check of the empty string.
How about
return db_name or None
since the empty string taken as a boolean is False.
--
http://mail.python.org/mailman/listinfo/python-list
John Salerno wrote:
> Hi guys. I'm looking for a nicer, more compact way of writing this code.
Ok, one more thing. Let's assume I'm using this (or the other):
def create_db_name(self):
dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',
Paul Rubin wrote:
> I like
>
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> else:
> db_name = None
> dlg.Destroy()
> return db_name
>
> better than
>
> db_name = None
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
>
Paul Rubin wrote:
> I like
>
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> else:
> db_name = None
> dlg.Destroy()
> return db_name
>
> better than
>
> db_name = None
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
John Salerno <[EMAIL PROTECTED]> writes:
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> dlg.Destroy()
> return db_name
> else:
> dlg.Destroy()
> return
I like
if dlg.ShowModal() == wx.ID_OK:
John Salerno wrote:
> Hi guys. I'm looking for a nicer, more compact way of writing this code.
> It doesn't have to be anything fancy, just something without the
> duplication and preferably only one return statement.
>
> def create_db_name(self):
> dlg = wx.TextEntryDialog(self.fram
Hi guys. I'm looking for a nicer, more compact way of writing this code.
It doesn't have to be anything fancy, just something without the
duplication and preferably only one return statement.
def create_db_name(self):
dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',
Simon Forman wrote:
> Boris Borcic wrote:
>> John Salerno wrote:
>>> The code to look at is the try statement in the NumbersValidator class,
>>> just a few lines down. Is this a clean way to write it? i.e. is it okay
>>> to have all those return statements? Is this a good use of try? Etc.
>>>
>>> T
John Salerno <[EMAIL PROTECTED]> wrote:
> try:
> if int(text) != 0:
> return True
> else:
> self.error_message()
> return False
> except ValueError:
> self.error_message()
> return False
John Salerno wrote:
> The code to look at is the try statement in the NumbersValidator class,
> just a few lines down. Is this a clean way to write it? i.e. is it okay
> to have all those return statements? Is this a good use of try? Etc.
Ok, I came up with this. It looks much nicer, I think, th
Simon Forman wrote:
> Maybe I did miss something: Are you actually trying to make a static
> method? Say, to be able to call it elsewhere than just the Validate()
> method?
I don't know if a static method is the best way to do it, but what I was
trying to do was make a regular function within
Peter Otten wrote:
> John Salerno wrote:
>
>> The code to look at is the try statement in the NumbersValidator class,
>> just a few lines down. Is this a clean way to write it? i.e. is it okay
>> to have all those return statements? Is this a good use of try? Etc.
>>
>> Thanks.
>>
>> -
John Salerno wrote:
> The code to look at is the try statement in the NumbersValidator class,
> just a few lines down. Is this a clean way to write it? i.e. is it okay
> to have all those return statements? Is this a good use of try? Etc.
>
> Thanks.
>
>
>
> import
Boris Borcic wrote:
> John Salerno wrote:
> > The code to look at is the try statement in the NumbersValidator class,
> > just a few lines down. Is this a clean way to write it? i.e. is it okay
> > to have all those return statements? Is this a good use of try? Etc.
> >
> > Thanks.
> >
> >
John Salerno wrote:
> John Salerno wrote:
> > The code to look at is the try statement in the NumbersValidator class,
> > just a few lines down. Is this a clean way to write it? i.e. is it okay
> > to have all those return statements? Is this a good use of try? Etc.
>
> I cleaned it up a little and
John Salerno wrote:
> The code to look at is the try statement in the NumbersValidator class,
> just a few lines down. Is this a clean way to write it? i.e. is it okay
> to have all those return statements? Is this a good use of try? Etc.
>
> Thanks.
>
>
>
> import
Here's how I would do it:
def Validate(self, parent):
try:
text_ctrl = self.GetWindow()
text = text_ctrl.GetValue()
if not text: raise ValueError
if int(text) <= 0: raise ValueError
return True
except ValueError, error
Simon Forman wrote:
> John Salerno wrote:
> > John Salerno wrote:
> > > The code to look at is the try statement in the NumbersValidator class,
> > > just a few lines down. Is this a clean way to write it? i.e. is it okay
> > > to have all those return statements? Is this a good use of try? Etc.
>
John Salerno wrote:
> John Salerno wrote:
> > The code to look at is the try statement in the NumbersValidator class,
> > just a few lines down. Is this a clean way to write it? i.e. is it okay
> > to have all those return statements? Is this a good use of try? Etc.
>
> I cleaned it up a little and
John Salerno wrote:
> The code to look at is the try statement in the NumbersValidator class,
> just a few lines down. Is this a clean way to write it? i.e. is it okay
> to have all those return statements? Is this a good use of try? Etc.
I cleaned it up a little and did this, but of course this
The code to look at is the try statement in the NumbersValidator class,
just a few lines down. Is this a clean way to write it? i.e. is it okay
to have all those return statements? Is this a good use of try? Etc.
Thanks.
import wx
class NumbersValidator(wx.PyVali
45 matches
Mail list logo