Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an API in tkSimpleDialog for defining custom validation functions #56932

Closed
rabbidous mannequin opened this issue Aug 10, 2011 · 7 comments
Closed

Provide an API in tkSimpleDialog for defining custom validation functions #56932

rabbidous mannequin opened this issue Aug 10, 2011 · 7 comments
Labels
topic-tkinter type-feature A feature request or enhancement

Comments

@rabbidous
Copy link
Mannequin

rabbidous mannequin commented Aug 10, 2011

BPO 12723
Nosy @terryjreedy, @bitdancer, @asvetlov
Files
  • askstring.patch: patch on tkSimpleDialog.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-04-16.13:06:04.701>
    created_at = <Date 2011-08-10.15:23:11.036>
    labels = ['type-feature', 'expert-tkinter']
    title = 'Provide an API in tkSimpleDialog for defining custom validation functions'
    updated_at = <Date 2012-04-16.13:06:04.701>
    user = 'https://bugs.python.org/rabbidous'

    bugs.python.org fields:

    activity = <Date 2012-04-16.13:06:04.701>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-04-16.13:06:04.701>
    closer = 'asvetlov'
    components = ['Tkinter']
    creation = <Date 2011-08-10.15:23:11.036>
    creator = 'rabbidous'
    dependencies = []
    files = ['22875']
    hgrepos = []
    issue_num = 12723
    keywords = ['patch']
    message_count = 7.0
    messages = ['141868', '141887', '141901', '141903', '141985', '142023', '157463']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'r.david.murray', 'asvetlov', 'rabbidous']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12723'
    versions = ['Python 3.3']

    @rabbidous
    Copy link
    Mannequin Author

    rabbidous mannequin commented Aug 10, 2011

    tkSimpleDialog.askstring allows empty input. The attached patch adds validation to the input to ensure it is not empty.

    @rabbidous rabbidous mannequin added topic-tkinter type-feature A feature request or enhancement labels Aug 10, 2011
    @bitdancer
    Copy link
    Member

    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.

    @rabbidous
    Copy link
    Mannequin Author

    rabbidous mannequin commented Aug 11, 2011

    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?

    @bitdancer
    Copy link
    Member

    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.

    @bitdancer bitdancer changed the title tkSimpleDialog.askstring shouldn't allow empty string input Provide an API in tkSimpleDialog for defining custom validation functions Aug 11, 2011
    @rabbidous
    Copy link
    Mannequin Author

    rabbidous mannequin commented Aug 12, 2011

    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.

    @bitdancer
    Copy link
    Member

    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.

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Apr 4, 2012

    I think we have to reject this issue.
    Adding generic validation make sense, but adding just permanent check for non-empty string is wrong.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants