make double tap working in pty
This commit is contained in:
		| @@ -1,5 +1,7 @@ | |||||||
| # f1 - fenrir help | # f1 - fenrir help | ||||||
| ^[OP=toggle_tutorial_mode | ^[OP=toggle_tutorial_mode | ||||||
|  | # double tap control+end read attributes | ||||||
|  | ^[[1;5F^[[1;5F=attribute_cursor | ||||||
| # escape - stop speech | # escape - stop speech | ||||||
| ^[=shut_up | ^[=shut_up | ||||||
| # context menu key - stop speech | # context menu key - stop speech | ||||||
|   | |||||||
| @@ -5,13 +5,19 @@ | |||||||
| # By Chrys, Storm Dragon, and contributers. | # By Chrys, Storm Dragon, and contributers. | ||||||
|  |  | ||||||
| from fenrirscreenreader.core import debug | from fenrirscreenreader.core import debug | ||||||
| import os, inspect, re | from fenrirscreenreader.core.eventData import fenrirEventType | ||||||
|  | import os, inspect, re, time | ||||||
| currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe())))) | currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe())))) | ||||||
| fenrirPath = os.path.dirname(currentdir) | fenrirPath = os.path.dirname(currentdir) | ||||||
|  |  | ||||||
| class byteManager(): | class byteManager(): | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         pass |         self.command = '' | ||||||
|  |         self.switchCtrlModeOnce = 0  | ||||||
|  |         self.controlMode = True | ||||||
|  |         self.repeat = 1 | ||||||
|  |         self.lastInputTime = time.time() | ||||||
|  |         self.lastByteKey = b'' | ||||||
|     def initialize(self, environment): |     def initialize(self, environment): | ||||||
|         self.env = environment   |         self.env = environment   | ||||||
|     def shutdown(self): |     def shutdown(self): | ||||||
| @@ -23,7 +29,63 @@ class byteManager(): | |||||||
|         if len(convertedEscapeSequence) > 1: |         if len(convertedEscapeSequence) > 1: | ||||||
|             if convertedEscapeSequence[0] == 94 and convertedEscapeSequence[1] ==91: |             if convertedEscapeSequence[0] == 94 and convertedEscapeSequence[1] ==91: | ||||||
|                 convertedEscapeSequence = b'^[' + convertedEscapeSequence[2:]             |                 convertedEscapeSequence = b'^[' + convertedEscapeSequence[2:]             | ||||||
|         return convertedEscapeSequence         |         return convertedEscapeSequence | ||||||
|  |     def handleByteInput(self, eventData): | ||||||
|  |         if not eventData: | ||||||
|  |             return | ||||||
|  |         if eventData == b'': | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         convertedEscapeSequence = self.unifyEscapeSeq(eventData)             | ||||||
|  |  | ||||||
|  |         if self.switchCtrlModeOnce > 0: | ||||||
|  |             self.switchCtrlModeOnce -= 1        | ||||||
|  |         | ||||||
|  |         isControlMode = False | ||||||
|  |         if self.controlMode and not self.switchCtrlModeOnce == 1 or\ | ||||||
|  |           not self.controlMode: | ||||||
|  |             isControlMode = self.handleControlMode(eventData) | ||||||
|  |         shortcutData = convertedEscapeSequence | ||||||
|  |         if self.lastByteKey == convertedEscapeSequence: | ||||||
|  |             if time.time() - self.lastInputTime <= self.env['runtime']['settingsManager'].getSettingAsFloat('keyboard','doubleTapTimeout'): | ||||||
|  |                 self.repeat += 1 | ||||||
|  |                 shortcutData = shortcutData + convertedEscapeSequence | ||||||
|  |         isCommand = False                 | ||||||
|  |         if self.controlMode and not self.switchCtrlModeOnce == 1 or\ | ||||||
|  |           not self.controlMode and self.switchCtrlModeOnce == 1: | ||||||
|  |             isCommand = self.detectByteCommand(shortcutData) | ||||||
|  |             if not isCommand: | ||||||
|  |                 isCommand = self.detectByteCommand(convertedEscapeSequence)  | ||||||
|  |                 self.repeat = 1                                                | ||||||
|  |         if not (isCommand or isControlMode): | ||||||
|  |             self.env['runtime']['screenManager'].injectTextToScreen(eventData) | ||||||
|  |         if not isCommand: | ||||||
|  |             self.repeat = 1                     | ||||||
|  |         self.lastByteKey = convertedEscapeSequence | ||||||
|  |         self.lastInputTime = time.time() | ||||||
|  |     def handleControlMode(self, escapeSequence):  | ||||||
|  |         convertedEscapeSequence = self.unifyEscapeSeq(escapeSequence) | ||||||
|  |         if convertedEscapeSequence == b'^[R': | ||||||
|  |             self.controlMode = not self.controlMode | ||||||
|  |             self.switchCtrlModeOnce = 0 | ||||||
|  |             if self.controlMode: | ||||||
|  |                 self.env['runtime']['outputManager'].presentText(_('Sticky Mode On'), soundIcon='Accept', interrupt=True, flush=True) | ||||||
|  |             else: | ||||||
|  |                 self.env['runtime']['outputManager'].presentText(_('Sticky Mode On'), soundIcon='Cancel', interrupt=True, flush=True) | ||||||
|  |             return True                 | ||||||
|  |         if convertedEscapeSequence == b'^[:': | ||||||
|  |             self.switchCtrlModeOnce = 2 | ||||||
|  |             self.env['runtime']['outputManager'].presentText(_('bypass'), soundIcon='PTYBypass', interrupt=True, flush=True) | ||||||
|  |             return True | ||||||
|  |         return False           | ||||||
|  |     def detectByteCommand(self, escapeSequence): | ||||||
|  |         convertedEscapeSequence = self.unifyEscapeSeq(escapeSequence) | ||||||
|  |         self.command = self.env['runtime']['inputManager'].getCommandForShortcut(convertedEscapeSequence) | ||||||
|  |         if self.command != '':         | ||||||
|  |             self.env['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) | ||||||
|  |             self.command = '' | ||||||
|  |             return True | ||||||
|  |         return False         | ||||||
|     def loadByteShortcuts(self, kbConfigPath=fenrirPath + '/../../config/keyboard/pty.conf'): |     def loadByteShortcuts(self, kbConfigPath=fenrirPath + '/../../config/keyboard/pty.conf'): | ||||||
|         kbConfig = open(kbConfigPath,"r") |         kbConfig = open(kbConfigPath,"r") | ||||||
|         while(True): |         while(True): | ||||||
|   | |||||||
| @@ -92,38 +92,12 @@ class fenrirManager(): | |||||||
|             return |             return | ||||||
|         if event['Data'] == b'': |         if event['Data'] == b'': | ||||||
|             return |             return | ||||||
|         self.environment['runtime']['commandManager'].executeDefaultTrigger('onByteInput')                    |         self.environment['runtime']['byteManager'].handleByteInput(event['Data']) | ||||||
|         |                     | ||||||
|         if self.switchCtrlModeOnce > 0: |         self.environment['runtime']['commandManager'].executeDefaultTrigger('onByteInput') | ||||||
|             self.switchCtrlModeOnce -= 1        |     def handleExecuteCommand(self, event):   | ||||||
|         |         if not event['Data']: | ||||||
|         isControlMode = False |             return           | ||||||
|         if self.controlMode and not self.switchCtrlModeOnce == 1 or\ |  | ||||||
|           not self.controlMode: |  | ||||||
|             isControlMode = self.handleControlMode(event['Data']) |  | ||||||
|  |  | ||||||
|         isCommand = False                 |  | ||||||
|         if self.controlMode and not self.switchCtrlModeOnce == 1 or\ |  | ||||||
|           not self.controlMode and self.switchCtrlModeOnce == 1: |  | ||||||
|             isCommand = self.detectByteCommand(event['Data']) |  | ||||||
|         if not (isCommand or isControlMode): |  | ||||||
|             self.environment['runtime']['screenManager'].injectTextToScreen(event['Data']) |  | ||||||
|     def handleControlMode(self, escapeSequence):  |  | ||||||
|         convertedEscapeSequence = self.environment['runtime']['byteManager'].unifyEscapeSeq(escapeSequence) |  | ||||||
|         if convertedEscapeSequence == b'^[R': |  | ||||||
|             self.controlMode = not self.controlMode |  | ||||||
|             self.switchCtrlModeOnce = 0 |  | ||||||
|             if self.controlMode: |  | ||||||
|                 self.environment['runtime']['outputManager'].presentText(_('Sticky Mode On'), soundIcon='Accept', interrupt=True, flush=True) |  | ||||||
|             else: |  | ||||||
|                 self.environment['runtime']['outputManager'].presentText(_('Sticky Mode On'), soundIcon='Cancel', interrupt=True, flush=True) |  | ||||||
|             return True                 |  | ||||||
|         if convertedEscapeSequence == b'^[:': |  | ||||||
|             self.switchCtrlModeOnce = 2 |  | ||||||
|             self.environment['runtime']['outputManager'].presentText(_('bypass'), soundIcon='PTYBypass', interrupt=True, flush=True) |  | ||||||
|             return True |  | ||||||
|         return False         |  | ||||||
|     def handleExecuteCommand(self, event):         |  | ||||||
|         if event['Data'] == '': |         if event['Data'] == '': | ||||||
|             return |             return | ||||||
|         command = event['Data'] |         command = event['Data'] | ||||||
| @@ -173,15 +147,7 @@ class fenrirManager(): | |||||||
|         self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat',force=True)   |         self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat',force=True)   | ||||||
|         #self.environment['runtime']['outputManager'].brailleText(flush=False)                         |         #self.environment['runtime']['outputManager'].brailleText(flush=False)                         | ||||||
|  |  | ||||||
|     def detectByteCommand(self, escapeSequence): |  | ||||||
|         convertedEscapeSequence = self.environment['runtime']['byteManager'].unifyEscapeSeq(escapeSequence) |  | ||||||
|  |  | ||||||
|         self.command = self.environment['runtime']['inputManager'].getCommandForShortcut(convertedEscapeSequence) |  | ||||||
|         self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) |  | ||||||
|         if self.command != '': |  | ||||||
|             self.command = '' |  | ||||||
|             return True |  | ||||||
|         return False |  | ||||||
|     def detectShortcutCommand(self):     |     def detectShortcutCommand(self):     | ||||||
|         if self.environment['input']['keyForeward'] > 0: |         if self.environment['input']['keyForeward'] > 0: | ||||||
|             return |             return | ||||||
|   | |||||||
| @@ -76,7 +76,7 @@ class driver(screenDriver): | |||||||
|         self.env['general']['currUser'] = getpass.getuser() |         self.env['general']['currUser'] = getpass.getuser() | ||||||
|     def readAll(self,fd, timeout = 9999999, interruptFdList = None): |     def readAll(self,fd, timeout = 9999999, interruptFdList = None): | ||||||
|         starttime = time.time()     |         starttime = time.time()     | ||||||
|         bytes = os.read(fd, 200) |         bytes = os.read(fd, 4096) | ||||||
|         if bytes == b'': |         if bytes == b'': | ||||||
|             raise EOFError |             raise EOFError | ||||||
|         # respect timeout but wait a little bit of time to see if something more is here |         # respect timeout but wait a little bit of time to see if something more is here | ||||||
| @@ -88,7 +88,7 @@ class driver(screenDriver): | |||||||
|                     break |                     break | ||||||
|             if (time.time() - starttime) >= timeout: |             if (time.time() - starttime) >= timeout: | ||||||
|                 break |                 break | ||||||
|             data = os.read(fd, 100) |             data = os.read(fd, 4096) | ||||||
|             if data == b'': |             if data == b'': | ||||||
|                 raise EOFError |                 raise EOFError | ||||||
|             bytes += data |             bytes += data | ||||||
| @@ -156,7 +156,7 @@ class driver(screenDriver): | |||||||
|                 # output |                 # output | ||||||
|                 if self.p_out in r: |                 if self.p_out in r: | ||||||
|                     try: |                     try: | ||||||
|                         msgBytes = self.readAll(self.p_out.fileno(), timeout=0.1, interruptFdList=[sys.stdin]) |                         msgBytes = self.readAll(self.p_out.fileno(), timeout=0.05, interruptFdList=[sys.stdin]) | ||||||
|                     except (EOFError, OSError): |                     except (EOFError, OSError): | ||||||
|                         active.value = False |                         active.value = False | ||||||
|                         break     |                         break     | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user