0
0
mirror of https://github.com/python/cpython.git synced 2024-11-28 16:45:42 +01:00

Added a delete() method to menu entries. Only the last entry of a menu

can be deleted, but that's good enough for things like a "Windows"
menu with the dynamic list of open windows at the end of the menu.
This commit is contained in:
Jack Jansen 1998-07-13 13:41:02 +00:00
parent f22e67dcb5
commit 5c44027d8a

View File

@ -526,7 +526,7 @@ class Menu:
del self.items
del self.menu
del self.id
def additem(self, label, shortcut=None, callback=None, kind=None):
self.menu.AppendMenu('x') # add a dummy string
self.items.append(label, shortcut, callback, kind)
@ -535,6 +535,12 @@ class Menu:
if shortcut:
self.menu.SetItemCmd(item, ord(shortcut))
return item
def delitem(self, item):
if item != len(self.items):
raise 'Can only delete last item of a menu'
self.menu.DeleteMenuItem(item)
del self.items[item-1]
def addcheck(self, label, shortcut=None, callback=None):
return self.additem(label, shortcut, callback, 'check')
@ -583,6 +589,8 @@ class Menu:
self.menu.EnableItem(0)
else:
self.menu.DisableItem(0)
if self.bar and self.bar.parent:
self.bar.parent.needmenubarredraw = 1
class PopupMenu(Menu):
def __init__(self, bar):
@ -610,6 +618,11 @@ class MenuItem:
self.item = menu.additem(title, shortcut, callback)
self.menu = menu
def delete(self):
self.menu.delitem(self.item)
del self.menu
del self.item
def check(self, onoff):
self.menu.menu.CheckItem(self.item, onoff)