[liblouis-liblouisxml] [liblouis commit] r41 - in branches/python/python: . louis

  • From: codesite-noreply@xxxxxxxxxx
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Tue, 18 Nov 2008 20:33:37 +0000

Author: eitan@xxxxxxxxxxxx
Date: Tue Nov 18 12:31:48 2008
New Revision: 41

Added:
   branches/python/python/
   branches/python/python/louis/
   branches/python/python/louis/__init__.py

Log:
* python/louis/__init__.py: Copied from NVDA sources, with a
  modification for loading liblouis.so when needed.


Added: branches/python/python/louis/__init__.py
==============================================================================
--- (empty file)
+++ branches/python/python/louis/__init__.py    Tue Nov 18 12:31:48 2008
@@ -0,0 +1,61 @@
+# Liblouis Python ctypes bindings
+# authors: Michael Curran, James Teh
+# based on work by Eitan Isaacson
+
+from ctypes import *
+import struct
+import atexit
+
+try:
+    liblouis = cdll.liblouis
+except OSError:
+    liblouis = cdll.LoadLibrary("liblouis.so")
+
+atexit.register(liblouis.lou_free)
+
+liblouis.lou_version.restype = c_char_p
+version = liblouis.lou_version
+
+def translate(tran_tables, inbuf, typeform=None,cursorPos=0, mode=0):
+    tablesString = ",".join([str(x) for x in tran_tables])
+    inbuf = unicode(inbuf)
+    if typeform:
+        typeform = struct.pack('B'*len(typeform),*typeform)
+    else:
+        typeform = None
+    inlen = c_int(len(inbuf))
+    outlen = c_int(inlen.value*2)
+    outbuf = create_unicode_buffer(outlen.value)
+    inPos = (c_int*outlen.value)()
+    outPos = (c_int*inlen.value)()
+    cursorPos = c_int(cursorPos)
+ if not liblouis.lou_translate(tablesString, inbuf, byref(inlen), outbuf, byref(outlen), typeform, None, byref(outPos), byref(inPos), byref(cursorPos), mode): + raise RuntimeError("can't translate: tables %s, inbuf %s, typeform %s, cursorPos %s, mode %s"%(tran_tables, inbuf, typeform, cursorPos, mode)) + return outbuf.value, inPos[:outlen.value], outPos[:inlen.value], cursorPos.value
+
+def translateString(tran_tables, inbuf, typeform = None, mode = 0):
+    tablesString = ",".join([str(x) for x in tran_tables])
+    inbuf = unicode(inbuf)
+    if typeform:
+        typeform = struct.pack('B'*len(typeform), *typeform)
+    else:
+        typeform = None
+    inlen = c_int(len(inbuf))
+    outlen = c_int(inlen.value*2)
+    outbuf = create_unicode_buffer(outlen.value)
+ if not liblouis.lou_translateString(tablesString, inbuf, byref(inlen), outbuf, byref(outlen), typeform, None, mode): + raise RuntimeError("can't translate: tables %s, inbuf %s, typeform %s, mode %s"%(tran_tables, inbuf, typeform, mode))
+    return outbuf.value
+
+# typeforms
+plain_text = 0
+italic = 1
+underline = 2
+bold = 4
+computer_braille = 8
+
+# translationModes
+noContractions = 1
+compbrlAtCursor = 2
+dotsIO = 4
+comp8Dots =  8
For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts:

  • » [liblouis-liblouisxml] [liblouis commit] r41 - in branches/python/python: . louis - codesite-noreply