comparison engine/extensions/pychan/widgets/basictextwidget.py @ 248:a2d5e2721489

widgets.py split up.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 26 Mar 2009 16:20:16 +0000
parents
children 51cc05d862f2
comparison
equal deleted inserted replaced
247:040387b7167f 248:a2d5e2721489
1 # -*- coding: utf-8 -*-
2 from widget import Widget
3 from common import *
4
5 class BasicTextWidget(Widget):
6 """
7 The base class for widgets which display a string - L{Label},L{ClickLabel},L{Button}, etc.
8 Do not use directly.
9
10 New Attributes
11 ==============
12
13 - text: The text (depends on actual widget)
14
15 Data
16 ====
17
18 The text can be set via the L{distributeInitialData} method.
19 """
20
21 ATTRIBUTES = Widget.ATTRIBUTES + [UnicodeAttr('text')]
22
23 def __init__(self, text = u"",**kwargs):
24 self.margins = (5,5)
25 self.text = text
26 super(BasicTextWidget,self).__init__(**kwargs)
27
28 # Prepare Data collection framework
29 self.accepts_initial_data = True
30 self._realSetInitialData = self._setText
31
32 def _getText(self): return gui2text(self.real_widget.getCaption())
33 def _setText(self,text): self.real_widget.setCaption(text2gui(text))
34 text = property(_getText,_setText)
35
36 def resizeToContent(self, recurse = True):
37 self.height = self.real_font.getHeight() + self.margins[1]*2
38 self.width = self.real_font.getWidth(text2gui(self.text)) + self.margins[0]*2