def displayFromContext(self, element, ctx=None): """ Gets the presentation string from the given context. @param ctx: The given context (widget, webapp, node) @type ctx: any @param element: The given element which has the focus. @type element: WebAppWidget or WebApp or NodeField @returns True if some text has been output, False otherwise. @rtype Bool """ # Gets presentation string f!om the context, if any. ret = () if ctx is not None: ret = self.extractAttributes(ctx) config = ctx.getPresentationConfig() else: # log.info("Getting presentation from element.") ret = self.extractAttributes(element) config = self.webApp.getPresentationConfig() brailleString = ret[1] presString = ret[0] if presString is False: raise ValueError("Template building failed.") if brailleString is False: brailleString = presString log.info("Will speak: %s" % presString) speech.speakMessage(presString) region = braille.TextRegion(brailleString) region.obj = None region.update() # TODO : Apply cursor positioning and text selection attributes. if 'braille.stripBlanks' in config: outBrl = [] startStrip = False for i in region.brailleCells: if i == 0x00 and startStrip == False: outBrl.append(i) startStrip = True elif i != 0x00: outBrl.append(i) startStrip = False region.brailleCells = outBrl self.bh.mainBuffer.clear() self.bh.mainBuffer.regions.append(region) self.bh.mainBuffer.update() self.bh.update() return True
def showSpeech(index, allowReadEntry=False): try: if braille.handler.getTether() == TETHER_SPEECH: text = speechList[index] if config.conf["brailleExtender"]["speechHistoryMode"][ "numberEntries"]: size_limit = len( str(config.conf["brailleExtender"]["speechHistoryMode"] ["limit"])) text = f"#%.{size_limit}d:{text}" % (index + 1) region = braille.TextRegion(text) region.update() braille.handler._doNewObject([region]) if allowReadEntry and config.conf["brailleExtender"][ "speechHistoryMode"]["speakEntries"]: speech.cancelSpeech() speak([speechList[index]], saveString=False) except BaseException: pass
def event_gainFocus(self): try: if ( # usual condition for SysListView32 # (the unique child should be the header list) (len(self.children) == 1 and not isinstance(self.children[0], ListItem)) or # condition for possible strange cases (not len(self.children))): super(EmptyList, self).event_gainFocus() # brailled and spoken the "0 elements" message text = ' '.join(["0", NVDALocale("Elements").lower()]) speech.speakMessage(text) region = braille.TextRegion(" " + text) region.focusToHardLeft = True region.update() braille.handler.buffer.regions.append(region) braille.handler.buffer.focus(region) braille.handler.buffer.update() braille.handler.update() # bind arrows to focus again (and repeat message) for item in ["Up", "Down", "Left", "Right"]: self.bindGesture("kb:%sArrow" % item, "alert") # other useful gesture to remap # script_reportCurrentFocus for gesture in getScriptGestures( commands.script_reportCurrentFocus): self.bindGesture(gesture, "alert") # self.bindGesture("kb:NVDA+tab", "alert") # script_reportCurrentLine for gesture in getScriptGestures( commands.script_reportCurrentLine): self.bindGesture(gesture, "alert") # script_reportCurrentSelection for gesture in getScriptGestures( commands.script_reportCurrentSelection): self.bindGesture(gesture, "alert") else: self.clearGestureBindings() super(EmptyList, self).event_gainFocus() except: pass
def displayBraille(self): s = "" selected = None plage = 0 self.brlPositions = [] cells = self.getRow().getCells() if cells is None: return curColVisible = False for i in range(0, self.getColCount()): try: text = cells[i].brlText() selected = cells[i].selected visited = cells[i].visited except: text = "err" selected = False visited = False if len(s) + len(text) > braille.handler.displaySize: # on dépasse la taille de la plage braille if self.forceBrlPlage: if plage == self.curBrlPlage: break else: if curColVisible: break # on réinitialise le calcule de la plage s = "" self.brlPositions = [] plage += 1 debut = len(s) fin = debut + len(text) self.brlPositions.append((debut, fin, i)) s += text + " " if i == self._curCol - 1: curColVisible = True if selected is None: return self.curBrlPlage = plage bh = braille.handler region = braille.TextRegion(s) region.obj = None region.update() if selected or visited: for x in xrange(len(region.brailleCells)): region.brailleCells[x] |= braille.DOT7 | braille.DOT8 else: for pos in self.brlPositions: debut, fin, i = pos if i == self._curCol - 1: start = False for x in xrange(len(region.brailleCells)): if x == debut and start is False: start = True # if region.brailleCells[x] == 0x00 and x + 1 < fin and region.brailleCells[x + 1] == 0x00: # start = False if start: region.brailleCells[ x] |= braille.DOT7 | braille.DOT8 if x == fin - 1: start = False bh.mainBuffer.clear() bh.mainBuffer.regions.append(region) bh.mainBuffer.update() bh.update()
def elten_command(ac): global eltenmod global eltenbraille global eltenbrailletext global eltenindex global eltenindexid global eltenqueue try: if(('ac' in ac)==False): return {} if(ac['ac']=="speak"): eltenindex=None eltenindexid=None text="" if('text' in ac): text=ac['text'] if(speech.isBlank(text)==False): queueHandler.queueFunction(queueHandler.eventQueue,speech.speakText,text) if(ac['ac']=="speakindexed"): eltenindex=None eltenindexid=None texts=[] indexes=[] indid=None if('texts' in ac): texts=ac['texts'] if('indexes' in ac): indexes=ac['indexes'] if('indid' in ac): indid=ac['indid'] v=[] for i in range(0, len(texts)): if is_python_3_or_above: if(speech.isBlank(texts[i])): continue if(i<len(indexes)): v.append(EltenIndexCallback(indexes[i], indid)) if(i<len(indexes) and i>0 and texts[i-1]!="" and texts[i-1][-1]=="\n"): v.append(speech.EndUtteranceCommand()) else: eltenindexid=indid if(i<len(indexes)): v.append(speech.IndexCommand(indexes[i])) v.append(texts[i]) speech.cancelSpeech() speech.speak(v) if(ac['ac']=='stop'): speech.cancelSpeech() eltenindex=None eltenindexid=None if(ac['ac']=='sleepmode'): st=eltenmod.sleepMode if('st' in ac): st=ac['st'] eltenmod.sleepMode=st return {'st': st} if(ac['ac']=='init'): pid=0 if('pid' in ac): pid=ac['pid'] eltenmod = appModuleHandler.getAppModuleFromProcessID(pid) def script_eltengesture(self, gesture): global eltenqueue eltenqueue['gestures']+=gesture.identifiers eltenmod.__class__.script_eltengesture = types.MethodType(script_eltengesture, eltenmod.__class__) eltenmod.bindGesture('kb(laptop):NVDA+A', 'eltengesture') eltenmod.bindGesture('kb(laptop):NVDA+L', 'eltengesture') eltenmod.bindGesture('kb(desktop):NVDA+downArrow', 'eltengesture') eltenmod.bindGesture('kb(desktop):NVDA+upArrow', 'eltengesture') if(ac['ac']=='braille'): text="" if('text' in ac): text=ac['text'] if('type' in ac and 'index' in ac): if ac['type']==-1: text=eltenbrailletext[:ac['index']]+eltenbrailletext[ac['index']+1:] elif ac['type']==1: text=eltenbrailletext[:ac['index']]+text+eltenbrailletext[ac['index']:] eltenbrailletext=text+" " regions=[] for phrase in re.split("([.,:/\n?!])", eltenbrailletext): if phrase=="": continue if len(regions)>10000: continue; region=braille.TextRegion(phrase) if hasattr(region, 'parseUndefinedChars'): region.parseUndefinedChars=False region.update() regions.append(region) eltenbraille.regions=regions if('pos' in ac): poses = eltenbraille.rawToBraillePos if(ac['pos']<len(text) and ac['pos']<len(poses)): reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['pos']]) eltenbraille.scrollTo(reg, pos) if('cursor' in ac and ac['cursor'] is not None): poses = eltenbraille.rawToBraillePos reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['cursor']]) reg.cursorPos=reg.brailleToRawPos[pos] reg.update() eltenbraille.update() braille.handler.update() if(ac['ac']=='braillepos' and 'pos' in ac and len(eltenbraille.regions)>0): poses = eltenbraille.rawToBraillePos if(ac['pos']<len(poses)): reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['pos']]) eltenbraille.scrollTo(reg, pos) reg.update() if('cursor' in ac and ac['cursor'] is not None): reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['cursor']]) reg.cursorPos=reg.brailleToRawPos[pos] reg.update() eltenbraille.update() braille.handler.update() if(ac['ac']=='getversion'): return {'version': 33} if(ac['ac']=='getnvdaversion'): return {'version': buildVersion.version} if(ac['ac']=='getindex'): if(is_python_3_or_above): return {'index': eltenindex, 'indid': eltenindexid} else: return {'index': speech.getLastSpeechIndex(), 'indid': eltenindexid} except Exception as Argument: log.exception("Elten: command thread") return {} return {}