annotate engine/extensions/pychan/widgets/label.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents a2d5e2721489
children 48c99636453e
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
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 248
diff changeset
29 def resizeToContent(self, recurse=True):
248
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")