orca r3533 - in trunk: . src/louis
- From: eitani svn gnome org
- To: svn-commits-list gnome org
- Subject: orca r3533 - in trunk: . src/louis
- Date: Fri, 1 Feb 2008 09:34:46 +0000 (GMT)
Author: eitani
Date: Fri Feb 1 09:34:46 2008
New Revision: 3533
URL: http://svn.gnome.org/viewvc/orca?rev=3533&view=rev
Log:
* src/louis/__init__.py: Override the translate function with some
fixups until we get fixes into liblouis proper.
Modified:
trunk/ChangeLog
trunk/src/louis/__init__.py
Modified: trunk/src/louis/__init__.py
==============================================================================
--- trunk/src/louis/__init__.py (original)
+++ trunk/src/louis/__init__.py Fri Feb 1 09:34:46 2008
@@ -22,7 +22,6 @@
__copyright__ = "Copyright (c) 2007-2008 Eitan Isaacson"
__license__ = "LGPL"
-from _louis import *
from constants import *
import os
@@ -49,3 +48,104 @@
pass
return ''
+
+#####################################################################
+#
+# The following code is here to compensate on a few current liblouis
+# bugs.
+#
+#####################################################################
+
+import _louis
+version = _louis.version
+translateString = _louis.translateString
+
+def translate(tran_tables, inbuf, typeform=[], cursorPos=0, mode=0):
+ if mode == MODE.compbrlAtCursor:
+ contracted, inPos, outPos, cursorPos, = \
+ _expandAtCursor(tran_tables, inbuf,
+ typeform, cursorPos, mode)
+ else:
+ contracted, inPos, outPos, cursorPos, = \
+ _louis.translate(tran_tables, inbuf,
+ typeform, cursorPos, mode)
+
+ return contracted, inPos, outPos, cursorPos
+
+def _expandAtCursor(tran_tables, inbuf, typeform=[], cursorPos=0, mode=0):
+ """Contracts a inbuf, leaving the word under the cursor expanded.
+ This is a temporary method that should disappear once liblouis
+ get it right.
+
+ Arguments:
+ - inbuf: Inbuf to contract.
+ - cursorPos: Offset of cursor.
+ """
+ prefix, uncontractedWord, suffix = \
+ _divideLine(inbuf, cursorPos)
+
+ cursorInWord = cursorPos - len(prefix)
+
+ # Contract prefix
+ #
+ prefixContracted, prefixInPos, prefixOutPos, cursorPos = \
+ _louis.translate(tran_tables,
+ prefix.decode())
+
+ # Contract suffix
+ #
+ suffixContracted, suffixInPos, suffixOutPos, cursorPos = \
+ _louis.translate(tran_tables,
+ suffix.decode())
+
+ cursorPos = len(prefixContracted) + cursorInWord
+
+ contracted = prefixContracted + \
+ uncontractedWord + \
+ suffixContracted
+
+ inPos = _mushPosArrays(prefixInPos,
+ len(uncontractedWord),
+ suffixInPos)
+
+ outPos = _mushPosArrays(prefixOutPos,
+ len(uncontractedWord),
+ suffixOutPos)
+
+ return contracted, inPos, outPos, cursorPos
+
+def _mushPosArrays(prefixPos, uncontractedLen, suffixPos):
+ try:
+ uncontractedPos = range(prefixPos[-1] + 1,
+ uncontractedLen+prefixPos[-1] + 1)
+ except IndexError:
+ uncontractedPos = range(uncontractedLen)
+
+ pos = prefixPos + \
+ uncontractedPos
+
+ try:
+ suffixOffset = pos[-1] + 1
+ except IndexError:
+ suffixOffset = 0
+
+ pos += [offs + suffixOffset for offs in suffixPos]
+
+ return pos
+
+def _divideLine(line, offset):
+ """Isolates a word the cursor is on and returns the prefix,
+ the cursored word, and the suffix. This is a temporary method
+ that avoids a liblouis bug.
+
+ Arguments:
+ - line: The line to process.
+ - offset: The offset of the cursor.
+ """
+ if len(line) <= offset:
+ return line, '', ''
+ firstHalf = line[:offset].rpartition(' ')
+ secondHalf = line[offset:].partition(' ')
+ return firstHalf[0] + firstHalf[1], \
+ firstHalf[2] + secondHalf[0], \
+ secondHalf[1] + secondHalf[2]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]