From 5d168d232a22707cbf342f9d951b2a2eb635c025 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 4 Feb 2019 23:11:45 +0100 Subject: [PATCH] add remote bits --- src/fenrirscreenreader/core/remoteManager.py | 13 ++++ src/fenrirscreenreader/core/vmenuManager.py | 69 ++++---------------- 2 files changed, 26 insertions(+), 56 deletions(-) diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 040d7687..b42b5589 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -35,6 +35,8 @@ class remoteManager(): # command controll self.commandConst = 'COMMAND ' self.sayConst = 'SAY ' + self.vmenuConst = 'VMENU ' + self.resetVmenuConst = 'RESETVMENU' self.interruptConst = 'INTERRUPT' self.defineWindowConst = 'WINDOW ' self.resetWindowConst = 'RESETWINDOW' @@ -80,6 +82,13 @@ class remoteManager(): # interrupt if upperCommandText.startswith(self.interruptConst): self.interruptSpeech() + # set vmenu + if upperCommandText.startswith(self.vmenuConst): + parameterText = commandText[len(self.vmenuConst):] + self.setVMenu(parameterText) + # reset vmenu + if upperCommandText.startswith(self.resetVmenuConst): + self.resetVMenu() # define window if upperCommandText.startswith(self.defineWindowConst): parameterText = commandText[len(self.defineWindowConst):] @@ -91,6 +100,10 @@ class remoteManager(): if upperCommandText.startswith(self.setClipboardConst): parameterText = commandText[len(self.setClipboardConst):] self.setClipboard(parameterText) + def setVMenu(self, vmenu = ''): + self.env['runtime']['vmenuManager'].setCurrMenu(vmenu) + def resetVMenu(self): + self.env['runtime']['vmenuManager'].setCurrMenu() def setClipboard(self, text = ''): self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', text) def defineWindow(self, windowText): diff --git a/src/fenrirscreenreader/core/vmenuManager.py b/src/fenrirscreenreader/core/vmenuManager.py index 036a8f3f..a673b587 100755 --- a/src/fenrirscreenreader/core/vmenuManager.py +++ b/src/fenrirscreenreader/core/vmenuManager.py @@ -27,17 +27,22 @@ class vmenuManager(): def setCurrMenu(self, currMenu = ''): self.currIndex = None self.currMenu = '' - currIndex = None if currMenu != '': + currMenu += ' ' + _('Menu') try: t = self.menuDict[currMenu] - l = list(menuDict.keys()) - currIndex = [l.index(currMenu)] - except: + l = list(self.menuDict.keys()) + self.currIndex = [l.index(currMenu)] + except Exception as e: + print(e) + self.currMenu = '' + self.currIndex = None return if self.incLevel(): - self.currIndex = currIndex self.currMenu = currMenu + else: + self.currMenu = '' + self.currIndex = None def getCurrMenu(self): return self.currMenu def getActive(self): @@ -54,6 +59,9 @@ class vmenuManager(): try: if self.currMenu != '': self.setCurrMenu(self.currMenu) + if self.currIndex == None: + if len(self.menuDict) > 0: + self.currIndex = [0] except Exception as e: print(e) try: @@ -83,8 +91,6 @@ class vmenuManager(): menu = self.fs_tree_to_dict( self.defaultVMenuPath) if menu: self.menuDict = menu - if len(self.menuDict) > 0: - self.currIndex = [0] def executeMenu(self): if self.currIndex == None: return @@ -105,7 +111,6 @@ class vmenuManager(): return False try: r = self.getValueByPath(self.menuDict, self.currIndex +[0]) - print(r) if r == {}: return False except: @@ -141,7 +146,6 @@ class vmenuManager(): return True def getCurrentEntry(self): - print( self.getKeysByPath(self.menuDict, self.currIndex)[self.currIndex[-1]]) return self.getKeysByPath(self.menuDict, self.currIndex)[self.currIndex[-1]] def fs_tree_to_dict(self, path_): for root, dirs, files in os.walk(path_): @@ -182,50 +186,3 @@ class vmenuManager(): for i in path: d = d[list(d.keys())[i]] return d -''' -import os -level = [0] - -def fs_tree_to_dict( path_): - file_token = '' - for root, dirs, files in os.walk(path_): - tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} - print(files, root, dirs) - tree.update({f: root + '/' + f for f in files}) - return tree # note we discontinue iteration trough os.walk - - -v = fs_tree_to_dict( '/home/chrys/Projekte/fenrir/src/fenrirscreenreader/commands/vmenu/KEY') - - -def getNestedByPath(complete, path): - path = path.copy() - if path != []: - index = list(complete.keys())[path[0]] - path.remove(0) - nested = getNestedByPath(complete[index], path) - return nested - else: - return complete - -def getKeysByPath(complete, path): - d = complete - for i in path[:-1]: - d = d[list(d.keys())[i]] - return list(d.keys()) - - -def getValueByPath(complete, path): - d = complete - for i in path: - d = d[list(d.keys())[i]] - return d - - -c = [0,0,0] - - -getKeysByPath(v,c) -getValueByPath(v,c) - -'''