annotate engine/extensions/pychan/widgets/common.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 1cc51d145af9
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 import fife
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import pychan.tools as tools
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 import pychan.events as events
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 from pychan.exceptions import *
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 from pychan.attrs import Attr,UnicodeAttr, PointAttr,ColorAttr,BoolAttr,IntAttr,FloatAttr
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 from pychan.properties import ColorProperty
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
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 def get_manager():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 import pychan
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 return pychan.manager
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 def text2gui(text):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 This function is applied to all text set on widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 It replaces tabs by four spaces.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 It assumes the text to be a unicode object.
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 if not isinstance(text,unicode):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 print "Widget text needs to be set from an unicode object. Got: '%s'" % repr(text)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 text = unicode(text,"utf8")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 return text.encode("utf8",*get_manager().unicodePolicy).replace("\t"," "*4).replace("[br]","\n")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 def gui2text(text):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 This function is applied to all text get from widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 Translates the encoded string into a unicode object.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 return unicode(text,"utf8",*get_manager().unicodePolicy)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 def isLayouted(widget):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 from containers import LayoutBase
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 return isinstance(widget,LayoutBase)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 class DummyImage(object):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 def getWidth(self): return 0
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 def getHeight(self): return 0