comparison clients/editor/selection.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 28532ae6f9f6
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 import pychan
2 import pychan.widgets as widgets
3
4 class Selection():
5 """
6 Selection displays a list of options for the user to select from. The result is passed to onSelection.
7 list - the list to select from
8 onSelection - the function to call when a selection is made. Accepts one argument: an element of the list.
9 """
10 def __init__(self, list, onSelection):
11 self.list = list
12 self._callback = onSelection
13
14 self._widget = pychan.loadXML('content/gui/selection.xml')
15
16 self._widget.mapEvents({
17 'okButton' : self._selected,
18 'cancelButton' : self._widget.hide
19 })
20
21 self._widget.distributeInitialData({
22 'optionDrop' : list
23 })
24 self._widget.show()
25
26 def _selected(self):
27 selection = self._widget.collectData('optionDrop')
28 if selection < 0: return
29 self._callback(self.list[selection])
30 self._widget.hide()
31
32 class ClickSelection():
33 """
34 ClickSelection displays a list of options for the user to select from. The result is passed to onSelection.
35 Differs from Selection: the selection is made when a list element is clicked, rather than when the box is closed.
36 list - the list to select from
37 onSelection - the function to call when a selection is made. Accepts one argument: an element of the list.
38 """
39 def __init__(self, list, onSelection):
40 self.list = list
41 self._callback = onSelection
42
43 self._widget = pychan.loadXML('content/gui/selection.xml')
44
45 self._widget.mapEvents({
46 'okButton' : self._widget.hide,
47 'cancelButton' : self._widget.hide,
48 'optionDrop' : self._selected
49 })
50
51 self._widget.distributeInitialData({
52 'optionDrop' : list
53 })
54 self._widget.show()
55
56 def _selected(self):
57 selection = self._widget.collectData('optionDrop')
58 if selection < 0: return
59 self._callback(self.list[selection])