Mercurial > fife-parpg
comparison tools/editor/scripts/gui/action.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 |
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 from scripts.events.signal import Signal | |
25 import fife.extensions.pychan.internal | |
26 | |
27 changed = Signal(providing_args=[]) | |
28 toggled = Signal(providing_args=["toggled"]) | |
29 activated = Signal(providing_args=[]) | |
30 #triggered = Signal(providing_args=["action"]) | |
31 | |
32 class Action: | |
33 def __init__(self, text="", icon="", separator=False, checkable=False, checked=False): | |
34 self._separator = separator | |
35 self._text = text | |
36 self._icon = icon | |
37 self._shortcut = "" | |
38 self._helptext = "" | |
39 self._enabled = True | |
40 self._checked = checked | |
41 self._checkable = checkable | |
42 | |
43 def __str__(self): | |
44 return "%s(name='%s')" % (self.__class__.__name__,self.text) | |
45 | |
46 def __repr__(self): | |
47 return "<%s(name='%s') at %x>" % (self.__class__.__name__,self.text,id(self)) | |
48 | |
49 | |
50 def activate(self): | |
51 if self.isCheckable(): | |
52 self.setChecked(not self.isChecked()) | |
53 activated.send(sender=self) | |
54 | |
55 def _changed(self): | |
56 changed.send(sender=self) | |
57 | |
58 def setSeparator(self, separator): | |
59 self._separator = separator | |
60 self._changed() | |
61 def isSeparator(self): return self._separator | |
62 | |
63 def _setText(self, text): | |
64 self._text = text | |
65 self._changed(self) | |
66 def _getText(self): return self._text | |
67 text = property(_getText, _setText) | |
68 | |
69 def _setIcon(self, icon): | |
70 self._icon = icon | |
71 self._changed() | |
72 def _getIcon(self): return self._icon | |
73 icon = property(_getIcon, _setIcon) | |
74 | |
75 def _setShortcut(self, keysequence): | |
76 self._shortcut = keysequence | |
77 self._changed() | |
78 def _getShortcut(self): return self._shortcut | |
79 shortcut = property(_getShortcut, _setShortcut) | |
80 | |
81 def _setHelpText(self, helptext): | |
82 self._helptext = helptext | |
83 self._changed() | |
84 def _getHelpText(self): return self._helptext | |
85 helptext = property(_getHelpText, _setHelpText) | |
86 | |
87 def setEnabled(self, enabled): | |
88 self._enabled = enabled | |
89 self._changed() | |
90 | |
91 def isEnabled(self): | |
92 return self._enabled | |
93 | |
94 def setChecked(self, checked): | |
95 self._checked = checked | |
96 self._changed() | |
97 toggled.send(sender=self, toggled=checked) | |
98 | |
99 def isChecked(self): | |
100 return self._checked | |
101 | |
102 def setCheckable(self, checkable): | |
103 self._checkable = checkable | |
104 if self._checkable is False and self._checked is True: | |
105 self.checked = False | |
106 | |
107 self._changed() | |
108 | |
109 def isCheckable(self): | |
110 return self._checkable | |
111 | |
112 class ActionGroup: | |
113 def __init__(self, exclusive=False, name="actiongroup"): | |
114 self._exclusive = exclusive | |
115 self._enabled = True | |
116 self._actions = [] | |
117 self.name = name | |
118 | |
119 def __str__(self): | |
120 return "%s(name='%s')" % (self.__class__.__name__,self.name) | |
121 | |
122 def __repr__(self): | |
123 return "<%s(name='%s') at %x>" % (self.__class__.__name__,self.name,id(self)) | |
124 | |
125 | |
126 def setEnabled(self, enabled): | |
127 self._enabled = enabled | |
128 self._changed() | |
129 | |
130 def isEnabled(self): | |
131 return self._enabled | |
132 | |
133 def setExclusive(self, exclusive): | |
134 self._exclusive = exclusive | |
135 self._changed() | |
136 | |
137 def isExclusive(self): | |
138 return self._exclusive | |
139 | |
140 def addAction(self, action): | |
141 if self.hasAction(action): | |
142 print "Actiongroup already has this action" | |
143 return | |
144 self._actions.append(action) | |
145 toggled.connect(self._actionToggled, sender=action) | |
146 self._changed() | |
147 | |
148 def addSeparator(self): | |
149 separator = Action(separator=True) | |
150 self.addAction(separator) | |
151 self._changed() | |
152 | |
153 def getActions(self): | |
154 return self._actions | |
155 | |
156 def removeAction(self, action): | |
157 self._actions.remove(action) | |
158 toggled.disconnect(self._actionToggled, sender=action) | |
159 self._changed() | |
160 | |
161 def clear(self): | |
162 for action in self._actions: | |
163 toggled.disconnect(self._actionToggled, sender=action) | |
164 self._actions = [] | |
165 self._changed() | |
166 | |
167 def hasAction(self, action): | |
168 for a in self._actions: | |
169 if a == action: | |
170 return True | |
171 return False | |
172 | |
173 def _actionToggled(self, sender): | |
174 if sender.isChecked() is False or self._exclusive is False: | |
175 return | |
176 | |
177 for a in self._actions: | |
178 if a != sender and a.isChecked(): | |
179 a.setChecked(False) | |
180 | |
181 def getChecked(self): | |
182 for a in self._actions: | |
183 if a.isChecked(): | |
184 return a | |
185 | |
186 return None | |
187 | |
188 def _changed(self): | |
189 changed.send(sender=self) | |
190 |