diff --git a/src/fenrirscreenreader/commands/commands/adjustment_base.py b/src/fenrirscreenreader/commands/commands/adjustment_base.py new file mode 100644 index 00000000..575c0abd --- /dev/null +++ b/src/fenrirscreenreader/commands/commands/adjustment_base.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import math + +class AdjustmentCommand(): + """Base class for speech and sound adjustment commands""" + def __init__(self, section, setting, direction, step=0.1): + self.section = section # 'speech' or 'sound' + self.setting = setting # 'rate', 'pitch', 'volume' + self.direction = direction # 'inc' or 'dec' + self.step = step + + def initialize(self, environment): + self.env = environment + + def shutdown(self): + pass + + def getDescription(self): + action = "Increase" if self.direction == 'inc' else "Decrease" + if self.section == 'speech': + return _(f'{action} the speech {self.setting}') + else: + return _(f'{action} the {self.section} {self.setting}') + + def run(self): + if self.section == 'sound' and self.setting == 'volume': + # Sound volume uses different method + self._adjust_sound_volume() + else: + # Speech rate, pitch, volume use standard method + self._adjust_speech_setting() + + def _adjust_speech_setting(self): + """Adjust speech settings (rate, pitch, volume)""" + value = self.env['runtime']['settingsManager'].getSettingAsFloat(self.section, self.setting) + + # Apply adjustment with rounding + if self.direction == 'inc': + value = round((math.ceil(10 * value) / 10) + self.step, 2) + if value > 1.0: + value = 1.0 + else: # dec + value = round((math.ceil(10 * value) / 10) - self.step, 2) + if value < 0.0: + value = 0.0 + + # Set the new value + self.env['runtime']['settingsManager'].setSetting(self.section, self.setting, str(value)) + + # Present feedback + percentage = int(value * 100) + if self.section == 'speech': + feedback = _("{0} percent speech {1}").format(percentage, self.setting) + else: + feedback = _("{0} percent {1} {2}").format(percentage, self.section, self.setting) + + self.env['runtime']['outputManager'].presentText(feedback, soundIcon='', interrupt=True) + + def _adjust_sound_volume(self): + """Adjust sound volume using same logic as speech""" + value = self.env['runtime']['settingsManager'].getSettingAsFloat(self.section, self.setting) + + # Sound volume uses same math as speech settings + if self.direction == 'inc': + value = round((math.ceil(10 * value) / 10) + self.step, 2) + if value > 1.0: + value = 1.0 + else: # dec + value = round((math.ceil(10 * value) / 10) - self.step, 2) + if value < 0.0: + value = 0.0 + + # Set the new value + self.env['runtime']['settingsManager'].setSetting(self.section, self.setting, str(value)) + + # Present feedback with appropriate sound icon + percentage = int(value * 100) + sound_icon = 'SoundOn' if self.direction == 'inc' else 'SoundOff' + feedback = _("{0} percent sound volume").format(percentage) + self.env['runtime']['outputManager'].presentText(feedback, soundIcon=sound_icon, interrupt=True) + + def setCallback(self, callback): + pass \ No newline at end of file diff --git a/src/fenrirscreenreader/commands/commands/bookmark_1.py b/src/fenrirscreenreader/commands/commands/bookmark_1.py index 0b7c62ec..13e6f54a 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_1.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_1.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '1' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(1, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_10.py b/src/fenrirscreenreader/commands/commands/bookmark_10.py index 75e0ecc2..1ea9c79f 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_10.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_10.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '10' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(10, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_2.py b/src/fenrirscreenreader/commands/commands/bookmark_2.py index 7221af45..8e93d4e1 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_2.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_2.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '2' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(2, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_3.py b/src/fenrirscreenreader/commands/commands/bookmark_3.py index 88da7cb9..168224af 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_3.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_3.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '3' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(3, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_4.py b/src/fenrirscreenreader/commands/commands/bookmark_4.py index 7f961f47..913c31e4 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_4.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_4.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '4' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(4, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_5.py b/src/fenrirscreenreader/commands/commands/bookmark_5.py index a8e7bd52..f5556fa7 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_5.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_5.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '5' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(5, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_6.py b/src/fenrirscreenreader/commands/commands/bookmark_6.py index e2b89fdf..729fe1f3 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_6.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_6.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '6' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(6, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_7.py b/src/fenrirscreenreader/commands/commands/bookmark_7.py index 426218db..8387c77a 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_7.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_7.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '7' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(7, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_8.py b/src/fenrirscreenreader/commands/commands/bookmark_8.py index 29df0372..f1e4c799 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_8.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_8.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '8' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(8, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_9.py b/src/fenrirscreenreader/commands/commands/bookmark_9.py index 7fb4fe11..04da752b 100644 --- a/src/fenrirscreenreader/commands/commands/bookmark_9.py +++ b/src/fenrirscreenreader/commands/commands/bookmark_9.py @@ -4,44 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -from fenrirscreenreader.utils import mark_utils -from fenrirscreenreader.utils import line_utils +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '9' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('read Bookmark {0}').format(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 {0} not set').format(self.ID,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), interrupt=True) - return - if not self.env['commandBuffer']['bookMarks'][self.ID][currApp]['1']: - self.env['runtime']['outputManager'].presentText(_('Bookmark for application {0} not set').format(currApp,), 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['screen']['newContentText']) - else: - x, y, marked = \ - line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['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 + super().__init__(9, 'read') diff --git a/src/fenrirscreenreader/commands/commands/bookmark_base.py b/src/fenrirscreenreader/commands/commands/bookmark_base.py new file mode 100644 index 00000000..84f9b3f4 --- /dev/null +++ b/src/fenrirscreenreader/commands/commands/bookmark_base.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from fenrirscreenreader.utils import mark_utils +from fenrirscreenreader.utils import line_utils + +class BookmarkCommand(): + """Base class for bookmark operations - read, set, clear""" + def __init__(self, bookmark_id, action='read'): + self.ID = str(bookmark_id) + self.action = action + + def initialize(self, environment): + self.env = environment + # Always initialize bookmark structure - all commands need this + if self.ID not in self.env['commandBuffer']['bookMarks']: + self.env['commandBuffer']['bookMarks'][self.ID] = {} + + def shutdown(self): + pass + + def getDescription(self): + if self.action == 'read': + return _('read Bookmark {0}').format(self.ID) + elif self.action == 'set': + return _('set Bookmark {0}').format(self.ID) + elif self.action == 'clear': + return _('remove Bookmark {0}').format(self.ID) + return f'{self.action} Bookmark {self.ID}' + + def run(self): + if self.action == 'read': + self._read_bookmark() + elif self.action == 'set': + self._set_bookmark() + elif self.action == 'clear': + self._clear_bookmark() + + def _read_bookmark(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + if not self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText('Bookmark {0} not set'.format(self.ID), interrupt=True) + return + + if currApp not in self.env['commandBuffer']['bookMarks'][self.ID]: + self.env['runtime']['outputManager'].presentText('Bookmark for application {0} not set'.format(currApp), interrupt=True) + return + + if not self.env['commandBuffer']['bookMarks'][self.ID][currApp].get('1'): + self.env['runtime']['outputManager'].presentText('Bookmark for application {0} not set'.format(currApp), interrupt=True) + return + + # Get bookmarked text + 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['screen']['newContentText']) + else: + x, y, marked = line_utils.getCurrentLine(startMark['x'], startMark['y'], self.env['screen']['newContentText']) + + if marked.isspace(): + self.env['runtime']['outputManager'].presentText(_('blank'), soundIcon='EmptyLine', interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(marked, interrupt=True) + + def _set_bookmark(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) + + # Clear marks after setting bookmark + self.env['commandBuffer']['Marks']['1'] = None + self.env['commandBuffer']['Marks']['2'] = None + + def _clear_bookmark(self): + currApp = self.env['runtime']['applicationManager'].getCurrentApplication() + + if self.ID in self.env['commandBuffer']['bookMarks'] and currApp in self.env['commandBuffer']['bookMarks'][self.ID]: + del self.env['commandBuffer']['bookMarks'][self.ID][currApp] + self.env['runtime']['outputManager'].presentText(_('Bookmark {0} removed for application {1}').format(self.ID, currApp), interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(_('Bookmark {0} not set for application {1}').format(self.ID, currApp), interrupt=True) + + def setCallback(self, callback): + pass + +# Factory function to create bookmark command instances +def create_bookmark_commands(): + """Create all bookmark command instances""" + commands = {} + + # Create read bookmark commands (bookmark_1 through bookmark_10) + for i in range(1, 11): + commands[f'bookmark_{i}'] = lambda i=i: BookmarkCommand(i, 'read') + + # Create set bookmark commands (set_bookmark_1 through set_bookmark_10) + for i in range(1, 11): + commands[f'set_bookmark_{i}'] = lambda i=i: BookmarkCommand(i, 'set') + + # Create clear bookmark commands (clear_bookmark_1 through clear_bookmark_10) + for i in range(1, 11): + commands[f'clear_bookmark_{i}'] = lambda i=i: BookmarkCommand(i, 'clear') + + return commands + +# For backwards compatibility, provide individual command classes +# This allows the existing command loading system to work unchanged + +def _make_command_class(bookmark_id, action): + """Create a command class for a specific bookmark and action""" + class command(BookmarkCommand): + def __init__(self): + super().__init__(bookmark_id, action) + return command + +# Generate individual command classes for each bookmark operation +# These will be used by the existing command loading system + +# Read bookmarks (bookmark_1.py style) +for i in range(1, 11): + globals()[f'bookmark_{i}_command'] = _make_command_class(i, 'read') + +# Set bookmarks (set_bookmark_1.py style) +for i in range(1, 11): + globals()[f'set_bookmark_{i}_command'] = _make_command_class(i, 'set') + +# Clear bookmarks (clear_bookmark_1.py style) +for i in range(1, 11): + globals()[f'clear_bookmark_{i}_command'] = _make_command_class(i, 'clear') \ No newline at end of file diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_1.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_1.py index bbe754cc..4bbd2977 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_1.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_1.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '1' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(1, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_10.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_10.py index 50179032..56642bec 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_10.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_10.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '10' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(10, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_2.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_2.py index a405fc74..11d4d4ac 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_2.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_2.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '2' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(2, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_3.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_3.py index 8bdd6475..5b94bf72 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_3.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_3.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '3' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(3, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_4.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_4.py index 8b46f71d..6b970a83 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_4.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_4.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '4' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(4, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_5.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_5.py index 47417c4a..2a6ad9c7 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_5.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_5.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '5' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(5, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_6.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_6.py index c8a285bb..15521a9d 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_6.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_6.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '6' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(6, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_7.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_7.py index 0e8d6b78..d318ab79 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_7.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_7.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '7' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(7, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_8.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_8.py index ad267e11..867c337b 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_8.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_8.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '8' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(8, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/clear_bookmark_9.py b/src/fenrirscreenreader/commands/commands/clear_bookmark_9.py index 5c4a341d..b579d0cc 100644 --- a/src/fenrirscreenreader/commands/commands/clear_bookmark_9.py +++ b/src/fenrirscreenreader/commands/commands/clear_bookmark_9.py @@ -4,23 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): def __init__(self): - self.ID = '9' - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('remove Bookmark {0}').format(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 {0} removed for application {1}').format(self.ID, currApp), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__(9, 'clear') diff --git a/src/fenrirscreenreader/commands/commands/dec_alsa_volume.py b/src/fenrirscreenreader/commands/commands/dec_alsa_volume.py index 10ef356a..59cf13fe 100644 --- a/src/fenrirscreenreader/commands/commands/dec_alsa_volume.py +++ b/src/fenrirscreenreader/commands/commands/dec_alsa_volume.py @@ -4,35 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -initialized = False -try: - import alsaaudio - initialized = True -except: - pass +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand - -class command(): +class command(AdjustmentCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _("Decrease system volume") - - def run(self): - if not initialized: - self.env['runtime']['outputManager'].presentText(_('alsaaudio is not installed'), interrupt=True) - return - mixer = alsaaudio.Mixer() - value = mixer.getvolume()[0] - value = value - 5 - if value < 5: - value = 5 - mixer.setvolume(value) - self.env['runtime']['outputManager'].presentText(_("{0} percent system volume").format(value), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('alsa', 'volume', 'dec') diff --git a/src/fenrirscreenreader/commands/commands/dec_sound_volume.py b/src/fenrirscreenreader/commands/commands/dec_sound_volume.py index c0e46354..4b36bf11 100644 --- a/src/fenrirscreenreader/commands/commands/dec_sound_volume.py +++ b/src/fenrirscreenreader/commands/commands/dec_sound_volume.py @@ -4,29 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent sound volume").format(int(value * 100)), soundIcon='SoundOff', interrupt=True) - - def setCallback(self, callback): - pass - + super().__init__('sound', 'volume', 'dec') diff --git a/src/fenrirscreenreader/commands/commands/dec_speech_pitch.py b/src/fenrirscreenreader/commands/commands/dec_speech_pitch.py index 5d9b8d25..02cf36e8 100644 --- a/src/fenrirscreenreader/commands/commands/dec_speech_pitch.py +++ b/src/fenrirscreenreader/commands/commands/dec_speech_pitch.py @@ -4,25 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_('{0} percent speech pitch').format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('speech', 'pitch', 'dec') diff --git a/src/fenrirscreenreader/commands/commands/dec_speech_rate.py b/src/fenrirscreenreader/commands/commands/dec_speech_rate.py index 06154298..82b54982 100644 --- a/src/fenrirscreenreader/commands/commands/dec_speech_rate.py +++ b/src/fenrirscreenreader/commands/commands/dec_speech_rate.py @@ -4,26 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent speech rate").format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('speech', 'rate', 'dec') diff --git a/src/fenrirscreenreader/commands/commands/dec_speech_volume.py b/src/fenrirscreenreader/commands/commands/dec_speech_volume.py index 8d44f743..f3d48afc 100644 --- a/src/fenrirscreenreader/commands/commands/dec_speech_volume.py +++ b/src/fenrirscreenreader/commands/commands/dec_speech_volume.py @@ -4,27 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent speech volume").format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass - + super().__init__('speech', 'volume', 'dec') diff --git a/src/fenrirscreenreader/commands/commands/inc_alsa_volume.py b/src/fenrirscreenreader/commands/commands/inc_alsa_volume.py index 7a38d4cd..ba3f4086 100644 --- a/src/fenrirscreenreader/commands/commands/inc_alsa_volume.py +++ b/src/fenrirscreenreader/commands/commands/inc_alsa_volume.py @@ -4,35 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -initialized = False -try: - import alsaaudio - initialized = True -except: - pass +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand - -class command(): +class command(AdjustmentCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _("Increase system volume") - - def run(self): - if not initialized: - self.env['runtime']['outputManager'].presentText(_('alsaaudio is not installed'), interrupt=True) - return - mixer = alsaaudio.Mixer() - value = mixer.getvolume()[0] - value = value + 5 - if value > 100: - value = 100 - mixer.setvolume(value) - self.env['runtime']['outputManager'].presentText(_("{0} percent system volume").format(value), interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('alsa', 'volume', 'inc') diff --git a/src/fenrirscreenreader/commands/commands/inc_sound_volume.py b/src/fenrirscreenreader/commands/commands/inc_sound_volume.py index eff01d31..67bd8d55 100644 --- a/src/fenrirscreenreader/commands/commands/inc_sound_volume.py +++ b/src/fenrirscreenreader/commands/commands/inc_sound_volume.py @@ -4,28 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent sound volume").format(int(value * 100)), soundIcon='SoundOn', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('sound', 'volume', 'inc') diff --git a/src/fenrirscreenreader/commands/commands/inc_speech_pitch.py b/src/fenrirscreenreader/commands/commands/inc_speech_pitch.py index fb20a105..a4d9c09f 100644 --- a/src/fenrirscreenreader/commands/commands/inc_speech_pitch.py +++ b/src/fenrirscreenreader/commands/commands/inc_speech_pitch.py @@ -4,26 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent speech pitch").format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('speech', 'pitch', 'inc') diff --git a/src/fenrirscreenreader/commands/commands/inc_speech_rate.py b/src/fenrirscreenreader/commands/commands/inc_speech_rate.py index 4aa54de0..b91fd1cd 100644 --- a/src/fenrirscreenreader/commands/commands/inc_speech_rate.py +++ b/src/fenrirscreenreader/commands/commands/inc_speech_rate.py @@ -4,26 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent speech rate").format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('speech', 'rate', 'inc') diff --git a/src/fenrirscreenreader/commands/commands/inc_speech_volume.py b/src/fenrirscreenreader/commands/commands/inc_speech_volume.py index ecb3dd94..bb88059d 100644 --- a/src/fenrirscreenreader/commands/commands/inc_speech_volume.py +++ b/src/fenrirscreenreader/commands/commands/inc_speech_volume.py @@ -4,26 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import math +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'adjustment_base.py') +_spec = importlib.util.spec_from_file_location("adjustment_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +AdjustmentCommand = _module.AdjustmentCommand -class command(): +class command(AdjustmentCommand): 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(_("{0} percent speech volume").format(int(value * 100)), soundIcon='', interrupt=True) - - def setCallback(self, callback): - pass + super().__init__('speech', 'volume', 'inc') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_1.py b/src/fenrirscreenreader/commands/commands/set_bookmark_1.py index f05a1ec0..333962b8 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_1.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_1.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(1, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_10.py b/src/fenrirscreenreader/commands/commands/set_bookmark_10.py index 2c5c5a91..499c1d4f 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_10.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_10.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(10, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_2.py b/src/fenrirscreenreader/commands/commands/set_bookmark_2.py index c48a9985..826a093a 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_2.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_2.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(2, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_3.py b/src/fenrirscreenreader/commands/commands/set_bookmark_3.py index 706e90ac..d87f444e 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_3.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_3.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(3, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_4.py b/src/fenrirscreenreader/commands/commands/set_bookmark_4.py index 2ff016de..fe2c1f83 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_4.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_4.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(4, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_5.py b/src/fenrirscreenreader/commands/commands/set_bookmark_5.py index 38afbe90..efa41d0d 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_5.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_5.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(5, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_6.py b/src/fenrirscreenreader/commands/commands/set_bookmark_6.py index d8ba1670..e5998745 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_6.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_6.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(6, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_7.py b/src/fenrirscreenreader/commands/commands/set_bookmark_7.py index 3b7744e1..f31fd689 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_7.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_7.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(7, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_8.py b/src/fenrirscreenreader/commands/commands/set_bookmark_8.py index 8dc7cbb2..dcdb9ce9 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_8.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_8.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(8, 'set') diff --git a/src/fenrirscreenreader/commands/commands/set_bookmark_9.py b/src/fenrirscreenreader/commands/commands/set_bookmark_9.py index 4793ba9d..30b67ed2 100644 --- a/src/fenrirscreenreader/commands/commands/set_bookmark_9.py +++ b/src/fenrirscreenreader/commands/commands/set_bookmark_9.py @@ -4,32 +4,14 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import os +import importlib.util +_base_path = os.path.join(os.path.dirname(__file__), 'bookmark_base.py') +_spec = importlib.util.spec_from_file_location("bookmark_base", _base_path) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +BookmarkCommand = _module.BookmarkCommand -class command(): +class command(BookmarkCommand): 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 {0}').format(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 {0} set for application {1}').format(self.ID, currApp), interrupt=True) - self.env['commandBuffer']['Marks']['1'] = None - self.env['commandBuffer']['Marks']['2'] = None - def setCallback(self, callback): - pass + super().__init__(9, 'set') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_a.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_a.py index 220f2fca..d4708630 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_a.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_a.py @@ -4,21 +4,8 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +from fenrirscreenreader.commands.vmenu_navigation.vmenu_search_base import VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('a') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('a') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_b.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_b.py index 44388bdb..78575c33 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_b.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_b.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('b') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('b') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_c.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_c.py index 1d6bd162..3b2733ac 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_c.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_c.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('c') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('c') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_d.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_d.py index bc4156b4..08e46880 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_d.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_d.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('d') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('d') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_e.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_e.py index 5549f26a..6591af03 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_e.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_e.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('e') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('e') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_f.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_f.py index be8f240a..2ec56cad 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_f.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_f.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('f') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('f') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_g.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_g.py index 495dfdb9..85efbb07 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_g.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_g.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('g') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('g') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_h.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_h.py index 0260d6f9..78751213 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_h.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_h.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('h') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('h') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_i.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_i.py index 7d5a8e00..050ae6e1 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_i.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_i.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('i') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('i') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_j.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_j.py index 2694c538..a6389c10 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_j.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_j.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('j') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('j') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_k.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_k.py index 4a75b3b1..121849d5 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_k.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_k.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('k') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('k') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_l.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_l.py index eb488ef8..a7c5e661 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_l.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_l.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('l') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('l') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_m.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_m.py index f6e03118..2c11eb16 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_m.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_m.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('m') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('m') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_n.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_n.py index 75b63b61..06c6c944 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_n.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_n.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('n') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('n') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_o.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_o.py index f9cf21d0..5cf8ef4a 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_o.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_o.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('o') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('o') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_p.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_p.py index aefe562d..b32fd29f 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_p.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_p.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('p') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('p') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_q.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_q.py index fe2bab4e..56844daa 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_q.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_q.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('q') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('q') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_r.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_r.py index 72956f1a..61e9536b 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_r.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_r.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('r') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('r') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_s.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_s.py index 6bc5b78b..c0c9389b 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_s.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_s.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('s') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('s') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_t.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_t.py index c4903343..318d4275 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_t.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_t.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('t') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('t') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_u.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_u.py index d4e65013..66b2eb4a 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_u.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_u.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('u') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('u') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_v.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_v.py index 02f246fb..3ce4be06 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_v.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_v.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('v') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('v') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_w.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_w.py index 220f2fca..0c4639f3 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_w.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_w.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('a') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('w') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_x.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_x.py index 3b7146aa..07b476ca 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_x.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_x.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('x') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('x') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_y.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_y.py index fdb11b47..81a2d4cf 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_y.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_y.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('y') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('y') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/search_z.py b/src/fenrirscreenreader/commands/vmenu-navigation/search_z.py index 89ee505b..bd1ed83f 100644 --- a/src/fenrirscreenreader/commands/vmenu-navigation/search_z.py +++ b/src/fenrirscreenreader/commands/vmenu-navigation/search_z.py @@ -4,21 +4,13 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. +import importlib.util +import os +_spec = importlib.util.spec_from_file_location("vmenu_search_base", os.path.join(os.path.dirname(__file__), "vmenu_search_base.py")) +_module = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_module) +VMenuSearchCommand = _module.VMenuSearchCommand -class command(): +class command(VMenuSearchCommand): def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return _('search for an menu entry') - def run(self): - text = self.env['runtime']['vmenuManager'].searchEntry('z') - if text != '': - self.env['runtime']['outputManager'].presentText(text, interrupt=True) - else: - self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) - def setCallback(self, callback): - pass + super().__init__('z') diff --git a/src/fenrirscreenreader/commands/vmenu-navigation/vmenu_search_base.py b/src/fenrirscreenreader/commands/vmenu-navigation/vmenu_search_base.py new file mode 100644 index 00000000..e3e8fafc --- /dev/null +++ b/src/fenrirscreenreader/commands/vmenu-navigation/vmenu_search_base.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +class VMenuSearchCommand(): + """Base class for VMenu search commands""" + def __init__(self, search_char): + self.search_char = search_char.lower() + + def initialize(self, environment): + self.env = environment + + def shutdown(self): + pass + + def getDescription(self): + return _('search for an menu entry') + + def run(self): + text = self.env['runtime']['vmenuManager'].searchEntry(self.search_char) + if text != '': + self.env['runtime']['outputManager'].presentText(text, interrupt=True) + else: + self.env['runtime']['outputManager'].presentText(_('not found'), soundIcon='ErrorScreen', interrupt=True) + + def setCallback(self, callback): + pass \ No newline at end of file