Mercurial > fife-parpg
comparison engine/extensions/pychan/internal.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 | 756b895e1dab |
children | 48c99636453e |
comparison
equal
deleted
inserted
replaced
254:10b5f7f36dd4 | 255:51cc05d862f2 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 | 2 |
3 from compat import guichan, in_fife | 3 from compat import guichan, in_fife |
4 import widgets | 4 import widgets |
5 import fife_timer as timer | |
5 import fonts | 6 import fonts |
6 from exceptions import * | 7 from exceptions import * |
7 from traceback import print_exc | 8 from traceback import print_exc |
8 | 9 |
9 def get_manager(): | 10 def get_manager(): |
22 return get_manager().hook.screen_height | 23 return get_manager().hook.screen_height |
23 | 24 |
24 class Manager(object): | 25 class Manager(object): |
25 manager = None | 26 manager = None |
26 | 27 |
27 def __init__(self, hook, debug = False): | 28 def __init__(self, hook, debug = False, compat_layout = False): |
28 super(Manager,self).__init__() | 29 super(Manager,self).__init__() |
29 self.hook = hook | 30 self.hook = hook |
30 self.debug = debug | 31 self.debug = debug |
32 self.compat_layout = compat_layout | |
31 self.unicodePolicy = ('ignore',) | 33 self.unicodePolicy = ('ignore',) |
32 | 34 |
33 if in_fife: | 35 if in_fife: |
34 if not hook.engine.getEventManager(): | 36 if not hook.engine.getEventManager(): |
35 raise InitializationError("No event manager installed.") | 37 raise InitializationError("No event manager installed.") |
36 if not hook.engine.getGuiManager(): | 38 if not hook.engine.getGuiManager(): |
37 raise InitializationError("No GUI manager installed.") | 39 raise InitializationError("No GUI manager installed.") |
40 timer.init(hook.engine.getTimeManager()) | |
38 | 41 |
39 self.fonts = {} | 42 self.fonts = {} |
40 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"' | 43 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"' |
41 self.fonts['default'] = hook.default_font | 44 self.fonts['default'] = hook.default_font |
42 | 45 |
43 self.styles = {} | 46 self.styles = {} |
44 self.addStyle('default',DEFAULT_STYLE) | 47 self.addStyle('default',DEFAULT_STYLE) |
45 | 48 |
46 Manager.manager = self | 49 Manager.manager = self |
47 | 50 |
48 # Setup synchronous dialogs | 51 # Setup synchronous dialogs |
49 self.mainLoop = None | 52 self.mainLoop = None |
50 self.breakFromMainLoop = None | 53 self.breakFromMainLoop = None |
51 self.can_execute = False | 54 self.can_execute = False |
52 | 55 |
56 import weakref | |
57 self.allWidgets = weakref.WeakKeyDictionary() | |
58 | |
53 # Autopos | 59 # Autopos |
54 from autoposition import placeWidget | 60 from autoposition import placeWidget |
55 self.placeWidget = placeWidget | 61 self.placeWidget = placeWidget |
56 | 62 |
57 def setupModalExecution(self,mainLoop,breakFromMainLoop): | 63 def setupModalExecution(self,mainLoop,breakFromMainLoop): |
65 def show(self,widget): | 71 def show(self,widget): |
66 """ | 72 """ |
67 Shows a widget on screen. Used by L{Widget.show} - do not use directly. | 73 Shows a widget on screen. Used by L{Widget.show} - do not use directly. |
68 """ | 74 """ |
69 self.placeWidget(widget, widget.position_technique) | 75 self.placeWidget(widget, widget.position_technique) |
76 assert widget not in self.allWidgets | |
77 self.allWidgets[ widget ] = 1 | |
70 self.hook.add_widget( widget.real_widget ) | 78 self.hook.add_widget( widget.real_widget ) |
71 | 79 |
72 def hide(self,widget): | 80 def hide(self,widget): |
73 """ | 81 """ |
74 Hides a widget again. Used by L{Widget.hide} - do not use directly. | 82 Hides a widget again. Used by L{Widget.hide} - do not use directly. |
75 """ | 83 """ |
76 self.hook.remove_widget( widget.real_widget ) | 84 self.hook.remove_widget( widget.real_widget ) |
85 del self.allWidgets[ widget ] | |
77 | 86 |
78 def setDefaultFont(self,name): | 87 def setDefaultFont(self,name): |
79 self.fonts['default'] = self.getFont(name) | 88 self.fonts['default'] = self.getFont(name) |
80 | 89 |
81 def getFont(self,name): | 90 def getFont(self,name): |
131 for k,v in specstyle.items(): | 140 for k,v in specstyle.items(): |
132 v = kwargs.get(k,v) | 141 v = kwargs.get(k,v) |
133 setattr(widget,k,v) | 142 setattr(widget,k,v) |
134 | 143 |
135 def _remapStyleKeys(self,style): | 144 def _remapStyleKeys(self,style): |
145 """ | |
146 Translate style selectors to tuples of widget classes. (internal) | |
147 """ | |
136 # Remap class names, create copy: | 148 # Remap class names, create copy: |
137 def _toClass(class_): | 149 def _toClass(class_): |
138 if class_ == "default": | 150 if class_ == "default": |
139 return class_ | 151 return class_ |
140 | 152 |
166 'margins': (0,0), | 178 'margins': (0,0), |
167 'base_color' : guichan.Color(28,28,28), | 179 'base_color' : guichan.Color(28,28,28), |
168 'foreground_color' : guichan.Color(255,255,255), | 180 'foreground_color' : guichan.Color(255,255,255), |
169 'background_color' : guichan.Color(50,50,50), | 181 'background_color' : guichan.Color(50,50,50), |
170 'selection_color' : guichan.Color(80,80,80), | 182 'selection_color' : guichan.Color(80,80,80), |
183 'font' : 'default' | |
171 }, | 184 }, |
172 'Button' : { | 185 'Button' : { |
173 'border_size': 2, | 186 'border_size': 2, |
174 'margins' : (5,2), | 187 'margins' : (5,2), |
175 'min_size' : (15,10), | 188 'min_size' : (15,10), |
181 'border_size': 0, | 194 'border_size': 0, |
182 'background_color' : guichan.Color(0,0,0), | 195 'background_color' : guichan.Color(0,0,0), |
183 }, | 196 }, |
184 'Label' : { | 197 'Label' : { |
185 'border_size': 0, | 198 'border_size': 0, |
199 'background_color' : guichan.Color(50,50,50,0) | |
186 }, | 200 }, |
187 'ClickLabel' : { | 201 'ClickLabel' : { |
188 'border_size': 0, | 202 'border_size': 0, |
189 }, | 203 }, |
190 'ListBox' : { | 204 'ListBox' : { |
192 }, | 206 }, |
193 'Window' : { | 207 'Window' : { |
194 'border_size': 0, | 208 'border_size': 0, |
195 'margins': (5,5), | 209 'margins': (5,5), |
196 'opaque' : 1, | 210 'opaque' : 1, |
211 'padding':2, | |
197 'titlebar_height' : 12, | 212 'titlebar_height' : 12, |
198 'vexpanding' : 1, | 213 'background_image' : None, |
199 #'background_image' : 'gui/backgrounds/background.png', | |
200 #'font' : 'samanata_large' | |
201 }, | 214 }, |
202 'TextBox' : { | 215 'TextBox' : { |
203 }, | 216 }, |
204 ('Container','HBox','VBox') : { | 217 ('Container','HBox','VBox') : { |
205 'border_size': 0, | 218 'border_size': 0, |
206 'margins': (0,0), | 219 'margins': (0,0), |
207 'padding':2, | 220 'padding':2, |
208 #'background_image' : 'gui/backgrounds/background.png', | 221 'opaque' : 1, |
222 'background_image' : None, | |
209 } | 223 } |
210 } | 224 } |