diff engine/extensions/pychan/__init__.py @ 228:756b895e1dab

Merged unicode-support back into trunk. Now all GUI/visible strings should be unicode. Internal strings unchanged. Remember to use a font that actually has the desired codepoints. Current default unicode policiy is 'ignore'.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 21 Mar 2009 10:38:11 +0000
parents 724f3a5f3e96
children 92c7ce181881
line wrap: on
line diff
--- a/engine/extensions/pychan/__init__.py	Fri Mar 20 15:17:28 2009 +0000
+++ b/engine/extensions/pychan/__init__.py	Sat Mar 21 10:38:11 2009 +0000
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # coding: utf-8
 
 """\
@@ -185,6 +186,18 @@
   - row_spacing: Extra height per row. Default is 0.
   - glyph_spacing: Extra space per glyph. Default is 0. B{Currently buggy in the engine!}
 
+Unicode and internationalisation
+================================
+
+All text that is visible and editable by the player has to be a unicode object.
+All text that is used internally, e.g. widget names, have to be normal strings.
+
+While PyChan will not raise an exception, if you do not follow this guideline,
+you are encouraged to so.
+
+You can change the way unicode encoding errors are handled by using the
+function L{setUnicodePolicy}.
+
 
 Widget hierachy
 ===============
@@ -277,7 +290,7 @@
 
 	def _printTag(self,name,attrs):
 		if not manager.debug: return
-		attrstrings = map(lambda t: '%s="%s"' % tuple(map(str,t)),attrs.items())
+		attrstrings = map(lambda t: '%s="%s"' % tuple(map(unicode,t)),attrs.items())
 		tag = "<%s " % name + " ".join(attrstrings) + ">"
 		print self.indent + tag
 
@@ -406,3 +419,23 @@
 	if not manager:
 		raise InitializationError("PyChan is not initialized yet.")
 	manager.setupModalExecution(mainLoop,breakFromMainLoop)
+
+def setUnicodePolicy(*policy):
+	"""
+	Possible options are:
+	- 'strict' meaning that encoding errors raise a UnicodeEncodeError.
+	- 'ignore' all encoding errors will be silently ignored.
+	- 'replace' all errors are replaced by the next argument.
+
+	For further information look at the python documentation,
+	especially L{codecs.register_error}.
+
+	Example:
+		pychan.setUnicodePolicy('replace','?')
+	"""
+	if not manager:
+		raise InitializationError("PyChan is not initialized yet.")
+	manager.unicodePolicy = policy
+
+
+