|
1 | 1 | import FrameWork |
2 | 2 | import Qd |
3 | | -import Wbase |
| 3 | +import Wbase, Wcontrols, Ctl, Controls |
4 | 4 | from types import * |
5 | 5 | import Wapplication |
6 | 6 |
|
7 | 7 | _arrowright = Qd.GetPicture(472) |
8 | 8 | _arrowdown = Qd.GetPicture(473) |
9 | 9 |
|
10 | 10 |
|
| 11 | +class PopupControl(Wcontrols.ControlWidget): |
| 12 | + |
| 13 | + def __init__(self, possize, items=None, callback=None): |
| 14 | + if items is None: |
| 15 | + items = [] |
| 16 | + procID = Controls.popupMenuProc|Controls.popupFixedWidth|Controls.useWFont |
| 17 | + Wcontrols.ControlWidget.__init__(self, possize, "", procID, callback, 0, 0, 0) |
| 18 | + self._items = items[:] |
| 19 | + |
| 20 | + def set(self, value): |
| 21 | + self._control.SetControlValue(value+1) |
| 22 | + |
| 23 | + def get(self): |
| 24 | + return self._control.GetControlValue() - 1 |
| 25 | + |
| 26 | + def open(self): |
| 27 | + self.menu = menu = FrameWork.Menu(self._parentwindow.parent.menubar, 'Foo', -1) |
| 28 | + |
| 29 | + for i in range(len(self._items)): |
| 30 | + item = self._items[i] |
| 31 | + if type(item) == StringType: |
| 32 | + menuitemtext = object = item |
| 33 | + elif type(item) == TupleType and len(item) == 2: |
| 34 | + menuitemtext, object = item |
| 35 | + self._items[i] = object |
| 36 | + else: |
| 37 | + raise Wbase.WidgetsError, "illegal itemlist for popup menu" |
| 38 | + menuitem = FrameWork.MenuItem(menu, menuitemtext, None, None) |
| 39 | + |
| 40 | + self._calcbounds() |
| 41 | + self._control = Ctl.NewControl(self._parentwindow.wid, |
| 42 | + self._bounds, |
| 43 | + self._title, |
| 44 | + 1, |
| 45 | + self._value, |
| 46 | + self.menu.id, |
| 47 | + self._max, |
| 48 | + self._procID, |
| 49 | + 0) |
| 50 | + self.SetPort() |
| 51 | + self.enable(self._enabled) |
| 52 | + |
| 53 | + def close(self): |
| 54 | + self.menu.delete() |
| 55 | + return Wcontrols.ControlWidget.close(self) |
| 56 | + |
| 57 | + def click(self, point, modifiers): |
| 58 | + if not self._enabled: |
| 59 | + return |
| 60 | + part = self._control.TrackControl(point, -1) |
| 61 | + if part: |
| 62 | + if self._callback: |
| 63 | + Wbase.CallbackCall(self._callback, 0, self._items[self.get()]) |
| 64 | + |
11 | 65 |
|
12 | 66 | class PopupWidget(Wbase.ClickableWidget): |
13 | 67 |
|
14 | 68 | """Simple title-less popup widget. Should be 16x16 pixels. |
15 | 69 | Builds the menu items on the fly, good for dynamic popup menus.""" |
16 | 70 |
|
17 | | - def __init__(self, possize, items = [], callback = None): |
18 | | - Wbase.Widget.__init__(self, possize) |
| 71 | + def __init__(self, possize, items=None, callback=None): |
| 72 | + Wbase.ClickableWidget.__init__(self, possize) |
| 73 | + if items is None: |
| 74 | + items = [] |
19 | 75 | self._items = items |
20 | 76 | self._itemsdict = {} |
21 | 77 | self._callback = callback |
22 | 78 | self._enabled = 1 |
23 | 79 |
|
24 | 80 | def close(self): |
25 | | - Wbase.Widget.close(self) |
| 81 | + Wbase.ClickableWidget.close(self) |
26 | 82 | self._items = None |
27 | 83 | self._itemsdict = {} |
28 | 84 |
|
|
0 commit comments