diff --git a/config/sound/default/HasAtributes.wav b/config/sound/default/HasAtributes.wav deleted file mode 100644 index 516ceae3..00000000 Binary files a/config/sound/default/HasAtributes.wav and /dev/null differ diff --git a/config/sound/default/soundicons.conf b/config/sound/default/soundicons.conf index 4fc0f767..d65fbec9 100644 --- a/config/sound/default/soundicons.conf +++ b/config/sound/default/soundicons.conf @@ -43,7 +43,7 @@ ErrorSpeech='ErrorSpeech.wav' ErrorBraille='ErrorBraille.wav' ErrorScreen='ErrorScreen.wav' # If you cursor over an text that has attributs (like color) -HasAttributes='HasAttributes.wav' +HasAttributes='has_attribute.wav' # fenrir can promote strings if they appear on the screen. PromotedText='PromotedText.wav' # missspelled indicator diff --git a/src/fenrirscreenreader/commands/onCursorChange/77000-has_attribute.py b/src/fenrirscreenreader/commands/onCursorChange/77000-has_attribute.py new file mode 100644 index 00000000..a6f85d06 --- /dev/null +++ b/src/fenrirscreenreader/commands/onCursorChange/77000-has_attribute.py @@ -0,0 +1,31 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from fenrirscreenreader.core import debug +from fenrirscreenreader.utils import screen_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('Reads attributes of current cursor position') + def run(self): + # is a vertical change? + if not (self.env['runtime']['cursorManager'].isCursorVerticalMove() or\ + self.env['runtime']['cursorManager'].isCursorHorizontalMove()): + return + + cursorPos = self.env['screen']['newCursor'] + + if not self.env['runtime']['attributeManager'].hasAttributes(cursorPos): + return + self.env['runtime']['outputManager'].presentText('has attribute', soundIcon='HasAttributes', interrupt=False) + def setCallback(self, callback): + pass diff --git a/src/fenrirscreenreader/core/attributeManager.py b/src/fenrirscreenreader/core/attributeManager.py index 586e2afc..7a93d0d4 100644 --- a/src/fenrirscreenreader/core/attributeManager.py +++ b/src/fenrirscreenreader/core/attributeManager.py @@ -14,11 +14,24 @@ class attributeManager(): self.currAttributeDelta = '' self.currAttributeCursor = None self.prefAttributeCursor = None - self.setDefaultAttributes() + self.setDefaultAttributes() + self.prevLastCursorAttribute = None + self.currLastCursorAttribute = None + def initialize(self, environment): self.env = environment def shutdown(self): pass + def setLastCursorAttribute(self, lastCursorAttribute): + self.prevLastCursorAttribute = self.currLastCursorAttribute + self.currLastCursorAttribute = lastCursorAttribute + def resetLastCursorAttribute(self, lastCursorAttribute): + self.prevLastCursorAttribute = None + self.currLastCursorAttribute = None + def isLastCursorAttributeChange(self): + if self.prevLastCursorAttribute == None: + return True + return self.prevLastCursorAttribute != self.currLastCursorAttribute def getCurrAttributeCursor(self): return self.currAttributeCursor def isAttributeCursorActive(self): @@ -56,7 +69,7 @@ class attributeManager(): if len(self.currAttributes[y]) < x - 1: return None try: - return self.currAttributes[y][x].copy() + return self.currAttributes[y][x] except KeyError: try: return self.defaultAttributes[0] @@ -89,8 +102,29 @@ class attributeManager(): 'default', # fontsize 'default' # fontfamily )) #end attribute - def isDefaultAttribute(self,attribute): - return attribute in self.defaultAttributes + def isDefaultAttribute(self,attribute): + useAttribute = None + if not attribute: + useAttribute = self.currAttributes + else: + useAttribute = attribute + return useAttribute in self.defaultAttributes + def hasAttributes(self, cursor, update=True): + if not cursor: + return False + cursorPos = cursor.copy() + try: + attributes = self.getAttributeByXY( cursorPos['x'], cursorPos['y']) + + if self.isDefaultAttribute(attributes): + return False + if update: + self.setLastCursorAttribute(attributes) + if not self.isLastCursorAttributeChange(): + return False + except Exception as e: + return False + return True def formatAttributes(self, attribute, attributeFormatString = None): # "black", # "red", @@ -254,7 +288,6 @@ class attributeManager(): # background.append(bgStat[1][0]) except Exception as e: print(e) - #background.append((7,7,0,0,0,0)) for line in range(len(self.prevAttributes)): if self.prevAttributes[line] != self.currAttributes[line]: for column in range(len(self.prevAttributes[line])):