home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / gl / glstdwin / glstdwmenu.py < prev    next >
Text File  |  1992-12-14  |  1KB  |  63 lines

  1. # Define menu operations for GL stdwin
  2.  
  3. import gl
  4. from glstdwin import key2code
  5.  
  6. class MenuObject:
  7.     #
  8.     def _init(self, win, title):
  9.         self._win = win
  10.         self._title = title
  11.         self._items = []
  12.         return self
  13.     #
  14.     def close(self):
  15.         self._win.remove(self)
  16.         del self._win
  17.     #
  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])
  26.     #
  27.     def setitem(self, i, text):
  28.         self._items[i][0] = text
  29.     #
  30.     def enable(self, i, flag):
  31.         self._items[i][2] = flag
  32.     #
  33.     def check(self, i, flag):
  34.         self._items[i][3] = flag
  35.     #
  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
  55.     #
  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
  62.     #
  63.