unify more loops, remove spaces

This commit is contained in:
Chrys 2019-09-05 23:12:05 +02:00
parent 8663ad1ac9
commit 3f85d672a6
12 changed files with 96 additions and 96 deletions

View File

@ -16,11 +16,11 @@ class driver(brailleDriver):
self.env = environment
try:
import brlapi
self._brl = brlapi.Connection()
self._deviceSize = self._brl.displaySize
self._brl = brlapi.Connection()
self._deviceSize = self._brl.displaySize
except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
return
self._isInitialized = True

View File

@ -44,6 +44,6 @@ class driver(brailleDriver):
def shutdown(self):
if self._isInitialized:
self.leveScreen()
self._isInitialized = False
self.leveScreen()
self._isInitialized = False
print('Braille Debug Driver: Shutdown')

View File

@ -14,14 +14,14 @@ class driver(inputDriver):
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('KEY')
self._initialized = True
print('Input Debug Driver: Initialized')
self.env['runtime']['inputManager'].setShortcutType('KEY')
self._initialized = True
print('Input Debug Driver: Initialized')
def shutdown(self):
if self._initialized:
self.removeAllDevices()
self._initialized = False
self.removeAllDevices()
self._initialized = False
print('Input Debug Driver: Shutdown')
def getInputEvent(self):
@ -32,32 +32,32 @@ class driver(inputDriver):
return None
def writeEventBuffer(self):
if not self._initialized:
return
return
print('Input Debug Driver: writeEventBuffer')
def clearEventBuffer(self):
if not self._initialized:
return
del self.env['input']['eventBuffer'][:]
return
del self.env['input']['eventBuffer'][:]
print('Input Debug Driver: clearEventBuffer')
def updateInputDevices(self, newDevices = None, init = False):
if not self._initialized:
return
return
print('Input Debug Driver: updateInputDevices')
def getLedState(self, led = 0):
if not self._initialized:
return False
return False
return False
return False
def toggleLedState(self, led = 0):
if not self._initialized:
return
return
print('Input Debug Driver: toggleLedState')
def grabAllDevices(self):
if not self._initialized:
return
return
print('Input Debug Driver: grabAllDevices')
def ungrabAllDevices(self):
if not self._initialized:
return
return
print('Input Debug Driver: ungrabAllDevices')
def removeAllDevices(self):
@ -67,6 +67,6 @@ class driver(inputDriver):
def __del__(self):
if self._initialized:
self.removeAllDevices()
print('Input Debug Driver: __del__')
print('Input Debug Driver: __del__')

View File

@ -10,9 +10,9 @@ from fenrirscreenreader.core.inputDriver import inputDriver
class driver(inputDriver):
def __init__(self):
self._isInitialized = False
self._isInitialized = False
inputDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('BYTE')
self._isInitialized = True
self._isInitialized = True

View File

@ -33,7 +33,7 @@ class driver(screenDriver):
self.charmap = {}
self.bgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'white'}
self.fgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'light gray', 8: 'dark gray', 9: 'light blue', 10: 'light green', 11: 'light cyan', 12: 'light red', 13: 'light magenta', 14: 'light yellow', 15: 'white'}
self.hichar = None
self.hichar = None
def initialize(self, environment):
self.env = environment
self.env['runtime']['attributeManager'].appendDefaultAttributes([
@ -47,11 +47,11 @@ class driver(screenDriver):
False, # blink
'default', # fontsize
'default' # fontfamily
]) #end attribute )
]) #end attribute )
self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog, multiprocess=True)
def getCurrScreen(self):
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
try:
try:
currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r')
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
currScreenFile.close()
@ -121,7 +121,7 @@ class driver(screenDriver):
watchdog = select.epoll()
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
watchdog.register(tty, select.POLLPRI | select.POLLERR)
while active.value == 1:
while active.value:
changes = watchdog.poll(1)
for change in changes:
fileno = change[0]
@ -229,7 +229,7 @@ class driver(screenDriver):
tty = open('/dev/tty' + screen, 'rb')
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:' + str(e),debug.debugLevel.ERROR)
return
return
GIO_UNIMAP = 0x4B66
VT_GETHIFONTMASK = 0x560D
himask = array("H", (0,))

View File

@ -28,7 +28,7 @@ class driver(soundDriver):
def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0):
if not self._initialized:
return
return
if interrupt:
self.cancel()
popenFrequenceCommand = shlex.split(self.frequenceCommand)
@ -36,28 +36,28 @@ class driver(soundDriver):
word = word.replace('fenrirVolume', str(self.volume + adjustVolume ))
word = word.replace('fenrirFreqDuration', str(duration))
word = word.replace('fenrirFrequence', str(frequence))
popenFrequenceCommand[idx] = word
popenFrequenceCommand[idx] = word
self.proc = subprocess.Popen(popenFrequenceCommand, stdin=None, stdout=None, stderr=None, shell=False)
self.soundType = 'frequence'
def playSoundFile(self, filePath, interrupt = True):
if not self._initialized:
return
return
if interrupt:
self.cancel()
popenSoundFileCommand = shlex.split(self.soundFileCommand)
for idx, word in enumerate(popenSoundFileCommand):
word = word.replace('fenrirVolume', str(self.volume ))
word = word.replace('fenrirSoundFile', str(filePath))
popenSoundFileCommand[idx] = word
popenSoundFileCommand[idx] = word
self.proc = subprocess.Popen(popenSoundFileCommand, shell=False)
self.soundType = 'file'
def cancel(self):
if not self._initialized:
return
return
if self.soundType == '':
return
if self.soundType == 'file':
self.proc.kill()
if self.soundType == 'frequence':
self.proc.kill()
self.soundType = ''
self.proc.kill()
self.soundType = ''

View File

@ -10,11 +10,11 @@ from fenrirscreenreader.core.soundDriver import soundDriver
_gstreamerAvailable = False
try:
import gi
from gi.repository import GLib
import gi
from gi.repository import GLib
gi.require_version('Gst', '1.0')
from gi.repository import Gst
_gstreamerAvailable, args = Gst.init_check(None)
_gstreamerAvailable, args = Gst.init_check(None)
except Exception as e:
_gstreamerAvailable = False
_availableError = str(e)
@ -28,10 +28,10 @@ class driver(soundDriver):
def initialize(self, environment):
self.env = environment
global _gstreamerAvailable
self._initialized = _gstreamerAvailable
self._initialized = _gstreamerAvailable
if not self._initialized:
global _availableError
self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available ' + _availableError,debug.debugLevel.ERROR)
self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available ' + _availableError,debug.debugLevel.ERROR)
return
self._player = Gst.ElementFactory.make('playbin', 'player')
bus = self._player.get_bus()
@ -48,7 +48,7 @@ class driver(soundDriver):
self._pipeline.add(self._source)
self._pipeline.add(self._sink)
self._source.link(self._sink)
self.mainloop = GLib.MainLoop()
self.mainloop = GLib.MainLoop()
self.thread = threading.Thread(target=self.mainloop.run)
self.thread.start()
@ -66,7 +66,7 @@ class driver(soundDriver):
elif message.type == Gst.MessageType.ERROR:
self._player.set_state(Gst.State.NULL)
error, info = message.parse_error()
self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
def _onPipelineMessage(self, bus, message):
if not self._initialized:
@ -80,12 +80,12 @@ class driver(soundDriver):
def _onTimeout(self, element):
if not self._initialized:
return
return
element.set_state(Gst.State.NULL)
def playSoundFile(self, fileName, interrupt=True):
if not self._initialized:
return
return
if interrupt:
self.cancel()
self._player.set_property('uri', 'file://%s' % fileName)
@ -93,7 +93,7 @@ class driver(soundDriver):
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
if not self._initialized:
return
return
if interrupt:
self.cancel()
self._source.set_property('volume', tone.volume)

View File

@ -19,7 +19,7 @@ class driver(speechDriver):
def shutdown(self):
if self._isInitialized:
self.cancel()
self._isInitialized = False
self._isInitialized = False
print('Speech Debug Driver: Shutdown')
def speak(self,text, queueable=True):
@ -33,42 +33,42 @@ class driver(speechDriver):
def cancel(self):
if not self._isInitialized:
return
print('Speech Debug Driver: Cancel')
print('Speech Debug Driver: Cancel')
def setCallback(self, callback):
print('Speech Debug Driver: setCallback')
print('Speech Debug Driver: setCallback')
def clear_buffer(self):
if not self._isInitialized:
return
print('Speech Debug Driver: clear_buffer')
print('Speech Debug Driver: clear_buffer')
def setVoice(self, voice):
if not self._isInitialized:
return
print('Speech Debug Driver: setVoice:' + str(voice))
print('Speech Debug Driver: setVoice:' + str(voice))
def setPitch(self, pitch):
if not self._isInitialized:
return
print('Speech Debug Driver: setPitch:' + str(pitch))
print('Speech Debug Driver: setPitch:' + str(pitch))
def setRate(self, rate):
if not self._isInitialized:
return
print('Speech Debug Driver: setRate:' + str(rate))
print('Speech Debug Driver: setRate:' + str(rate))
def setModule(self, module):
if not self._isInitialized:
return
print('Speech Debug Driver: setModule:' + str(module))
return
print('Speech Debug Driver: setModule:' + str(module))
def setLanguage(self, language):
if not self._isInitialized:
return
print('Speech Debug Driver: setLanguage:' + str(language))
print('Speech Debug Driver: setLanguage:' + str(language))
def setVolume(self, volume):
if not self._isInitialized:
return
return
print('Speech Debug Driver: setVolume:' + str(volume))

View File

@ -15,19 +15,19 @@ class driver(speechDriver):
def __init__(self):
speechDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self.env = environment
try:
self.server = pexpect.spawn('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath'))
self._isInitialized = True
self._isInitialized = True
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
def shutdown(self):
if self.server:
try:
self.server.terminate()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:shutdown:self.server.terminate():' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:shutdown:self.server.terminate():' + str(e),debug.debugLevel.ERROR)
def speak(self,text, queueable=True):
if not self._isInitialized:
@ -45,7 +45,7 @@ class driver(speechDriver):
cleanText = 'tts_say \"' + cleanText +'\"'
self.server.sendline(cleanText)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:speak:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:speak:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
def cancel(self):
if not self._isInitialized:
@ -54,7 +54,7 @@ class driver(speechDriver):
self.server.sendline('stop')
except Exception as e:
print(e)
self.env['runtime']['debug'].writeDebugOut('speechDriver:cancel:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:cancel:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
def setRate(self, rate):
if not self._isInitialized:
@ -62,7 +62,7 @@ class driver(speechDriver):
try:
self.server.sendline('tts_set_speech_rate ' + str(int(rate * 400)))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:setRate:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:setRate:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
def setLanguage(self, language):
if not self._isInitialized:

View File

@ -14,13 +14,13 @@ class driver(speechDriver):
self._es = None
def initialize(self, environment):
self.env = environment
self.env = environment
try:
from espeak import espeak
self._es = espeak
self._isInitialized = True
except Exception as e:
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
self._initialized = False
def speak(self,text, interrupt=True):
@ -30,10 +30,10 @@ class driver(speechDriver):
self.cancel()
if self.language != None:
if self.language != '':
self._es.set_voice(self.language)
self._es.set_voice(self.language)
elif self.voice != None:
if self.voice != '':
self._es.set_voice(self.voice)
if self.voice != '':
self._es.set_voice(self.voice)
self._es.synth(text)
def cancel(self):

View File

@ -27,11 +27,11 @@ class driver(speechDriver):
self.speechThread = Thread(target=self.worker)
self.lock = Lock()
self.textQueue = speakQueue()
def initialize(self, environment):
def initialize(self, environment):
self.env = environment
self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinVolume')
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxVolume')
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinPitch')
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxVolume')
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinPitch')
self.maxPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxPitch')
self.minRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinRate')
self.maxRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxRate')
@ -40,23 +40,23 @@ class driver(speechDriver):
if self.speechCommand == '':
self.speechCommand = 'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice -- "fenrirText"'
if False: #for debugging overwrite here
#self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
self.speechCommand = 'flite -t "fenrirText"'
#self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
self.speechCommand = 'flite -t "fenrirText"'
self._isInitialized = True
self._isInitialized = True
if self._isInitialized:
self.speechThread.start()
self.speechThread.start()
def shutdown(self):
if not self._isInitialized:
return
self.cancel()
self.cancel()
self.textQueue.put(-1)
def speak(self,text, queueable=True):
if not self._isInitialized:
return
if not queueable:
self.cancel()
if not queueable:
self.cancel()
utterance = {
'text': text,
'volume': self.volume,
@ -65,7 +65,7 @@ class driver(speechDriver):
'module': self.module,
'language': self.language,
'voice': self.voice,
}
}
self.textQueue.put(utterance.copy())
def cancel(self):
@ -77,20 +77,20 @@ class driver(speechDriver):
try:
self.proc.terminate()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
try:
self.proc.kill()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
self.proc = None
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
self.proc = None
self.lock.release()
def setCallback(self, callback):
print('SpeechDummyDriver: setCallback')
print('SpeechDummyDriver: setCallback')
def clear_buffer(self):
if not self._isInitialized:
return
self.textQueue.clear()
self.textQueue.clear()
def setVoice(self, voice):
if not self._isInitialized:
@ -137,7 +137,7 @@ class driver(speechDriver):
if not 'text' in utterance:
continue
if not isinstance(utterance['text'],str):
continue
continue
if utterance['text'] == '':
continue
# check for valid data fields
@ -178,13 +178,13 @@ class driver(speechDriver):
popenSpeechCommand[idx] = word
try:
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO)
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO)
self.lock.acquire(True)
self.proc = Popen(popenSpeechCommand, stdin=None, stdout=None, stderr=None, shell=False)
self.lock.release()
self.proc.wait()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + str(e),debug.debugLevel.ERROR)
self.lock.acquire(True)
self.proc = None

View File

@ -14,12 +14,12 @@ class driver(speechDriver):
speechDriver.__init__(self)
self._engine = None
def initialize(self, environment):
self.env = environment
self.env = environment
def shutdown(self):
if self._isInitialized:
self.cancel()
self.cancel()
self._engine.endLoop()
self._initialized = False
self._initialized = False
def eventLoop(self):
self._engine.startLoop()
def startEngine(self):
@ -28,17 +28,17 @@ class driver(speechDriver):
if self.module != '':
self._engine = pyttsx3.init(self.module)
else:
self._engine = pyttsx3.init()
self._engine = pyttsx3.init()
self.eventLoopThread = Thread(target=self.eventLoop)
self._isInitialized = True
self.eventLoopThread.start()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
def speak(self,text, interrupt=True):
if not self._isInitialized:
self.startEngine()
if not self._isInitialized:
if not self._isInitialized:
return
if not interrupt:
self.cancel()
@ -51,15 +51,15 @@ class driver(speechDriver):
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:rate:' + str(e),debug.debugLevel.ERROR)
try:
self._engine.setProperty('pitch', self.pitch)
self._engine.setProperty('pitch', self.pitch)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:pitch:' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:pitch:' + str(e),debug.debugLevel.ERROR)
if self.language != None:
if self.language != '':
try:
self._engine.setProperty('voice', self.language)
self._engine.setProperty('voice', self.language)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:language:' + str(e),debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:language:' + str(e),debug.debugLevel.ERROR)
elif self.voice != None:
if self.voice != '':