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

Add support for the new data option supported by event generate (Tk 8.5) #47655

Open
gpolo mannequin opened this issue Jul 18, 2008 · 8 comments
Open

Add support for the new data option supported by event generate (Tk 8.5) #47655

gpolo mannequin opened this issue Jul 18, 2008 · 8 comments
Labels
stdlib Python modules in the Lib dir topic-tkinter type-feature A feature request or enhancement

Comments

@gpolo
Copy link
Mannequin

gpolo mannequin commented Jul 18, 2008

BPO 3405
Nosy @mkiever, @mark-summerfield, @asvetlov, @serhiy-storchaka
PRs
  • bpo-3405: Add support for user data of Tk virtual events to tkinter #7142
  • Files
  • event_generate__data2.diff
  • 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 = None
    created_at = <Date 2008-07-18.12:52:45.025>
    labels = ['type-feature', 'expert-tkinter']
    title = 'Add support for the new data option supported by event generate (Tk 8.5)'
    updated_at = <Date 2018-05-29.14:18:00.977>
    user = 'https://bugs.python.org/gpolo'

    bugs.python.org fields:

    activity = <Date 2018-05-29.14:18:00.977>
    actor = 'mkiever'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2008-07-18.12:52:45.025>
    creator = 'gpolo'
    dependencies = []
    files = ['10948']
    hgrepos = []
    issue_num = 3405
    keywords = ['patch']
    message_count = 8.0
    messages = ['69951', '70040', '127658', '165234', '165254', '315621', '315624', '318035']
    nosy_count = 7.0
    nosy_names = ['mkiever', 'mark', 'gpolo', 'asvetlov', 'dghjfrdj', 'serhiy.storchaka', 'alex.rodas']
    pr_nums = ['7142']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3405'
    versions = ['Python 3.4']

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Jul 18, 2008

    Follows a patch that adds support for the new data option supported
    event generate. It allows virtual events to pass a tcl object.

    This patch is only intended to correctly support tcl objects, trying to
    pass other objects (like a dict) will result in None being returned. If
    you want to correctly pass and receive a dict, make it an attribute of
    the tcl object being passed.

    E.g.:

    import Tkinter
    
    def handle_it(event):
        print event.data.something
    
    root = Tkinter.Tk()
    root.something = {1: 2}
    root.after(1, lambda: root.event_generate('<<Test>>', data=root))
    root.bind('<<Test>>', handle_it)
    root.mainloop()

    @gpolo gpolo mannequin added the topic-tkinter label Jul 18, 2008
    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Jul 19, 2008

    Actually, it could be the "detail" field too according to
    http://www.tcl.tk/man/tcl8.5/TkCmd/bind.htm#M24
    And this field may not exist, so I'm checking for that now.

    New patch added.

    @bitdancer bitdancer added the type-feature A feature request or enhancement label Dec 22, 2010
    @dghjfrdj
    Copy link
    Mannequin

    dghjfrdj mannequin commented Jan 31, 2011

    Hello,

    I read the proposed patch "event_generate__data2.diff" and the Tcl/Tk manual http://www.tcl.tk/man/tcl8.5/TkCmd/bind.htm#M24

    • Could you please also add a field "e.user_data" ? This would simply be a copy of 'd' :
      ---
    e.detail = d
    e.user_data = d

    My reasoning is that the Tcl/Tk manual mentions the two names "detail" and "user_data". However, "user_data" may often be preferred because it has a clear meaning, whereas "detail" is quite vague.

    • I did not understand why you try to get a widget reference from the "%d" field. Is it supposed to contain a widget name at some point ? According to the manual (and if I understood it well), it should never.

    Best regards,

    O.C.

    @mark-summerfield
    Copy link
    Mannequin

    mark-summerfield mannequin commented Jul 11, 2012

    According to the Tcl/Tk docs the 'data' field is a string (i.e., for any user data) and the 'detail' field contains some internal data (so shouldn't be messed with); see http://www.tcl.tk/man/tcl8.5/TkCmd/event.htm#M16

    Anyway, I hope you add a data field for user created virtual events.

    @dghjfrdj
    Copy link
    Mannequin

    dghjfrdj mannequin commented Jul 11, 2012

    I don't agree with this comment.

    1. The 'detail' field also contains a string, one of the following: "NotifyAncestor", "NotifyNonlinearVirtual",...

    2. When an event is received, the 'detail' and 'user_data' fields are de facto mixed up. Indeed, the "%d" field contains "the detail or user_data field from the event".

    This information comes form the documentation I cited, http://www.tcl.tk/man/tcl8.5/TkCmd/bind.htm#M24 :

    • The "%d" field contains "the detail or user_data field from the event".
    • They are both strings:
    • "the %d is replaced by a string identifying the detail"
    • "For virtual events, the string will be whatever value is stored in the user_data field when the event was created (typically with event generate), or the empty string if the field is NULL"

    From the document cited in msg165234 (http://www.tcl.tk/man/tcl8.5/TkCmd/event.htm#M16), my understanding is:

    • For virtual events, the "data" string parameter given to "event generate" will be stored in the "user_data field" for the event. This string will then be available from the event through the "%d" substitution.

    • For events "Enter", "Leave", "FocusIn" and "FocusOut", the "detail" field will store a string among "NotifyAncestor", etc. This string will then be available from the event through the "%d" substitution.

    So, from the point of view of the guy who receives the event, the "%d" field can EITHER be a "detail" string like "NotifyAncestor" if event was "Enter"/"Leave"/"FocusIn"/"FocusOut" OR a "user_data" string in the case of a virtual event. It seems sensible that the Python interface provides both names. As a consequence, I think the patch should read:

    + # value passed to the data option is not a widget, take it
    + # as the detail field
    + e.data = None
    + e.detail = d
    + e.user_data = d

    I hope I understood the doc correctly.

    @mkiever
    Copy link
    Mannequin

    mkiever mannequin commented Apr 22, 2018

    I have a patched Python 3.5.3 running mostly following
    the comments by O.C. If no one else is active on this
    I can try to prepare something for submission.

    @serhiy-storchaka
    Copy link
    Member

    Fill free to create a pull request. It may need tests and documentation though.

    @mkiever
    Copy link
    Mannequin

    mkiever mannequin commented May 29, 2018

    So I pulled, but it seems the CLA is stuck somewhere. Investigating...

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants