comparison engine/python/fife/extensions/pychan/widgets/common.py @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2009 by the FIFE team
5 # http://www.fifengine.de
6 # This file is part of FIFE.
7 #
8 # FIFE is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # ####################################################################
23
24 from fife import fife
25 from fife.extensions.pychan import tools
26 from fife.extensions.pychan import events
27 from fife.extensions.pychan.exceptions import *
28 from fife.extensions.pychan.attrs import Attr,UnicodeAttr, PointAttr,ColorAttr,BoolAttr,IntAttr,FloatAttr
29 from fife.extensions.pychan.properties import ColorProperty
30
31 AlignTop, AlignBottom, AlignLeft, AlignRight, AlignCenter = range(5)
32
33 def get_manager():
34 from fife.extensions import pychan
35 return pychan.manager
36
37 def text2gui(text):
38 """
39 This function is applied to all text set on widgets.
40 It replaces tabs by four spaces.
41 It assumes the text to be a unicode object.
42 """
43 if not isinstance(text,unicode):
44 print "Widget text needs to be set from an unicode object. Got: '%s'" % repr(text)
45 text = unicode(text,"utf8")
46 return text.encode("utf8",*get_manager().unicodePolicy).replace("\t"," "*4).replace("[br]","\n")
47
48 def gui2text(text):
49 """
50 This function is applied to all text get from widgets.
51 Translates the encoded string into a unicode object.
52 """
53 return unicode(text,"utf8",*get_manager().unicodePolicy)
54
55 def gui2str(text):
56 """
57 This function returns an 8-bit representation of the
58 unicode string. This is useful for passing strings
59 to SWIG functions.
60 """
61 try:
62 return text.__str__()
63 except:
64 # String contains non-ascii characters
65 return text.encode("utf-8")
66
67 def isLayouted(widget):
68 from layout import LayoutBase
69 return isinstance(widget,LayoutBase)
70