From 93f4c92a104f2fa131fd6e061efee0741ec17ac7 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 3 Nov 2017 13:33:06 +0100 Subject: [PATCH] WIP memoryManager --- .../commands/commands/00_init_commands.py | 26 ++++++++++ .../commands/commands/WIP/00_init_commands.py | 26 ++++++++++ .../WIP/{Done => }/clear_clipboard.py | 0 .../{Done => }/copy_last_echo_to_clipboard.py | 0 .../{Done => }/copy_marked_to_clipboard.py | 0 .../commands/WIP/export_clipboard_to_file.py | 21 +++----- .../commands/WIP/export_clipboard_to_x.py | 16 ++---- .../commands/commands/WIP/first_clipboard.py | 9 ++-- .../WIP/import_clipboard_from_file.py | 3 +- .../commands/commands/WIP/last_clipboard.py | 9 ++-- .../commands/commands/WIP/next_clipboard.py | 22 ++++---- .../commands/commands/WIP/paste_clipboard.py | 18 ++----- .../commands/commands/WIP/prev_clipboard.py | 22 ++++---- .../commands/commands/clear_clipboard.py | 24 +++++++++ .../commands/copy_last_echo_to_clipboard.py | 26 ++++++++++ .../commands/copy_marked_to_clipboard.py | 39 +++++++++++++++ .../commands/commands/curr_clipboard.py | 27 ++++++++++ .../commands/export_clipboard_to_file.py | 39 +++++++++++++++ .../commands/export_clipboard_to_x.py | 50 +++++++++++++++++++ .../commands/commands/first_clipboard.py | 28 +++++++++++ .../commands/import_clipboard_from_file.py | 44 ++++++++++++++++ .../commands/commands/last_clipboard.py | 28 +++++++++++ .../commands/commands/next_clipboard.py | 36 +++++++++++++ .../commands/commands/paste_clipboard.py | 30 +++++++++++ .../commands/commands/prev_clipboard.py | 36 +++++++++++++ src/fenrir/core/commandData.py | 5 -- src/fenrir/core/memoryManager.py | 27 +++++++--- 27 files changed, 529 insertions(+), 82 deletions(-) create mode 100644 src/fenrir/commands/commands/00_init_commands.py create mode 100644 src/fenrir/commands/commands/WIP/00_init_commands.py rename src/fenrir/commands/commands/WIP/{Done => }/clear_clipboard.py (100%) rename src/fenrir/commands/commands/WIP/{Done => }/copy_last_echo_to_clipboard.py (100%) rename src/fenrir/commands/commands/WIP/{Done => }/copy_marked_to_clipboard.py (100%) create mode 100644 src/fenrir/commands/commands/clear_clipboard.py create mode 100644 src/fenrir/commands/commands/copy_last_echo_to_clipboard.py create mode 100644 src/fenrir/commands/commands/copy_marked_to_clipboard.py create mode 100644 src/fenrir/commands/commands/curr_clipboard.py create mode 100644 src/fenrir/commands/commands/export_clipboard_to_file.py create mode 100644 src/fenrir/commands/commands/export_clipboard_to_x.py create mode 100644 src/fenrir/commands/commands/first_clipboard.py create mode 100644 src/fenrir/commands/commands/import_clipboard_from_file.py create mode 100644 src/fenrir/commands/commands/last_clipboard.py create mode 100644 src/fenrir/commands/commands/next_clipboard.py create mode 100644 src/fenrir/commands/commands/paste_clipboard.py create mode 100644 src/fenrir/commands/commands/prev_clipboard.py diff --git a/src/fenrir/commands/commands/00_init_commands.py b/src/fenrir/commands/commands/00_init_commands.py new file mode 100644 index 00000000..6ab81bb1 --- /dev/null +++ b/src/fenrir/commands/commands/00_init_commands.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +# this command is just to initialize stuff. +# like init index lists in memoryManager +# it is not useful to execute it +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + # clipboard + self.env['runtime']['memoryManager'].addIndexList(self, 'clipboardHistory', self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards')) + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + pass + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/WIP/00_init_commands.py b/src/fenrir/commands/commands/WIP/00_init_commands.py new file mode 100644 index 00000000..6ab81bb1 --- /dev/null +++ b/src/fenrir/commands/commands/WIP/00_init_commands.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +# this command is just to initialize stuff. +# like init index lists in memoryManager +# it is not useful to execute it +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + # clipboard + self.env['runtime']['memoryManager'].addIndexList(self, 'clipboardHistory', self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards')) + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + pass + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/WIP/Done/clear_clipboard.py b/src/fenrir/commands/commands/WIP/clear_clipboard.py similarity index 100% rename from src/fenrir/commands/commands/WIP/Done/clear_clipboard.py rename to src/fenrir/commands/commands/WIP/clear_clipboard.py diff --git a/src/fenrir/commands/commands/WIP/Done/copy_last_echo_to_clipboard.py b/src/fenrir/commands/commands/WIP/copy_last_echo_to_clipboard.py similarity index 100% rename from src/fenrir/commands/commands/WIP/Done/copy_last_echo_to_clipboard.py rename to src/fenrir/commands/commands/WIP/copy_last_echo_to_clipboard.py diff --git a/src/fenrir/commands/commands/WIP/Done/copy_marked_to_clipboard.py b/src/fenrir/commands/commands/WIP/copy_marked_to_clipboard.py similarity index 100% rename from src/fenrir/commands/commands/WIP/Done/copy_marked_to_clipboard.py rename to src/fenrir/commands/commands/WIP/copy_marked_to_clipboard.py diff --git a/src/fenrir/commands/commands/WIP/export_clipboard_to_file.py b/src/fenrir/commands/commands/WIP/export_clipboard_to_file.py index acaa6c99..914de532 100644 --- a/src/fenrir/commands/commands/WIP/export_clipboard_to_file.py +++ b/src/fenrir/commands/commands/WIP/export_clipboard_to_file.py @@ -24,23 +24,14 @@ class command(): clipboardFilePath = clipboardFilePath.replace('$User',self.env['general']['currUser']) clipboardFile = open(clipboardFilePath,'w') try: - currClipboard = self.env['commandBuffer']['currClipboard'] - if currClipboard < 0: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard']: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard'][currClipboard]: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) return - if self.env['commandBuffer']['clipboard'][currClipboard] == '': - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - clipboardFile.write(self.env['commandBuffer']['clipboard'][currClipboard]) - clipboardFile.close() - os.chmod(clipboardFilePath, 0o666) - self.env['runtime']['outputManager'].presentText(_('clipboard exported to file'), interrupt=True) + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + clipboardFile.write(clipboard) + clipboardFile.close() + os.chmod(clipboardFilePath, 0o666) + self.env['runtime']['outputManager'].presentText(_('clipboard exported to file'), interrupt=True) except Exception as e: self.env['runtime']['debug'].writeDebugOut('export_clipboard_to_file:run: Filepath:'+ clipboardFile +' trace:' + str(e),debug.debugLevel.ERROR) diff --git a/src/fenrir/commands/commands/WIP/export_clipboard_to_x.py b/src/fenrir/commands/commands/WIP/export_clipboard_to_x.py index 8c11945e..25175c1f 100644 --- a/src/fenrir/commands/commands/WIP/export_clipboard_to_x.py +++ b/src/fenrir/commands/commands/WIP/export_clipboard_to_x.py @@ -24,22 +24,12 @@ class command(): def _threadRun(self): try: - currClipboard = self.env['commandBuffer']['currClipboard'] - - if currClipboard < 0: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard']: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard'][currClipboard]: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) return - if self.env['commandBuffer']['clipboard'][currClipboard] == '': - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') for display in range(10): - p = Popen('su ' + self.env['general']['currUser'] + ' -c "echo -n \\\"' + self.env['commandBuffer']['clipboard'][currClipboard].replace('"','\\\\\\"') +'\\\" | xclip -d :' + str(display) + ' -selection c"' , stdout=PIPE, stderr=PIPE, shell=True) + p = Popen('su ' + self.env['general']['currUser'] + ' -c "echo -n \\\"' + clipboard.replace('"','\\\\\\"') +'\\\" | xclip -d :' + str(display) + ' -selection c"' , stdout=PIPE, stderr=PIPE, shell=True) stdout, stderr = p.communicate() self.env['runtime']['outputManager'].interruptOutput() #screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding') diff --git a/src/fenrir/commands/commands/WIP/first_clipboard.py b/src/fenrir/commands/commands/WIP/first_clipboard.py index 152f65ed..a4d98c87 100644 --- a/src/fenrir/commands/commands/WIP/first_clipboard.py +++ b/src/fenrir/commands/commands/WIP/first_clipboard.py @@ -17,11 +17,12 @@ class command(): return _('selects the first clipboard') def run(self): - if len(self.env['commandBuffer']['clipboard']) == 0: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - self.env['commandBuffer']['currClipboard'] = 0 - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + return + self.env['runtime']['memoryManager'].setFirstIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard, interrupt=True) def setCallback(self, callback): pass diff --git a/src/fenrir/commands/commands/WIP/import_clipboard_from_file.py b/src/fenrir/commands/commands/WIP/import_clipboard_from_file.py index f9d6e2ee..67b4f398 100644 --- a/src/fenrir/commands/commands/WIP/import_clipboard_from_file.py +++ b/src/fenrir/commands/commands/WIP/import_clipboard_from_file.py @@ -29,8 +29,7 @@ class command(): clipboardFile = open(clipboardFilePath,'r') imported = clipboardFile.read() clipboardFile.close() - self.env['commandBuffer']['clipboard'] = [imported] + self.env['commandBuffer']['clipboard'][:self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards') -1] - self.env['commandBuffer']['currClipboard'] = 0 + self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', imported) self.env['runtime']['outputManager'].presentText('Import to Clipboard', soundIcon='CopyToClipboard', interrupt=True) self.env['runtime']['outputManager'].presentText(imported, soundIcon='', interrupt=False) diff --git a/src/fenrir/commands/commands/WIP/last_clipboard.py b/src/fenrir/commands/commands/WIP/last_clipboard.py index 2d8d2f5c..2cf2f0bd 100644 --- a/src/fenrir/commands/commands/WIP/last_clipboard.py +++ b/src/fenrir/commands/commands/WIP/last_clipboard.py @@ -17,11 +17,12 @@ class command(): return _('selects the last clipboard') def run(self): - if len(self.env['commandBuffer']['clipboard']) == 0: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - self.env['commandBuffer']['currClipboard'] = len(self.env['commandBuffer']['clipboard']) -1 - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + return + self.env['runtime']['memoryManager'].setLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard, interrupt=True) def setCallback(self, callback): pass diff --git a/src/fenrir/commands/commands/WIP/next_clipboard.py b/src/fenrir/commands/commands/WIP/next_clipboard.py index 7e3d2070..01d5607a 100644 --- a/src/fenrir/commands/commands/WIP/next_clipboard.py +++ b/src/fenrir/commands/commands/WIP/next_clipboard.py @@ -17,16 +17,20 @@ class command(): return _('selects the next clipboard') def run(self): - if len(self.env['commandBuffer']['clipboard']) == 0: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - self.env['commandBuffer']['currClipboard'] += 1 - if self.env['commandBuffer']['currClipboard'] > len(self.env['commandBuffer']['clipboard']) -1: - self.env['commandBuffer']['currClipboard'] = 0 - self.env['runtime']['outputManager'].presentText(_('First clipboard '), interrupt=True) - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=False) - else: - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + return + self.env['runtime']['memoryManager'].getNextIndex('clipboardHistory') + isFirst = self.env['runtime']['memoryManager'].isFirstIndex('clipboardHistory') + isLast = self.env['runtime']['memoryManager'].isLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + if isFirst: + self.env['runtime']['outputManager'].presentText(_('First clipboard '), interrupt=True) + if isLast: + self.env['runtime']['outputManager'].presentText(_('Last clipboard '), interrupt=True) + + speechInterrupt = not(isLast or isFirst) + self.env['runtime']['outputManager'].presentText(clipboard, interrupt = speechInterrupt) def setCallback(self, callback): pass diff --git a/src/fenrir/commands/commands/WIP/paste_clipboard.py b/src/fenrir/commands/commands/WIP/paste_clipboard.py index d611558f..1223a54b 100644 --- a/src/fenrir/commands/commands/WIP/paste_clipboard.py +++ b/src/fenrir/commands/commands/WIP/paste_clipboard.py @@ -19,22 +19,12 @@ class command(): return _('pastes the text from the currently selected clipboard') def run(self): - currClipboard = self.env['commandBuffer']['currClipboard'] - if currClipboard < 0: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard']: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if not self.env['commandBuffer']['clipboard'][currClipboard]: - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - if self.env['commandBuffer']['clipboard'][currClipboard] == '': - self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return + return self.env['runtime']['outputManager'].presentText('paste clipboard', soundIcon='PasteClipboardOnScreen', interrupt=True) - time.sleep(0.01) - self.env['runtime']['screenManager'].injectTextToScreen(self.env['commandBuffer']['clipboard'][currClipboard]) + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['screenManager'].injectTextToScreen(clipboard) def setCallback(self, callback): pass diff --git a/src/fenrir/commands/commands/WIP/prev_clipboard.py b/src/fenrir/commands/commands/WIP/prev_clipboard.py index 197d34ee..9aaaeaf9 100644 --- a/src/fenrir/commands/commands/WIP/prev_clipboard.py +++ b/src/fenrir/commands/commands/WIP/prev_clipboard.py @@ -17,16 +17,20 @@ class command(): return _('selects the previous clipboard') def run(self): - if len(self.env['commandBuffer']['clipboard']) == 0: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) - return - self.env['commandBuffer']['currClipboard'] -= 1 - if self.env['commandBuffer']['currClipboard'] < 0: - self.env['commandBuffer']['currClipboard'] = len(self.env['commandBuffer']['clipboard']) -1 - self.env['runtime']['outputManager'].presentText(_('Last clipboard '), interrupt=True) - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=False) - else: - self.env['runtime']['outputManager'].presentText(self.env['commandBuffer']['clipboard'][self.env['commandBuffer']['currClipboard']], interrupt=True) + return + self.env['runtime']['memoryManager'].setPrefIndex('clipboardHistory') + isFirst = self.env['runtime']['memoryManager'].isFirstIndex('clipboardHistory') + isLast = self.env['runtime']['memoryManager'].isLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + if isFirst: + self.env['runtime']['outputManager'].presentText(_('First clipboard '), interrupt=True) + if isLast: + self.env['runtime']['outputManager'].presentText(_('Last clipboard '), interrupt=True) + + speechInterrupt = not(isLast or isFirst) + self.env['runtime']['outputManager'].presentText(clipboard, interrupt = speechInterrupt) def setCallback(self, callback): pass diff --git a/src/fenrir/commands/commands/clear_clipboard.py b/src/fenrir/commands/commands/clear_clipboard.py new file mode 100644 index 00000000..781e6acf --- /dev/null +++ b/src/fenrir/commands/commands/clear_clipboard.py @@ -0,0 +1,24 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('clears the currently selected clipboard') + + def run(self): + self.env['runtime']['memoryManager'].clearCurrentIndexList('clipboardHistory') + self.env['runtime']['outputManager'].presentText(_('clipboard cleared'), interrupt=True) + return + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py b/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py new file mode 100644 index 00000000..a735a5a7 --- /dev/null +++ b/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py @@ -0,0 +1,26 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('copies last presented text to the currently selected clipboard') + + def run(self): + lastEcho = self.env['runtime']['outputManager'].getLastEcho() + self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', lastEcho) + self.env['runtime']['outputManager'].presentText(lastEcho, soundIcon='CopyToClipboard', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/copy_marked_to_clipboard.py b/src/fenrir/commands/commands/copy_marked_to_clipboard.py new file mode 100644 index 00000000..c83fdeb0 --- /dev/null +++ b/src/fenrir/commands/commands/copy_marked_to_clipboard.py @@ -0,0 +1,39 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('copies marked text to the currently selected clipboard') + + def run(self): + if not self.env['commandBuffer']['Marks']['1']: + self.env['runtime']['outputManager'].presentText(_("one or two marks needed"), interrupt=True) + return + if not self.env['commandBuffer']['Marks']['2']: + self.env['runtime']['cursorManager'].setMark() + + # use the last first and the last setted mark as range + startMark = self.env['commandBuffer']['Marks']['1'].copy() + endMark = self.env['commandBuffer']['Marks']['2'].copy() + + marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screen']['newContentText']) + self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', marked) + # reset marks + self.env['runtime']['cursorManager'].clearMarks() + + self.env['runtime']['outputManager'].presentText(marked, soundIcon='CopyToClipboard', interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/curr_clipboard.py b/src/fenrir/commands/commands/curr_clipboard.py new file mode 100644 index 00000000..9c2baf3e --- /dev/null +++ b/src/fenrir/commands/commands/curr_clipboard.py @@ -0,0 +1,27 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('speaks the contents of the currently selected clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard , interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/export_clipboard_to_file.py b/src/fenrir/commands/commands/export_clipboard_to_file.py new file mode 100644 index 00000000..f0aec632 --- /dev/null +++ b/src/fenrir/commands/commands/export_clipboard_to_file.py @@ -0,0 +1,39 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import os + +class command(): + def __init__(self): + pass + def initialize(self, environment, scriptPath=''): + self.env = environment + + def shutdown(self): + pass + def getDescription(self): + return _('export the current fenrir clipboard to a file') + def run(self): + clipboardFilePath = self.env['runtime']['settingsManager'].getSetting('general', 'clipboardExportPath') + clipboardFilePath = clipboardFilePath.replace('$user',self.env['general']['currUser']) + clipboardFilePath = clipboardFilePath.replace('$USER',self.env['general']['currUser']) + clipboardFilePath = clipboardFilePath.replace('$User',self.env['general']['currUser']) + clipboardFile = open(clipboardFilePath,'w') + try: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + clipboardFile.write(clipboard) + clipboardFile.close() + os.chmod(clipboardFilePath, 0o666) + self.env['runtime']['outputManager'].presentText(_('clipboard exported to file'), interrupt=True) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('export_clipboard_to_file:run: Filepath:'+ clipboardFile +' trace:' + str(e),debug.debugLevel.ERROR) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/export_clipboard_to_x.py b/src/fenrir/commands/commands/export_clipboard_to_x.py new file mode 100644 index 00000000..25175c1f --- /dev/null +++ b/src/fenrir/commands/commands/export_clipboard_to_x.py @@ -0,0 +1,50 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import subprocess, os +from subprocess import Popen, PIPE +import _thread + +class command(): + def __init__(self): + pass + def initialize(self, environment, scriptPath=''): + self.env = environment + self.scriptPath = scriptPath + def shutdown(self): + pass + def getDescription(self): + return _('export the current fenrir clipboard to X clipboard') + def run(self): + _thread.start_new_thread(self._threadRun , ()) + + def _threadRun(self): + try: + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + for display in range(10): + p = Popen('su ' + self.env['general']['currUser'] + ' -c "echo -n \\\"' + clipboard.replace('"','\\\\\\"') +'\\\" | xclip -d :' + str(display) + ' -selection c"' , stdout=PIPE, stderr=PIPE, shell=True) + stdout, stderr = p.communicate() + self.env['runtime']['outputManager'].interruptOutput() + #screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding') + stderr = stderr.decode('utf-8') + stdout = stdout.decode('utf-8') + if (stderr == ''): + break + #stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') + #stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') + if stderr != '': + self.env['runtime']['outputManager'].presentText(stderr , soundIcon='', interrupt=False) + else: + self.env['runtime']['outputManager'].presentText('exported to the X session.', interrupt=True) + except Exception as e: + self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/first_clipboard.py b/src/fenrir/commands/commands/first_clipboard.py new file mode 100644 index 00000000..a4d98c87 --- /dev/null +++ b/src/fenrir/commands/commands/first_clipboard.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('selects the first clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['memoryManager'].setFirstIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/import_clipboard_from_file.py b/src/fenrir/commands/commands/import_clipboard_from_file.py new file mode 100644 index 00000000..8dde0bd4 --- /dev/null +++ b/src/fenrir/commands/commands/import_clipboard_from_file.py @@ -0,0 +1,44 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils +import os + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['memoryManager'].isFirstIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard, interrupt=True) +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('imports text from clipboard file to the clipboard') + + def run(self): + clipboardFilePath = self.env['runtime']['settingsManager'].getSetting('general', 'clipboardExportPath') + clipboardFilePath = clipboardFilePath.replace('$user',self.env['general']['currUser']) + clipboardFilePath = clipboardFilePath.replace('$USER',self.env['general']['currUser']) + clipboardFilePath = clipboardFilePath.replace('$User',self.env['general']['currUser']) + if not os.path.exists(clipboardFilePath): + self.env['runtime']['outputManager'].presentText(_('File does not exist'), soundIcon='', interrupt=True) + return + clipboardFile = open(clipboardFilePath,'r') + imported = clipboardFile.read() + clipboardFile.close() + self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', imported) + + self.env['runtime']['outputManager'].presentText('Import to Clipboard', soundIcon='CopyToClipboard', interrupt=True) + self.env['runtime']['outputManager'].presentText(imported, soundIcon='', interrupt=False) + + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/last_clipboard.py b/src/fenrir/commands/commands/last_clipboard.py new file mode 100644 index 00000000..2cf2f0bd --- /dev/null +++ b/src/fenrir/commands/commands/last_clipboard.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('selects the last clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['memoryManager'].setLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['outputManager'].presentText(clipboard, interrupt=True) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/next_clipboard.py b/src/fenrir/commands/commands/next_clipboard.py new file mode 100644 index 00000000..01d5607a --- /dev/null +++ b/src/fenrir/commands/commands/next_clipboard.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('selects the next clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['memoryManager'].getNextIndex('clipboardHistory') + isFirst = self.env['runtime']['memoryManager'].isFirstIndex('clipboardHistory') + isLast = self.env['runtime']['memoryManager'].isLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + if isFirst: + self.env['runtime']['outputManager'].presentText(_('First clipboard '), interrupt=True) + if isLast: + self.env['runtime']['outputManager'].presentText(_('Last clipboard '), interrupt=True) + + speechInterrupt = not(isLast or isFirst) + self.env['runtime']['outputManager'].presentText(clipboard, interrupt = speechInterrupt) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/paste_clipboard.py b/src/fenrir/commands/commands/paste_clipboard.py new file mode 100644 index 00000000..1223a54b --- /dev/null +++ b/src/fenrir/commands/commands/paste_clipboard.py @@ -0,0 +1,30 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +import time + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.env['runtime']['memoryManager'].addIndexList('clipboardHistory', self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards')) + def shutdown(self): + pass + def getDescription(self): + return _('pastes the text from the currently selected clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['outputManager'].presentText('paste clipboard', soundIcon='PasteClipboardOnScreen', interrupt=True) + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + self.env['runtime']['screenManager'].injectTextToScreen(clipboard) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/commands/commands/prev_clipboard.py b/src/fenrir/commands/commands/prev_clipboard.py new file mode 100644 index 00000000..9aaaeaf9 --- /dev/null +++ b/src/fenrir/commands/commands/prev_clipboard.py @@ -0,0 +1,36 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('selects the previous clipboard') + + def run(self): + if self.env['runtime']['memoryManager'].isIndexListEmpty('clipboardHistory'): + self.env['runtime']['outputManager'].presentText(_('clipboard empty'), interrupt=True) + return + self.env['runtime']['memoryManager'].setPrefIndex('clipboardHistory') + isFirst = self.env['runtime']['memoryManager'].isFirstIndex('clipboardHistory') + isLast = self.env['runtime']['memoryManager'].isLastIndex('clipboardHistory') + clipboard = self.env['runtime']['memoryManager'].getIndexListElement('clipboardHistory') + if isFirst: + self.env['runtime']['outputManager'].presentText(_('First clipboard '), interrupt=True) + if isLast: + self.env['runtime']['outputManager'].presentText(_('Last clipboard '), interrupt=True) + + speechInterrupt = not(isLast or isFirst) + self.env['runtime']['outputManager'].presentText(clipboard, interrupt = speechInterrupt) + + def setCallback(self, callback): + pass diff --git a/src/fenrir/core/commandData.py b/src/fenrir/core/commandData.py index 987810f0..e653de30 100644 --- a/src/fenrir/core/commandData.py +++ b/src/fenrir/core/commandData.py @@ -11,11 +11,6 @@ import time # use this in your own commands commandBuffer = { 'enableSpeechOnKeypress': False, -'genericList':[], -'genericListSource':'', -'genericListSelection': 0, -'clipboard':[], -'currClipboard': 0, 'Marks':{'1':None, '2':None}, 'bookMarks':{}, 'windowArea':{}, diff --git a/src/fenrir/core/memoryManager.py b/src/fenrir/core/memoryManager.py index 2b152f76..ac7a09f4 100644 --- a/src/fenrir/core/memoryManager.py +++ b/src/fenrir/core/memoryManager.py @@ -15,22 +15,27 @@ class memoryManager(): def shutdown(self): pass def listStorageValid(self,name, index = None): + print(index,self.listStorage[name]['list']) try: if index == None: - index = self.listStorage[name]['index'] + index = self.listStorage[name]['index'] + if index == -1: + return self.listStorage[name]['list'] == [] return self.listStorage[name]['list'][index] != None - except e as Exception: + except Exception as e: self.env['runtime']['debug'].writeDebugOut("listStorageValid " + str(e),debug.debugLevel.ERROR) return False - def addValueToFirstIndex(self, name, value, index = 0): - if not self.listStorageValid(name, index): + def addValueToFirstIndex(self, name, value): + if not self.listStorageValid(name): return if self.listStorage[name]['maxLength'] != None: self.listStorage[name]['list'] = [value] + self.listStorage[name]['list'] else: self.listStorage[name]['list'] = [value] + self.listStorage[name]['list'][:self.listStorage[name]['maxLength'] -1] self.listStorage[name]['index'] = index - def addIndexList(self, name, maxLength = None, currList = [], currIndex = 0): + def addIndexList(self, name, maxLength = None, currList = [], currIndex = -1): + if len(currList) != 0 and (currIndex == -1): + currIndex = 0 self.listStorage[name] = {'list': currList, 'index': currIndex, 'maxLength': maxLength} def isLastIndex(self, name): if not self.listStorageValid(name): @@ -67,7 +72,14 @@ class memoryManager(): self.listStorage[name]['index'] = -1 return False self.listStorage[name]['index'] = 0 - return True + return True + def getIndexListLen(self, name): + if not self.listStorageValid(name): + return 0 + if self.isIndexListEmpty(name): + self.listStorage[name]['index'] = -1 + return 0 + return len(self.listStorage[name]['index']) def setLastIndex(self, name): if not self.listStorageValid(name): return False @@ -102,7 +114,8 @@ class memoryManager(): currIndex = self.getCurrentIndex(name) if currIndex == -1: return None - try: + try: + print(self.listStorage[name]['list']) return self.listStorage[name]['list'][currIndex] except: return None