Ditched '_find_SET()', since it was a no-value-added wrapper around
[python/dscho.git] / Demo / sgi / gl / glstdwin / glstdwmenu.py
blobdd6d90b6ea22ebd0ff64ca7a4a0118a65e216581
1 # Define menu operations for GL stdwin
3 import gl
4 from glstdwin import key2code
6 class MenuObject:
8 def _init(self, win, title):
9 self._win = win
10 self._title = title
11 self._items = []
12 return self
14 def close(self):
15 self._win.remove(self)
16 del self._win
18 def additem(self, *args):
19 if len(args) == 2:
20 text, shortcut = args
21 elif len(args) == 1:
22 text, shortcut = args[0], None
23 else:
24 raise TypeError, 'arg count'
25 self._items.append([text, shortcut, 1, 0])
27 def setitem(self, i, text):
28 self._items[i][0] = text
30 def enable(self, i, flag):
31 self._items[i][2] = flag
33 def check(self, i, flag):
34 self._items[i][3] = flag
36 def _makepup(self, firstitem):
37 pup = gl.newpup()
38 if self._title:
39 gl.addtopup(pup, self._title + '%t', 0)
40 for item in self._items:
41 text = item[0]
42 if not item[2]: # Disabled
43 text = ' ( ' + text + ' )%x-1'
44 else:
45 if item[3]: # Check mark
46 text = '-> ' + text
47 else:
48 text = ' ' + text
49 if key2code.has_key(item[1]):
50 text = text + ' [Alt-' + item[1] + ']'
51 text = text + '%x' + `firstitem`
52 gl.addtopup(pup, text, 0)
53 firstitem = firstitem + 1
54 return pup
56 def _checkshortcut(self, char):
57 for i in range(len(self._items)):
58 item = self._items[i]
59 if item[2] and item[1] == char:
60 return i
61 return -1