Mercurial > fife-parpg
comparison clients/editor/scripts/gui/selection.py @ 255:51cc05d862f2
Merged editor_rewrite branch to trunk.
This contains changes that may break compatibility against existing clients.
For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 16:00:02 +0000 |
parents | |
children | 8b125ec749d7 |
comparison
equal
deleted
inserted
replaced
254:10b5f7f36dd4 | 255:51cc05d862f2 |
---|---|
1 import pychan | |
2 import pychan.widgets as widgets | |
3 | |
4 class SelectionDialog(object): | |
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('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 ClickSelectionDialog(object): | |
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('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]) |