This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年08月10日 15:23 by rabbidous, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| askstring.patch | rabbidous, 2011年08月10日 15:23 | patch on tkSimpleDialog.py | ||
| Messages (7) | |||
|---|---|---|---|
| msg141868 - (view) | Author: Matthew Hemke (rabbidous) | Date: 2011年08月10日 15:23 | |
tkSimpleDialog.askstring allows empty input. The attached patch adds validation to the input to ensure it is not empty. |
|||
| msg141887 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2011年08月11日 00:45 | |
But what if the empty string is valid input? This change would be backward incompatible. I think this should instead be a feature request for exposing _QueryDialog so that you can subclass it and provide your own getresult function. |
|||
| msg141901 - (view) | Author: Matthew Hemke (rabbidous) | Date: 2011年08月11日 12:09 | |
What about adding a validatecommand option like on Tkinter.Entry? For what I am trying to do it was sort of a kludge to validate the entry because an empty string was invalid, but in the interface design, it would have been "rude" to validate after the dialog closes and then keep popping up another tkSimpleDialog.askstring until the input is correct. It almost makes askstring useless because I can't validate on close. That wouldn't break backwards compatibility would it? |
|||
| msg141903 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2011年08月11日 12:24 | |
Adding an option would also be a reasonable feature request, but I think exposing _QueryDialog would be a more general solution, since it would apply to more than just strings. While not backward incompatible, either of these is a new feature and so can only go into 3.3. |
|||
| msg141985 - (view) | Author: Matthew Hemke (rabbidous) | Date: 2011年08月12日 18:26 | |
I'm not sure if I misunderstood you, or you misunderstood me, but adding an option to the askstring dialog that would take a function handle would also allow you to use it for things other than strings (ints,etc.) Tkinter Entry does this: you set the validatecommand option to a function handle that returns true or false to determine whether the input was valid. I will try and code an example over the weekend. |
|||
| msg142023 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2011年08月13日 15:44 | |
A bit of both, I think. The current function is actually 'getvalue' and is responsible for retrieving the value, validating its type, and converting to that type (the current ones do both in the same operation). It feels to me like a cleaner interface to decouple retrieval and validation/conversion, so that the validation function gets passed a string and returns the desired type. But in that case, having the string dialog take the validation/coercion function makes the name of the askstring function just wrong. So, I still think the cleaner API is to expose the class and let the application subclass to provide the validation function. |
|||
| msg157463 - (view) | Author: Andrew Svetlov (asvetlov) * (Python committer) | Date: 2012年04月04日 06:36 | |
I think we have to reject this issue. Adding generic validation make sense, but adding just permanent check for non-empty string is wrong. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:20 | admin | set | github: 56932 |
| 2012年04月16日 13:06:04 | asvetlov | set | status: open -> closed resolution: rejected |
| 2012年04月04日 06:36:10 | asvetlov | set | nosy:
+ asvetlov messages: + msg157463 |
| 2011年08月13日 15:44:03 | r.david.murray | set | messages: + msg142023 |
| 2011年08月12日 18:26:57 | rabbidous | set | messages: + msg141985 |
| 2011年08月12日 18:13:20 | terry.reedy | set | nosy:
+ terry.reedy |
| 2011年08月11日 12:24:58 | r.david.murray | set | title: tkSimpleDialog.askstring shouldn't allow empty string input -> Provide an API in tkSimpleDialog for defining custom validation functions stage: needs patch messages: + msg141903 versions: + Python 3.3, - Python 2.7 |
| 2011年08月11日 12:09:05 | rabbidous | set | messages: + msg141901 |
| 2011年08月11日 00:45:15 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg141887 |
| 2011年08月10日 15:23:26 | rabbidous | set | versions: + Python 2.7 |
| 2011年08月10日 15:23:11 | rabbidous | create | |