comparison engine/extensions/pychan/manager.py @ 129:9a1529f9625e

* Indentation patch by GreyGhost
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 07 Aug 2008 15:46:46 +0000
parents 4a0efb7baf70
children 3fddb45c0304
comparison
equal deleted inserted replaced
128:6e1fd3571440 129:9a1529f9625e
15 15
16 if not self.engine.getEventManager(): 16 if not self.engine.getEventManager():
17 raise InitializationError("No event manager installed.") 17 raise InitializationError("No event manager installed.")
18 if not self.engine.getGuiManager(): 18 if not self.engine.getGuiManager():
19 raise InitializationError("No GUI manager installed.") 19 raise InitializationError("No GUI manager installed.")
20 20
21 self.guimanager = engine.getGuiManager() 21 self.guimanager = engine.getGuiManager()
22 self.fonts = {} 22 self.fonts = {}
23 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"' 23 #glyphs = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/:();%`\'*#=[]"'
24 self.fonts['default'] = self.engine.getDefaultFont() 24 self.fonts['default'] = self.engine.getDefaultFont()
25 25
26 self.styles = {} 26 self.styles = {}
27 self.addStyle('default',DEFAULT_STYLE) 27 self.addStyle('default',DEFAULT_STYLE)
28 28
29 self.widgetEvents = {} 29 self.widgetEvents = {}
30 self.engine.getEventManager().addWidgetListener(self) 30 self.engine.getEventManager().addWidgetListener(self)
31 Manager.manager = self 31 Manager.manager = self
32 32
33 self.mainLoop = None 33 self.mainLoop = None
58 self.guimanager.remove( widget.real_widget ) 58 self.guimanager.remove( widget.real_widget )
59 59
60 def getFont(self,name): 60 def getFont(self,name):
61 """ 61 """
62 Returns a GuiFont identified by its name. 62 Returns a GuiFont identified by its name.
63 63
64 @param name: A string identifier from the font definitions in pychans config files. 64 @param name: A string identifier from the font definitions in pychans config files.
65 """ 65 """
66 font = self.fonts.get(name) 66 font = self.fonts.get(name)
67 67
68 # For the default font directly return it, 68 # For the default font directly return it,
69 # otherwise the GuiFont is in the font attribute. 69 # otherwise the GuiFont is in the font attribute.
70 return getattr(font,"font",font) 70 return getattr(font,"font",font)
71 71
72 def addFont(self,font): 72 def addFont(self,font):
73 """ 73 """
74 Add a font to the font registry. It's not necessary to call this directly. 74 Add a font to the font registry. It's not necessary to call this directly.
75 But it expects a L{Font} instance and throws an L{InitializationError} 75 But it expects a L{Font} instance and throws an L{InitializationError}
76 otherwise. 76 otherwise.
77 77
78 @param font: A L{Font} instance. 78 @param font: A L{Font} instance.
79 """ 79 """
80 if not isinstance(font,fonts.Font): 80 if not isinstance(font,fonts.Font):
81 raise InitializationError("PyChan Manager expected a fonts.Font instance, not %s." % repr(font)) 81 raise InitializationError("PyChan Manager expected a fonts.Font instance, not %s." % repr(font))
82 self.fonts[font.name] = font 82 self.fonts[font.name] = font
83 83
84 def addStyle(self,name,style): 84 def addStyle(self,name,style):
85 style = self._remapStyleKeys(style) 85 style = self._remapStyleKeys(style)
86 86
87 for k,v in self.styles.get('default',{}).items(): 87 for k,v in self.styles.get('default',{}).items():
88 style[k] = style.get(k,v) 88 style[k] = style.get(k,v)
89 self.styles[name] = style 89 self.styles[name] = style
90 90
91 def stylize(self,widget, style, **kwargs): 91 def stylize(self,widget, style, **kwargs):
92 style = self.styles[style] 92 style = self.styles[style]
93 for k,v in style.get('default',{}).items(): 93 for k,v in style.get('default',{}).items():
94 v = kwargs.get(k,v) 94 v = kwargs.get(k,v)
95 setattr(widget,k,v) 95 setattr(widget,k,v)
96 96
97 cls = widget.__class__ 97 cls = widget.__class__
98 for applicable,specstyle in style.items(): 98 for applicable,specstyle in style.items():
99 if not isinstance(applicable,tuple): 99 if not isinstance(applicable,tuple):
100 applicable = (applicable,) 100 applicable = (applicable,)
101 if cls in applicable: 101 if cls in applicable:
106 def _remapStyleKeys(self,style): 106 def _remapStyleKeys(self,style):
107 # Remap class names, create copy: 107 # Remap class names, create copy:
108 def _toClass(class_): 108 def _toClass(class_):
109 if class_ == "default": 109 if class_ == "default":
110 return class_ 110 return class_
111 111
112 if type(class_) == type(widgets.Widget) and issubclass(class_,widgets.Widget): 112 if type(class_) == type(widgets.Widget) and issubclass(class_,widgets.Widget):
113 return class_ 113 return class_
114 if not widgets.WIDGETS.has_key(str(class_)): 114 if not widgets.WIDGETS.has_key(str(class_)):
115 raise InitializationError("Can't resolve %s to a widget class." % repr(class_)) 115 raise InitializationError("Can't resolve %s to a widget class." % repr(class_))
116 return widgets.WIDGETS[str(class_)] 116 return widgets.WIDGETS[str(class_)]
117 117
118 style_copy = {} 118 style_copy = {}
119 for k,v in style.items(): 119 for k,v in style.items():
120 if isinstance(k,tuple): 120 if isinstance(k,tuple):
121 new_k = tuple(map(_toClass,k)) 121 new_k = tuple(map(_toClass,k))
122 else: 122 else: