Mercurial > fife-parpg
comparison tools/editor/scripts/gui/selection.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | ef0c7a0cacab |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 import fife.extensions.pychan | |
25 import fife.extensions.pychan.widgets as widgets | |
26 | |
27 class SelectionDialog(object): | |
28 """ | |
29 Selection displays a list of options for the user to select from. The result is passed to onSelection. | |
30 list - the list to select from | |
31 onSelection - the function to call when a selection is made. Accepts one argument: an element of the list. | |
32 """ | |
33 def __init__(self, list, onSelection): | |
34 self.list = list | |
35 self._callback = onSelection | |
36 | |
37 self._widget = pychan.loadXML('gui/selection.xml') | |
38 | |
39 self._widget.mapEvents({ | |
40 'okButton' : self._selected, | |
41 'cancelButton' : self._widget.hide | |
42 }) | |
43 | |
44 self._widget.distributeInitialData({ | |
45 'optionDrop' : list | |
46 }) | |
47 self._widget.show() | |
48 | |
49 def _selected(self): | |
50 selection = self._widget.collectData('optionDrop') | |
51 if selection < 0: return | |
52 self._callback(self.list[selection]) | |
53 self._widget.hide() | |
54 | |
55 class ClickSelectionDialog(object): | |
56 """ | |
57 ClickSelection displays a list of options for the user to select from. The result is passed to onSelection. | |
58 Differs from Selection: the selection is made when a list element is clicked, rather than when the box is closed. | |
59 list - the list to select from | |
60 onSelection - the function to call when a selection is made. Accepts one argument: an element of the list. | |
61 """ | |
62 def __init__(self, list, onSelection): | |
63 self.list = list | |
64 self._callback = onSelection | |
65 | |
66 self._widget = pychan.loadXML('gui/selection.xml') | |
67 | |
68 self._widget.mapEvents({ | |
69 'okButton' : self._widget.hide, | |
70 'cancelButton' : self._widget.hide, | |
71 'optionDrop' : self._selected | |
72 }) | |
73 | |
74 self._widget.distributeInitialData({ | |
75 'optionDrop' : list | |
76 }) | |
77 self._widget.show() | |
78 | |
79 def _selected(self): | |
80 selection = self._widget.collectData('optionDrop') | |
81 if selection < 0: return | |
82 self._callback(self.list[selection]) |