Mercurial > fife-parpg
annotate engine/extensions/pychan/widgets/label.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 |
rev | line source |
---|---|
248
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 from common import * |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 from basictextwidget import BasicTextWidget |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 class Label(BasicTextWidget): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 A basic label - displaying a string. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 Also allows text wrapping and onMouse hover callbacks. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 New Attributes |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 ============== |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 - wrap_text: Boolean: Enable/Disable automatic text wrapping. Disabled by default. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 Currently to actually see text wrapping you have to explicitly set a max_size with |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 the desired width of the text, as the layout engine is not capable of deriving |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 the maximum width from a parent container. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('wrap_text')] |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 def __init__(self,wrap_text=False,**kwargs): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 self.real_widget = fife.Label("") |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 self.wrap_text = wrap_text |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 super(Label,self).__init__(**kwargs) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 def resizeToContent(self): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 self.real_widget.setWidth( self.max_size[0] ) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 self.real_widget.adjustSize() |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 self.height = self.real_widget.getHeight() + self.margins[1]*2 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 self.width = self.real_widget.getWidth() + self.margins[0]*2 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 #print self.width,self.max_size[0] |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 def _setTextWrapping(self,wrapping): self.real_widget.setTextWrapping(wrapping) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 def _getTextWrapping(self): self.real_widget.isTextWrapping() |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 wrap_text = property(_getTextWrapping,_setTextWrapping) |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 class ClickLabel(Label): |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 Deprecated - use L{Label} instead. |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 """ |
a2d5e2721489
widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 __init__ = tools.this_is_deprecated(Label.__init__,message = "ClickLabel - Use Label instead") |