comparison engine/extensions/pychan/widgets.py @ 238:d76169461729

Removed HelpText from C++. Moved helptext to base widget. Now all widgets may have a helptext.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 24 Mar 2009 16:06:02 +0000
parents e476b6b7b2f0
children 99b36f59a5d5
comparison
equal deleted inserted replaced
237:45c63a621366 238:d76169461729
71 - base_color: Color 71 - base_color: Color
72 - background_color: Color 72 - background_color: Color
73 - foreground_color: Color 73 - foreground_color: Color
74 - selection_color: Color 74 - selection_color: Color
75 - font: String: This should identify a font that was loaded via L{loadFonts} before. 75 - font: String: This should identify a font that was loaded via L{loadFonts} before.
76 - helptext: Unicode: Text which can be used for e.g. tooltips.
76 - border_size: Integer: The size of the border in pixels. 77 - border_size: Integer: The size of the border in pixels.
77 - position_technique: This can be either "automatic" or "explicit" - only L{Window} has this set to "automatic" which 78 - position_technique: This can be either "automatic" or "explicit" - only L{Window} has this set to "automatic" which
78 results in new windows being centered on screen (for now). 79 results in new windows being centered on screen (for now).
79 If it is set to "explicit" the position attribute will not be touched. 80 If it is set to "explicit" the position attribute will not be touched.
80 81
100 101
101 ATTRIBUTES = [ Attr('name'), PointAttr('position'), 102 ATTRIBUTES = [ Attr('name'), PointAttr('position'),
102 PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'), 103 PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'),
103 ColorAttr('base_color'),ColorAttr('background_color'),ColorAttr('foreground_color'),ColorAttr('selection_color'), 104 ColorAttr('base_color'),ColorAttr('background_color'),ColorAttr('foreground_color'),ColorAttr('selection_color'),
104 Attr('style'), Attr('font'),IntAttr('border_size'),Attr('position_technique'), 105 Attr('style'), Attr('font'),IntAttr('border_size'),Attr('position_technique'),
106 UnicodeAttr('helptext')
105 ] 107 ]
106 108
107 DEFAULT_NAME = '__unnamed__' 109 DEFAULT_NAME = '__unnamed__'
108 110
109 HIDE_SHOW_ERROR = """\ 111 HIDE_SHOW_ERROR = """\
111 Use 'addChild' or 'removeChild' to add/remove labels for example. 113 Use 'addChild' or 'removeChild' to add/remove labels for example.
112 """ 114 """
113 115
114 def __init__(self,parent = None, name = DEFAULT_NAME, 116 def __init__(self,parent = None, name = DEFAULT_NAME,
115 size = (-1,-1), min_size=(0,0), max_size=(5000,5000), 117 size = (-1,-1), min_size=(0,0), max_size=(5000,5000),
118 helptext=u"",
116 style = None, **kwargs): 119 style = None, **kwargs):
117 120
118 assert( hasattr(self,'real_widget') ) 121 assert( hasattr(self,'real_widget') )
119 self.event_mapper = events.EventMapper(self) 122 self.event_mapper = events.EventMapper(self)
120 self._visible = False 123 self._visible = False
137 # Inherit style 140 # Inherit style
138 if style is None and parent: 141 if style is None and parent:
139 style = parent.style 142 style = parent.style
140 self.style = style or "default" 143 self.style = style or "default"
141 144
145 self.helptext = helptext
142 # Not needed as attrib assignment will trigger manager.stylize call 146 # Not needed as attrib assignment will trigger manager.stylize call
143 #manager.stylize(self,self.style) 147 #manager.stylize(self,self.style)
144 148
145 def execute(self,bind): 149 def execute(self,bind):
146 """ 150 """
1163 - up_image: String: The source location of the Image for the B{unpressed} state. 1167 - up_image: String: The source location of the Image for the B{unpressed} state.
1164 - down_image: String: The source location of the Image for the B{pressed} state. 1168 - down_image: String: The source location of the Image for the B{pressed} state.
1165 - hover_image: String: The source location of the Image for the B{unpressed hovered} state. 1169 - hover_image: String: The source location of the Image for the B{unpressed hovered} state.
1166 """ 1170 """
1167 1171
1168 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [Attr('up_image'),Attr('down_image'),PointAttr('offset'),UnicodeAttr('helptext'),Attr('hover_image')] 1172 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [Attr('up_image'),Attr('down_image'),PointAttr('offset'),Attr('hover_image')]
1169 1173
1170 def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),**kwargs): 1174 def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),**kwargs):
1171 self.real_widget = fife.TwoButton() 1175 self.real_widget = fife.TwoButton()
1172 super(ImageButton,self).__init__(**kwargs) 1176 super(ImageButton,self).__init__(**kwargs)
1173 1177
1238 self.real_widget.setDownOffset(offset[0], offset[1]) 1242 self.real_widget.setDownOffset(offset[0], offset[1])
1239 def _getOffset(self): 1243 def _getOffset(self):
1240 return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset()) 1244 return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset())
1241 offset = property(_getOffset,_setOffset) 1245 offset = property(_getOffset,_setOffset)
1242 1246
1243 def _setHelpText(self, txt):
1244 self.real_widget.setHelpText(txt)
1245 def _getHelpText(self):
1246 return self.real_widget.getHelpText()
1247 helptext = property(_getHelpText,_setHelpText)
1248
1249 def resizeToContent(self): 1247 def resizeToContent(self):
1250 self.height = max(self._upimage.getHeight(),self._downimage.getHeight(),self._hoverimage.getHeight()) + self.margins[1]*2 1248 self.height = max(self._upimage.getHeight(),self._downimage.getHeight(),self._hoverimage.getHeight()) + self.margins[1]*2
1251 self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2 1249 self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2
1252 1250
1253 class ToggleButton(BasicTextWidget): 1251 class ToggleButton(BasicTextWidget):
1263 - toggled: Boolean: Whether the button is toggled or not. 1261 - toggled: Boolean: Whether the button is toggled or not.
1264 """ 1262 """
1265 1263
1266 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [ 1264 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [
1267 Attr('up_image'),Attr('down_image'),Attr('hover_image'), 1265 Attr('up_image'),Attr('down_image'),Attr('hover_image'),
1268 PointAttr('offset'), 1266 PointAttr('offset'),Attr('group')
1269 UnicodeAttr('helptext'),Attr('group')
1270 ] 1267 ]
1271 1268
1272 def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),group="",**kwargs): 1269 def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),group="",**kwargs):
1273 1270
1274 self.real_widget = fife.ToggleButton() 1271 self.real_widget = fife.ToggleButton()
1330 def _setOffset(self, offset): 1327 def _setOffset(self, offset):
1331 self.real_widget.setDownOffset(offset[0], offset[1]) 1328 self.real_widget.setDownOffset(offset[0], offset[1])
1332 def _getOffset(self): 1329 def _getOffset(self):
1333 return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset()) 1330 return (self.real_widget.getDownXOffset(), self.real_widget.getDownYOffset())
1334 offset = property(_getOffset,_setOffset) 1331 offset = property(_getOffset,_setOffset)
1335
1336 def _setHelpText(self, txt):
1337 self.real_widget.setHelpText(_text2gui(txt))
1338 def _getHelpText(self):
1339 return _gui2text(self.real_widget.getHelpText())
1340 helptext = property(_getHelpText,_setHelpText)
1341 1332
1342 def resizeToContent(self): 1333 def resizeToContent(self):
1343 self.height = max(self._upimage.getHeight(),self._downimage.getHeight(),self._hoverimage.getHeight()) + self.margins[1]*2 1334 self.height = max(self._upimage.getHeight(),self._downimage.getHeight(),self._hoverimage.getHeight()) + self.margins[1]*2
1344 self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2 1335 self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2
1345 1336