annotate engine/extensions/pychan/widgets/common.py @ 354:dfd48d49c044

* Removed shebang and svn:executable for python files which are not meant to be executed directly * Made sure all executable files with shebang has svn:executable
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 21 Sep 2009 19:48:00 +0000
parents a9482d3d989e
children
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
331
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
3 # ####################################################################
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
5 # http://www.fifengine.de
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
6 # This file is part of FIFE.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
7 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
8 # FIFE is free software; you can redistribute it and/or
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
10 # License as published by the Free Software Foundation; either
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
12 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
13 # This library is distributed in the hope that it will be useful,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
16 # Lesser General Public License for more details.
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
17 #
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
19 # License along with this library; if not, write to the
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
20 # Free Software Foundation, Inc.,
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
22 # ####################################################################
48c99636453e Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 330
diff changeset
23
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 import fife
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 import pychan.tools as tools
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 import pychan.events as events
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 from pychan.exceptions import *
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 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
29 from pychan.properties import ColorProperty
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30
249
1cc51d145af9 Further split up the containers.py; bugfix.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 248
diff changeset
31 AlignTop, AlignBottom, AlignLeft, AlignRight, AlignCenter = range(5)
248
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 get_manager():
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 import pychan
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 return pychan.manager
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 def text2gui(text):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 This function is applied to all text set on widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 It replaces tabs by four spaces.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 It assumes the text to be a unicode object.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 if not isinstance(text,unicode):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 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
45 text = unicode(text,"utf8")
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 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
47
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 def gui2text(text):
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 This function is applied to all text get from widgets.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 Translates the encoded string into a unicode object.
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 """
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 return unicode(text,"utf8",*get_manager().unicodePolicy)
264
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
54
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
55 def gui2str(text):
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
56 """
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
57 This function returns an 8-bit representation of the
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
58 unicode string. This is useful for passing strings
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
59 to SWIG functions.
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
60 """
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
61 try:
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
62 return text.__str__()
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
63 except:
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
64 # String contains non-ascii characters
ea85ddce2b36 * Fixed a bug where resizing a listbox with non-ascii characters would give errors
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 249
diff changeset
65 return text.encode("utf-8")
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 def isLayouted(widget):
249
1cc51d145af9 Further split up the containers.py; bugfix.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 248
diff changeset
68 from layout import LayoutBase
248
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 return isinstance(widget,LayoutBase)
a2d5e2721489 widgets.py split up.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70