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

Make Tkinter.py's nametowidget work with cloned menu widgets #38464

Open
gregcouch mannequin opened this issue May 7, 2003 · 13 comments
Open

Make Tkinter.py's nametowidget work with cloned menu widgets #38464

gregcouch mannequin opened this issue May 7, 2003 · 13 comments
Labels
stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@gregcouch
Copy link
Mannequin

gregcouch mannequin commented May 7, 2003

BPO 734176
Nosy @terryjreedy, @abalkin, @serhiy-storchaka
Files
  • Tkinter.py.diffs: nametowidget patch for cloned widgets
  • nametowidget_clonedmenus.diff
  • issue734176_py3.patch: Python 3 patch
  • nametowidget_clonedmenus_2.diff
  • nametowidget_clonedmenus_3.patch
  • 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 2003-05-07.20:11:52.000>
    labels = ['type-bug', 'expert-tkinter']
    title = "Make Tkinter.py's nametowidget work with cloned menu widgets"
    updated_at = <Date 2021-07-09.21:02:53.288>
    user = 'https://bugs.python.org/gregcouch'

    bugs.python.org fields:

    activity = <Date 2021-07-09.21:02:53.288>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2003-05-07.20:11:52.000>
    creator = 'gregcouch'
    dependencies = []
    files = ['5260', '12509', '30320', '31426', '43851']
    hgrepos = []
    issue_num = 734176
    keywords = ['patch']
    message_count = 13.0
    messages = ['43671', '43672', '78634', '114239', '114244', '189566', '189637', '189674', '195928', '270902', '271130', '271131', '397223']
    nosy_count = 6.0
    nosy_names = ['jepler', 'terry.reedy', 'belopolsky', 'gregcouch', 'gpolo', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue734176'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @gregcouch
    Copy link
    Mannequin Author

    gregcouch mannequin commented May 7, 2003

    Tk will clone menu widgets when they are torn off and
    it gives them names at are similar to the original
    widget's names. The patch extends the nametowidget so
    it will return the original widget when given the name
    of a cloned widget. We used this patch to provide
    balloon help in cloned menus. This patch isn't
    perfect, it will fail on clones of clones, but it is a
    big help.

    This patch was made against the latest CVS version
    1.173 of Tkinter.py but works against older
    Tkinter.py's too.

     - Greg Couch
    

    @gregcouch gregcouch mannequin added topic-tkinter labels May 7, 2003
    @jepler
    Copy link
    Mannequin

    jepler mannequin commented May 11, 2003

    Logged In: YES
    user_id=2772

    I don't believe that the naming convention of cloned menus is actually documented anywhere (it's certainly not documented in menu(n) of tk-8.3.5 as packaged by RedHat. The only promise that the documentation makes is that the clone "is a child of the original". (but that can be violated if "menu clone" is invoked directly:

    % menu .m
    .m
    % .m clone .n
    %
    )

    That said, the convention for automatically generated clones hasn't varied in the versions of Tk I'm aware of (at least 8.2 through 8.4) so it might be reasonable to depend on this.

    Does anybody in Python development also keep up with Tcl/Tk development? It might be reasonable to ask them to document the format of automatically generated clone names.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Dec 31, 2008

    Eh.. old.
    Anyway, I have made a patch against trunk now and it should work with
    any nested level of cloned menus according to how tk names cloned menus.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Aug 18, 2010

    A small simple patch that I see no problems with.

    @BreamoreBoy BreamoreBoy mannequin added type-feature A feature request or enhancement labels Aug 18, 2010
    @abalkin
    Copy link
    Member

    abalkin commented Aug 18, 2010

    Can someone post a script demonstrating the proposed feature? Is "clones of clones" issue mentioned by OP resolved in the latest patch?

    Given that nobody commented on this issue for 7 years, I am skeptical about the utility of this feature.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented May 19, 2013

    Ten years on does anybody actually care about this? If you do the patch will need reworking as in Python 3 the code exists in lib/tkinter/init.py.

    @gregcouch
    Copy link
    Mannequin Author

    gregcouch mannequin commented May 20, 2013

    We still apply that patch to the Python that we embed in our application
    and have for the last 10 years :-)

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented May 20, 2013

    I've attached a patch for Python 3 which I hope is okay as it's my first attempt using TortoiseHg on Windows.

    @serhiy-storchaka
    Copy link
    Member

    bpo-18686 have a script which demonstrates the proposed feature.

    However Guilherme's patch is a little wrong. Here is updated patch.

    Note that even this patch is not absolute correct, because Tk adds count if new name is not unique. I.e. if .bpo-12345 already exists it try .bpo-123451, .bpo-123452, .bpo-123453, etc. It is impossible restore original name in general case.

    @terryjreedy
    Copy link
    Member

    Serhiy, if you are sure your patch is an improvement, then I think you should commit it without waiting for perfection.

    Only the other hand, bpo-18686 does not demonstrate a problem *to me* as it does not fail for me. Does anyone else reproduce the failure on a current non-Windows system? Based just on what I can see, I would be inclined to close this.

    @serhiy-storchaka
    Copy link
    Member

    bpo-18686 is reproducible to me. Here is a script based on bpo-18686 example. Run it and open the "File" menu.

    $ python3 issue18686.py 
    .#3069298188.#3069298188#3069298252
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__
        return self.func(*args)
      File "issue18686.py", line 24, in entry_focus_lost
        widget_with_focus = self.focus_get()
      File "/usr/lib/python3.5/tkinter/__init__.py", line 550, in focus_get
        return self._nametowidget(name)
      File "/usr/lib/python3.5/tkinter/__init__.py", line 1204, in nametowidget
        w = w.children[n]
    KeyError: '#3069298188'

    But my patch doesn't help in case of tearoff menu. Detach the "File" menu and hover a mouse on its item.

    $ ./python issue18686.py 
    .#`menu.#`menu#`menu
    .`menu.`menu
    .tearoff1
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 1712, in __call__
        return self.func(*args)
      File "issue18686.py", line 24, in entry_focus_lost
        widget_with_focus = self.focus_get()
      File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 692, in focus_get
        return self._nametowidget(name)
      File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 1344, in nametowidget
        w = w.children[n]
    KeyError: 'tearoff1'

    @serhiy-storchaka
    Copy link
    Member

    Following patch tries to handle the case when there are multiple clones (but it doesn't help with tearoff menus).

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Jul 24, 2016
    @terryjreedy
    Copy link
    Member

    See bpo-44592, closed as duplicate of this.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants