def onTextInserted(self, event): """Called whenever text is inserted into an object. Arguments: - event: the Event """ obj = event.source self._debug("onTextInserted: name='%s', role='%s', parent='%s'" \ % (obj.name, obj.role, obj.parent.role)) parent = obj.parent if parent.role == rolenames.ROLE_AUTOCOMPLETE: # Thunderbird does not present all the text in an # autocompletion text entry. This is a workaround. # speech.stop() utterances = [] [text, caretOffset, startOffset] = self.getTextLineAtCaret(obj) utterances.append(text) self._debug("onTextInserted: utterances='%s'" % utterances) speech.speakUtterances(utterances) else: Gecko.Script.onTextInserted(self, event)
def _speakStatusBar(self): """Speaks the status bar.""" if not self._statusBar: return utterances = [] text = self._getObjLabelAndName(self._statusBar) utterances.append(text) speech.speakUtterances(utterances)
def _speakEnclosingPanel(self, obj): """Speak the enclosing panel for the object, if it is named. Going two containers up the hierarchy appears to be far enough to find a named panel, if there is one. Don't speak panels whose name begins with 'chrome://'""" self._debug("_speakEnclosingPanel") parent = obj.parent if not parent: return if parent.name != "" \ and (not parent.name.startswith("chrome://")) \ and (parent.role == rolenames.ROLE_PANEL): # Speak the parent panel name, but only once. # if parent.name != self._containingPanelName: self._containingPanelName = parent.name utterances = [] # Translators: this is the name of a panel in Thunderbird. # text = _("%s panel") % parent.name utterances.append(text) speech.speakUtterances(utterances) else: grandparent = parent.parent if grandparent \ and (grandparent.name != "") \ and (not grandparent.name.startswith("chrome://")) \ and (grandparent.role == rolenames.ROLE_PANEL): # Speak the grandparent panel name, but only once. # if grandparent.name != self._containingPanelName: self._containingPanelName = grandparent.name utterances = [] # Translators: this is the name of a panel in Thunderbird. # text = _("%s panel") % grandparent.name utterances.append(text) speech.speakUtterances(utterances)
def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus): """Called when the visual object with focus changes. Arguments: - event: if not None, the Event that caused the change - oldLocusOfFocus: Accessible that is the old locus of focus - newLocusOfFocus: Accessible that is the new locus of focus """ # First pass the event onto the parent class to be handled in # the default way. # default.Script.locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus) # Correctly handle the "System" tab (see Orca bug #433818). # If the locus of focus is on a page tab in the main GNOME # System Monitor window, then get a list of all the panels # on that page. For all of the panels that have a name, find # all the unrelated labels and speak them. # rolesList = [rolenames.ROLE_PAGE_TAB, \ rolenames.ROLE_PAGE_TAB_LIST, \ rolenames.ROLE_FILLER, \ rolenames.ROLE_FRAME] if self.isDesiredFocusedItem(event.source, rolesList): debug.println( self.debugLevel, "GNOME System Monitor.locusOfFocusChanged - page tab.") line = braille.getShowingLine() utterances = [] panels = self.findByRole(newLocusOfFocus, rolenames.ROLE_PANEL) for panel in panels: if panel.name and len(panel.name) > 0: line.addRegion(braille.Region(" " + panel.name)) utterances.append(panel.name) labels = self.findUnrelatedLabels(panel) for label in labels: line.addRegion(braille.Region(" " + label.name)) utterances.append(label.name) speech.speakUtterances(utterances) braille.refresh()
def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus): """Called when the visual object with focus changes. Arguments: - event: if not None, the Event that caused the change - oldLocusOfFocus: Accessible that is the old locus of focus - newLocusOfFocus: Accessible that is the new locus of focus """ # First pass the event onto the parent class to be handled in # the default way. # default.Script.locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus) # Correctly handle the "System" tab (see Orca bug #433818). # If the locus of focus is on a page tab in the main GNOME # System Monitor window, then get a list of all the panels # on that page. For all of the panels that have a name, find # all the unrelated labels and speak them. # rolesList = [rolenames.ROLE_PAGE_TAB, \ rolenames.ROLE_PAGE_TAB_LIST, \ rolenames.ROLE_FILLER, \ rolenames.ROLE_FRAME] if self.isDesiredFocusedItem(event.source, rolesList): debug.println(self.debugLevel, "GNOME System Monitor.locusOfFocusChanged - page tab.") line = braille.getShowingLine() utterances = [] panels = self.findByRole(newLocusOfFocus, rolenames.ROLE_PANEL) for panel in panels: if panel.name and len(panel.name) > 0: line.addRegion(braille.Region(" " + panel.name)) utterances.append(panel.name) labels = self.findUnrelatedLabels(panel) for label in labels: line.addRegion(braille.Region(" " + label.name)) utterances.append(label.name) speech.speakUtterances(utterances) braille.refresh()
def onCaretMoved(self, event): """Called whenever the caret moves. Arguments: - event: the Event """ debug.printObjectEvent(self.debugLevel, event, event.source.toString()) # self.printAncestry(event.source) # If we've received a text caret moved event and the current locus # of focus is on the Find button on the Find dialog or the combo # box in the Find dialog and the last input event was a Return, # and if the current line contains the phrase we were looking for, # then speak the current text line, to give an indication of what # we've just found. # if self.isFocusOnFindDialog() \ and orca_state.lastNonModifierKeyEvent.event_string == "Return": debug.println(self.debugLevel, "gedit.onCaretMoved - find dialog.") allComboBoxes = self.findByRole(orca_state.locusOfFocus.app, rolenames.ROLE_COMBO_BOX) phrase = self.getDisplayedText(allComboBoxes[0]) [text, caretOffset, startOffset] = \ self.getTextLineAtCaret(event.source) if text.lower().find(phrase) != -1: # Translators: this indicates a find command succeeded in # finding something. # speech.speak(_("Phrase found.")) utterances = self.speechGenerator.getSpeech(event.source, True) speech.speakUtterances(utterances) # For everything else, pass the caret moved event onto the parent # class to be handled in the default way. default.Script.onCaretMoved(self, event)
def onStateChanged(self, event): """Called whenever an object's state changes. Arguments: - event: the Event """ if event.type.startswith("object:state-changed:checked") and \ event.source.role == rolenames.ROLE_RADIO_BUTTON: # Radio buttons in the Search panel are not automatically # selected when you arrow to them. You have to press Space # to select the current radio button. Watch for this. # orca.visualAppearanceChanged(event, event.source) return elif event.type.startswith("object:state-changed:focused") and \ event.detail1 == 1: if event.source.role == rolenames.ROLE_PUSH_BUTTON: # Try to minimize chattiness in the Search panel # utterances = \ self.speechGenerator.getSpeech(event.source, False) speech.speakUtterances(utterances) brailleRegions = \ self.brailleGenerator.getBrailleRegions(event.source) braille.displayRegions(brailleRegions) orca.setLocusOfFocus(event, event.source, False) return elif event.source.role == rolenames.ROLE_TEXT: # There's an excellent chance that the Find toolbar just # gained focus. Check. # if self.isInFindToolbar(event.source): self.findToolbarActive = True default.Script.onStateChanged(self, event)
def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus): """Called when the visual object with focus changes. Overridden in this script to minimize the repetition of text along with the unnecessary speaking of object types. Arguments: - event: if not None, the Event that caused the change - oldLocusOfFocus: Accessible that is the old locus of focus - newLocusOfFocus: Accessible that is the new locus of focus """ if not newLocusOfFocus or (oldLocusOfFocus == newLocusOfFocus): return # Eliminate unnecessary chattiness related to the Find toolbar. # if self.findToolbarActive: if newLocusOfFocus.role == rolenames.ROLE_TEXT: newText = self.getTextLineAtCaret(newLocusOfFocus) if newText == self.preFindLine: orca.setLocusOfFocus(event, oldLocusOfFocus, False) return if newLocusOfFocus.role == rolenames.ROLE_DRAWING_AREA: orca.setLocusOfFocus(event, oldLocusOfFocus, False) return utterances = \ self.speechGenerator.getSpeech(newLocusOfFocus, False) speech.speakUtterances(utterances) brailleRegions = \ self.brailleGenerator.getBrailleRegions(newLocusOfFocus) braille.displayRegions(brailleRegions) orca.setLocusOfFocus(event, newLocusOfFocus, False) return # Eliminate unnecessary chattiness in the Search panel. # if newLocusOfFocus.role == rolenames.ROLE_PUSH_BUTTON and \ oldLocusOfFocus and oldLocusOfFocus.role == self.ROLE_LINK and \ newLocusOfFocus.name == oldLocusOfFocus.name: return # Eliminate general document chattiness. # if newLocusOfFocus.role == self.ROLE_DOCUMENT or \ newLocusOfFocus.role == rolenames.ROLE_DRAWING_AREA: orca.setLocusOfFocus(event, newLocusOfFocus, False) return elif newLocusOfFocus.role == self.ROLE_LINK: # It seems that this will be the only event we will get. But # the default script's onFocus will result in unnecessary # verboseness: reporting the drawing area(s) in which this link # is contained, speaking the periods in a table of contents, etc. # utterances = self.speechGenerator.getSpeech(newLocusOfFocus, False) adjustedUtterances = [] for utterance in utterances: adjustedUtterances.append(self.adjustForRepeats(utterance)) speech.speakUtterances(adjustedUtterances) brailleRegions = \ self.brailleGenerator.getBrailleRegions(newLocusOfFocus) braille.displayRegions(brailleRegions) orca.setLocusOfFocus(event, newLocusOfFocus, False) return default.Script.locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus)
def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus): """Called when the visual object with focus changes. Arguments: - event: if not None, the Event that caused the change - oldLocusOfFocus: Accessible that is the old locus of focus - newLocusOfFocus: Accessible that is the new locus of focus """ brailleGen = self.brailleGenerator speechGen = self.speechGenerator debug.printObjectEvent(self.debugLevel, event, event.source.toString()) # Here we handle the case when focus is in the "Work online/offline" # button near the status bar that has an image without a description. # We speak and braille "Online/Offline button" here, until the # developer of the application adds a description to the images # associated with the button, which shows the online or offline # work mode. # rolesList = [rolenames.ROLE_PUSH_BUTTON, rolenames.ROLE_FILLER, rolenames.ROLE_FILLER, rolenames.ROLE_FRAME] # We are checking if the button with the focus is the button to # turn on/off the work mode in liferea. This push button is # hierarchically located in the main window of the application # (frame), inside a filler and inside another filler. # if self.isDesiredFocusedItem(event.source, rolesList): # If we are focusing this button we construct a utterance and # a braille region to speak/braille "online/offline button". # Here we declare utterances and add the localized string # "online/offline". # utterances = [] utterances.append(_("Work online / offline")) # Here we extend the utterances with the speech generator for # the object with focus (the push button). # utterances.extend(speechGen.getSpeech(event.source,False)) # Finally we speak/braille the utterances/regions. # speech.speakUtterances(utterances) regions = brailleGen.getBrailleRegions(event.source) regions[0].insert(0, braille.Region(utterances[0] + " ")) braille.displayRegions(regions) return # Here we handle the case when the focus is in the headlines table. # See comment #3 of bug #350233. # http://bugzilla.gnome.org/show_bug.cgi?id=350233 # if orca_state.locusOfFocus.role == rolenames.ROLE_TABLE_COLUMN_HEADER: table = event.source.parent cells = self.findByRole(table, rolenames.ROLE_TABLE_CELL) eventsynthesizer.clickObject(cells[1], 1) default.Script.locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus)
def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus): """Called when the visual object with focus changes. Arguments: - event: if not None, the Event that caused the change - oldLocusOfFocus: Accessible that is the old locus of focus - newLocusOfFocus: Accessible that is the new locus of focus """ brailleGen = self.brailleGenerator speechGen = self.speechGenerator debug.printObjectEvent(self.debugLevel, event, event.source.toString()) # Here we handle the case when focus is in the "Work online/offline" # button near the status bar that has an image without a description. # We speak and braille "Online/Offline button" here, until the # developer of the application adds a description to the images # associated with the button, which shows the online or offline # work mode. # rolesList = [ rolenames.ROLE_PUSH_BUTTON, rolenames.ROLE_FILLER, rolenames.ROLE_FILLER, rolenames.ROLE_FRAME ] # We are checking if the button with the focus is the button to # turn on/off the work mode in liferea. This push button is # hierarchically located in the main window of the application # (frame), inside a filler and inside another filler. # if self.isDesiredFocusedItem(event.source, rolesList): # If we are focusing this button we construct a utterance and # a braille region to speak/braille "online/offline button". # Here we declare utterances and add the localized string # "online/offline". # utterances = [] utterances.append(_("Work online / offline")) # Here we extend the utterances with the speech generator for # the object with focus (the push button). # utterances.extend(speechGen.getSpeech(event.source, False)) # Finally we speak/braille the utterances/regions. # speech.speakUtterances(utterances) regions = brailleGen.getBrailleRegions(event.source) regions[0].insert(0, braille.Region(utterances[0] + " ")) braille.displayRegions(regions) return # Here we handle the case when the focus is in the headlines table. # See comment #3 of bug #350233. # http://bugzilla.gnome.org/show_bug.cgi?id=350233 # if orca_state.locusOfFocus.role == rolenames.ROLE_TABLE_COLUMN_HEADER: table = event.source.parent cells = self.findByRole(table, rolenames.ROLE_TABLE_CELL) eventsynthesizer.clickObject(cells[1], 1) default.Script.locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus)