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.

classification
Title: Provide an API in tkSimpleDialog for defining custom validation functions
Type: enhancement Stage: needs patch
Components: Tkinter Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, r.david.murray, rabbidous, terry.reedy
Priority: normal Keywords: patch

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:20adminsetgithub: 56932
2012-04-16 13:06:04asvetlovsetstatus: open -> closed
resolution: rejected
2012-04-04 06:36:10asvetlovsetnosy: + asvetlov
messages: + msg157463
2011-08-13 15:44:03r.david.murraysetmessages: + msg142023
2011-08-12 18:26:57rabbidoussetmessages: + msg141985
2011-08-12 18:13:20terry.reedysetnosy: + terry.reedy
2011-08-11 12:24:58r.david.murraysettitle: 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:05rabbidoussetmessages: + msg141901
2011-08-11 00:45:15r.david.murraysetnosy: + r.david.murray
messages: + msg141887
2011-08-10 15:23:26rabbidoussetversions: + Python 2.7
2011-08-10 15:23:11rabbidouscreate