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

tkinter Menu.delete bug #48024

Closed
skomoroh mannequin opened this issue Sep 4, 2008 · 24 comments
Closed

tkinter Menu.delete bug #48024

skomoroh mannequin opened this issue Sep 4, 2008 · 24 comments

Comments

@skomoroh
Copy link
Mannequin

skomoroh mannequin commented Sep 4, 2008

BPO 3774
Nosy @loewis, @benjaminp
Files
  • menu_bug.py
  • menu_bag.patch
  • issue3774.diff
  • menu_fix.patch
  • issue3774_2.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 = <Date 2008-11-03.18:20:28.033>
    created_at = <Date 2008-09-04.13:19:15.108>
    labels = ['easy', 'expert-tkinter']
    title = 'tkinter Menu.delete bug'
    updated_at = <Date 2008-11-04.06:28:19.179>
    user = 'https://bugs.python.org/skomoroh'

    bugs.python.org fields:

    activity = <Date 2008-11-04.06:28:19.179>
    actor = 'ocean-city'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-11-03.18:20:28.033>
    closer = 'ocean-city'
    components = ['Tkinter']
    creation = <Date 2008-09-04.13:19:15.108>
    creator = 'skomoroh'
    dependencies = []
    files = ['11373', '11375', '11476', '11477', '11479']
    hgrepos = []
    issue_num = 3774
    keywords = ['patch', 'easy']
    message_count = 24.0
    messages = ['72501', '72502', '72508', '73084', '73085', '73090', '73091', '73093', '73094', '73099', '73101', '73102', '73103', '73108', '73119', '73123', '73297', '74122', '74130', '74139', '75474', '75475', '75478', '75490']
    nosy_count = 8.0
    nosy_names = ['loewis', 'svenil', 'ocean-city', 'benjamin.peterson', 'gpolo', 'schuppenies', 'skomoroh', 'indiedan']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3774'
    versions = ['Python 2.6', 'Python 2.5', 'Python 3.0', 'Python 2.7']

    @skomoroh
    Copy link
    Mannequin Author

    skomoroh mannequin commented Sep 4, 2008

    When I create a menu item without command and them remove it, I have a
    error:
    File "/usr/local/lib/python3.0/tkinter/init.py", line 2661, in delete
    if c in self._tclCommands:
    TypeError: argument of type 'NoneType' is not iterable

    @skomoroh skomoroh mannequin added the topic-tkinter label Sep 4, 2008
    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 4, 2008

    I tried, and I confirmed released python2.5.2 runs fine. and
    py3k, trunk, release25-maint fails. Probably something changed after
    2.5.2 release.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 4, 2008

    I've not tested this so heavily, but patch could be simple.
    self._tclCommands could be None, so should check it.

    @ocean-city ocean-city mannequin added the easy label Sep 4, 2008
    @indiedan
    Copy link
    Mannequin

    indiedan mannequin commented Sep 12, 2008

    Please forgive my rookie bug filing:

    I'm getting this bug / crash sometimes when Menu.delete() is called too

    It seems to be because self.index( ) sometimes returns None which is of
    course un-iterable and delete() tries to iterate through it:

    for i in range(self.index(index1), self.index(index2)+1):

    As a fix the previous (simpler) delete works for me, but I don't
    understand the purpose of the extra self.deletecommand() code appended
    so I'm probably missing something.

    My crash:
    File "C:\CCPN\ccpn\python\memops\gui\Menu.py", line 127, in
    deleteMenuItems
    self.delete(0, Tkinter.END)
    File "C:\Python26\lib\lib-tk\Tkinter.py", line 2665, in delete
    for i in range(self.index(index1), self.index(index2)+1):
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 12, 2008

    for i in range(self.index(index1), self.index(index2)+1):

    Probably your working copy is bit old. Please try latest file.
    This issue was fixed in r65971. :-)

    # I've added nosy list from bpo-1342811.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    Python 2.6b2 was released with this bug, and got fixed later.

    @gpolo gpolo mannequin closed this as completed Sep 12, 2008
    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    I meant beta3, sorry.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    Oops, sorry, I misread the bug report, reopening it (let me go eat
    something now).

    @gpolo gpolo mannequin removed the easy label Sep 12, 2008
    @gpolo gpolo mannequin reopened this Sep 12, 2008
    @gpolo gpolo mannequin added the easy label Sep 12, 2008
    @indiedan
    Copy link
    Mannequin

    indiedan mannequin commented Sep 12, 2008

    Thanks guys - I was running an old build. revision 65971 fixed this as Hirokazu mentioned.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    The patch attached is probably the most direct way to fix it, but, can
    someone remind why we just don't call deletecommand (if there is a
    command to delete) and let it try to remove the command from _tclCommand
    then ? (note that this is not really the case for this bug report).
    I'm attaching a patch that is a bit "different". It relies on the fact
    that if the menu entry was created with add_command but no command was
    specified, then there is no command to specify. And if a command was
    specified then _tclCommands would be a list and deletecommand would work
    properly.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    Again, I meant the previously attached patch (the one by ocean-city) was
    the most direct way.

    @skomoroh
    Copy link
    Mannequin Author

    skomoroh mannequin commented Sep 12, 2008

    Seems I found the bug.

    I've attached the patch for current py3k-trunk.

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    My patch already does what is proposed in your patch, except yours may
    possibly not work. It is not guaranteed that "self.entrycget(i,
    'command')" will return an empty string if the command associated to
    that menu entry is an empty string. Tcl may return another object
    containing the representation of this menu command so that if statement
    will evalute as True while its representation is actually an empty string.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 12, 2008

    self.deletecommand doesn't remove menu item, so we don't have to care
    about index shifting like bellow. +1 for gpolo's patch.

    >>> a = [0, 1, 2, 3]
    >>> for i in xrange(len(a)):
    ...     del a[i]
    ...
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
    IndexError: list assignment index out of range

    I'm not sure (self._tclCommands is not None) check is not really needed.
    I was looking for the place self._tclCommands is initialized, and found
    _register() is that place, but what is 'needcleanup'? :-0
    But probably, gpolo's patch is right.

    P.S.
    This is not related to this issue, I think
    """Delete menu items between INDEX1 and INDEX2 (not included)."""
    should be changed to
    """Delete menu items between INDEX1 and INDEX2 (included)."""

    Please look at http://www.tcl.tk/man/tcl8.5/TkCmd/menu.htm#M59

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    This "needcleanup" parameter indicates that the function added to
    _tclCommands needs to (and will) be removed later. Nevertheless, I
    believe the proper initialization of _tclCommands should be done elsewhere.

    And about that docstring.. yes, the change is needed. (I could swear I
    saw it fixed some time ago, but no.. it didn't happen)

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Sep 12, 2008

    New patch, this one fixes the docstring previously mentioned and may set
    _tclCommands to an empty list at BaseWidget.__init__

    @indiedan
    Copy link
    Mannequin

    indiedan mannequin commented Sep 16, 2008

    It may be because I'm calling delete incorrectly (I don't think so - see
    below) but I'm getting an error

    File "C:\CCPN\ccpn\python\memops\gui\Menu.py", line 127, in
    deleteMenuItems
    self.delete(0, Tkinter.END)
    File "C:\Python-2.6_svn\lib\lib-tk\Tkinter.py", line 2670, in delete
    if c in self._tclCommands:
    TypeError: argument of type 'NoneType' is not iterable

    Which can easily be fixed with

    • if c in self._tclCommands:
      + if c and c in self._tclCommands:

    line 2670 Tkinter.py

    Should I create a patch or have I missed something? Thanks.

    @indiedan
    Copy link
    Mannequin

    indiedan mannequin commented Oct 1, 2008

    gpolo's patch issue3774_2.diff does seem to fix this bug, but it's not in
    the SVN trunk - could this be done before 2.6 final? Thanks!

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Oct 1, 2008

    I think gpolo's patch can go.

    I'm not sure (self._tclCommands is not None) check is not really needed.

    I want to cancel this opinion. I saw no self._tclCommands check before
    any other deletecommand() call, I beleive this is OK.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 1, 2008

    gpolo's patch issue3774_2.diff does seem to fix this bug, but it's not in
    the SVN trunk - could this be done before 2.6 final?

    Definitely not. The release is about to be produced today.

    @indiedan
    Copy link
    Mannequin

    indiedan mannequin commented Nov 3, 2008

    Sorry to drag this up again, but if no-one has any complaints it would be
    a huge help if gpolo's patch could be checked in. Thanks

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Nov 3, 2008

    Fixed in r67082(trunk), r67083(release26-maint), r67084(release25-maint).

    @ocean-city ocean-city mannequin closed this as completed Nov 3, 2008
    @benjaminp
    Copy link
    Contributor

    Could you port this to 3.0, please?

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Nov 4, 2008

    Done. Fixed in r67095(py3k).

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant