From 3757a1ceeb3986dffb1a052c418e019f809809f8 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 8 Dec 2024 05:02:29 -0500 Subject: [PATCH] Updated brlapi driver. Hopefully will now actually work. --- .../brailleDriver/brlapiDriver.py | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/fenrirscreenreader/brailleDriver/brlapiDriver.py b/src/fenrirscreenreader/brailleDriver/brlapiDriver.py index f2df2a50..acab6f76 100644 --- a/src/fenrirscreenreader/brailleDriver/brlapiDriver.py +++ b/src/fenrirscreenreader/brailleDriver/brlapiDriver.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/bin/python # -*- coding: utf-8 -*- # Fenrir TTY screen reader @@ -8,8 +8,7 @@ from fenrirscreenreader.core import debug from fenrirscreenreader.core.brailleDriver import brailleDriver class driver(brailleDriver): - """BRLAPI implementation of the braille driver interface. - Supports all braille displays compatible with BRLTTY.""" + """BRLAPI implementation of the braille driver interface.""" def __init__(self): """Initialize the BRLAPI driver.""" @@ -24,7 +23,6 @@ class driver(brailleDriver): import brlapi self._brl = brlapi.Connection() self._deviceSize = self._brl.displaySize - # Accept all key types from any braille display self._brl.acceptKeys(brlapi.rangeType_all, [0, brlapi.KEY_MAX]) self._current_cursor_pos = 0 except Exception as e: @@ -39,16 +37,31 @@ class driver(brailleDriver): return self._deviceSize def writeText(self, text): - """Write text to the braille display.""" + """Write text to the braille display. + Handles both flush and non-flush text from the output manager.""" if not self._isInitialized: return try: + # Remove the 'flush ' or 'notflush ' prefix + if text.startswith('flush '): + text = text[6:] # Remove 'flush ' prefix + elif text.startswith('notflush '): + text = text[9:] # Remove 'notflush ' prefix + self._last_written_text = text + # Handle unicode properly for international braille if isinstance(text, str): self._brl.writeText(text) else: self._brl.writeText(text.decode('utf-8', 'replace')) + + # Update cursor if needed + if 'screen' in self.env and 'newCursorReview' in self.env['screen']: + new_pos = self.env['screen']['newCursorReview']['x'] + if new_pos != self._current_cursor_pos: + self.setCursor(new_pos) + except Exception as e: self.env['runtime']['debug'].writeDebugOut('BRAILLE.writeText ' + str(e), debug.debugLevel.ERROR) @@ -57,7 +70,6 @@ class driver(brailleDriver): try: import brlapi self._brl = brlapi.Connection() - # Accept all key types from the connected display self._brl.acceptKeys(brlapi.rangeType_all, [0, brlapi.KEY_MAX]) return True except Exception as e: @@ -89,7 +101,6 @@ class driver(brailleDriver): try: max_pos = self.getDeviceSize()[0] - 1 self._current_cursor_pos = max(0, min(position, max_pos)) - # Use BRLAPI's cursor command which works across different displays self._brl.writeDots(1 << self._current_cursor_pos) except Exception as e: self.env['runtime']['debug'].writeDebugOut('BRAILLE.setCursor ' + str(e), debug.debugLevel.ERROR) @@ -122,8 +133,7 @@ class driver(brailleDriver): self.env['runtime']['debug'].writeDebugOut('BRAILLE.flush ' + str(e), debug.debugLevel.ERROR) def handleKeyInput(self, key): - """Handle input from any BRLTTY-compatible braille display. - Returns the key event for processing by Fenrir's input system.""" + """Handle input from any BRLTTY-compatible braille display.""" if not self._isInitialized: return False try: @@ -131,8 +141,6 @@ class driver(brailleDriver): if not key_code: return False - # Let Fenrir's input system handle the key - # This allows proper handling regardless of display type if self.env['runtime']['debug'].debugLevel >= debug.debugLevel.INFO: self.env['runtime']['debug'].writeDebugOut( 'BRAILLE.keyPressed: ' + str(key_code),