annotate engine/extensions/pychan/internal.py @ 251:92c7ce181881

Documentation cross reference fixes.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 27 Mar 2009 11:52:55 +0000
parents 756b895e1dab
children 51cc05d862f2
rev   line source
207
40257a6dc57d PyChan: Meaningful error if a font wasn't loaded.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 205
diff changeset
1 # -*- coding: utf-8 -*-
205
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 from compat import guichan, in_fife
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import widgets
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 import fonts
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 from exceptions import *
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 from traceback import print_exc
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 def get_manager():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 Get the manager from inside pychan.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 To avoid cyclic imports write::
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 from internal import get_manager
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 return Manager.manager
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 def screen_width():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 return get_manager().hook.screen_width
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 def screen_height():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 return get_manager().hook.screen_height
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 class Manager(object):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 manager = None
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 def __init__(self, hook, debug = False):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 super(Manager,self).__init__()
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 self.hook = hook
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 self.debug = debug
228
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 218
diff changeset
31 self.unicodePolicy = ('ignore',)
205
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 if in_fife:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 if not hook.engine.getEventManager():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 raise InitializationError("No event manager installed.")
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 if not hook.engine.getGuiManager():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 raise InitializationError("No GUI manager installed.")
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self.fonts = {}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"'
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 self.fonts['default'] = hook.default_font
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 self.styles = {}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 self.addStyle('default',DEFAULT_STYLE)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 Manager.manager = self
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 # Setup synchronous dialogs
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 self.mainLoop = None
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 self.breakFromMainLoop = None
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 self.can_execute = False
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 # Autopos
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 from autoposition import placeWidget
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self.placeWidget = placeWidget
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 def setupModalExecution(self,mainLoop,breakFromMainLoop):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 Setup synchronous execution of dialogs.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 self.mainLoop = mainLoop
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 self.breakFromMainLoop = breakFromMainLoop
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 self.can_execute = True
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 def show(self,widget):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 Shows a widget on screen. Used by L{Widget.show} - do not use directly.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 self.placeWidget(widget, widget.position_technique)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 self.hook.add_widget( widget.real_widget )
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 def hide(self,widget):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 Hides a widget again. Used by L{Widget.hide} - do not use directly.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 self.hook.remove_widget( widget.real_widget )
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 def setDefaultFont(self,name):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self.fonts['default'] = self.getFont(name)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 def getFont(self,name):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 B{pending deprecation}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 Returns a GuiFont identified by its name.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 @param name: A string identifier from the font definitions in pychans config files.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 if in_fife:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 font = self.fonts.get(name)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 if isinstance(font,guichan.GuiFont):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 return font
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 if hasattr(font,"font") and isinstance(getattr(font,"font"),guichan.GuiFont):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 return font.font
207
40257a6dc57d PyChan: Meaningful error if a font wasn't loaded.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 205
diff changeset
95 raise InitializationError("Couldn't find the font '%s' - did you forget loading a .fontdef?" % str(name))
205
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 else:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 return self.hook.get_font(name)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 def addFont(self,font):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 B{deprecated}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 Add a font to the font registry. It's not necessary to call this directly.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 But it expects a L{Font} instance and throws an L{InitializationError}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 otherwise.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 @param font: A L{Font} instance.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 """
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 if not isinstance(font,fonts.Font):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 raise InitializationError("PyChan Manager expected a fonts.Font instance, not %s." % repr(font))
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 self.fonts[font.name] = font
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 def addStyle(self,name,style):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 style = self._remapStyleKeys(style)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 for k,v in self.styles.get('default',{}).items():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 style[k] = style.get(k,v)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 self.styles[name] = style
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 def stylize(self,widget, style, **kwargs):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 style = self.styles[style]
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 for k,v in style.get('default',{}).items():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 v = kwargs.get(k,v)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 setattr(widget,k,v)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 cls = widget.__class__
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 for applicable,specstyle in style.items():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 if not isinstance(applicable,tuple):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 applicable = (applicable,)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 if cls in applicable:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 for k,v in specstyle.items():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 v = kwargs.get(k,v)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 setattr(widget,k,v)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 def _remapStyleKeys(self,style):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 # Remap class names, create copy:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 def _toClass(class_):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 if class_ == "default":
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 return class_
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 if type(class_) == type(widgets.Widget) and issubclass(class_,widgets.Widget):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 return class_
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 if not widgets.WIDGETS.has_key(str(class_)):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 raise InitializationError("Can't resolve %s to a widget class." % repr(class_))
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145 return widgets.WIDGETS[str(class_)]
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 style_copy = {}
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 for k,v in style.items():
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 if isinstance(k,tuple):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 new_k = tuple(map(_toClass,k))
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 else:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 new_k = _toClass(k)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 style_copy[new_k] = v
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 return style_copy
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 def loadImage(self,filename):
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 if not filename:
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 raise InitializationError("Empty Image file.")
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 return self.hook.load_image(filename)
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 # Default Widget style.
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 DEFAULT_STYLE = {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 'default' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 'margins': (0,0),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 'base_color' : guichan.Color(28,28,28),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 'foreground_color' : guichan.Color(255,255,255),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 'background_color' : guichan.Color(50,50,50),
218
724f3a5f3e96 Added selection_color, and darkened the default for it a bit.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 207
diff changeset
170 'selection_color' : guichan.Color(80,80,80),
205
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 'Button' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 'border_size': 2,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 'margins' : (5,2),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 'min_size' : (15,10),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 'CheckBox' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 'RadioButton' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 'background_color' : guichan.Color(0,0,0),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 'Label' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 'ClickLabel' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 'ListBox' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 'Window' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 'margins': (5,5),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 'opaque' : 1,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 'titlebar_height' : 12,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 'vexpanding' : 1,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199 #'background_image' : 'gui/backgrounds/background.png',
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 #'font' : 'samanata_large'
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202 'TextBox' : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203 },
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 ('Container','HBox','VBox') : {
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 'border_size': 0,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 'margins': (0,0),
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 'padding':2,
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 #'background_image' : 'gui/backgrounds/background.png',
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 }
54bfd1015b35 * PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 }