diff --git a/src/fenrir/1ChangeTTY.opus b/src/fenrir/1ChangeTTY.opus new file mode 100644 index 00000000..e147023b Binary files /dev/null and b/src/fenrir/1ChangeTTY.opus differ diff --git a/src/fenrir/1ChangeTTY.wav b/src/fenrir/1ChangeTTY.wav new file mode 100644 index 00000000..124e213c Binary files /dev/null and b/src/fenrir/1ChangeTTY.wav differ diff --git a/src/fenrir/__init__.py b/src/fenrir/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/braille/__init__.py b/src/fenrir/braille/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/braille/braille.py b/src/fenrir/braille/braille.py new file mode 100644 index 00000000..aff4f599 --- /dev/null +++ b/src/fenrir/braille/braille.py @@ -0,0 +1,15 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class braille(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass diff --git a/src/fenrir/commands/__init__.py b/src/fenrir/commands/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/commands/command_template.py b/src/fenrir/commands/command_template.py new file mode 100644 index 00000000..25b6b1a8 --- /dev/null +++ b/src/fenrir/commands/command_template.py @@ -0,0 +1,21 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + pass + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/__init__.py b/src/fenrir/commands/commands/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/commands/commands/add_word_to_spell_check.py b/src/fenrir/commands/commands/add_word_to_spell_check.py new file mode 100644 index 00000000..ce334347 --- /dev/null +++ b/src/fenrir/commands/commands/add_word_to_spell_check.py @@ -0,0 +1,55 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = None + def initialize(self, environment): + self.env = environment + self.updateSpellLanguage() + def shutdown(self): + pass + def getDescription(self): + return 'adds the current word to the exceptions dictionary' + def updateSpellLanguage(self): + self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')) + self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') + + def run(self): + if not initialized: + self.env['runtime']['outputManager'].presentText('pychant is not installed', interrupt=True) + return + if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language: + try: + self.updateSpellLanguage() + except: + return + + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + # get the word + newContent = self.env['screenData']['newContentText'].split('\n')[cursorPos['y']] + x, y, currWord = word_utils.getCurrentWord(cursorPos['x'], 0, newContent) + + if currWord != '': + if self.spellChecker.is_added(currWord): + self.env['runtime']['outputManager'].presentText(currWord + ' is already in dict',soundIcon='Cancel', interrupt=True) + else: + self.spellChecker.add(currWord) + self.env['runtime']['outputManager'].presentText(currWord + ' added',soundIcon='Accept', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_1.py b/src/fenrir/commands/commands/bookmark_1.py new file mode 100644 index 00000000..d7426c43 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_1.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '1' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_10.py b/src/fenrir/commands/commands/bookmark_10.py new file mode 100644 index 00000000..a975772b --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_10.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '10' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_2.py b/src/fenrir/commands/commands/bookmark_2.py new file mode 100644 index 00000000..5eb9a660 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_2.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '2' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_3.py b/src/fenrir/commands/commands/bookmark_3.py new file mode 100644 index 00000000..95c521d7 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_3.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '3' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_4.py b/src/fenrir/commands/commands/bookmark_4.py new file mode 100644 index 00000000..7386f998 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_4.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '4' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_5.py b/src/fenrir/commands/commands/bookmark_5.py new file mode 100644 index 00000000..9250b058 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_5.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '5' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_6.py b/src/fenrir/commands/commands/bookmark_6.py new file mode 100644 index 00000000..0749587e --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_6.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '6' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_7.py b/src/fenrir/commands/commands/bookmark_7.py new file mode 100644 index 00000000..e680dbdf --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_7.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '7' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_8.py b/src/fenrir/commands/commands/bookmark_8.py new file mode 100644 index 00000000..d540c758 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_8.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '8' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/bookmark_9.py b/src/fenrir/commands/commands/bookmark_9.py new file mode 100644 index 00000000..a6f53387 --- /dev/null +++ b/src/fenrir/commands/commands/bookmark_9.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +from utils import line_utils + +class command(): + def __init__(self): + self.ID = '9' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'read Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText("Bookmark " + self.ID + "not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: + self.env['runtime']['outputManager'].presentText("Bookmark for application " + currApp + " not set", interrupt=True) + return + + # set marks + marked = '' + startMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'].copy() + if self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2']: + endMark = self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'].copy() + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + else: + x, y, marked = \ + line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screenData']['newContentText']) + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_1.py b/src/fenrir/commands/commands/clear_bookmark_1.py new file mode 100644 index 00000000..686b7ff0 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_1.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '1' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_10.py b/src/fenrir/commands/commands/clear_bookmark_10.py new file mode 100644 index 00000000..335a73b9 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_10.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '10' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_2.py b/src/fenrir/commands/commands/clear_bookmark_2.py new file mode 100644 index 00000000..3f6f7139 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_2.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '2' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_3.py b/src/fenrir/commands/commands/clear_bookmark_3.py new file mode 100644 index 00000000..22471fa8 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_3.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '3' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_4.py b/src/fenrir/commands/commands/clear_bookmark_4.py new file mode 100644 index 00000000..3d440a3b --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_4.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '4' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_5.py b/src/fenrir/commands/commands/clear_bookmark_5.py new file mode 100644 index 00000000..17d275bd --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_5.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '5' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_6.py b/src/fenrir/commands/commands/clear_bookmark_6.py new file mode 100644 index 00000000..d7906f01 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_6.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '6' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_7.py b/src/fenrir/commands/commands/clear_bookmark_7.py new file mode 100644 index 00000000..3a46a111 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_7.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '7' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_8.py b/src/fenrir/commands/commands/clear_bookmark_8.py new file mode 100644 index 00000000..f9ce2a31 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_8.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '8' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_bookmark_9.py b/src/fenrir/commands/commands/clear_bookmark_9.py new file mode 100644 index 00000000..79e47f39 --- /dev/null +++ b/src/fenrir/commands/commands/clear_bookmark_9.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '9' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'remove Bookmark ' + self.ID + + def run(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " removed for application " + currApp, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_clipboard.py b/src/fenrir/commands/commands/clear_clipboard.py new file mode 100644 index 00000000..8e82bfb0 --- /dev/null +++ b/src/fenrir/commands/commands/clear_clipboard.py @@ -0,0 +1,25 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'clears the currently selected clipboard' + + def run(self): + self.env['commandBuffer']['currClipboard'] = -1 + del self.env['commandBuffer']['clipboard'][:] + self.env['runtime']['outputManager'].presentText('clipboard cleared', interrupt=True) + return + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/clear_window_application.py b/src/fenrir/commands/commands/clear_window_application.py new file mode 100644 index 00000000..81d1707c --- /dev/null +++ b/src/fenrir/commands/commands/clear_window_application.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'Turn off window mode for application' + + def run(self): + if self.env['runtime']['cursorManager'].clearWindowForApplication(): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['runtime']['outputManager'].presentText('Window Mode off for application ' + currApp, interrupt=True) + else: + self.env['runtime']['outputManager'].presentText("Not in window Mode", interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/copy_marked_to_clipboard.py b/src/fenrir/commands/commands/copy_marked_to_clipboard.py new file mode 100644 index 00000000..730082fc --- /dev/null +++ b/src/fenrir/commands/commands/copy_marked_to_clipboard.py @@ -0,0 +1,43 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'copies marked text to the currently selected clipboard' + + def run(self): + if not (self.env['commandBuffer']['Marks']['1'] and \ + self.env['commandBuffer']['Marks']['2']): + self.env['runtime']['outputManager'].presentText("two marks needed", interrupt=True) + return + # use the last first and the last setted mark as range + startMark = self.env['commandBuffer']['Marks']['1'].copy() + endMark = self.env['commandBuffer']['Marks']['2'].copy() + + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + + self.env['commandBuffer']['clipboard'] = [marked] + self.env['commandBuffer']['clipboard'][:self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards') -1] + self.env['commandBuffer']['currClipboard'] = 0 + # reset marks + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_char_phonetic.py b/src/fenrir/commands/commands/curr_char_phonetic.py new file mode 100644 index 00000000..8408b41e --- /dev/null +++ b/src/fenrir/commands/commands/curr_char_phonetic.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'phonetically presents the current character' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + x, y, currChar = \ + char_utils.getCurrentChar(cursorPos['x'], cursorPos['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("blank" ,interrupt=True) + else: + currChar = char_utils.getPhonetic(currChar) + self.env['runtime']['outputManager'].presentText(currChar ,interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_clipboard.py b/src/fenrir/commands/commands/curr_clipboard.py new file mode 100644 index 00000000..d47caec0 --- /dev/null +++ b/src/fenrir/commands/commands/curr_clipboard.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'speaks the contents of the currently selected clipboard' + + def run(self): + if len(self.env['commandBuffer']['clipboard']) == 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_screen.py b/src/fenrir/commands/commands/curr_screen.py new file mode 100644 index 00000000..8a1d42b0 --- /dev/null +++ b/src/fenrir/commands/commands/curr_screen.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'reads the contents of the current screen' + + def run(self): + if self.env['screenData']['newContentText'].isspace(): + self.env['runtime']['outputManager'].presentText("screen is empty", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newContentText'],interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_screen_after_cursor.py b/src/fenrir/commands/commands/curr_screen_after_cursor.py new file mode 100644 index 00000000..7b33dff7 --- /dev/null +++ b/src/fenrir/commands/commands/curr_screen_after_cursor.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'reads from the cursor to the bottom of the screen' + + def run(self): + # Prefer review cursor over text cursor + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + textAfterCursor = mark_utils.getTextAfterMark(cursorPos, self.env['screenData']['newContentText']) + + if textAfterCursor.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(textAfterCursor, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_screen_before_cursor.py b/src/fenrir/commands/commands/curr_screen_before_cursor.py new file mode 100644 index 00000000..e9367411 --- /dev/null +++ b/src/fenrir/commands/commands/curr_screen_before_cursor.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'Reads from the top of the screen to the cursor position' + + def run(self): + # Prefer review cursor over text cursor + if self.env['screenData']['newCursorReview']: + cursorPos = self.env['screenData']['newCursorReview'].copy() + else: + cursorPos = self.env['screenData']['newCursor'].copy() + + textBeforeCursor = mark_utils.getTextBeforeMark(cursorPos, self.env['screenData']['newContentText']) + + if textBeforeCursor.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(textBeforeCursor, interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/curr_word_phonetic.py b/src/fenrir/commands/commands/curr_word_phonetic.py new file mode 100644 index 00000000..737e70c5 --- /dev/null +++ b/src/fenrir/commands/commands/curr_word_phonetic.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'phonetically spells the current word' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + x, y, currWord = \ + word_utils.getCurrentWord(cursorPos['x'], cursorPos['y'], self.env['screenData']['newContentText']) + + if currWord.isspace(): + self.env['runtime']['outputManager'].presentText("blank", interrupt=True) + else: + firstSequence = True + for c in currWord: + currChar = char_utils.getPhonetic(c) + self.env['runtime']['outputManager'].presentText(currChar, interrupt=firstSequence) + firstSequence = False + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/cursor_position.py b/src/fenrir/commands/commands/cursor_position.py new file mode 100644 index 00000000..9acc912d --- /dev/null +++ b/src/fenrir/commands/commands/cursor_position.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'displays the position of the review cursor' + + def run(self): + # Prefer review cursor over text cursor + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + self.env['runtime']['outputManager'].presentText("line "+ str(cursorPos['y']+1) + " column "+ str(cursorPos['x']+1), interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/date.py b/src/fenrir/commands/commands/date.py new file mode 100644 index 00000000..cbf3a380 --- /dev/null +++ b/src/fenrir/commands/commands/date.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import datetime + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'presents the date' + + def run(self): + dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat') + + # get the time formatted + dateString = datetime.datetime.strftime(datetime.datetime.now(), dateFormat) + + # present the time via speak and braile, there is no soundicon, interrupt the current speech + self.env['runtime']['outputManager'].presentText(dateString , soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/dec_sound_volume.py b/src/fenrir/commands/commands/dec_sound_volume.py new file mode 100644 index 00000000..1cf1a640 --- /dev/null +++ b/src/fenrir/commands/commands/dec_sound_volume.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'decrease sound volume' + + def run(self): + + value = self.env['runtime']['settingsManager'].getSettingAsFloat('sound', 'volume') + + value = round((math.ceil(10 * value) / 10) - 0.1, 2) + if value < 0.1: + value = 0.1 + self.env['runtime']['settingsManager'].setSetting('sound', 'volume', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent sound volume", soundIcon='SoundOff', interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/dec_speech_pitch.py b/src/fenrir/commands/commands/dec_speech_pitch.py new file mode 100644 index 00000000..fa818db1 --- /dev/null +++ b/src/fenrir/commands/commands/dec_speech_pitch.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'decreases the pitch of the speech' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch') + value = round((math.ceil(10 * value) / 10) - 0.1, 2) + if value < 0.0: + value = 0.0 + self.env['runtime']['settingsManager'].setSetting('speech', 'pitch', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech pitch", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/dec_speech_rate.py b/src/fenrir/commands/commands/dec_speech_rate.py new file mode 100644 index 00000000..244ba9b9 --- /dev/null +++ b/src/fenrir/commands/commands/dec_speech_rate.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'decreases the rate of the speech' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate') + value = round((math.ceil(10 * value) / 10) - 0.1, 2) + if value < 0.0: + value = 0.0 + self.env['runtime']['settingsManager'].setSetting('speech', 'rate', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech rate", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/dec_speech_volume.py b/src/fenrir/commands/commands/dec_speech_volume.py new file mode 100644 index 00000000..6ad5ba02 --- /dev/null +++ b/src/fenrir/commands/commands/dec_speech_volume.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'decreases the volume of the speech' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume') + value = round((math.ceil(10 * value) / 10) - 0.1, 2) + if value < 0.1: + value = 0.1 + self.env['runtime']['settingsManager'].setSetting('speech', 'volume', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech volume", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/exit_review.py b/src/fenrir/commands/commands/exit_review.py new file mode 100644 index 00000000..6e9c72c5 --- /dev/null +++ b/src/fenrir/commands/commands/exit_review.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'exits review mode' + + def run(self): + if not self.env['runtime']['cursorManager'].isReviewMode(): + self.env['runtime']['outputManager'].presentText("Not in review mode", interrupt=True) + return + + self.env['runtime']['cursorManager'].clearReviewCursor() + self.env['runtime']['outputManager'].presentText("leve review mode", interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/first_clipboard.py b/src/fenrir/commands/commands/first_clipboard.py new file mode 100644 index 00000000..c6cee34b --- /dev/null +++ b/src/fenrir/commands/commands/first_clipboard.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'selects the first clipboard' + + def run(self): + if len(self.env['commandBuffer']['clipboard']) == 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + self.env['commandBuffer']['currClipboard'] = 0 + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/forward_keypress.py b/src/fenrir/commands/commands/forward_keypress.py new file mode 100644 index 00000000..6aed1d65 --- /dev/null +++ b/src/fenrir/commands/commands/forward_keypress.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'sends the following keypress to the terminal' + + def run(self): + self.env['input']['keyForeward'] = 3 + self.env['runtime']['outputManager'].presentText('Foreward next keypress', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/inc_sound_volume.py b/src/fenrir/commands/commands/inc_sound_volume.py new file mode 100644 index 00000000..f3c31558 --- /dev/null +++ b/src/fenrir/commands/commands/inc_sound_volume.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'adjusts the volume for in coming sounds' + + def run(self): + + value = self.env['runtime']['settingsManager'].getSettingAsFloat('sound', 'volume') + + value = round((math.ceil(10 * value) / 10) + 0.1, 2) + if value > 1.0: + value = 1.0 + self.env['runtime']['settingsManager'].setSetting('sound', 'volume', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent sound volume", soundIcon='SoundOn', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/inc_speech_pitch.py b/src/fenrir/commands/commands/inc_speech_pitch.py new file mode 100644 index 00000000..3d99df97 --- /dev/null +++ b/src/fenrir/commands/commands/inc_speech_pitch.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'increases the pitch of the speech' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch') + value = round((math.ceil(10 * value) / 10) + 0.1, 2) + if value > 1.0: + value = 1.0 + self.env['runtime']['settingsManager'].setSetting('speech', 'pitch', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech pitch", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/inc_speech_rate.py b/src/fenrir/commands/commands/inc_speech_rate.py new file mode 100644 index 00000000..3f20ae6b --- /dev/null +++ b/src/fenrir/commands/commands/inc_speech_rate.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'increase the speech rate' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate') + value = round((math.ceil(10 * value) / 10) + 0.1, 2) + if value > 1.0: + value = 1.0 + self.env['runtime']['settingsManager'].setSetting('speech', 'rate', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech rate", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/inc_speech_volume.py b/src/fenrir/commands/commands/inc_speech_volume.py new file mode 100644 index 00000000..1ea41d32 --- /dev/null +++ b/src/fenrir/commands/commands/inc_speech_volume.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import math + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'increase the speech volume' + + def run(self): + value = self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume') + value = round((math.ceil(10 * value) / 10) + 0.1, 2) + if value > 1.0: + value = 1.0 + self.env['runtime']['settingsManager'].setSetting('speech', 'volume', str(value)) + + self.env['runtime']['outputManager'].presentText(str(int(value * 100)) + " percent speech volume", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/indent_curr_line.py b/src/fenrir/commands/commands/indent_curr_line.py new file mode 100644 index 00000000..4cfe3bdf --- /dev/null +++ b/src/fenrir/commands/commands/indent_curr_line.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'shows the indention level for the current line' + + def run(self): + # Prefer review cursor over text cursor + + if self.env['screenData']['newCursorReview']: + cursorPos = self.env['screenData']['newCursorReview'].copy() + else: + cursorPos = self.env['screenData']['newCursor'].copy() + x, y, currLine = \ + line_utils.getCurrentLine(cursorPos['x'], cursorPos['y'], self.env['screenData']['newContentText']) + + if currLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText("indent "+ str(len(currLine) - len(currLine.lstrip())), interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/last_clipboard.py b/src/fenrir/commands/commands/last_clipboard.py new file mode 100644 index 00000000..cf08b299 --- /dev/null +++ b/src/fenrir/commands/commands/last_clipboard.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'selects the last clipboard' + + def run(self): + if len(self.env['commandBuffer']['clipboard']) == 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + self.env['commandBuffer']['currClipboard'] = len(self.env['commandBuffer']['clipboard']) -1 + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/last_incoming.py b/src/fenrir/commands/commands/last_incoming.py new file mode 100644 index 00000000..84b2f46a --- /dev/null +++ b/src/fenrir/commands/commands/last_incoming.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'displays the last received text' + + def run(self): + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newDelta'], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/linux_paste_clipboard.py b/src/fenrir/commands/commands/linux_paste_clipboard.py new file mode 100644 index 00000000..88003398 --- /dev/null +++ b/src/fenrir/commands/commands/linux_paste_clipboard.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import fcntl +import termios +import time, sys + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'pastes the text from the currently selected clipboard' + + def run(self): + currClipboard = self.env['commandBuffer']['currClipboard'] + if currClipboard < 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + with open("/dev/tty" + self.env['screenData']['newTTY'], 'w') as fd: + for c in self.env['commandBuffer']['clipboard'][currClipboard]: + fcntl.ioctl(fd, termios.TIOCSTI, c) + time.sleep(0.02) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/marked_text.py b/src/fenrir/commands/commands/marked_text.py new file mode 100644 index 00000000..7e7bc323 --- /dev/null +++ b/src/fenrir/commands/commands/marked_text.py @@ -0,0 +1,38 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'speaks the currently selected text that will be copied to the clipboard' + + def run(self): + if not (self.env['commandBuffer']['Marks']['1'] and \ + self.env['commandBuffer']['Marks']['2']): + self.env['runtime']['outputManager'].presentText("please set begin and endmark", interrupt=True) + return + + # use the last first and the last setted mark as range + startMark = self.env['commandBuffer']['Marks']['1'].copy() + endMark = self.env['commandBuffer']['Marks']['2'].copy() + + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screenData']['newContentText']) + + if marked.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/next_clipboard.py b/src/fenrir/commands/commands/next_clipboard.py new file mode 100644 index 00000000..457bd9b6 --- /dev/null +++ b/src/fenrir/commands/commands/next_clipboard.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'selects the next clipboard' + + def run(self): + if len(self.env['commandBuffer']['clipboard']) == 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + self.env['commandBuffer']['currClipboard'] += 1 + if self.env['commandBuffer']['currClipboard'] > len(self.env['commandBuffer']['clipboard']) -1: + self.env['commandBuffer']['currClipboard'] = 0 + self.env['runtime']['outputManager'].presentText('First clipboard ', interrupt=True) + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=False) + else: + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/present_first_line.py b/src/fenrir/commands/commands/present_first_line.py new file mode 100644 index 00000000..40954173 --- /dev/null +++ b/src/fenrir/commands/commands/present_first_line.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'present first line' + + def run(self): + x, y, firstLine = \ + line_utils.getCurrentLine(0, 0, self.env['screenData']['newContentText']) + + if firstLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(firstLine, interrupt=True) + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/present_last_line.py b/src/fenrir/commands/commands/present_last_line.py new file mode 100644 index 00000000..f53af172 --- /dev/null +++ b/src/fenrir/commands/commands/present_last_line.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'current line' + + def run(self): + x, y, lastLine = \ + line_utils.getCurrentLine(0, self.env['screenData']['lines'] -1, self.env['screenData']['newContentText']) + + if lastLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(lastLine, interrupt=True) + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/prev_clipboard.py b/src/fenrir/commands/commands/prev_clipboard.py new file mode 100644 index 00000000..8659d662 --- /dev/null +++ b/src/fenrir/commands/commands/prev_clipboard.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'selects the previous clipboard' + + def run(self): + if len(self.env['commandBuffer']['clipboard']) == 0: + self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True) + return + self.env['commandBuffer']['currClipboard'] -= 1 + if self.env['commandBuffer']['currClipboard'] < 0: + self.env['commandBuffer']['currClipboard'] = len(self.env['commandBuffer']['clipboard']) -1 + self.env['runtime']['outputManager'].presentText('Last clipboard ', interrupt=True) + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=False) + else: + self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/quit_fenrir.py b/src/fenrir/commands/commands/quit_fenrir.py new file mode 100644 index 00000000..0be6540c --- /dev/null +++ b/src/fenrir/commands/commands/quit_fenrir.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'exits Fenrir' + + def run(self): + self.env['generalInformation']['running'] = False + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/remove_marks.py b/src/fenrir/commands/commands/remove_marks.py new file mode 100644 index 00000000..a180d853 --- /dev/null +++ b/src/fenrir/commands/commands/remove_marks.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'removes marks from selected text' + + def run(self): + self.env['runtime']['cursorManager'].clearMarks() + self.env['runtime']['outputManager'].presentText('Remove marks', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/remove_word_from_spell_check.py b/src/fenrir/commands/commands/remove_word_from_spell_check.py new file mode 100644 index 00000000..6758ef26 --- /dev/null +++ b/src/fenrir/commands/commands/remove_word_from_spell_check.py @@ -0,0 +1,55 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = None + def initialize(self, environment): + self.env = environment + self.updateSpellLanguage() + def shutdown(self): + pass + def getDescription(self): + return 'removes the current word from the exceptions dictionary' + def updateSpellLanguage(self): + self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')) + self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') + + def run(self): + if not initialized: + self.env['runtime']['outputManager'].presentText('pychant is not installed', interrupt=True) + return + if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language: + try: + self.updateSpellLanguage() + except: + return + + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + # get the word + newContent = self.env['screenData']['newContentText'].split('\n')[cursorPos['y']] + x, y, currWord = word_utils.getCurrentWord(cursorPos['x'], 0, newContent) + + if not currWord.isspace(): + if self.spellChecker.is_removed(currWord): + self.env['runtime']['outputManager'].presentText(currWord + ' is already removed from dict',soundIcon='Cancel', interrupt=True) + else: + self.spellChecker.remove(currWord) + self.env['runtime']['outputManager'].presentText(currWord + ' removed',soundIcon='Accept', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_bottom.py b/src/fenrir/commands/commands/review_bottom.py new file mode 100644 index 00000000..acc05f88 --- /dev/null +++ b/src/fenrir/commands/commands/review_bottom.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'move review to bottom of screen' + + def run(self): + self.env['screenData']['newCursorReview'] = { 'x': 0, 'y':self.env['screenData']['lines'] -1} + self.env['runtime']['outputManager'].presentText("Bottom", interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_curr_char.py b/src/fenrir/commands/commands/review_curr_char.py new file mode 100644 index 00000000..993f5929 --- /dev/null +++ b/src/fenrir/commands/commands/review_curr_char.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'presents the current character.' + + def run(self): + self.env['runtime']['cursorManager'].enterReviewModeCurrTextCursor() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getCurrentChar(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("blank" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_curr_line.py b/src/fenrir/commands/commands/review_curr_line.py new file mode 100644 index 00000000..6d8c9c19 --- /dev/null +++ b/src/fenrir/commands/commands/review_curr_line.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'current line' + + def run(self): + self.env['runtime']['cursorManager'].enterReviewModeCurrTextCursor() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getCurrentLine(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currLine, interrupt=True) + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/commands/review_curr_word.py b/src/fenrir/commands/commands/review_curr_word.py new file mode 100644 index 00000000..0d657a6b --- /dev/null +++ b/src/fenrir/commands/commands/review_curr_word.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'current word.' + + def run(self): + self.env['runtime']['cursorManager'].enterReviewModeCurrTextCursor() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getCurrentWord(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currWord.isspace(): + self.env['runtime']['outputManager'].presentText("blank", interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_down.py b/src/fenrir/commands/commands/review_down.py new file mode 100644 index 00000000..bea47c06 --- /dev/null +++ b/src/fenrir/commands/commands/review_down.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to end of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], downChar = \ + char_utils.getDownChar(self.env['screenData']['newCursorReview']['x'],self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + if downChar.isspace(): + self.env['runtime']['outputManager'].presentText("line is empty" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(downChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_line_begin.py b/src/fenrir/commands/commands/review_line_begin.py new file mode 100644 index 00000000..e69c0a37 --- /dev/null +++ b/src/fenrir/commands/commands/review_line_begin.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to begin of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['runtime']['cursorManager'].setReviewCursorPosition(0 ,cursorPos['y']) + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getCurrentChar(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("blank" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + self.env['runtime']['outputManager'].presentText("beginning of line", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_line_end.py b/src/fenrir/commands/commands/review_line_end.py new file mode 100644 index 00000000..9bb30561 --- /dev/null +++ b/src/fenrir/commands/commands/review_line_end.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to end of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['runtime']['cursorManager'].setReviewCursorPosition(self.env['screenData']['columns']-1 ,cursorPos['y']) + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getCurrentChar(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("space" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + self.env['runtime']['outputManager'].presentText("end of line", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_line_last_char.py b/src/fenrir/commands/commands/review_line_last_char.py new file mode 100644 index 00000000..bb405abd --- /dev/null +++ b/src/fenrir/commands/commands/review_line_last_char.py @@ -0,0 +1,33 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to end of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['runtime']['cursorManager'].setReviewCursorPosition(self.env['screenData']['columns']-1 ,cursorPos['y']) + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], lastChar = \ + char_utils.getLastCharInLine(self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if lastChar.isspace(): + self.env['runtime']['outputManager'].presentText("line is empty" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(lastChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + self.env['runtime']['outputManager'].presentText("last char in line", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_next_char.py b/src/fenrir/commands/commands/review_next_char.py new file mode 100644 index 00000000..aa74a972 --- /dev/null +++ b/src/fenrir/commands/commands/review_next_char.py @@ -0,0 +1,34 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review to the next character and presents it' + + def run(self): + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + if not self.env['screenData']['newCursorReview']: + self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getNextChar(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("space", interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_next_line.py b/src/fenrir/commands/commands/review_next_line.py new file mode 100644 index 00000000..94966046 --- /dev/null +++ b/src/fenrir/commands/commands/review_next_line.py @@ -0,0 +1,34 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review to the next line and presents it' + + def run(self): + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + if not self.env['screenData']['newCursorReview']: + self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getNextLine(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currLine, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_next_word.py b/src/fenrir/commands/commands/review_next_word.py new file mode 100644 index 00000000..c41c6f5d --- /dev/null +++ b/src/fenrir/commands/commands/review_next_word.py @@ -0,0 +1,34 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review to the next word and presents it' + + def run(self): + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + if self.env['screenData']['newCursorReview'] == None: + self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getNextWord(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currWord.isspace(): + self.env['runtime']['outputManager'].presentText("blank", interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_prev_char.py b/src/fenrir/commands/commands/review_prev_char.py new file mode 100644 index 00000000..6cfb8705 --- /dev/null +++ b/src/fenrir/commands/commands/review_prev_char.py @@ -0,0 +1,34 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review to the previous character and presents it' + + def run(self): + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + if not self.env['screenData']['newCursorReview']: + self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currChar = \ + char_utils.getPrevChar(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currChar.isspace(): + self.env['runtime']['outputManager'].presentText("space", interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_prev_line.py b/src/fenrir/commands/commands/review_prev_line.py new file mode 100644 index 00000000..16d1f135 --- /dev/null +++ b/src/fenrir/commands/commands/review_prev_line.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import line_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review to the previous line and presents it' + + def run(self): + self.env['runtime']['cursorManager'].enterReviewModeCurrTextCursor() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currLine = \ + line_utils.getPrevLine(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currLine, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_prev_word.py b/src/fenrir/commands/commands/review_prev_word.py new file mode 100644 index 00000000..2085492b --- /dev/null +++ b/src/fenrir/commands/commands/review_prev_word.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'moves review focus to the previous word and presents it' + + def run(self): + self.env['runtime']['cursorManager'].enterReviewModeCurrTextCursor() + + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], currWord = \ + word_utils.getPrevWord(self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + + if currWord.isspace(): + self.env['runtime']['outputManager'].presentText("blank", interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_top.py b/src/fenrir/commands/commands/review_top.py new file mode 100644 index 00000000..b48f7308 --- /dev/null +++ b/src/fenrir/commands/commands/review_top.py @@ -0,0 +1,25 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'move review to top of screen' + + def run(self): + self.env['screenData']['newCursorReview'] = {'x':0,'y':0} + self.env['runtime']['outputManager'].presentText("Top", interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/review_up.py b/src/fenrir/commands/commands/review_up.py new file mode 100644 index 00000000..9637f9e2 --- /dev/null +++ b/src/fenrir/commands/commands/review_up.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import char_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set review cursor to end of current line and display the content' + + def run(self): + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + self.env['screenData']['newCursorReview']['x'], self.env['screenData']['newCursorReview']['y'], upChar = \ + char_utils.getUpChar(self.env['screenData']['newCursorReview']['x'],self.env['screenData']['newCursorReview']['y'], self.env['screenData']['newContentText']) + if upChar.isspace(): + self.env['runtime']['outputManager'].presentText("line is empty" ,interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(upChar ,interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_1.py b/src/fenrir/commands/commands/set_bookmark_1.py new file mode 100644 index 00000000..a5582b5c --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_1.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '1' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_10.py b/src/fenrir/commands/commands/set_bookmark_10.py new file mode 100644 index 00000000..1e51729a --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_10.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '10' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_2.py b/src/fenrir/commands/commands/set_bookmark_2.py new file mode 100644 index 00000000..8087700e --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_2.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '2' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_3.py b/src/fenrir/commands/commands/set_bookmark_3.py new file mode 100644 index 00000000..ee00d310 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_3.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '3' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_4.py b/src/fenrir/commands/commands/set_bookmark_4.py new file mode 100644 index 00000000..b983b418 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_4.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '4' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_5.py b/src/fenrir/commands/commands/set_bookmark_5.py new file mode 100644 index 00000000..10dbb868 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_5.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '5' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_6.py b/src/fenrir/commands/commands/set_bookmark_6.py new file mode 100644 index 00000000..43979791 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_6.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '6' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_7.py b/src/fenrir/commands/commands/set_bookmark_7.py new file mode 100644 index 00000000..6fbbcbbc --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_7.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '7' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_8.py b/src/fenrir/commands/commands/set_bookmark_8.py new file mode 100644 index 00000000..dd87c7f4 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_8.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '8' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_bookmark_9.py b/src/fenrir/commands/commands/set_bookmark_9.py new file mode 100644 index 00000000..5136e375 --- /dev/null +++ b/src/fenrir/commands/commands/set_bookmark_9.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + self.ID = '9' + def initialize(self, environment): + self.env = environment + self.env['commandBuffer']['bookMarks'][self.ID] = {} + def shutdown(self): + pass + def getDescription(self): + return 'set Bookmark ' + self.ID + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText("No Mark found", interrupt=True) + return + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['commandBuffer']['bookMarks'][self.ID][currApp] = {} + + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1'] = self.env['commandBuffer']['Marks']['1'].copy() + if self.env['commandBuffer']['Marks']['2']: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = self.env['commandBuffer']['Marks']['2'].copy() + else: + self.env['commandBuffer']['bookMarks'][self.ID][currApp]['2'] = None + self.env['runtime']['outputManager'].presentText('Bookmark ' + self.ID + " set for application " + currApp, interrupt=True) + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_mark.py b/src/fenrir/commands/commands/set_mark.py new file mode 100644 index 00000000..fd25ba99 --- /dev/null +++ b/src/fenrir/commands/commands/set_mark.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'places marks to select text to copy to the clipboard' + + def run(self): + if not self.env['runtime']['cursorManager'].isReviewMode(): + self.env['runtime']['outputManager'].presentText('no review cursor', interrupt=True) + return + + self.env['runtime']['cursorManager'].setMark() + self.env['runtime']['outputManager'].presentText('set mark', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/set_window_application.py b/src/fenrir/commands/commands/set_window_application.py new file mode 100644 index 00000000..61940b31 --- /dev/null +++ b/src/fenrir/commands/commands/set_window_application.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'set Window Mode, needs 2 marks ' + + def run(self): + if self.env['runtime']['cursorManager'].setWindowForApplication(): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + self.env['runtime']['outputManager'].presentText('Window Mode on for application ' + currApp, interrupt=True) + self.env['runtime']['cursorManager'].clearMarks() + else: + self.env['runtime']['outputManager'].presentText("Set window beginn and end marks", interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/shut_up.py b/src/fenrir/commands/commands/shut_up.py new file mode 100644 index 00000000..f9060aee --- /dev/null +++ b/src/fenrir/commands/commands/shut_up.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'interrupts the current presentation' + def run(self): + if len(self.env['input']['prevDeepestInput']) > len(self.env['input']['currInput']): + return + self.env['runtime']['outputManager'].interruptOutput() + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/spell_check.py b/src/fenrir/commands/commands/spell_check.py new file mode 100644 index 00000000..363b8624 --- /dev/null +++ b/src/fenrir/commands/commands/spell_check.py @@ -0,0 +1,53 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = None + def initialize(self, environment): + self.env = environment + self.updateSpellLanguage() + def shutdown(self): + pass + def getDescription(self): + return 'checks the spelling of the current word' + def updateSpellLanguage(self): + self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')) + self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') + + def run(self): + if not initialized: + self.env['runtime']['outputManager'].presentText('pychant is not installed', interrupt=True) + return + if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language: + try: + self.updateSpellLanguage() + except: + return + + cursorPos = self.env['runtime']['cursorManager'].getReviewOrTextCursor() + + # get the word + newContent = self.env['screenData']['newContentText'].split('\n')[cursorPos['y']] + x, y, currWord = word_utils.getCurrentWord(cursorPos['x'], 0, newContent) + + if not currWord.isspace(): + if not self.spellChecker.check(currWord): + self.env['runtime']['outputManager'].presentText('misspelled',soundIcon='mispell', interrupt=True) + elif not ignore: + self.env['runtime']['outputManager'].presentText('correct',soundIcon='', interrupt=True) + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/time.py b/src/fenrir/commands/commands/time.py new file mode 100644 index 00000000..f34e9c04 --- /dev/null +++ b/src/fenrir/commands/commands/time.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import datetime + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'presents the time' + + def run(self): + timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat') + + # get the time formatted + timeString = datetime.datetime.strftime(datetime.datetime.now(), timeFormat) + + # present the time via speak and braile, there is no soundicon, interrupt the current speech + self.env['runtime']['outputManager'].presentText(timeString , soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_auto_read.py b/src/fenrir/commands/commands/toggle_auto_read.py new file mode 100644 index 00000000..3090e2b2 --- /dev/null +++ b/src/fenrir/commands/commands/toggle_auto_read.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'enables or disables automatic reading of new text as it appears' + + def run(self): + self.env['runtime']['settingsManager'].setSetting('speech', 'autoReadIncoming', str(not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'autoReadIncoming'))) + if self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'autoReadIncoming'): + self.env['runtime']['outputManager'].presentText("autoread enabled", soundIcon='', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText("autoread disabled", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_auto_spell_check.py b/src/fenrir/commands/commands/toggle_auto_spell_check.py new file mode 100644 index 00000000..3e6028c3 --- /dev/null +++ b/src/fenrir/commands/commands/toggle_auto_spell_check.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'enables or disables automatic spell checking' + + def run(self): + self.env['runtime']['settingsManager'].setSetting('general', 'autoSpellCheck', str(not self.env['runtime']['settingsManager'].getSettingAsBool('general', 'autoSpellCheck'))) + if self.env['runtime']['settingsManager'].getSettingAsBool('general', 'autoSpellCheck'): + self.env['runtime']['outputManager'].presentText("auto spellcheck enabled", soundIcon='', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText("auto spellcheck disabled", soundIcon='', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_braille.py b/src/fenrir/commands/commands/toggle_braille.py new file mode 100644 index 00000000..9aed3436 --- /dev/null +++ b/src/fenrir/commands/commands/toggle_braille.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'enables and disables output in braille' + + def run(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'): + self.env['runtime']['outputManager'].presentText("braille disabled", soundIcon='BrailleOff', interrupt=True) + self.env['runtime']['settingsManager'].setSetting('braille', 'enabled', str(not self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'))) + if self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'): + self.env['runtime']['outputManager'].presentText("braille enabled", soundIcon='BrailleOn', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_output.py b/src/fenrir/commands/commands/toggle_output.py new file mode 100644 index 00000000..95708651 --- /dev/null +++ b/src/fenrir/commands/commands/toggle_output.py @@ -0,0 +1,34 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'toggles all output settings' + + def run(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled') or \ + self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled') or \ + self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'): + self.env['runtime']['outputManager'].presentText("fenrir muted", soundIcon='Accept', interrupt=True) + self.env['runtime']['settingsManager'].setSetting('speech', 'enabled','False') + self.env['runtime']['settingsManager'].setSetting('sound', 'enabled','False') + self.env['runtime']['settingsManager'].setSetting('braille', 'enabled','False') + else: + self.env['runtime']['settingsManager'].setSetting('speech', 'enabled','True') + self.env['runtime']['settingsManager'].setSetting('sound', 'enabled','True') + self.env['runtime']['settingsManager'].setSetting('braille', 'enabled','True') + self.env['runtime']['outputManager'].presentText("fenrir unmuted", soundIcon='Cancel', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_punctuation_level.py b/src/fenrir/commands/commands/toggle_punctuation_level.py new file mode 100644 index 00000000..ab43a10b --- /dev/null +++ b/src/fenrir/commands/commands/toggle_punctuation_level.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return '' + + def run(self): + self.env['runtime']['punctuationManager'].cyclePunctuation() + self.env['runtime']['outputManager'].presentText(self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel'), interrupt=True, ignorePunctuation=True) + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_sound.py b/src/fenrir/commands/commands/toggle_sound.py new file mode 100644 index 00000000..bc7c5a8a --- /dev/null +++ b/src/fenrir/commands/commands/toggle_sound.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'enables or disables sound' + + def run(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'): + self.env['runtime']['outputManager'].presentText("sound disabled", soundIcon='SoundOff', interrupt=True) + self.env['runtime']['settingsManager'].setSetting('sound', 'enabled', str(not self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'))) + if self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'): + self.env['runtime']['outputManager'].presentText("sound enabled", soundIcon='SoundOn', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_speech.py b/src/fenrir/commands/commands/toggle_speech.py new file mode 100644 index 00000000..971c957e --- /dev/null +++ b/src/fenrir/commands/commands/toggle_speech.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'enables or disables speech' + + def run(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'): + self.env['runtime']['outputManager'].presentText("speech disabled", soundIcon='SpeechOff', interrupt=True) + self.env['runtime']['settingsManager'].setSetting('speech', 'enabled', str(not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'))) + if self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'): + self.env['runtime']['outputManager'].presentText("speech enabled", soundIcon='SpeechOn', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/toggle_tutorial_mode.py b/src/fenrir/commands/commands/toggle_tutorial_mode.py new file mode 100644 index 00000000..e5ad15c8 --- /dev/null +++ b/src/fenrir/commands/commands/toggle_tutorial_mode.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + self.env['generalInformation']['tutorialMode'] = False + return 'You are leving the tutorial mode. Press that shortcut again to enter the tutorial mode again.' + + def run(self): + text = 'you entered the tutorial mode. In that mode the commands are not executed. but you get a description of what the shortcut does. To leve the tutorial mode, press that shortcut again.' + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + self.env['generalInformation']['tutorialMode'] = True + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onApplicationChange/test.py b/src/fenrir/commands/onApplicationChange/test.py new file mode 100644 index 00000000..ca4d74b6 --- /dev/null +++ b/src/fenrir/commands/onApplicationChange/test.py @@ -0,0 +1,25 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + #print('new ', self.env['screenData']['newApplication']) + #print('old ', self.env['screenData']['oldApplication']) + #print('-----------') + pass + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/10000-shut_up.py b/src/fenrir/commands/onInput/10000-shut_up.py new file mode 100644 index 00000000..09c47165 --- /dev/null +++ b/src/fenrir/commands/onInput/10000-shut_up.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return '' + + def run(self): + if self.env['runtime']['inputManager'].noKeyPressed(): + return + if len(self.env['input']['prevDeepestInput']) > len(self.env['input']['currInput']): + return + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'interruptOnKeyPress'): + return + if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: + return + self.env['runtime']['outputManager'].interruptOutput() + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py b/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py new file mode 100644 index 00000000..bb7bc291 --- /dev/null +++ b/src/fenrir/commands/onInput/45000-present_char_if_cursor_change_horizontal.py @@ -0,0 +1,38 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return '' + + def run(self): + if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + # detect an change on the screen, we just want to cursor arround, so no change should appear + if self.env['screenData']['newDelta'] != '': + return + if self.env['screenData']['newNegativeDelta'] != '': + return + # is it a horizontal change? + if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y'] or\ + self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: + return + currChar = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']][self.env['screenData']['newCursor']['x']] + if not currChar.isspace(): + self.env['runtime']['outputManager'].presentText(currChar, interrupt=True, ignorePunctuation=True, announceCapital=True) + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onInput/50000-char_echo.py b/src/fenrir/commands/onInput/50000-char_echo.py new file mode 100644 index 00000000..528b6530 --- /dev/null +++ b/src/fenrir/commands/onInput/50000-char_echo.py @@ -0,0 +1,37 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charEcho'): + return + # detect deletion or chilling + if self.env['screenData']['newCursor']['x'] <= self.env['screenData']['oldCursor']['x']: + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + # is there any change? + if self.env['screenData']['newDelta'] == '': + return + # big changes are no char (but the value is bigger than one maybe the differ needs longer than you can type, so a little strange random buffer for now) + if len(self.env['screenData']['newDelta']) > 3: + return + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newDelta'], interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py b/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py new file mode 100644 index 00000000..da0800f7 --- /dev/null +++ b/src/fenrir/commands/onInput/55000-present_line_if_cursor_change_vertical.py @@ -0,0 +1,38 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return '' + + def run(self): + if self.env['runtime']['inputManager'].noKeyPressed(): + return + if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: + return + if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']: + return + if self.env['screenData']['newCursor']['y'] == self.env['screenData']['oldCursor']['y']: + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + currLine = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] + if currLine.isspace(): + self.env['runtime']['outputManager'].presentText("blank", soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(currLine, interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onInput/60000-word_echo.py b/src/fenrir/commands/onInput/60000-word_echo.py new file mode 100644 index 00000000..7474e410 --- /dev/null +++ b/src/fenrir/commands/onInput/60000-word_echo.py @@ -0,0 +1,56 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'wordEcho'): + return + + # just when cursor move worddetection is needed + if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + # for now no new line + if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: + return + if len(self.env['screenData']['newDelta']) > 1: + return + + # first place could not be the end of a word + if self.env['screenData']['newCursor']['x'] == 0: + return + + # get the word + newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] + x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent) + # was this a typed word? + if self.env['screenData']['newDelta'] != '': + if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']): + return + else: + # or just arrow arround? + if not(newContent[self.env['screenData']['newCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['newCursor']['x']): + return + + if currWord != '': + self.env['runtime']['outputManager'].presentText(currWord, interrupt=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onInput/62000-spell_check.py b/src/fenrir/commands/onInput/62000-spell_check.py new file mode 100644 index 00000000..087c37fd --- /dev/null +++ b/src/fenrir/commands/onInput/62000-spell_check.py @@ -0,0 +1,122 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import word_utils +import os + +initialized = False +try: + import enchant + initialized = True +except: + pass + +class command(): + def __init__(self): + self.language = '' + self.spellChecker = '' + def initialize(self, environment): + self.env = environment + self.updateSpellLanguage() + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def updateSpellLanguage(self): + self.spellChecker = enchant.Dict(self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage')) + self.language = self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('general', 'autoSpellCheck'): + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + if not initialized: + return + if self.env['runtime']['settingsManager'].getSetting('general', 'spellCheckLanguage') != self.language: + try: + self.updateSpellLanguage() + except: + return + + # just when cursor move worddetection is needed + if self.env['screenData']['newCursor']['x'] == self.env['screenData']['oldCursor']['x']: + return + + # for now no new line + if self.env['screenData']['newCursor']['y'] != self.env['screenData']['oldCursor']['y']: + return + if len(self.env['screenData']['newDelta']) > 1: + return + if self.env['screenData']['newNegativeDelta'] != '': + return + # first place could not be the end of a word + if self.env['screenData']['newCursor']['x'] == 0: + return + + # get the word + newContent = self.env['screenData']['newContentText'].split('\n')[self.env['screenData']['newCursor']['y']] + x, y, currWord = word_utils.getCurrentWord(self.env['screenData']['newCursor']['x'], 0, newContent) + # was this a typed word? + if self.env['screenData']['newDelta'] != '': + if not(newContent[self.env['screenData']['oldCursor']['x']].strip(" \t\n") == '' and x != self.env['screenData']['oldCursor']['x']): + return + else: + # or just arrow arround? + if not(newContent[self.env['screenData']['newCursor']['x']].isspace() and x != self.env['screenData']['newCursor']['x']): + return + + # ignore empty + if currWord[0] =='': + return + # ignore bash buildins + if currWord in ['cd','fg','bg','alias','bind','dir','caller','buildin','command','declare','echo','enable','help','let','local','logout',\ + 'mapfile','printf','read','readarray','source','type','typeset','ulimit','unalias']: + return + # ignore the application name + if currWord.upper() == 'FENRIR': + return + if currWord[0] =='-': + return + if currWord[0] == '/': + return + if currWord[0] == '#': + return + if currWord.startswith('./'): + return + if '@' in currWord and '.' in currWord: + return + if currWord[0] == '@': + return + if currWord.isnumeric(): + return + if currWord.isdecimal(): + return + if currWord.isspace(): + return + + try: + if os.path.exists("/bin/"+currWord): + return + except: + pass + try: + if os.path.exists("/usr/bin/"+currWord): + return + except: + pass + try: + if os.path.exists("/sbin/"+currWord): + return + except: + pass + if not self.spellChecker.check(currWord): + self.env['runtime']['outputManager'].presentText('misspelled',soundIcon='mispell', interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/65000-char_delete_echo.py b/src/fenrir/commands/onInput/65000-char_delete_echo.py new file mode 100644 index 00000000..4b20a094 --- /dev/null +++ b/src/fenrir/commands/onInput/65000-char_delete_echo.py @@ -0,0 +1,44 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'charDeleteEcho'): + return + + # detect typing or chilling + if self.env['screenData']['newCursor']['x'] >= self.env['screenData']['oldCursor']['x']: + return + + # More than just a deletion happend + if self.env['screenData']['newDelta'].strip() != '': + if self.env['screenData']['newDelta'] != self.env['screenData']['oldDelta']: + return + if self.env['runtime']['inputManager'].noKeyPressed(): + return + # No deletion + if self.env['screenData']['newNegativeDelta'] == '': + return + # too much for a single backspace... + if len(self.env['screenData']['newNegativeDelta']) >= 5: + return + + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newNegativeDelta'], interrupt=True, ignorePunctuation=True, announceCapital=True) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onInput/80000-capslock.py b/src/fenrir/commands/onInput/80000-capslock.py new file mode 100644 index 00000000..411df45d --- /dev/null +++ b/src/fenrir/commands/onInput/80000-capslock.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + if self.env['input']['oldCapsLock'] == self.env['input']['newCapsLock']: + return + if self.env['input']['newCapsLock']: + self.env['runtime']['outputManager'].presentText("Capslock on", interrupt=False) + else: + self.env['runtime']['outputManager'].presentText("Capslock off", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/80300-scrolllock.py b/src/fenrir/commands/onInput/80300-scrolllock.py new file mode 100644 index 00000000..0e6ec67c --- /dev/null +++ b/src/fenrir/commands/onInput/80300-scrolllock.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + if self.env['input']['oldScrollLock'] == self.env['input']['newScrollLock']: + return + if self.env['input']['newScrollLock']: + self.env['runtime']['outputManager'].presentText("Scrolllock on", interrupt=False) + else: + self.env['runtime']['outputManager'].presentText("Scrolllock off", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/80500-numlock.py b/src/fenrir/commands/onInput/80500-numlock.py new file mode 100644 index 00000000..a2ebbc54 --- /dev/null +++ b/src/fenrir/commands/onInput/80500-numlock.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + if self.env['input']['oldNumLock'] == self.env['input']['newNumLock']: + return + if self.env['input']['newNumLock']: + self.env['runtime']['outputManager'].presentText("Numlock on", interrupt=False) + else: + self.env['runtime']['outputManager'].presentText("Numlock off", interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onInput/__init__.py b/src/fenrir/commands/onInput/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/commands/onScreenChanged/10000-shut_up.py b/src/fenrir/commands/onScreenChanged/10000-shut_up.py new file mode 100644 index 00000000..6e18eb70 --- /dev/null +++ b/src/fenrir/commands/onScreenChanged/10000-shut_up.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return '' + + def run(self): + + self.env['runtime']['outputManager'].interruptOutput() + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onScreenChanged/80000-screen_change_announcement.py b/src/fenrir/commands/onScreenChanged/80000-screen_change_announcement.py new file mode 100644 index 00000000..39b473bd --- /dev/null +++ b/src/fenrir/commands/onScreenChanged/80000-screen_change_announcement.py @@ -0,0 +1,25 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + self.env['runtime']['outputManager'].presentText("screen " + str(self.env['screenData']['newTTY']),soundIcon='ChangeTTY', interrupt=True) + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newContentText'], interrupt=False) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_marks.py b/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_marks.py new file mode 100644 index 00000000..ff7cab4b --- /dev/null +++ b/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_marks.py @@ -0,0 +1,25 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_review.py b/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_review.py new file mode 100644 index 00000000..b63b0d5a --- /dev/null +++ b/src/fenrir/commands/onScreenChanged/85000-screen_chnage_reset_review.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + self.env['runtime']['cursorManager'].clearReviewCursor() + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onScreenChanged/89000-screen_chnage_leve_review_mode.py b/src/fenrir/commands/onScreenChanged/89000-screen_chnage_leve_review_mode.py new file mode 100644 index 00000000..b0b6147a --- /dev/null +++ b/src/fenrir/commands/onScreenChanged/89000-screen_chnage_leve_review_mode.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + self.env['runtime']['cursorManager'].clearMarks() + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onScreenChanged/__init__.py b/src/fenrir/commands/onScreenChanged/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/commands/onScreenUpdate/70000-incoming.py b/src/fenrir/commands/onScreenUpdate/70000-incoming.py new file mode 100644 index 00000000..317b9444 --- /dev/null +++ b/src/fenrir/commands/onScreenUpdate/70000-incoming.py @@ -0,0 +1,35 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'autoReadIncoming'): + return + # is there something to read? + if self.env['screenData']['newDelta'] == '': + return + + # its a cursor movement (experimental) - maybe also check current shortcut string? + if abs(self.env['screenData']['newCursor']['x'] - self.env['screenData']['oldCursor']['x']) >= 1: + if len(self.env['screenData']['newDelta']) <= 5: + return + + self.env['runtime']['outputManager'].presentText(self.env['screenData']['newDelta'], interrupt=False) + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onScreenUpdate/75000-incoming_promote.py b/src/fenrir/commands/onScreenUpdate/75000-incoming_promote.py new file mode 100644 index 00000000..3ec3f43b --- /dev/null +++ b/src/fenrir/commands/onScreenUpdate/75000-incoming_promote.py @@ -0,0 +1,39 @@ +#!/bin/python +import time +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No Description found' + + def run(self): + if not self.env['runtime']['settingsManager'].getSettingAsBool('promote', 'enabled'): + return + if self.env['runtime']['settingsManager'].getSetting('promote', 'list').strip(" \t\n") == '': + return + if self.env['screenData']['newDelta'] == '': + return + if int(time.time() - self.env['input']['lastInputTime']) < self.env['runtime']['settingsManager'].getSettingAsInt('promote', 'inactiveTimeoutSec'): + return + if len(self.env['runtime']['settingsManager'].getSetting('promote', 'list')) == 0: + return + for promote in self.env['runtime']['settingsManager'].getSetting('promote', 'list').split(','): + if promote in self.env['screenData']['newDelta']: + self.env['runtime']['outputManager'].playSoundIcon('PromotedText') + self.env['input']['lastInputTime'] = time.time() + return + + def setCallback(self, callback): + pass + diff --git a/src/fenrir/commands/onScreenUpdate/__init__.py b/src/fenrir/commands/onScreenUpdate/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/commands/onSwitchApplicationProfile/__init__.py b/src/fenrir/commands/onSwitchApplicationProfile/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/fenrir/commands/onSwitchApplicationProfile/agetty.py b/src/fenrir/commands/onSwitchApplicationProfile/agetty.py new file mode 100644 index 00000000..dbd5250d --- /dev/null +++ b/src/fenrir/commands/onSwitchApplicationProfile/agetty.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('agetty') + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('agetty') + print('unload old',self.env['screenData']['oldApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onSwitchApplicationProfile/bash.py b/src/fenrir/commands/onSwitchApplicationProfile/bash.py new file mode 100644 index 00000000..d82b6e9d --- /dev/null +++ b/src/fenrir/commands/onSwitchApplicationProfile/bash.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('bash') + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('bash') + print('unload old',self.env['screenData']['oldApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onSwitchApplicationProfile/default.py b/src/fenrir/commands/onSwitchApplicationProfile/default.py new file mode 100644 index 00000000..40255936 --- /dev/null +++ b/src/fenrir/commands/onSwitchApplicationProfile/default.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('default') + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('default') + print('unload old',self.env['screenData']['oldApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/onSwitchApplicationProfile/vim.py b/src/fenrir/commands/onSwitchApplicationProfile/vim.py new file mode 100644 index 00000000..74ae0c40 --- /dev/null +++ b/src/fenrir/commands/onSwitchApplicationProfile/vim.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def load(self): + print('--------------') + print('vim') + print('load new',self.env['screenData']['newApplication']) + print('--------------') + + def unload(self): + print('--------------') + print('vim') + print('unload old',self.env['screenData']['oldApplication']) + print('--------------') + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/switchTrigger_template.py b/src/fenrir/commands/switchTrigger_template.py new file mode 100644 index 00000000..8efbea56 --- /dev/null +++ b/src/fenrir/commands/switchTrigger_template.py @@ -0,0 +1,23 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def unload(self): + pass + def load(self): + pass + def setCallback(self, callback): + pass diff --git a/src/fenrir/core/__init__.py b/src/fenrir/core/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/core/applicationManager.py b/src/fenrir/core/applicationManager.py new file mode 100644 index 00000000..8f127b88 --- /dev/null +++ b/src/fenrir/core/applicationManager.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class applicationManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getCurrentApplication(self): + currApp = self.env['screenData']['newApplication'].upper() + if not currApp: + currApp == 'DEFAULT' + if currApp == '': + currApp == 'DEFAULT' + return currApp + def getPrevApplication(self): + prevApp = self.env['screenData']['oldApplication'].upper() + if not prevApp: + prevApp == 'DEFAULT' + if prevApp == '': + prevApp == 'DEFAULT' + return prevApp + def isApplicationChange(self): + return self.env['screenData']['oldApplication'] != self.env['screenData']['newApplication'] diff --git a/src/fenrir/core/commandManager.py b/src/fenrir/core/commandManager.py new file mode 100644 index 00000000..423e79ed --- /dev/null +++ b/src/fenrir/core/commandManager.py @@ -0,0 +1,127 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import importlib.util +import glob, os, time +from core import debug + +class commandManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.env['runtime']['commandManager'].loadCommands('commands') + self.env['runtime']['commandManager'].loadCommands('onInput') + self.env['runtime']['commandManager'].loadCommands('onScreenUpdate') + self.env['runtime']['commandManager'].loadCommands('onScreenChanged') + self.env['runtime']['commandManager'].loadCommands('onApplicationChange') + self.env['runtime']['commandManager'].loadCommands('onSwitchApplicationProfile') + + def shutdown(self): + self.env['runtime']['commandManager'].shutdownCommands('commands') + self.env['runtime']['commandManager'].shutdownCommands('onInput') + self.env['runtime']['commandManager'].shutdownCommands('onScreenUpdate') + self.env['runtime']['commandManager'].shutdownCommands('onScreenChanged') + self.env['runtime']['commandManager'].shutdownCommands('onApplicationChange') + self.env['runtime']['commandManager'].shutdownCommands('onSwitchApplicationProfile') + + def loadCommands(self, section='commands'): + commandFolder = "commands/" + section +"/" + commandList = glob.glob(commandFolder+'*') + for command in commandList: + try: + fileName, fileExtension = os.path.splitext(command) + fileName = fileName.split('/')[-1] + if fileName in ['__init__','__pycache__']: + continue + if fileExtension.lower() == '.py': + spec = importlib.util.spec_from_file_location(fileName, command) + command_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(command_mod) + self.env['commands'][section][fileName.upper()] = command_mod.command() + self.env['commands'][section][fileName.upper()].initialize(self.env) + self.env['runtime']['debug'].writeDebugOut("Load command:" + section + "." + fileName.upper() ,debug.debugLevel.INFO) + + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + continue + + def shutdownCommands(self, section): + for command in sorted(self.env['commands'][section]): + try: + self.env['commands'][section][command].shutdown() + del self.env['commands'][section][command] + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Shutdown command:" + section + "." + command ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + continue + + def executeSwitchTrigger(self, trigger, unLoadScript, loadScript): + if self.env['runtime']['screenManager'].isSuspendingScreen(): + return + #unload + oldScript = unLoadScript + if self.commandExists(oldScript, trigger): + try: + self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.unload:" + trigger + "." + oldScript ,debug.debugLevel.INFO) + self.env['commands'][trigger][oldScript].unload() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + oldScript ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + #load + newScript = loadScript + if self.commandExists(newScript, trigger): + try: + self.env['runtime']['debug'].writeDebugOut("Executing switchtrigger.load:" + trigger + "." + newScript ,debug.debugLevel.INFO) + self.env['commands'][trigger][newScript].load() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + newScript ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def executeDefaultTrigger(self, trigger): + if self.env['runtime']['screenManager'].isSuspendingScreen(): + return + for command in sorted(self.env['commands'][trigger]): + if self.commandExists(command, trigger): + try: + self.env['runtime']['debug'].writeDebugOut("Executing trigger.command:" + trigger + "." + command ,debug.debugLevel.INFO) + self.env['commands'][trigger][command].run() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + command ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def executeCommand(self, command, section = 'commands'): + if self.env['runtime']['screenManager'].isSuspendingScreen(): + return + if self.commandExists(command, section): + try: + if self.env['generalInformation']['tutorialMode']: + self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO) + description = self.env['commands'][section][command].getDescription() + self.env['runtime']['outputManager'].presentText(description, interrupt=True) + else: + self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.INFO) + self.env['commands'][section][command].run() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + self.clearCommandQueued() + self.env['commandInfo']['lastCommandExecutionTime'] = time.time() + + def isCommandQueued(self): + return self.env['commandInfo']['currCommand'] != '' + + def clearCommandQueued(self): + self.env['commandInfo']['currCommand'] = '' + + def queueCommand(self, command): + if command == '': + return + self.env['commandInfo']['currCommand'] = command + + def commandExists(self, command, section = 'commands'): + return( command in self.env['commands'][section]) diff --git a/src/fenrir/core/commands.py b/src/fenrir/core/commands.py new file mode 100644 index 00000000..3e8ead6a --- /dev/null +++ b/src/fenrir/core/commands.py @@ -0,0 +1,45 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time + + +# used as shared memory between commands +# use this in your own commands +commandBuffer = { +'genericList':[], +'genericListSource':'', +'genericListSelection': 0, +'clipboard':[], +'currClipboard': 0, +'Marks':{'1':None, '2':None}, +'bookMarks':{}, +'windowArea':{}, +} + +# used by the commandManager +commandInfo = { +'currCommand': '', +'lastCommandExecutionTime': time.time(), +'lastCommandRequestTime': time.time(), +} + +# used by the commandManager +commands = { +'onInput':{ + }, +'onScreenChanged':{ + }, +'onScreenUpdate':{ + }, +'onApplicationChange':{ + }, +'commands':{ + }, +'onSwitchApplicationProfile':{ + }, +} diff --git a/src/fenrir/core/cursorManager.py b/src/fenrir/core/cursorManager.py new file mode 100644 index 00000000..30ccb21c --- /dev/null +++ b/src/fenrir/core/cursorManager.py @@ -0,0 +1,87 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class cursorManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def clearMarks(self): + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + def isMarkSet(self): + return self.env['commandBuffer']['Marks']['1'] != None + def isSingleMark(self): + return self.env['commandBuffer']['Marks']['1'] != None and \ + self.env['commandBuffer']['Marks']['2'] == None + def isMultibleMark(self): + return self.env['commandBuffer']['Marks']['1'] != None and \ + self.env['commandBuffer']['Marks']['2'] != None + def setMark(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['commandBuffer']['Marks']['1'] = self.env['screenData']['newCursorReview'].copy() + else: + self.env['commandBuffer']['Marks']['2'] = self.env['screenData']['newCursorReview'].copy() + def getReviewOrTextCursor(self): + if self.env['screenData']['newCursorReview']: + return self.env['screenData']['newCursorReview'].copy() + else: + return self.env['screenData']['newCursor'].copy() + def clearReviewCursor(self): + if not self.isReviewMode(): + return + self.env['screenData']['oldCursorReview'] = None + self.env['screenData']['newCursorReview'] = None + + def isReviewMode(self): + return self.env['screenData']['newCursorReview'] != None + def enterReviewModeCurrTextCursor(self, overwrite=False): + if self.isReviewMode() and not overwrite: + return + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + if not self.env['screenData']['newCursorReview']: + self.env['screenData']['newCursorReview'] = self.env['screenData']['newCursor'].copy() + def setReviewCursorPosition(self, x, y): + if not self.isReviewMode(): + self.enterReviewModeCurrTextCursor() + self.env['screenData']['oldCursorReview'] = self.env['screenData']['newCursorReview'] + self.env['screenData']['newCursorReview']['x'] = x + self.env['screenData']['newCursorReview']['y'] = y + def isApplicationWindowSet(self): + try: + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + if self.env['commandBuffer']['windowArea'][currApp]['1'] != None: + return True + except: + pass + return False + def setWindowForApplication(self): + if not self.env['commandBuffer']['Marks']['1']: + return False + if not self.env['commandBuffer']['Marks']['2']: + return False + 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() + 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() + return True + def clearWindowForApplication(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + try: + del self.env['commandBuffer']['windowArea'][currApp] + except: + return False + return True diff --git a/src/fenrir/core/debug.py b/src/fenrir/core/debug.py new file mode 100644 index 00000000..9b64b035 --- /dev/null +++ b/src/fenrir/core/debug.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# Debugger module for the Fenrir screen reader. + +from enum import Enum +from datetime import datetime + +class debugLevel(Enum): + DEACTIVE = 0 + ERROR = 1 + WARNING = 2 + INFO = 3 + def __int__(self): + return self.value + def __str__(self): + return self.name + +class debug(): + def __init__(self, fileName='/var/log/fenrir.log'): + self._fileName = fileName + self._file = None + self._fileOpened = False + def initialize(self, environment): + self.env = environment + def shutdown(self): + self.closeDebugFile() + def __del__(self): + try: + self.shutdown() + except: + pass + + def openDebugFile(self, fileName = ''): + self._fileOpened = False + if fileName != '': + self._fileName = fileName + if self._fileName != '': + self._file = open(self._fileName,'a') + self._fileOpened = True + + def writeDebugOut(self, text, level = debugLevel.DEACTIVE): + if self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') < int(level): + if self._fileOpened: + self.closeDebugFile() + return + else: + if not self._fileOpened: + self.openDebugFile() + msg = str(level) +' ' + str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') +) + ': ' + text + print(msg) + self._file.write(msg + '\n') + + + def closeDebugFile(self): + if not self._fileOpened: + return False + if self._file != None: + self._file.close() + self._fileOpened = False + return True + + def getDebugFile(self): + return self._fileName + + def setDebugFile(self, fileName): + self.closeDebugFile() + self._fileName = fileName diff --git a/src/fenrir/core/environment.py b/src/fenrir/core/environment.py new file mode 100644 index 00000000..ba768a91 --- /dev/null +++ b/src/fenrir/core/environment.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from core import settings +from core import runtime +from core import screenData +from core import generalInformation +from core import commands +from core import inputEvent + +environment = { +'screenData': screenData.screenData, +'runtime': runtime.runtime, +'generalInformation': generalInformation.generalInformation, +'settings': settings.settings, +'commands': commands.commands, +'commandInfo': commands.commandInfo, +'commandBuffer': commands.commandBuffer, +'input': inputEvent.input, +'soundIcons': {}, +'bindings': {}, +} diff --git a/src/fenrir/core/generalInformation.py b/src/fenrir/core/generalInformation.py new file mode 100644 index 00000000..2a0c6013 --- /dev/null +++ b/src/fenrir/core/generalInformation.py @@ -0,0 +1,12 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +generalInformation = { +'running': True, +'tutorialMode': False, +} diff --git a/src/fenrir/core/inputEvent.py b/src/fenrir/core/inputEvent.py new file mode 100644 index 00000000..583aeab5 --- /dev/null +++ b/src/fenrir/core/inputEvent.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time + +input = { +'currInput': [], +'prevDeepestInput': [], +'eventBuffer': [], +'shortcutRepeat': 0, +'fenrirKey': ['KEY_KP0'], +'keyForeward': 0, +'lastInputTime':time.time(), +'oldNumLock': True, +'newNumLock':True, +'oldScrollLock': True, +'newScrollLock':True, +'oldCapsLock':False, +'newCapsLock':False +} + +inputEvent = { +'EventName': '', +'EventValue': '', +'EventSec': 0, +'EventUsec': 0, +'EventState': 0, +} diff --git a/src/fenrir/core/inputManager.py b/src/fenrir/core/inputManager.py new file mode 100644 index 00000000..ed3d4445 --- /dev/null +++ b/src/fenrir/core/inputManager.py @@ -0,0 +1,156 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import time +from core import debug +from core import inputEvent + +class inputManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.env['runtime']['settingsManager'].loadDriver(\ + self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver') + # init LEDs with current state + self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() + self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] + self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() + self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] + self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() + self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] + self.grabDevices() + + def shutdown(self): + self.env['runtime']['inputManager'].releaseDevices() + self.env['runtime']['settingsManager'].shutdownDriver('inputDriver') + + def getInputEvent(self): + eventReceived = False + mEvent = self.env['runtime']['inputDriver'].getInputEvent() + if mEvent: + mEvent['EventName'] = self.convertEventName(mEvent['EventName']) + eventReceived = True + if mEvent['EventState'] == 0: + if mEvent['EventName'] in self.env['input']['currInput']: + self.env['input']['currInput'].remove(mEvent['EventName']) + if len(self.env['input']['currInput']) > 1: + self.env['input']['currInput'] = sorted(self.env['input']['currInput']) + if len(self.env['input']['currInput']) == 0: + self.env['input']['prevDeepestInput'] = [] + self.env['input']['shortcutRepeat'] = 1 + elif mEvent['EventState'] == 1: + if not mEvent['EventName'] in self.env['input']['currInput']: + self.env['input']['currInput'].append(mEvent['EventName']) + if len(self.env['input']['currInput']) > 1: + self.env['input']['currInput'] = sorted(self.env['input']['currInput']) + if len(self.env['input']['prevDeepestInput']) < len(self.env['input']['currInput']): + self.env['input']['prevDeepestInput'] = self.env['input']['currInput'].copy() + elif self.env['input']['prevDeepestInput'] == self.env['input']['currInput']: + self.env['input']['shortcutRepeat'] += 1 + + elif mEvent['EventState'] == 2: + pass + else: + pass + self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] + self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() + self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] + self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() + self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] + self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() + self.env['input']['lastInputTime'] = time.time() + return eventReceived + + def grabDevices(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + self.env['runtime']['inputDriver'].grabDevices() + + def releaseDevices(self): + try: + self.env['runtime']['inputDriver'].releaseDevices() + except: + pass + + def convertEventName(self, eventName): + if not eventName: + return '' + if eventName == '': + return '' + eventName = eventName.upper() + if eventName == 'KEY_LEFTCTRL': + eventName = 'KEY_CTRL' + elif eventName == 'KEY_RIGHTCTRL': + eventName = 'KEY_CTRL' + elif eventName == 'KEY_LEFTSHIFT': + eventName = 'KEY_SHIFT' + elif eventName == 'KEY_RIGHTSHIFT': + eventName = 'KEY_SHIFT' + elif eventName == 'KEY_LEFTALT': + eventName = 'KEY_ALT' + elif eventName == 'KEY_RIGHTALT': + eventName = 'KEY_ALT' + elif eventName == 'KEY_LEFTMETA': + eventName = 'KEY_META' + elif eventName == 'KEY_RIGHTMETA': + eventName = 'KEY_META' + if self.isFenrirKey(eventName): + eventName = 'KEY_FENRIR' + return eventName + + def isConsumeInput(self): + return self.env['runtime']['commandManager'].isCommandQueued() and \ + not self.env['input']['keyForeward'] + #and + # not (self.env['input']['keyForeward'] or \ + # self.env['runtime']['settingsManager'].getSettingAsBool(, 'keyboard', 'grabDevices')) + + def clearEventBuffer(self): + self.env['runtime']['inputDriver'].clearEventBuffer() + + def writeEventBuffer(self): + try: + if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + self.env['runtime']['inputDriver'].writeEventBuffer() + time.sleep(0.005) + self.clearEventBuffer() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Error while writeUInput",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def isFenrirKeyPressed(self): + return 'KEY_FENRIR' in self.env['input']['currInput'] + + def noKeyPressed(self): + return self.env['input']['currInput'] == [] + + def getPrevDeepestInput(self): + shortcut = [] + shortcut.append(self.env['input']['shortcutRepeat']) + shortcut.append(self.env['input']['prevDeepestInput']) + + def getPrevShortcut(self): + shortcut = [] + shortcut.append(self.env['input']['shortcutRepeat']) + shortcut.append(self.env['input']['prevInput']) + return str(shortcut) + + def getCurrShortcut(self): + shortcut = [] + shortcut.append(self.env['input']['shortcutRepeat']) + shortcut.append(self.env['input']['currInput']) + return str(shortcut) + + def isFenrirKey(self, eventName): + return eventName in self.env['input']['fenrirKey'] + + def getCommandForShortcut(self, shortcut): + if not self.shortcutExists(shortcut): + return '' + return self.env['bindings'][shortcut] + + def shortcutExists(self, shortcut): + return(shortcut in self.env['bindings']) diff --git a/src/fenrir/core/outputManager.py b/src/fenrir/core/outputManager.py new file mode 100644 index 00000000..d9544005 --- /dev/null +++ b/src/fenrir/core/outputManager.py @@ -0,0 +1,123 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import string + +class outputManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.env['runtime']['settingsManager'].loadDriver(\ + self.env['runtime']['settingsManager'].getSetting('speech', 'driver'), 'speechDriver') + self.env['runtime']['settingsManager'].loadDriver(\ + self.env['runtime']['settingsManager'].getSetting('sound', 'driver'), 'soundDriver') + + def shutdown(self): + self.env['runtime']['settingsManager'].shutdownDriver('soundDriver') + self.env['runtime']['settingsManager'].shutdownDriver('speechDriver') + + def presentText(self, text, interrupt=True, soundIcon = '', ignorePunctuation=False, announceCapital=False): + self.env['runtime']['debug'].writeDebugOut("presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO) + if self.playSoundIcon(soundIcon, interrupt): + self.env['runtime']['debug'].writeDebugOut("soundIcon found" ,debug.debugLevel.INFO) + return + toAnnounceCapital = announceCapital and len(text.strip(' \n\t')) == 1 and text.strip(' \n\t').isupper() + if toAnnounceCapital: + if self.playSoundIcon('capital', False): + toAnnounceCapital = False + + self.speakText(text, interrupt, ignorePunctuation,toAnnounceCapital) + self.brailleText(text, interrupt) + + def speakText(self, text, interrupt=True, ignorePunctuation=False, announceCapital=False): + if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'): + self.env['runtime']['debug'].writeDebugOut("Speech disabled in outputManager.speakText",debug.debugLevel.INFO) + return + if self.env['runtime']['speechDriver'] == None: + self.env['runtime']['debug'].writeDebugOut("No speechDriver in outputManager.speakText",debug.debugLevel.ERROR) + return + if interrupt: + self.interruptOutput() + try: + self.env['runtime']['speechDriver'].setLanguage(self.env['runtime']['settingsManager'].getSetting('speech', 'language')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("setting speech language in outputManager.speakText",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + self.env['runtime']['speechDriver'].setVoice(self.env['runtime']['settingsManager'].getSetting('speech', 'voice')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("Error while setting speech voice in outputManager.speakText",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + if announceCapital: + self.env['runtime']['speechDriver'].setPitch(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'capitalPitch')) + else: + self.env['runtime']['speechDriver'].setPitch(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + self.env['runtime']['speechDriver'].setRate(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("setting speech rate in outputManager.speakText",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + self.env['runtime']['speechDriver'].setModule(self.env['runtime']['settingsManager'].getSetting('speech', 'module')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("setting speech module in outputManager.speakText",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + self.env['runtime']['speechDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume')) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + try: + text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation) + self.env['runtime']['speechDriver'].speak(text) + self.env['runtime']['debug'].writeDebugOut("Speak: "+ text,debug.debugLevel.INFO) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("\"speak\" in outputManager.speakText ",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def brailleText(self, text, interrupt=True): + if not self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'): + return + if self.env['runtime']['brailleDriver'] == None: + return + print('braille:'+text) + + def interruptOutput(self): + self.env['runtime']['speechDriver'].cancel() + self.env['runtime']['debug'].writeDebugOut("Interrupt speech",debug.debugLevel.INFO) + + + def playSoundIcon(self, soundIcon = '', interrupt=True): + if soundIcon == '': + return False + soundIcon = soundIcon.upper() + if not self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'): + self.env['runtime']['debug'].writeDebugOut("Sound disabled in outputManager.speakText",debug.debugLevel.INFO) + return False + + if self.env['runtime']['soundDriver'] == None: + self.env['runtime']['debug'].writeDebugOut("No speechDriver in outputManager.speakText",debug.debugLevel.ERROR) + return False + try: + self.env['runtime']['soundDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('sound', 'volume')) + self.env['runtime']['soundDriver'].playSoundFile(self.env['soundIcons'][soundIcon], interrupt) + return True + except Exception as e: + self.env['runtime']['debug'].writeDebugOut("\"playSoundIcon\" in outputManager.speakText ",debug.debugLevel.ERROR) + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + return False diff --git a/src/fenrir/core/punctuationManager.py b/src/fenrir/core/punctuationManager.py new file mode 100644 index 00000000..2755b516 --- /dev/null +++ b/src/fenrir/core/punctuationManager.py @@ -0,0 +1,110 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import string +from core import debug + +class punctuationManager(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.allPunctNone = dict.fromkeys(map(ord, string.punctuation), ' ') + # replace with space: + # dot, comma, grave, apostrophe + for char in [ord('.'),ord(','),ord('`'),ord("'")]: + self.allPunctNone[char] = None + self.punctuation = { + 'levels':{ + 'none': '', + 'some': '#-$~+*-/\\@', + 'most': '.,:-$~+*-/\\@!#%^&*()[]}{<>;', + 'all': string.punctuation, + }, + 'punctuationDict':{ + '&':'and', + "'":"apostrophe", + '@':'at', + '\\':'backslash', + '|':'bar', + '!':'bang', + '^':'carrot', + ':':'colon', + ',':'comma', + '-':'dash', + '$':'dollar', + '.':'dot', + '>':'greater', + '`':'grave', + '#':'hash', + '{':'left brace', + '[':'left bracket', + '(':'left paren', + '<':'less', + '%':'percent', + '+':'plus', + '?':'question', + '"':'quote', + ')':'right paren', + '}':'right brace', + ']':'right bracket', + ';':'semicolon', + '/':'slash', + '*':'star', + '~':'tilde', + '_':'line', + '=':'equals', + }, + 'customDict':{ + ':)':'smiley', + ';)':'winking face', + 'XD':'loool', + ':@':'angry face', + ':D':'lought' + } + } + def shutdown(self): + pass + def removeUnused(self, text): + return text.translate(self.allPunctNone) + + def useCustomDict(self, text, customDict): + resultText = str(text) + if customDict: + for key,item in customDict.items(): + resultText = resultText.replace(str(key),str(item)) + return resultText + def usePunctuationDict(self, text, punctuationDict, punctuation): + resultText = str(text) + + if punctuationDict and punctuation and punctuation != '': + for key,item in punctuationDict.items(): + if key in punctuation: + resultText = resultText.replace(str(key),' ' +str(item) +' ') + return resultText + + def proceedPunctuation(self, text, ignorePunctuation=False): + resultText = self.useCustomDict(text, self.punctuation['customDict']) + currPunctLevel = '' + if not ignorePunctuation and self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower() in self.punctuation['levels']: + currPunctLevel = self.punctuation['levels'][self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()] + else: + currPunctLevel = string.punctuation + resultText = self.usePunctuationDict(resultText, self.punctuation['punctuationDict'], currPunctLevel) + resultText = self.removeUnused(resultText) + return resultText + + def cyclePunctuation(self): + punctList = list(self.punctuation['levels'].keys()) + try: + currIndex = punctList.index(self.env['runtime']['settingsManager'].getSetting('general', 'punctuationLevel').lower()) # curr punctuation + except: + return + currIndex += 1 + if currIndex >= len(punctList): + currIndex = 0 + currLevel = punctList[currIndex] + self.env['runtime']['settingsManager'].setSetting('general', currLevel.lower()) diff --git a/src/fenrir/core/runtime.py b/src/fenrir/core/runtime.py new file mode 100644 index 00000000..ad192bf6 --- /dev/null +++ b/src/fenrir/core/runtime.py @@ -0,0 +1,20 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +runtime = { +'speechDriver': None, +'screenDriver': None, +'soundDriver': None, +'inputDriver': None, +'brailleDriver': None, +'inputManager': None, +'commandManager': None, +'screenManager': None, +'outputManager': None, +'debug':None, +} diff --git a/src/fenrir/core/screenData.py b/src/fenrir/core/screenData.py new file mode 100644 index 00000000..28c43bda --- /dev/null +++ b/src/fenrir/core/screenData.py @@ -0,0 +1,32 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time + +screenData = { +'columns': 0, +'lines': 0, +'oldDelta': '', +'oldNegativeDelta': '', +'oldCursorReview':None, +'oldCursor':{'x':0,'y':0}, +'oldContentBytes': b'', +'oldContentText': '', +'oldContentAttrib': b'', +'oldApplication': '', +'oldTTY':'-1', +'newDelta': '', +'newNegativeDelta': '', +'newCursorReview':None, +'newCursor':{'x':0,'y':0}, +'newContentBytes': b'', +'newContentText': '', +'newContentAttrib': b'', +'newTTY':'0', +'newApplication': '', +'lastScreenUpdate': time.time() +} diff --git a/src/fenrir/core/screenManager.py b/src/fenrir/core/screenManager.py new file mode 100644 index 00000000..406f5ec4 --- /dev/null +++ b/src/fenrir/core/screenManager.py @@ -0,0 +1,51 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time + +class screenManager(): + def __init__(self): + self.autoIgnoreScreens = [] + + def initialize(self, environment): + self.env = environment + self.env['runtime']['settingsManager'].loadDriver(\ + self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver') + if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'): + self.autoIgnoreScreens = self.env['runtime']['screenDriver'].getIgnoreScreens() + + def shutdown(self): + self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') + + def update(self, trigger='onUpdate'): + self.env['runtime']['screenDriver'].getCurrScreen() + self.env['screenData']['oldApplication'] = self.env['screenData']['newApplication'] + if not self.isSuspendingScreen(): + self.env['runtime']['screenDriver'].update(trigger) + if trigger == 'onUpdate' or self.isScreenChange() or len(self.env['screenData']['newDelta']) > 6: + self.env['runtime']['screenDriver'].getCurrApplication() + self.env['screenData']['lastScreenUpdate'] = time.time() + + def isSuspendingScreen(self): + return ((self.env['screenData']['newTTY'] in \ + self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen').split(',')) or + (self.env['screenData']['newTTY'] in self.autoIgnoreScreens)) + + def isScreenChange(self): + return self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY'] + + def getWindowAreaInText(self, text): + if not self.env['runtime']['cursorManager'].isApplicationWindowSet(): + return text + windowText = '' + windowList = text.split('\n') + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + windowList = windowList[self.env['commandBuffer']['windowArea'][currApp]['1']['y']:self.env['commandBuffer']['windowArea'][currApp]['2']['y'] + 1] + for line in windowList: + windowText += line[self.env['commandBuffer']['windowArea'][currApp]['1']['x']:self.env['commandBuffer']['windowArea'][currApp]['2']['x'] + 1] + '\n' + return windowText + diff --git a/src/fenrir/core/settings.py b/src/fenrir/core/settings.py new file mode 100644 index 00000000..7e97843f --- /dev/null +++ b/src/fenrir/core/settings.py @@ -0,0 +1,68 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +settings = { +'sound': { + 'enabled': True, + 'driver': 'generic', + 'theme': 'default', + 'volume': 1.0, + 'genericPlayFileCommand': 'play -q -v fenrirVolume fenrirSoundFile', + 'genericFrequencyCommand': 'play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence' +}, +'speech':{ + 'enabled': True, + 'driver': 'speechd', + 'rate': 0.75, + 'pitch': 0.5, + 'capitalPitch':0.8, + 'volume': 1.0, + 'module': '', + 'voice': 'de', + 'language': 'de', + 'autoReadIncoming': True, +}, +'braille':{ + 'enabled': False, + 'layout': 'en', +}, +'screen':{ + 'driver': 'linux', + 'encoding': 'cp850', + 'screenUpdateDelay': 0.4, + 'suspendingScreen': '', + 'autodetectSuspendingScreen': False, +}, +'general':{ + 'debugLevel': debug.debugLevel.DEACTIVE, + 'punctuationLevel': 1, + 'numberOfClipboards': 10, + 'fenrirKeys': ['KEY_KP0'], + 'timeFormat': '%I:%M%P', + 'dateFormat': '%A, %B %d, %Y', + 'autoSpellCheck': False, + 'spellCheckLanguage': 'en_US', +}, +'promote':{ + 'enabled': True, + 'inactiveTimeoutSec': 120, + 'list': '', +}, +'keyboard':{ + 'driver': 'evdev', + 'device': 'all', + 'grabDevices': True, + 'ignoreShortcuts': False, + 'keyboardLayout': "desktop", + 'charEcho': False, + 'charDeleteEcho': True, + 'wordEcho': True, + 'interruptOnKeyPress': True, + 'doubleTapDelay': 0.2, +} +} diff --git a/src/fenrir/core/settingsManager.py b/src/fenrir/core/settingsManager.py new file mode 100644 index 00000000..1d404aef --- /dev/null +++ b/src/fenrir/core/settingsManager.py @@ -0,0 +1,214 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import importlib.util +import os +from configparser import ConfigParser +from core import inputManager +from core import outputManager +from core import commandManager +from core import screenManager +from core import punctuationManager +from core import cursorManager +from core import applicationManager +from core import environment +from core.settings import settings +from core import debug + +class settingsManager(): + def __init__(self): + self.settings = settings + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def loadShortcuts(self, kbConfigPath='../../config/keyboard/desktop.conf'): + kbConfig = open(kbConfigPath,"r") + while(True): + line = kbConfig.readline() + if not line: + break + line = line.replace('\n','') + if line.replace(" ","").startswith("#"): + continue + if line.count("=") != 1: + continue + sepLine = line.split('=') + commandName = sepLine[1].upper() + sepLine[0] = sepLine[0].replace(" ","") + sepLine[0] = sepLine[0].replace("'","") + sepLine[0] = sepLine[0].replace('"',"") + keys = sepLine[0].split(',') + shortcutKeys = [] + shortcutRepeat = 1 + shortcut = [] + for key in keys: + try: + shortcutRepeat = int(key) + except: + shortcutKeys.append(key.upper()) + shortcut.append(shortcutRepeat) + shortcut.append(sorted(shortcutKeys)) + self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO) + self.env['bindings'][str(shortcut)] = commandName + kbConfig.close() + + def loadSoundIcons(self, soundIconPath): + siConfig = open(soundIconPath + '/soundicons.conf',"r") + while(True): + line = siConfig.readline() + if not line: + break + line = line.replace('\n','') + if line.replace(" ","").startswith("#"): + continue + if line.count("=") != 1: + continue + Values = line.split('=') + soundIcon = Values[0].upper() + Values[1] = Values[1].replace("'","") + Values[1] = Values[1].replace('"',"") + soundIconFile = '' + if os.path.exists(Values[1]): + soundIconFile = Values[1] + else: + if not soundIconPath.endswith("/"): + soundIconPath += '/' + if os.path.exists(soundIconPath + Values[1]): + soundIconFile = soundIconPath + Values[1] + self.env['soundIcons'][soundIcon] = soundIconFile + siConfig.close() + + def loadSettings(self, settingConfigPath): + if not os.path.exists(settingConfigPath): + return False + self.env['settings'] = ConfigParser() + self.env['settings'].read(settingConfigPath) + return True + + def setSetting(self, section, setting, value): + self.env['settings'].set(section, setting, value) + + def getSetting(self, section, setting): + value = '' + try: + value = self.env['settings'].get(section, setting) + except: + value = str(self.settings[section][setting]) + return value + + def getSettingAsInt(self, section, setting): + value = 0 + try: + value = self.env['settings'].getint(section, setting) + except: + value = self.settings[section][setting] + return value + + def getSettingAsFloat(self, section, setting): + value = 0.0 + try: + value = self.env['settings'].getfloat(section, setting) + except: + value = self.settings[section][setting] + return value + + def getSettingAsBool(self, section, setting): + value = False + try: + value = self.env['settings'].getboolean(section, setting) + except: + value = self.settings[section][setting] + return value + + def loadDriver(self, driverName, driverType): + if self.env['runtime'][driverType] != None: + print('shutdown %s',driverType) + self.env['runtime'][driverType].shutdown(self.env) + spec = importlib.util.spec_from_file_location(driverName, driverType + '/' + driverName + '.py') + driver_mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(driver_mod) + self.env['runtime'][driverType] = driver_mod.driver() + self.env['runtime'][driverType].initialize(self.env) + + def shutdownDriver(self, driverType): + if self.env['runtime'][driverType] == None: + return + self.env['runtime'][driverType].shutdown() + del self.env['runtime'][driverType] + + def setFenrirKeys(self, keys): + keys = keys.upper() + keyList = keys.split(',') + for key in keyList: + if not key in self.env['input']['fenrirKey']: + self.env['input']['fenrirKey'].append(key) + + def keyIDasString(self, key): + try: + KeyID = self.getCodeForKeyID(key) + return str(KeyID) + except: + return '' + + def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/', settingsFile='settings.conf'): + environment['runtime']['debug'] = debug.debug() + environment['runtime']['debug'].initialize(environment) + if not os.path.exists(settingsRoot): + if os.path.exists('../../config/'): + settingsRoot = '../../config/' + else: + return None + + environment['runtime']['settingsManager'] = self + environment['runtime']['settingsManager'].initialize(environment) + + validConfig = environment['runtime']['settingsManager'].loadSettings(settingsRoot + '/settings/' + settingsFile) + if not validConfig: + return None + self.setFenrirKeys(self.getSetting('general','fenrirKeys')) + if not os.path.exists(self.getSetting('keyboard','keyboardLayout')): + if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')): + self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')) + environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) + if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf'): + self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf') + environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) + else: + environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) + + if not os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'): + if os.path.exists(settingsRoot + 'sound/'+ self.getSetting('sound','theme')): + self.setSetting('sound', 'theme', settingsRoot + 'sound/'+ self.getSetting('sound','theme')) + if os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'): + environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme')) + else: + environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme')) + + environment['runtime']['inputManager'] = inputManager.inputManager() + environment['runtime']['inputManager'].initialize(environment) + environment['runtime']['outputManager'] = outputManager.outputManager() + environment['runtime']['outputManager'].initialize(environment) + environment['runtime']['commandManager'] = commandManager.commandManager() + environment['runtime']['commandManager'].initialize(environment) + environment['runtime']['punctuationManager'] = punctuationManager.punctuationManager() + environment['runtime']['punctuationManager'].initialize(environment) + environment['runtime']['cursorManager'] = cursorManager.cursorManager() + environment['runtime']['cursorManager'].initialize(environment) + environment['runtime']['applicationManager'] = applicationManager.applicationManager() + environment['runtime']['applicationManager'].initialize(environment) + + if environment['runtime']['screenManager'] == None: + environment['runtime']['screenManager'] = screenManager.screenManager() + environment['runtime']['screenManager'].initialize(environment) + + environment['runtime']['debug'].writeDebugOut('\/-------environment-------\/',debug.debugLevel.ERROR) + environment['runtime']['debug'].writeDebugOut(str(environment),debug.debugLevel.ERROR) + environment['runtime']['debug'].writeDebugOut('\/-------settings.conf-------\/',debug.debugLevel.ERROR) + environment['runtime']['debug'].writeDebugOut(str(environment['settings']._sections +),debug.debugLevel.ERROR) + return environment + diff --git a/src/fenrir/fenrir.egg-info/PKG-INFO b/src/fenrir/fenrir.egg-info/PKG-INFO new file mode 100644 index 00000000..972b1420 --- /dev/null +++ b/src/fenrir/fenrir.egg-info/PKG-INFO @@ -0,0 +1,39 @@ +Metadata-Version: 1.0 +Name: fenrir +Version: 0.1 +Summary: An TTy Screen Reader For Linux. +Home-page: https://github.com/chrys87/fenrir/ +Author: Chrys and others +Author-email: chrys@web.de +License: UNKNOWN +Description: # fenrir (Alfa) + An TTY screenreader for Linux. + Its an early alpha version. You can test it. It is not recommended for production use. If you want to help just let me know. + + # requirements + - linux + - python3 + - python-espeak + - python-evdev + - loaded uinput kernel module + Read permission to the following files: + /sys/devices/virtual/tty/tty0/active + /dev/vcsa[1-64] + ReadWrite permission + /dev/input + /dev/uinput + + # optional + - sox [its used by default in the generic sound driver for playing sound-icons] + - speech-dispatcher, python3-speechd [to use the speech-dispatcher driver] + - brltty, python-brlapi [for using braille] # (not implemented yet) + - gstreamer [for soundicons via gstreamer] # not working yet + - python-pyenchant for spell check functionality + + # installation + Currently there is no setupscript (sorry). But you can just run as root or setup needed permission + cd src/fenrir-package/ + sudo ./fenrir.py + Settings are located in the config directory. + +Platform: UNKNOWN diff --git a/src/fenrir/fenrir.egg-info/SOURCES.txt b/src/fenrir/fenrir.egg-info/SOURCES.txt new file mode 100644 index 00000000..ff6855fd --- /dev/null +++ b/src/fenrir/fenrir.egg-info/SOURCES.txt @@ -0,0 +1,168 @@ +setup.py +src/fenrir-package/braille/__init__.py +src/fenrir-package/braille/braille.py +src/fenrir-package/commands/__init__.py +src/fenrir-package/commands/command_template.py +src/fenrir-package/commands/switchTrigger_template.py +src/fenrir-package/commands/commands/__init__.py +src/fenrir-package/commands/commands/add_word_to_spell_check.py +src/fenrir-package/commands/commands/bookmark_1.py +src/fenrir-package/commands/commands/bookmark_10.py +src/fenrir-package/commands/commands/bookmark_2.py +src/fenrir-package/commands/commands/bookmark_3.py +src/fenrir-package/commands/commands/bookmark_4.py +src/fenrir-package/commands/commands/bookmark_5.py +src/fenrir-package/commands/commands/bookmark_6.py +src/fenrir-package/commands/commands/bookmark_7.py +src/fenrir-package/commands/commands/bookmark_8.py +src/fenrir-package/commands/commands/bookmark_9.py +src/fenrir-package/commands/commands/clear_bookmark_1.py +src/fenrir-package/commands/commands/clear_bookmark_10.py +src/fenrir-package/commands/commands/clear_bookmark_2.py +src/fenrir-package/commands/commands/clear_bookmark_3.py +src/fenrir-package/commands/commands/clear_bookmark_4.py +src/fenrir-package/commands/commands/clear_bookmark_5.py +src/fenrir-package/commands/commands/clear_bookmark_6.py +src/fenrir-package/commands/commands/clear_bookmark_7.py +src/fenrir-package/commands/commands/clear_bookmark_8.py +src/fenrir-package/commands/commands/clear_bookmark_9.py +src/fenrir-package/commands/commands/clear_clipboard.py +src/fenrir-package/commands/commands/clear_window_application.py +src/fenrir-package/commands/commands/copy_marked_to_clipboard.py +src/fenrir-package/commands/commands/curr_char_phonetic.py +src/fenrir-package/commands/commands/curr_clipboard.py +src/fenrir-package/commands/commands/curr_screen.py +src/fenrir-package/commands/commands/curr_screen_after_cursor.py +src/fenrir-package/commands/commands/curr_screen_before_cursor.py +src/fenrir-package/commands/commands/curr_word_phonetic.py +src/fenrir-package/commands/commands/cursor_position.py +src/fenrir-package/commands/commands/date.py +src/fenrir-package/commands/commands/dec_sound_volume.py +src/fenrir-package/commands/commands/dec_speech_pitch.py +src/fenrir-package/commands/commands/dec_speech_rate.py +src/fenrir-package/commands/commands/dec_speech_volume.py +src/fenrir-package/commands/commands/exit_review.py +src/fenrir-package/commands/commands/first_clipboard.py +src/fenrir-package/commands/commands/forward_keypress.py +src/fenrir-package/commands/commands/inc_sound_volume.py +src/fenrir-package/commands/commands/inc_speech_pitch.py +src/fenrir-package/commands/commands/inc_speech_rate.py +src/fenrir-package/commands/commands/inc_speech_volume.py +src/fenrir-package/commands/commands/indent_curr_line.py +src/fenrir-package/commands/commands/last_clipboard.py +src/fenrir-package/commands/commands/last_incoming.py +src/fenrir-package/commands/commands/linux_paste_clipboard.py +src/fenrir-package/commands/commands/marked_text.py +src/fenrir-package/commands/commands/next_clipboard.py +src/fenrir-package/commands/commands/present_first_line.py +src/fenrir-package/commands/commands/present_last_line.py +src/fenrir-package/commands/commands/prev_clipboard.py +src/fenrir-package/commands/commands/quit_fenrir.py +src/fenrir-package/commands/commands/remove_marks.py +src/fenrir-package/commands/commands/remove_word_from_spell_check.py +src/fenrir-package/commands/commands/review_bottom.py +src/fenrir-package/commands/commands/review_curr_char.py +src/fenrir-package/commands/commands/review_curr_line.py +src/fenrir-package/commands/commands/review_curr_word.py +src/fenrir-package/commands/commands/review_down.py +src/fenrir-package/commands/commands/review_line_begin.py +src/fenrir-package/commands/commands/review_line_end.py +src/fenrir-package/commands/commands/review_line_last_char.py +src/fenrir-package/commands/commands/review_next_char.py +src/fenrir-package/commands/commands/review_next_line.py +src/fenrir-package/commands/commands/review_next_word.py +src/fenrir-package/commands/commands/review_prev_char.py +src/fenrir-package/commands/commands/review_prev_line.py +src/fenrir-package/commands/commands/review_prev_word.py +src/fenrir-package/commands/commands/review_top.py +src/fenrir-package/commands/commands/review_up.py +src/fenrir-package/commands/commands/set_bookmark_1.py +src/fenrir-package/commands/commands/set_bookmark_10.py +src/fenrir-package/commands/commands/set_bookmark_2.py +src/fenrir-package/commands/commands/set_bookmark_3.py +src/fenrir-package/commands/commands/set_bookmark_4.py +src/fenrir-package/commands/commands/set_bookmark_5.py +src/fenrir-package/commands/commands/set_bookmark_6.py +src/fenrir-package/commands/commands/set_bookmark_7.py +src/fenrir-package/commands/commands/set_bookmark_8.py +src/fenrir-package/commands/commands/set_bookmark_9.py +src/fenrir-package/commands/commands/set_mark.py +src/fenrir-package/commands/commands/set_window_application.py +src/fenrir-package/commands/commands/shut_up.py +src/fenrir-package/commands/commands/spell_check.py +src/fenrir-package/commands/commands/time.py +src/fenrir-package/commands/commands/toggle_auto_read.py +src/fenrir-package/commands/commands/toggle_auto_spell_check.py +src/fenrir-package/commands/commands/toggle_braille.py +src/fenrir-package/commands/commands/toggle_output.py +src/fenrir-package/commands/commands/toggle_punctuation_level.py +src/fenrir-package/commands/commands/toggle_sound.py +src/fenrir-package/commands/commands/toggle_speech.py +src/fenrir-package/commands/commands/toggle_tutorial_mode.py +src/fenrir-package/commands/onInput/10000-shut_up.py +src/fenrir-package/commands/onInput/45000-present_char_if_cursor_change_horizontal.py +src/fenrir-package/commands/onInput/50000-char_echo.py +src/fenrir-package/commands/onInput/55000-present_line_if_cursor_change_vertical.py +src/fenrir-package/commands/onInput/60000-word_echo.py +src/fenrir-package/commands/onInput/62000-spell_check.py +src/fenrir-package/commands/onInput/65000-char_delete_echo.py +src/fenrir-package/commands/onInput/80000-capslock.py +src/fenrir-package/commands/onInput/80300-scrolllock.py +src/fenrir-package/commands/onInput/80500-numlock.py +src/fenrir-package/commands/onInput/__init__.py +src/fenrir-package/commands/onScreenChanged/10000-shut_up.py +src/fenrir-package/commands/onScreenChanged/80000-screen_change_announcement.py +src/fenrir-package/commands/onScreenChanged/85000-screen_chnage_reset_marks.py +src/fenrir-package/commands/onScreenChanged/85000-screen_chnage_reset_review.py +src/fenrir-package/commands/onScreenChanged/89000-screen_chnage_leve_review_mode.py +src/fenrir-package/commands/onScreenChanged/__init__.py +src/fenrir-package/commands/onScreenUpdate/70000-incoming.py +src/fenrir-package/commands/onScreenUpdate/75000-incoming_promote.py +src/fenrir-package/commands/onScreenUpdate/__init__.py +src/fenrir-package/commands/onSwitchApplicationProfile/__init__.py +src/fenrir-package/commands/onSwitchApplicationProfile/agetty.py +src/fenrir-package/commands/onSwitchApplicationProfile/bash.py +src/fenrir-package/commands/onSwitchApplicationProfile/default.py +src/fenrir-package/commands/onSwitchApplicationProfile/vim.py +src/fenrir-package/core/__init__.py +src/fenrir-package/core/applicationManager.py +src/fenrir-package/core/commandManager.py +src/fenrir-package/core/commands.py +src/fenrir-package/core/cursorManager.py +src/fenrir-package/core/debug.py +src/fenrir-package/core/environment.py +src/fenrir-package/core/generalInformation.py +src/fenrir-package/core/inputEvent.py +src/fenrir-package/core/inputManager.py +src/fenrir-package/core/outputManager.py +src/fenrir-package/core/punctuationManager.py +src/fenrir-package/core/runtime.py +src/fenrir-package/core/screenData.py +src/fenrir-package/core/screenManager.py +src/fenrir-package/core/settings.py +src/fenrir-package/core/settingsManager.py +src/fenrir-package/fenrir.egg-info/PKG-INFO +src/fenrir-package/fenrir.egg-info/SOURCES.txt +src/fenrir-package/fenrir.egg-info/dependency_links.txt +src/fenrir-package/fenrir.egg-info/entry_points.txt +src/fenrir-package/fenrir.egg-info/not-zip-safe +src/fenrir-package/fenrir.egg-info/requires.txt +src/fenrir-package/fenrir.egg-info/top_level.txt +src/fenrir-package/inputDriver/__init__.py +src/fenrir-package/inputDriver/evdev.py +src/fenrir-package/screenDriver/__init__.py +src/fenrir-package/screenDriver/linux.py +src/fenrir-package/soundDriver/__init__.py +src/fenrir-package/soundDriver/generic.py +src/fenrir-package/soundDriver/gstreamer.py +src/fenrir-package/speechDriver/__init__.py +src/fenrir-package/speechDriver/espeak.py +src/fenrir-package/speechDriver/generic.py +src/fenrir-package/speechDriver/speechd.py +src/fenrir-package/utils/__init__.py +src/fenrir-package/utils/char_utils.py +src/fenrir-package/utils/fenrir-config.py +src/fenrir-package/utils/line_utils.py +src/fenrir-package/utils/mark_utils.py +src/fenrir-package/utils/review_utils.py +src/fenrir-package/utils/word_utils.py \ No newline at end of file diff --git a/src/fenrir/fenrir.egg-info/dependency_links.txt b/src/fenrir/fenrir.egg-info/dependency_links.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/fenrir/fenrir.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/src/fenrir/fenrir.egg-info/entry_points.txt b/src/fenrir/fenrir.egg-info/entry_points.txt new file mode 100644 index 00000000..3beb7040 --- /dev/null +++ b/src/fenrir/fenrir.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[console_scripts] +fenrir = fenrir:fenrir + diff --git a/src/fenrir/fenrir.egg-info/not-zip-safe b/src/fenrir/fenrir.egg-info/not-zip-safe new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/fenrir/fenrir.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/src/fenrir/fenrir.egg-info/requires.txt b/src/fenrir/fenrir.egg-info/requires.txt new file mode 100644 index 00000000..96c1e4c9 --- /dev/null +++ b/src/fenrir/fenrir.egg-info/requires.txt @@ -0,0 +1,3 @@ +evdev +sox +python-espeak diff --git a/src/fenrir/fenrir.egg-info/top_level.txt b/src/fenrir/fenrir.egg-info/top_level.txt new file mode 100644 index 00000000..787d26cb --- /dev/null +++ b/src/fenrir/fenrir.egg-info/top_level.txt @@ -0,0 +1,8 @@ +braille +commands +core +inputDriver +screenDriver +soundDriver +speechDriver +utils diff --git a/src/fenrir/fenrir.py b/src/fenrir/fenrir.py new file mode 100755 index 00000000..606b66d7 --- /dev/null +++ b/src/fenrir/fenrir.py @@ -0,0 +1,132 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import os, sys, signal, time + +if not os.getcwd() in sys.path: + sys.path.append(os.getcwd()) + +from core import settingsManager +from core import debug + +class fenrir(): + def __init__(self): + try: + self.environment = settingsManager.settingsManager().initFenrirConfig() + if not self.environment: + raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable') + except RuntimeError: + raise + self.environment['runtime']['outputManager'].presentText("Start Fenrir", soundIcon='ScreenReaderOn', interrupt=True) + signal.signal(signal.SIGINT, self.captureSignal) + signal.signal(signal.SIGTERM, self.captureSignal) + self.wasCommand = False + + def proceed(self): + while(self.environment['generalInformation']['running']): + try: + self.handleProcess() + except Exception as e: + self.environment['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + self.shutdown() + + def handleProcess(self): + #startTime = time.time() + eventReceived = self.environment['runtime']['inputManager'].getInputEvent() + if eventReceived: + self.prepareCommand() + if not (self.wasCommand or self.environment['runtime']['inputManager'].isFenrirKeyPressed() or self.environment['generalInformation']['tutorialMode']) or self.environment['runtime']['screenManager'].isSuspendingScreen(): + self.environment['runtime']['inputManager'].writeEventBuffer() + if self.environment['runtime']['inputManager'].noKeyPressed(): + if self.wasCommand: + self.wasCommand = False + self.environment['runtime']['inputManager'].clearEventBuffer() + if self.environment['generalInformation']['tutorialMode']: + self.environment['runtime']['inputManager'].clearEventBuffer() + if self.environment['input']['keyForeward'] > 0: + self.environment['input']['keyForeward'] -=1 + self.environment['runtime']['screenManager'].update('onInput') + self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput') + else: + self.environment['runtime']['screenManager'].update('onUpdate') + if self.environment['runtime']['applicationManager'].isApplicationChange(): + self.environment['runtime']['commandManager'].executeDefaultTrigger('onApplicationChange') + self.environment['runtime']['commandManager'].executeSwitchTrigger('onSwitchApplicationProfile', \ + self.environment['runtime']['applicationManager'].getPrevApplication(), \ + self.environment['runtime']['applicationManager'].getCurrentApplication()) + + if self.environment['runtime']['screenManager'].isScreenChange(): + self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged') + else: + self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate') + + self.handleCommands() + #print(time.time()-startTime) + + def prepareCommand(self): + if self.environment['runtime']['screenManager'].isSuspendingScreen(): + return + if self.environment['runtime']['inputManager'].noKeyPressed(): + return + if self.environment['input']['keyForeward'] > 0: + return + shortcut = self.environment['runtime']['inputManager'].getCurrShortcut() + command = self.environment['runtime']['inputManager'].getCommandForShortcut(shortcut) + if len(self.environment['input']['prevDeepestInput']) <= len(self.environment['input']['currInput']): + self.wasCommand = command != '' + if command == '': + return + + self.environment['runtime']['commandManager'].queueCommand(command) + + + def handleCommands(self): + if not self.environment['runtime']['commandManager'].isCommandQueued(): + return + self.environment['runtime']['commandManager'].executeCommand( self.environment['commandInfo']['currCommand'], 'commands') + + def shutdownRequest(self): + self.environment['generalInformation']['running'] = False + + def captureSignal(self, siginit, frame): + self.shutdownRequest() + + def shutdown(self): + if self.environment['runtime']['inputManager']: + self.environment['runtime']['inputManager'].shutdown() + del self.environment['runtime']['inputManager'] + self.environment['runtime']['outputManager'].presentText("Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True) + time.sleep(0.9) # wait a little for sound + + if self.environment['runtime']['screenManager']: + self.environment['runtime']['screenManager'].shutdown() + del self.environment['runtime']['screenManager'] + if self.environment['runtime']['commandManager']: + self.environment['runtime']['commandManager'].shutdown() + del self.environment['runtime']['commandManager'] + if self.environment['runtime']['outputManager']: + self.environment['runtime']['outputManager'].shutdown() + del self.environment['runtime']['outputManager'] + if self.environment['runtime']['punctuationManager']: + self.environment['runtime']['punctuationManager'].shutdown() + del self.environment['runtime']['punctuationManager'] + if self.environment['runtime']['cursorManager']: + self.environment['runtime']['cursorManager'].shutdown() + del self.environment['runtime']['cursorManager'] + if self.environment['runtime']['applicationManager']: + self.environment['runtime']['applicationManager'].shutdown() + del self.environment['runtime']['applicationManager'] + + if self.environment['runtime']['debug']: + self.environment['runtime']['debug'].shutdown() + del self.environment['runtime']['debug'] + time.sleep(0.2) # wait a little before splatter it :) + self.environment = None + +if __name__ == "__main__": + app = fenrir() + app.proceed() + del app diff --git a/src/fenrir/inputDriver/__init__.py b/src/fenrir/inputDriver/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/inputDriver/evdev.py b/src/fenrir/inputDriver/evdev.py new file mode 100644 index 00000000..33976591 --- /dev/null +++ b/src/fenrir/inputDriver/evdev.py @@ -0,0 +1,156 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import evdev +import time +from evdev import InputDevice, UInput +from select import select + +from core import inputEvent +from core import debug + +class driver(): + def __init__(self): + self.iDevices = {} + self.uDevices = {} + self.ledDevices = {} + + def initialize(self, environment): + self.env = environment + self.getInputDevices() + + def shutdown(self): + pass + def getInputEvent(self): + if not self.iDevices: + return None + if self.iDevices == {}: + return None + event = None + r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')) + if r != []: + for fd in r: + event = self.iDevices[fd].read_one() + while(event): + if not event: + return None + self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) + if event.code != 0: + currMapEvent = self.env['runtime']['inputDriver'].mapEvent(event) + if not currMapEvent: + return currMapEvent + if currMapEvent['EventState'] in [0,1,2]: + return currMapEvent + event = self.iDevices[fd].read_one() + return None + + def writeEventBuffer(self): + for iDevice, uDevice, event in self.env['input']['eventBuffer']: + self.writeUInput(uDevice, event) + + def clearEventBuffer(self): + del self.env['input']['eventBuffer'][:] + + def writeUInput(self, uDevice, event): + uDevice.write_event(event) + uDevice.syn() + def getInputDevices(self): + # 3 pos absolute + # 2 pos relative + # 17 LEDs + # 1 Keys + # we try to filter out mices and other stuff here + self.iDevices = map(evdev.InputDevice, (evdev.list_devices())) + self.ledDevices = map(evdev.InputDevice, (evdev.list_devices())) + if self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper() == 'ALL': + self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()} + self.ledDevices = {dev.fd: dev for dev in self.ledDevices if 1 in dev.capabilities() and 17 in dev.capabilities()} + elif self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper() == 'AUTO': + self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities() and not 3 in dev.capabilities() and not 2 in dev.capabilities()} + self.ledDevices = {dev.fd: dev for dev in self.ledDevices if 1 in dev.capabilities() and 17 in dev.capabilities() and not 3 in dev.capabilities() and not 2 in dev.capabilities()} + else: + self.iDevices = {dev.fd: dev for dev in self.iDevices if dev.name.upper() in self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper()} + self.ledDevices = {dev.fd: dev for dev in self.ledDevices if dev.name.upper() in self.env['runtime']['settingsManager'].getSetting('keyboard', 'device').upper()} + + def mapEvent(self, event): + if not event: + return None + mEvent = inputEvent.inputEvent + try: + mEvent['EventName'] = evdev.ecodes.keys[event.code] + mEvent['EventValue'] = event.code + mEvent['EventSec'] = event.sec + mEvent['EventUsec'] = event.usec + mEvent['EventState'] = event.value + return mEvent + except Exception as e: + return None + + def getNumlock(self): + if self.ledDevices == {}: + return True + if self.ledDevices == None: + return True + for fd, dev in self.ledDevices.items(): + return 0 in dev.leds() + return True + + def getCapslock(self): + if self.ledDevices == {}: + return False + if self.ledDevices == None: + return False + for fd, dev in self.ledDevices.items(): + return 1 in dev.leds() + return False + + def getScrollLock(self): + if self.ledDevices == {}: + return False + if self.ledDevices == None: + return False + for fd, dev in self.ledDevices.items(): + return 2 in dev.leds() + return False + + def grabDevices(self): + for fd in self.iDevices: + dev = self.iDevices[fd] + cap = dev.capabilities() + del cap[0] + self.uDevices[fd] = UInput( + cap, + dev.name, + #dev.info.vendor, + #dev.info.product, + #dev.version, + #dev.info.bustype, + #'/dev/uinput' + ) + dev.grab() + + def releaseDevices(self): + for fd in self.iDevices: + try: + self.iDevices[fd].ungrab() + except: + pass + try: + self.iDevices[fd].close() + except: + pass + try: + self.uDevices[fd].close() + except: + pass + + self.iDevices.clear() + self.uDevices.clear() + + def __del__(self): + self.releaseDevices() + + diff --git a/src/fenrir/screenDriver/__init__.py b/src/fenrir/screenDriver/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/screenDriver/linux.py b/src/fenrir/screenDriver/linux.py new file mode 100644 index 00000000..36b3a386 --- /dev/null +++ b/src/fenrir/screenDriver/linux.py @@ -0,0 +1,143 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import difflib +import re +import subprocess +from core import debug + +class driver(): + def __init__(self): + self.vcsaDevicePath = '/dev/vcsa' + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def insert_newlines(self, string, every=64): + return '\n'.join(string[i:i+every] for i in range(0, len(string), every)) + + def getCurrScreen(self): + self.env['screenData']['oldTTY'] = self.env['screenData']['newTTY'] + try: + currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r') + self.env['screenData']['newTTY'] = str(currScreenFile.read()[3:-1]) + currScreenFile.close() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def getCurrApplication(self): + apps = [] + try: + currScreen = self.env['screenData']['newTTY'] + apps = subprocess.Popen('ps -t tty' + currScreen + ' -o comm,tty,stat', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n') + except Exception as e: + print(e) + return + try: + for i in apps: + i = i.upper() + i = i.split() + i[0] = i[0] + i[1] = i[1] + if '+' in i[2]: + if i[0] != '': + if not "GREP" == i[0] and \ + not "SH" == i[0] and \ + not "PS" == i[0]: + if "TTY"+currScreen in i[1]: + if self.env['screenData']['newApplication'] != i[0]: + self.env['screenData']['newApplication'] = i[0] + return + except Exception as e: + print(e) + return + return + + def getIgnoreScreens(self): + xlist = [] + try: + x = subprocess.Popen('ps a -o tty,comm | grep Xorg', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n') + except Exception as e: + return xlist + for i in x: + if not "grep" in i and \ + not "ps" in i: + if (i[:3].lower() == 'tty'): + xlist.append(i[3]) + return xlist + + + def update(self, trigger='onUpdate'): + newContentBytes = b'' + try: + # read screen + vcsa = open(self.vcsaDevicePath + self.env['screenData']['newTTY'],'rb',0) + newContentBytes = vcsa.read() + vcsa.close() + if len(newContentBytes) < 5: + return + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + return + screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding') + # set new "old" values + self.env['screenData']['oldContentBytes'] = self.env['screenData']['newContentBytes'] + self.env['screenData']['oldContentText'] = self.env['screenData']['newContentText'] + self.env['screenData']['oldContentTextAttrib'] = self.env['screenData']['newContentAttrib'] + self.env['screenData']['oldCursor']['x'] = self.env['screenData']['newCursor']['x'] + self.env['screenData']['oldCursor']['y'] = self.env['screenData']['newCursor']['y'] + self.env['screenData']['oldDelta'] = self.env['screenData']['newDelta'] + self.env['screenData']['oldNegativeDelta'] = self.env['screenData']['newNegativeDelta'] + self.env['screenData']['newContentBytes'] = newContentBytes + # get metadata like cursor or screensize + self.env['screenData']['lines'] = int( self.env['screenData']['newContentBytes'][0]) + self.env['screenData']['columns'] = int( self.env['screenData']['newContentBytes'][1]) + self.env['screenData']['newCursor']['x'] = int( self.env['screenData']['newContentBytes'][2]) + self.env['screenData']['newCursor']['y'] = int( self.env['screenData']['newContentBytes'][3]) + # analyze content + self.env['screenData']['newContentText'] = self.env['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') + self.env['screenData']['newContentAttrib'] = self.env['screenData']['newContentBytes'][5:][::2] + self.env['screenData']['newContentText'] = self.insert_newlines(self.env['screenData']['newContentText'], self.env['screenData']['columns']) + + if self.env['screenData']['newTTY'] != self.env['screenData']['oldTTY']: + self.env['screenData']['oldContentBytes'] = b'' + self.env['screenData']['oldContentAttrib'] = b'' + self.env['screenData']['oldContentText'] = '' + self.env['screenData']['oldCursor']['x'] = 0 + self.env['screenData']['oldCursor']['y'] = 0 + self.env['screenData']['oldDelta'] = '' + self.env['screenData']['oldNegativeDelta'] = '' + # always clear current deltas + self.env['screenData']['newNegativeDelta'] = '' + self.env['screenData']['newDelta'] = '' + # changes on the screen + oldScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screenData']['oldContentText'])) + newScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screenData']['newContentText'])) + if (self.env['screenData']['oldContentText'] != self.env['screenData']['newContentText']) and \ + (self.env['screenData']['newContentText'] != '' ): + if oldScreenText == '' and\ + newScreenText != '': + self.env['screenData']['newDelta'] = newScreenText + else: + cursorLineStart = self.env['screenData']['newCursor']['y'] * self.env['screenData']['columns'] + self.env['screenData']['newCursor']['y'] + cursorLineEnd = cursorLineStart + self.env['screenData']['columns'] + if self.env['screenData']['oldCursor']['x'] != self.env['screenData']['newCursor']['x'] and \ + self.env['screenData']['oldCursor']['y'] == self.env['screenData']['newCursor']['y'] and \ + self.env['screenData']['newContentText'][:cursorLineStart] == self.env['screenData']['oldContentText'][:cursorLineStart]: + + oldScreenText = self.env['screenData']['oldContentText'][cursorLineStart:cursorLineEnd] + oldScreenText = re.sub(' +',' ',oldScreenText) + newScreenText = self.env['screenData']['newContentText'][cursorLineStart:cursorLineEnd] + newScreenText = re.sub(' +',' ',newScreenText) + diff = difflib.ndiff(oldScreenText, newScreenText) + else: + diff = difflib.ndiff( oldScreenText.split('\n'),\ + newScreenText.split('\n')) + + diffList = list(diff) + + self.env['screenData']['newDelta'] = ''.join(x[2:] for x in diffList if x[0] == '+') + self.env['screenData']['newNegativeDelta'] = ''.join(x[2:] for x in diffList if x[0] == '-') diff --git a/src/fenrir/sound.py b/src/fenrir/sound.py new file mode 100755 index 00000000..14e25704 --- /dev/null +++ b/src/fenrir/sound.py @@ -0,0 +1,9 @@ +#!/bin/python + +import time + +from sound.gstreamer import sound + +s = sound() +s.playSoundFile('/home/chrys/Projekte/fenrir/fenrir/src/fenrir-package/1ChangeTTY.opus') +time.sleep(10) diff --git a/src/fenrir/soundDriver/__init__.py b/src/fenrir/soundDriver/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/soundDriver/generic.py b/src/fenrir/soundDriver/generic.py new file mode 100644 index 00000000..ebbe1dc7 --- /dev/null +++ b/src/fenrir/soundDriver/generic.py @@ -0,0 +1,55 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import subprocess + +class driver(): + def __init__(self): + self.proc = None + self.volume = 1.0 + self.soundType = '' + self.soundFileCommand = '' + self.frequenceCommand = '' + def initialize(self, environment): + self.env = environment + self.soundFileCommand = self.env['runtime']['settingsManager'].getSetting('sound', 'genericPlayFileCommand') + self.frequenceCommand = self.env['runtime']['settingsManager'].getSetting('sound', 'genericFrequencyCommand') + if self.soundFileCommand == '': + self.soundFileCommand = 'play -q -v fenrirVolume fenrirSoundFile' + if self.frequenceCommand == '': + self.frequenceCommand = '=play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence' + return + def shutdown(self): + self.cancel() + return + def playFrequence(self, frequence, duration, adjustVolume): + if interrupt: + self.cancel() + popenFrequenceCommand = self.frequenceCommand.replace('fenrirVolume', str(self.volume + adjustVolume )) + popenFrequenceCommand = popenFrequenceCommand.replace('fenrirFreqDuration', str(duration)) + popenFrequenceCommand = popenFrequenceCommand.replace('fenrirFrequence', str(frequence)) + self.proc = subprocess.Popen(popenFrequenceCommand, shell=True) + self.soundType = 'frequence' + def playSoundFile(self, filePath, interrupt = True): + if interrupt: + self.cancel() + popenSoundFileCommand = self.soundFileCommand.replace('fenrirVolume', str(self.volume )) + popenSoundFileCommand = popenSoundFileCommand.replace('fenrirSoundFile', filePath) + self.proc = subprocess.Popen(popenSoundFileCommand, shell=True) + self.soundType = 'file' + def cancel(self): + if self.soundType == '': + return + if self.soundType == 'file': + self.proc.kill() + if self.soundType == 'frequence': + self.proc.kill() + self.soundType = '' + def setCallback(self, callback): + pass + def setVolume(self, volume): + self.volume = volume diff --git a/src/fenrir/soundDriver/gstreamer.py b/src/fenrir/soundDriver/gstreamer.py new file mode 100644 index 00000000..5e232532 --- /dev/null +++ b/src/fenrir/soundDriver/gstreamer.py @@ -0,0 +1,109 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import gi +import time +from gi.repository import GLib + +try: + gi.require_version('Gst', '1.0') + from gi.repository import Gst +except: + _gstreamerAvailable = False +else: + _gstreamerAvailable, args = Gst.init_check(None) + +class driver: + def __init__(self): + self._initialized = False + self._source = None + self._sink = None + self.volume = 1 + if not _gstreamerAvailable: + return + def initialize(self, environment): + if self._initialized: + return + if not _gstreamerAvailable: + return + self.env = environment + self._player = Gst.ElementFactory.make('playbin', 'player') + bus = self._player.get_bus() + bus.add_signal_watch() + bus.connect("message", self._onPlayerMessage) + + self._pipeline = Gst.Pipeline(name='fenrir-pipeline') + bus = self._pipeline.get_bus() + bus.add_signal_watch() + bus.connect("message", self._onPipelineMessage) + + self._source = Gst.ElementFactory.make('audiotestsrc', 'src') + self._sink = Gst.ElementFactory.make('autoaudiosink', 'output') + self._pipeline.add(self._source) + self._pipeline.add(self._sink) + self._source.link(self._sink) + + self._initialized = True + return + def shutdown(self): + global _gstreamerAvailable + if not _gstreamerAvailable: + return + self.cancel() + self._initialized = False + _gstreamerAvailable = False + + def _onPlayerMessage(self, bus, message): + if message.type == Gst.MessageType.EOS: + self._player.set_state(Gst.State.NULL) + elif message.type == Gst.MessageType.ERROR: + self._player.set_state(Gst.State.NULL) + error, info = message.parse_error() + print(error, info) + print('_onPlayerMessage') + def _onPipelineMessage(self, bus, message): + if message.type == Gst.MessageType.EOS: + self._pipeline.set_state(Gst.State.NULL) + elif message.type == Gst.MessageType.ERROR: + self._pipeline.set_state(Gst.State.NULL) + error, info = message.parse_error() + print(error, info) + print('_onPipelineMessage') + + def _onTimeout(self, element): + element.set_state(Gst.State.NULL) + return False + + def playSoundFile(self, fileName, interrupt=True): + if interrupt: + self.cancel() + self._player.set_property('uri', 'file://%s' % fileName) + self._player.set_state(Gst.State.PLAYING) + print('playSoundFile') + def playFrequence(self, frequence, duration, adjustVolume, interrupt=True): + if interrupt: + self.cancel() + self._source.set_property('volume', tone.volume) + self._source.set_property('freq', tone.frequency) + self._source.set_property('wave', tone.wave) + self._pipeline.set_state(Gst.State.PLAYING) + duration = int(1000 * tone.duration) + GLib.timeout_add(duration, self._onTimeout, self._pipeline) + + def cancel(self, element=None): + if not _gstreamerAvailable: + return + if element: + element.set_state(Gst.State.NULL) + return + self._player.set_state(Gst.State.NULL) + self._pipeline.set_state(Gst.State.NULL) + def setVolume(self, volume): + self.volume = volume + + + diff --git a/src/fenrir/speechDriver/Readme.md b/src/fenrir/speechDriver/Readme.md new file mode 100644 index 00000000..de077fd4 --- /dev/null +++ b/src/fenrir/speechDriver/Readme.md @@ -0,0 +1,3 @@ +espeak = espeak driver +speechd = speech-dispatcher driver +generic = generic driver via /bin/say diff --git a/src/fenrir/speechDriver/__init__.py b/src/fenrir/speechDriver/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/speechDriver/espeak.py b/src/fenrir/speechDriver/espeak.py new file mode 100644 index 00000000..18e960c0 --- /dev/null +++ b/src/fenrir/speechDriver/espeak.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# Espeak driver + +from core import debug + +class driver(): + def __init__(self ): + self._es = None + self._isInitialized = False + try: + from espeak import espeak + self._es = espeak + self._isInitialized = True + except: + self._initialized = False + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + + def speak(self,text, queueable=True): + if not self._isInitialized: + return False + if not queueable: + self.cancel() + self._es.synth(text) + return True + + def cancel(self): + if not self._isInitialized: + return False + self._es.cancel() + return True + + def setCallback(self, callback): + pass + + def clear_buffer(self): + if not self._isInitialized: + return False + return True + + def setVoice(self, voice): + if not self._isInitialized: + return False + return self._es.set_voice(voice) + + def setPitch(self, pitch): + if not self._isInitialized: + return False + + def setRate(self, rate): + if not self._isInitialized: + return False + return self._es.set_parameter(self._es.Parameter().Rate, int(rate*450 + 80)) + + return self._es.set_parameter(self._es.Parameter().Pitch, int(pitch * 99)) + def setModule(self, module): + if not self._isInitialized: + return False + + def setLanguage(self, language): + if not self._isInitialized: + return False + return self._es.set_voice(language) + + def setVolume(self, volume): + if not self._isInitialized: + return False + return self._es.set_parameter(self._es.Parameter().Volume, int(volume * 200)) diff --git a/src/fenrir/speechDriver/generic.py b/src/fenrir/speechDriver/generic.py new file mode 100644 index 00000000..1afb8717 --- /dev/null +++ b/src/fenrir/speechDriver/generic.py @@ -0,0 +1,66 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# generic driver + +from core import debug + +class driver(): + def __init__(self ): + pass + def initialize(self, environment): + self._isInitialized = False + self.env = environment + def shutdown(self): + pass + + def speak(self,text, queueable=True): + if not self._isInitialized: + return False + if not queueable: + self.cancel() + return True + + def cancel(self): + if not self._isInitialized: + return False + return True + + def setCallback(self, callback): + pass + + def clear_buffer(self): + if not self._isInitialized: + return False + return True + + def setVoice(self, voice): + if not self._isInitialized: + return False + return True + + def setPitch(self, pitch): + if not self._isInitialized: + return False + return True + + def setRate(self, rate): + if not self._isInitialized: + return False + return True + + def setModule(self, module): + if not self._isInitialized: + return False + + def setLanguage(self, language): + if not self._isInitialized: + return False + return True + + def setVolume(self, volume): + if not self._isInitialized: + return False + return True diff --git a/src/fenrir/speechDriver/speechd.py b/src/fenrir/speechDriver/speechd.py new file mode 100644 index 00000000..17e8c82a --- /dev/null +++ b/src/fenrir/speechDriver/speechd.py @@ -0,0 +1,102 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# speech-dispatcher driver + +from core import debug + +class driver(): + def __init__(self ): + self._sd = None + self._isInitialized = False + self._language = '' + try: + import speechd + self._sd = speechd.SSIPClient('fenrir') + self._isInitialized = True + except: + self._initialized = False + def initialize(self, environment): + self.env = environment + def shutdown(self): + if not self._isInitialized: + return + self._isInitialized = False + self.cancel() + self._sd.close() + return + + def speak(self,text, queueable=True): + if not self._isInitialized: + return False + if queueable == False: self.cancel() + try: + self._sd.set_synthesis_voice(self._language) + except: + pass + self._sd.speak(text) + return True + + def cancel(self): + if not self._isInitialized: + return False + self._sd.cancel() + return True + + def setCallback(self, callback): + pass + + def clear_buffer(self): + if not self._isInitialized: + return False + return True + + def setVoice(self, voice): + if not self._isInitialized: + return False + try: + if voice != '': + self._sd.set_voice(voice) + return True + except: + return False + + def setPitch(self, pitch): + if not self._isInitialized: + return False + try: + self._sd.set_pitch(int(-100 + pitch * 200)) + return True + except: + return False + + def setRate(self, rate): + if not self._isInitialized: + return False + try: + self._sd.set_rate(int(-100 + rate * 200)) + return True + except: + return False + + def setModule(self, module): + if not self._isInitialized: + return False + try: + self._sd.set_output_module(module) + return True + except: + return False + + def setLanguage(self, language): + if not self._isInitialized: + return False + self._language = language + + def setVolume(self, volume): + if not self._isInitialized: + return False + self._sd.set_volume(int(-100 + volume * 200)) + diff --git a/src/fenrir/utils/__init__.py b/src/fenrir/utils/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/src/fenrir/utils/char_utils.py b/src/fenrir/utils/char_utils.py new file mode 100644 index 00000000..344df9ff --- /dev/null +++ b/src/fenrir/utils/char_utils.py @@ -0,0 +1,90 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +def getPrevChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if x - 1 < 0: + if y - 1 > 0: + y -= 1 + x = len(wrappedLines[y]) - 1 + else: + x -= 1 + currChar = wrappedLines[y][x] + return x, y, currChar + +def getCurrentChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + +def getUpChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currY -= 1 + if currY < 0: + currY = 0 + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + +def getDownChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currY += 1 + if currY >= len(wrappedLines): + currY = len(wrappedLines) -1 + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + +def getLastCharInLine(currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + currX = len(wrappedLines[currY].rstrip())-1 + if currX < 0: + currX = 0 + currChar = wrappedLines[currY][currX] + return currX, currY, currChar + +def getNextChar(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if x + 1 == len(wrappedLines[y]): + if y + 1 < len(wrappedLines) - 1: + y += 1 + x = 0 + else: + x += 1 + currChar = wrappedLines[y][x] + return x, y, currChar + +def getPhonetic(currChar): + if len(currChar) != 1: + return currChar + phoneticsDict = { + "A":"alpha", "B":"bravo", "C":"charlie", "D":"delta", "E":"echo", + "F":"foxtrot", "G":"golf", "H":"hotel", "I":"india", "J":"juliet", + "K":"kilo", "L":"lima", "M":"mike", "N":"november", "O":"oscar", + "P":"papa", "Q":"quebec", "R":"romeo", "S":"sierra", "T":"tango", + "U":"uniform", "V":"victor", "W":"whisky", "X":"x ray", + "Y":"yankee", "Z":"zulu" + } + try: + return phoneticsDict[currChar.upper()] + except: + return currChar diff --git a/src/fenrir/utils/fenrir-config.py b/src/fenrir/utils/fenrir-config.py new file mode 100644 index 00000000..d512ba67 --- /dev/null +++ b/src/fenrir/utils/fenrir-config.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import configparser +import os +import sys +from os import listdir +from os.path import isfile, join +from inspect import isfunction +from xdg import BaseDirectory + +# Get configuration directory +if len(sys.argv) > 1: + configPath = sys.argv[1] +elif os.geteuid() == 0: + # Save settings system wide + configPath = "/etc/fenrir.conf" +else: + # Use local settings + configPath = BaseDirectory.xdg_data_home + "/fenrir" + if not os.path.exists(configPath): os.makedirs(configPath) + configPath = configPath + "/fenrir.conf" + + diff --git a/src/fenrir/utils/line_utils.py b/src/fenrir/utils/line_utils.py new file mode 100644 index 00000000..2de24fad --- /dev/null +++ b/src/fenrir/utils/line_utils.py @@ -0,0 +1,41 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +def getPrevLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if y - 1 >= 0: + y -= 1 + x = 0 + currLine = wrappedLines[y] + return x, y, currLine + +def getCurrentLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + x = 0 + currLine = wrappedLines[y] + return x, y, currLine + +def getNextLine(currX,currY, currText): + if currText == '': + return -1, -1, '' + wrappedLines = currText.split('\n') + x = currX + y = currY + if y + 1 < len(wrappedLines): + y += 1 + x = 0 + currLine = wrappedLines[y] + return x, y, currLine diff --git a/src/fenrir/utils/mark_utils.py b/src/fenrir/utils/mark_utils.py new file mode 100644 index 00000000..d52b53f1 --- /dev/null +++ b/src/fenrir/utils/mark_utils.py @@ -0,0 +1,60 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +def getTextBetweenMarks(firstMark, secondMark, inText): + if inText == None: + return '' + if not isinstance(inText, list): + inText = inText.split('\n') + if len(inText) < 1: + return '' + if firstMark == None: + return '' + if secondMark == None: + return '' + if (firstMark['y'] + 1) * (firstMark['x'] + 1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1): + startMark = firstMark.copy() + endMark = secondMark.copy() + else: + endMark = firstMark.copy() + startMark = secondMark.copy() + textPart = '' + if startMark['y'] == endMark['y']: + textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1] + else: + currY = startMark['y'] + while currY <= endMark['y']: + if currY < endMark['y']: + if currY == startMark['y']: + textPart += inText[currY][startMark['x']:] + else: + textPart += inText[currY] + if len(inText[currY].strip()) != 0: + if len(textPart) - len(textPart.rstrip()) > 0: + textPart = textPart[:len(textPart.rstrip())] + "\n" + else: + textPart += '\n' + else: + textPart += inText[currY][:endMark['x'] + 1] + currY += 1 + return textPart + +def getTextBeforeMark(mark, inText): + if inText == None: + return '' + if mark == None: + return '' + return getTextBetweenMarks({'x':0,'y':0}, mark, inText) + +def getTextAfterMark(mark, inText): + if inText == None: + return '' + if mark == None: + return '' + inText = inText.split('\n') + return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText) diff --git a/src/fenrir/utils/review_utils.py b/src/fenrir/utils/review_utils.py new file mode 100644 index 00000000..1bca1526 --- /dev/null +++ b/src/fenrir/utils/review_utils.py @@ -0,0 +1,8 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + diff --git a/src/fenrir/utils/word_utils.py b/src/fenrir/utils/word_utils.py new file mode 100644 index 00000000..aa4d30d3 --- /dev/null +++ b/src/fenrir/utils/word_utils.py @@ -0,0 +1,112 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +def getPrevWord(currX,currY, currText): + if currText == '': + return -1, -1, '' + x, y, currWord = getCurrentWord(currX,currY,currText) + wrappedLines = currText.split('\n') + if (currWord == ''): + return currX, currY, '' + while True: + if x < 2: + if y != 0: + y -= 1 + else: + return currX, currY, '' + x = len(wrappedLines[y]) - 1 + else: + x -= 1 + if wrappedLines[y] != '': + break + x, y, currWord = getCurrentWord(x, y, currText) + if currWord == '': + return currX, currY, '' + return x, y, currWord + +def getCurrentWord(currX,currY, currText): + if currText == '': + return -1, -1, '' + x = currX + y = currY + wrappedLines = currText.split('\n') + wordFound = False + currWord = '' + currLine = wrappedLines[y].replace("\t"," ") + if currLine[x] == ' ' and x > 1: + x = x - 2 + while not wordFound: + x = currLine[:x].rfind(" ") + if x == -1: + x = 0 + else: + x += 1 + wordEnd = currLine[x + 1:].find(" ") + if wordEnd == -1: + wordEnd = len(currLine) + else: + wordEnd += x + 1 + currWord = currLine[x:wordEnd] + wordFound = currWord.strip(" \t\n") != '' + if wordFound: + break + if x == 0: + if y != 0: + y -= 1 + currLine = wrappedLines[y].replace("\t"," ") + else: + return currX, currY, '' + x = len(wrappedLines[y]) - 1 + else: + x -= 1 + return x, y, currWord + +def getNextWord(currX,currY, currText): + if currText == '': + return -1, -1, '' + x = currX + y = currY + wrappedLines = currText.split('\n') + wordFound = False + currWord = '' + currLine = wrappedLines[y].replace("\t"," ") + while not wordFound: + xtmp = 0 + if x + 1 >= len(currLine): + if y < len(wrappedLines): + y += 1 + currLine = wrappedLines[y].replace("\t"," ") + else: + return currX, currY, '' + x = 0 + else: + x += 1 + xtmp = x + x = currLine[x:].find(" ") + if x == -1: + x = len(currLine) + continue + else: + if xtmp != 0: + xtmp += 1 + x += xtmp + if x + 1 < len(currLine): + wordEnd = currLine[x + 1:].find(" ") + else: + wordEnd = -1 + if wordEnd == -1: + wordEnd = len(currLine) + else: + wordEnd += x + 1 + if wordEnd >= len(currLine) and y + 1 >= len(wrappedLines): + return currX, currY, '' + currWord = currLine[x:wordEnd] + wordFound = currWord.strip(" \t\n") != '' + if not wordFound: + x = wordEnd + return x, y, currWord