python / cpython

The Python programming language
https://www.python.org/
Other
61.48k stars 29.61k forks source link

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

Open 67b7e3ee-c650-4643-a690-f7725ac3f411 opened 21 years ago

67b7e3ee-c650-4643-a690-f7725ac3f411 commented 21 years ago
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: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'expert-tkinter'] title = "Make Tkinter.py's nametowidget work with cloned menu widgets" updated_at = user = 'https://bugs.python.org/gregcouch' ``` bugs.python.org fields: ```python activity = actor = 'terry.reedy' assignee = 'none' closed = False closed_date = None closer = None components = ['Tkinter'] creation = 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'] ```

    67b7e3ee-c650-4643-a690-f7725ac3f411 commented 21 years ago

    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
    9dd6b116-0b30-4f36-938a-5d6ffefdc969 commented 21 years ago

    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.

    1fecb825-97ee-46b6-913c-bb07e2a288a6 commented 15 years ago

    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.

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 13 years ago

    A small simple patch that I see no problems with.

    abalkin commented 13 years ago

    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.

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 11 years ago

    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.

    67b7e3ee-c650-4643-a690-f7725ac3f411 commented 11 years ago

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

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 11 years ago

    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 commented 10 years ago

    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 commented 8 years ago

    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 commented 8 years ago

    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 commented 8 years ago

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

    terryjreedy commented 3 years ago

    See bpo-44592, closed as duplicate of this.