Merge branch 'remotesetting'

This commit is contained in:
chrys 2018-09-09 15:26:22 +02:00
commit 79b4ac32fb
17 changed files with 420 additions and 76 deletions

View File

@ -122,7 +122,6 @@ driver=vcsaDriver
encoding=auto
screenUpdateDelay=0.05
suspendingScreen=
suspendingScreenFile=/tmp/fenrirSuspend
autodetectSuspendingScreen=True
[keyboard]
@ -187,6 +186,21 @@ shell=
cursor=True
highlight=False
[remote]
enable=True
# connection type
# unix = unix sockets
# tcp = tcp (localhost only)
method=unix
# tcp port
port=22447
# socket filepath
socketpath=/tmp/
# allow settings to overwrite
enableSettingsRemote=True
# allow commands to be executed
enableCommandRemote=True
[barrier]
enabled=True
leftBarriers=│└┌─

View File

@ -124,7 +124,6 @@ driver=vcsaDriver
encoding=auto
screenUpdateDelay=0.05
suspendingScreen=
suspendingScreenFile=/tmp/fenrirSuspend
autodetectSuspendingScreen=True
[keyboard]
@ -197,6 +196,21 @@ cursor=True
#follow highlighted text changes
highlight=False
[remote]
enable=True
# connection type
# unix = unix sockets
# tcp = tcp (localhost only)
method=unix
# tcp port
port=22447
# socket filepath
socketpath=/tmp/
# allow settings to overwrite
enableSettingsRemote=True
# allow commands to be executed
enableCommandRemote=True
[barrier]
enabled=True
leftBarriers=│└┌─

View File

@ -125,7 +125,6 @@ driver=vcsaDriver
encoding=auto
screenUpdateDelay=0.05
suspendingScreen=
suspendingScreenFile=/tmp/fenrirSuspend
autodetectSuspendingScreen=True
[keyboard]
@ -198,6 +197,21 @@ cursor=True
#follow highlighted text changes
highlight=False
[remote]
enable=True
# connection type
# unix = unix sockets
# tcp = tcp (localhost only)
method=unix
# tcp port
port=22447
# socket filepath
socketpath=/tmp/
# allow settings to overwrite
enableSettingsRemote=True
# allow commands to be executed
enableCommandRemote=True
[barrier]
enabled=True
leftBarriers=│└┌─

View File

@ -79,7 +79,6 @@ driver=vcsaDriver
encoding=auto
screenUpdateDelay=0.05
suspendingScreen=
suspendingScreenFile=/tmp/fenrirSuspend
autodetectSuspendingScreen=True
[keyboard]
@ -143,6 +142,21 @@ cursor=True
#follow highlighted text changes
highlight=False
[remote]
enable=True
# connection type
# unix = unix sockets
# tcp = tcp (localhost only)
method=unix
# tcp port
port=22447
# socket filepath
socketpath=/tmp/
# allow settings to overwrite
enableSettingsRemote=True
# allow commands to be executed
enableCommandRemote=True
[barrier]
enabled=True
leftBarriers=│└┌─

View File

@ -124,7 +124,6 @@ driver=vcsaDriver
encoding=auto
screenUpdateDelay=0.05
suspendingScreen=
suspendingScreenFile=/tmp/fenrirSuspend
autodetectSuspendingScreen=True
[keyboard]
@ -197,6 +196,21 @@ cursor=True
#follow highlighted text changes
highlight=False
[remote]
enable=True
# connection type
# unix = unix sockets
# tcp = tcp (localhost only)
method=unix
# tcp port
port=22447
# socket filepath
socketpath=/tmp/
# allow settings to overwrite
enableSettingsRemote=True
# allow commands to be executed
enableCommandRemote=True
[barrier]
enabled=True
leftBarriers=│└┌─

13
realese nots/1.9.3 Normal file
View File

@ -0,0 +1,13 @@
- fix hight CPU load in VCSA pressing mute key
- add remote manager
- remote manager: TCP connection
- remote manager: UNIX Socket connection(default)
- remote manager: set settings set a setting (-o syntax) "setting set sound#enabled=False"
- remote manager: reset settings "setting reset"
- remote manager: save settings "setting save /path/settings.conf"
- remote Manager: say command (say something) "command say this is a test"
- remote manager: interrupt command (interrupt current speech) "command interrupt"
- remote manager: window command (to define window) "command window startX startY endX endY"
- remote manager: resetwindow command (to reset window) "command resetwindow"
- settings: store settings more centralized
- variouse speedups and bugfixes

View File

@ -82,21 +82,40 @@ class cursorManager():
except:
pass
return False
def setWindowForApplication(self):
def setWindowForApplication(self, start = None, end = None):
x1 = 0
x2 = 0
y1 = 0
y2 = 0
if start == None:
if not self.env['commandBuffer']['Marks']['1']:
return False
else:
x1 = self.env['commandBuffer']['Marks']['1']['x']
y1 = self.env['commandBuffer']['Marks']['1']['y']
else:
x1 = start['x']
y1 = start['y']
if end == None:
if not self.env['commandBuffer']['Marks']['2']:
return False
else:
x1 = self.env['commandBuffer']['Marks']['2']['x']
y1 = self.env['commandBuffer']['Marks']['2']['y']
else:
x1 = start['x']
y1 = start['y']
currApp = self.env['runtime']['applicationManager'].getCurrentApplication()
self.env['commandBuffer']['windowArea'][currApp] = {}
if self.env['commandBuffer']['Marks']['1']['x'] * self.env['commandBuffer']['Marks']['1']['y'] <= \
self.env['commandBuffer']['Marks']['2']['x'] * self.env['commandBuffer']['Marks']['2']['y']:
self.env['commandBuffer']['windowArea'][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy()
self.env['commandBuffer']['windowArea'][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy()
if x1 * y1 <= \
x2 * y2:
self.env['commandBuffer']['windowArea'][currApp]['1'] = {'x':x1, 'y':y1}
self.env['commandBuffer']['windowArea'][currApp]['2'] = {'x':x2, 'y':y2}
else:
self.env['commandBuffer']['windowArea'][currApp]['1'] = self.env['commandBuffer']['Marks']['2'].copy()
self.env['commandBuffer']['windowArea'][currApp]['2'] = self.env['commandBuffer']['Marks']['1'].copy()
self.env['commandBuffer']['windowArea'][currApp]['1'] = {'x':x2, 'y':y2}
self.env['commandBuffer']['windowArea'][currApp]['2'] = {'x':x1, 'y':y1}
return True
def clearWindowForApplication(self):
currApp = self.env['runtime']['applicationManager'].getCurrentApplication()

View File

@ -19,6 +19,7 @@ class fenrirEventType(Enum):
HeartBeat = 8 # for time based scheduling
ExecuteCommand = 9
ByteInput = 10
RemoteIncomming = 11
def __int__(self):
return self.value
def __str__(self):

View File

@ -56,6 +56,8 @@ class eventManager():
self.env['runtime']['fenrirManager'].handleExecuteCommand(event)
elif event['Type'] == fenrirEventType.ByteInput:
self.env['runtime']['fenrirManager'].handleByteInput(event)
elif event['Type'] == fenrirEventType.RemoteIncomming:
self.env['runtime']['fenrirManager'].handleRemoteIncomming(event)
def isMainEventLoopRunning(self):
return self.running.value == 1
def startMainEventLoop(self):

View File

@ -105,6 +105,10 @@ class fenrirManager():
self.environment['runtime']['commandManager'].executeCommand( command, 'help')
return
self.environment['runtime']['commandManager'].executeCommand( command, 'commands')
def handleRemoteIncomming(self, event):
if not event['Data']:
return
self.environment['runtime']['remoteManager'].handleRemoteIncomming(event['Data'])
def handleScreenChange(self, event):
self.environment['runtime']['screenManager'].hanldeScreenChange(event['Data'])
'''

View File

@ -0,0 +1,208 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
'''
Remote controll:
section<space>command<space>parameters
sections:command,setting
setting commands:
- set section#setting=value[,section#setting=value]
- reset
command commands:
- say text to speech
- interrupt
examples
settings:
settings set section#setting=value[,section#setting=value]
setting set speech#voice=de
setting reset
setting save /path/settings.conf
command:
command say this is a test
command interrupt
'''
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType
import time
import select
import socket
import os, os.path
class remoteManager():
def __init__(self):
# command controll
self.commandConst = 'COMMAND '
self.sayConst = 'SAY '
self.interruptConst = 'INTERRUPT'
self.defineWindowConst = 'WINDOW '
self.resetWindowConst = 'RESETWINDOW'
# setting controll
self.settingConst = 'SETTING '
self.setSettingConst = 'SET '
self.saveSettingConst = 'SAVE '
self.resetSettingConst = 'RESET'
def initialize(self, environment):
self.env = environment
if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'):
if self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'UNIX':
self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True)
elif self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'TCP':
self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True)
def shutdown(self):
if self.sock:
self.sock.close()
self.sock = None
def unixSocketWatchDog(self, active, eventQueue):
# echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrirscreenreader-deamon.sock
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-deamon.sock'
else:
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-' + str(os.getpid()) + '.sock'
if os.path.exists(socketpath):
os.remove(socketpath)
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.bind(socketpath)
self.sock.listen(1)
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
os.chmod(socketpath, 0o222)
while active.value == 1:
client_sock, client_addr = self.sock.accept()
if client_sock:
# Check if the client is still connected and if data is available:
try:
r, w, e = select.select([client_sock,], [], [])
except select.error:
return
if len(r) > 0:
rawdata = client_sock.recv(8129)
try:
data = rawdata.decode("utf-8").rstrip().lstrip()
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
"Data": data
})
except:
pass
client_sock.close()
if os.path.exists(socketpath):
os.remove(socketpath)
if self.sock:
self.sock.close()
self.sock = None
def tcpWatchDog(self, active, eventQueue):
# echo "command say this is a test" | nc localhost 22447
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.host = '127.0.0.1'
self.port = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'port')
self.sock.bind((self.host, self.port))
self.sock.listen(1)
while active.value == 1:
client_sock, client_addr = self.sock.accept()
if client_sock:
# Check if the client is still connected and if data is available:
try:
r, w, e = select.select([client_sock,], [], [])
except select.error:
return
if len(r) > 0:
rawdata = client_sock.recv(8129)
try:
data = rawdata.decode("utf-8").rstrip().lstrip()
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
"Data": data
})
except:
pass
client_sock.close()
if self.sock:
self.sock.close()
self.sock = None
def handleSettingsChange(self, settingsText):
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
return
upperSettingsText = settingsText.upper()
# set setting
if upperSettingsText.startswith(self.setSettingConst):
parameterText = settingsText[len(self.setSettingConst):]
self.setSettings(parameterText)
# save setting
if upperSettingsText.startswith(self.saveSettingConst):
parameterText = settingsText[len(self.saveSettingConst):]
self.saveSettings(parameterText)
# reset setting
if upperSettingsText.startswith(self.resetSettingConst):
self.resetSettings()
def handleCommandExecution(self, commandText):
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'):
return
upperCommandText = commandText.upper()
# say
if upperCommandText.startswith(self.sayConst):
parameterText = commandText[len(self.sayConst):]
self.say(parameterText)
# interrupt
if upperCommandText.startswith(self.interruptConst):
self.interruptSpeech()
# define window
if upperCommandText.startswith(self.defineWindowConst):
parameterText = commandText[len(self.defineWindowConst):]
self.defineWindow(parameterText)
# reset window
if upperCommandText.startswith(self.resetWindowConst):
self.resetWindow()
def defineWindow(self, windowText):
start = {}
end = {}
try:
windowList = windowText.split(' ')
if len(windowList) < 4:
return
start['x'] = int(windowList[0])
start['y'] = int(windowList[1])
end['x'] = int(windowList[2])
end['y'] = int(windowList[3])
self.env['runtime']['cursorManager'].setWindowForApplication(start, end)
except Exception as e:
pass
def resetWindow(self):
self.env['runtime']['cursorManager'].clearWindowForApplication()
def say(self, text):
if not text:
return
if text == '':
return
self.env['runtime']['outputManager'].speakText(text)
def interruptSpeech(self):
self.env['runtime']['outputManager'].interruptOutput()
def saveSettings(self, settingConfigPath):
if not settingConfigPath:
return
if settingConfigPath == '':
return
self.env['runtime']['settingsManager'].saveSettings(settingConfigPath)
def resetSettings(self):
self.env['runtime']['settingsManager'].resetSettingArgDict()
def setSettings(self, settingsArgs):
self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs)
def handleRemoteIncomming(self, eventData):
if not eventData:
return
upperEventData = eventData.upper()
if upperEventData.startswith(self.settingConst):
settingsText = eventData[len(self.settingConst):]
self.handleSettingsChange(settingsText)
elif upperEventData.startswith(self.commandConst):
commandText = eventData[len(self.commandConst):]
self.handleCommandExecution(commandText)

View File

@ -196,14 +196,6 @@ class screenManager():
ignoreScreens.extend(fixIgnoreScreens.split(','))
if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'):
ignoreScreens.extend(self.env['screen']['autoIgnoreScreens'])
try:
ignoreFileName = self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreenFile')
if ignoreFileName != '':
if os.access(ignoreFileName, os.R_OK):
with open(ignoreFileName) as fp:
ignoreScreens.extend(fp.read().replace('\n','').split(','))
except:
pass
self.env['runtime']['debug'].writeDebugOut('screenManager:isSuspendingScreen ignore:' + str(ignoreScreens) + ' current:'+ str(screen ), debug.debugLevel.INFO)
return (screen in ignoreScreens)

View File

@ -51,7 +51,6 @@ settingsData = {
'encoding': 'auto',
'screenUpdateDelay': 0.1,
'suspendingScreen': '',
'suspendingScreenFile': '/tmp/fenrirSuspend',
'autodetectSuspendingScreen': False,
},
'general':{
@ -80,7 +79,14 @@ settingsData = {
'focus':{
'cursor': True,
'highlight': False,
},
'remote':{
'enabled': True,
'method': 'unix',
'port': 22447,
'socketpath':'/tmp/',
'enableSettingsRemote': True,
'enableCommandRemote': True,
},
'barrier':{
'enabled': True,

View File

@ -5,6 +5,7 @@
# By Chrys, Storm Dragon, and contributers.
import os, inspect
currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe()))))
fenrirPath = os.path.dirname(currentdir)
@ -26,6 +27,7 @@ from fenrirscreenreader.core import tableManager
from fenrirscreenreader.core import byteManager
from fenrirscreenreader.core import attributeManager
from fenrirscreenreader.core import barrierManager
from fenrirscreenreader.core import remoteManager
from fenrirscreenreader.core import environment
from fenrirscreenreader.core.settingsData import settingsData
from fenrirscreenreader.core import debug
@ -77,9 +79,26 @@ class settingsManager():
self.env['settings'] = ConfigParser()
self.env['settings'].read(settingConfigPath)
return True
def setSetting(self, section, setting, value):
def saveSettings(self, settingConfigPath):
# set opt dict here
# save file
try:
#print('file: ',settingConfigPath)
for section, settings in self.settingArgDict.items():
for setting, value in settings.items():
#print(section, setting, value)
self.env['settings'].set(section, setting, value)
#print('full',self.env['settings'])
configFile = open(settingConfigPath, 'w')
self.env['settings'].write(configFile)
configFile.close()
os.chmod(settingConfigPath, 0o666)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('saveSettings: save settingsfile:' + settingConfigPath + 'failed. Error:' + str(e), debug.debugLevel.ERROR)
def setSetting(self, section, setting, value):
self.setOptionArgDict(section, setting, value)
#self.env['settings'].set(section, setting, value)
def getSetting(self, section, setting):
value = ''
@ -173,6 +192,8 @@ class settingsManager():
for key in keyList:
if not key in self.env['input']['scriptKey']:
self.env['input']['scriptKey'].append(key)
def resetSettingArgDict(self):
self.settingArgDict = {}
def setOptionArgDict(self, section, option, value):
section = section.lower()
option = option.lower()
@ -188,6 +209,7 @@ class settingsManager():
continue
if len(optionElem.split('#',1)[1].split('=',1)) != 2:
continue
section = str(optionElem.split('#',1)[0]).lower()
option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower()
value = optionElem.split('#',1)[1].split('=',1)[1]
@ -302,6 +324,10 @@ class settingsManager():
environment['runtime']['helpManager'] = helpManager.helpManager()
environment['runtime']['helpManager'].initialize(environment)
environment['runtime']['remoteManager'] = remoteManager.remoteManager()
environment['runtime']['remoteManager'].initialize(environment)
if environment['runtime']['inputManager'].getShortcutType() == 'KEY':
if not os.path.exists(self.getSetting('keyboard','keyboardLayout')):
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')):

View File

@ -108,8 +108,10 @@ class driver(inputDriver):
if event.code != 0:
currMapEvent = self.mapEvent(event)
if not currMapEvent:
event = self.iDevices[fd].read_one()
continue
if not isinstance(currMapEvent['EventName'], str):
event = self.iDevices[fd].read_one()
continue
if currMapEvent['EventState'] in [0,1,2]:
eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()})

View File

@ -156,6 +156,7 @@ class driver(screenDriver):
})
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
time.sleep(0.2)
def createScreenEventData(self, screen, content):