示例#1
0
    def sayPhrase(self, obj, startOffset, endOffset):
        """Speaks the text of an Accessible object between the given offsets.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        - startOffset: the start text offset.
        - endOffset: the end text offset.
        """

        phrase = self.utilities.substring(obj, startOffset, endOffset)
        if len(phrase) and phrase != "\n":
            if phrase.decode("UTF-8").isupper():
                voice = self.voices[settings.UPPERCASE_VOICE]
            else:
                voice = self.voices[settings.DEFAULT_VOICE]

            phrase = self.utilities.adjustForRepeats(phrase)
            links = filter(lambda x: x.getRole() == pyatspi.ROLE_LINK, obj)
            if links:
                phrase = self.utilities.adjustForLinks(obj, phrase, startOffset)
            speech.speak(phrase, voice)
        else:
            # Speak blank line if appropriate.
            #
            self.sayCharacter(obj)
示例#2
0
    def onChildrenChanged(self, event):
        """Called whenever a child object changes in some way.

        Arguments:
        - event: the text inserted Event
        """

        # Check to see if a new chat room tab has been created and if it
        # has, then announce its name. See bug #469098 for more details.
        #
        if event.type.startswith("object:children-changed:add"):
            rolesList = [pyatspi.ROLE_PAGE_TAB_LIST,
                         pyatspi.ROLE_FILLER,
                         pyatspi.ROLE_FRAME]
            if self.utilities.hasMatchingHierarchy(event.source, rolesList):
                # As it's possible to get this component hierarchy in other
                # places than the chat room (i.e. the Preferences dialog),
                # we check to see if the name of the frame is the same as one
                # of its children. If it is, then it's a chat room tab event.
                # For a final check, we only announce the new chat tab if the
                # last child has a name.
                #
                nameFound = False
                frameName = event.source.parent.parent.name
                for child in event.source:
                    if frameName and (frameName == child.name):
                        nameFound = True
                if nameFound:
                    child = event.source[-1]
                    if child.name:
                        line = messages.CHAT_NEW_TAB % child.name
                        speech.speak(line)
示例#3
0
    def onStateChanged(self, event):
        """Called whenever an object's state changes.

        Arguments:
        - event: the Event
        """
        obj = event.source

        self._debug("onStateChanged: '%s' %s (%d, %d)" % \
                    (obj.name, event.type, event.detail1, event.detail2))

        # Handle tooltip popups.
        #
        if obj.getRole() == pyatspi.ROLE_TOOL_TIP:
            if event.type.startswith("object:state-changed:showing") and \
               event.detail1 == 1:
                self.displayBrailleMessage(obj.name)
                utterances = self.speechGenerator.generateSpeech(obj)
                speech.speak(utterances)

        # If focus moves to something within a panel and focus was not
        # already in the containing panel, the panel will issue its
        # own state-changed:focused event with detail1 == 1 after the
        # event for the item with focus.  The panel is not focused,
        # plus the extraneous event results in unnecessary chattiness
        # and updates the braille display to "panel."
        #
        elif obj.getRole() == pyatspi.ROLE_PANEL and \
             event.type.startswith("object:state-changed:focused") and \
             event.detail1 == 1 and not \
             event.source.getState().contains(pyatspi.STATE_FOCUSED):
            return

        else:
            default.Script.onStateChanged(self, event)
示例#4
0
    def onChildrenChanged(self, event):
        """Called whenever a child object changes in some way.

        Arguments:
        - event: the text inserted Event
        """

        # Check to see if a new chat room tab has been created and if it
        # has, then announce its name. See bug #469098 for more details.
        #
        if event.type.startswith("object:children-changed:add"):
            rolesList = [rolenames.ROLE_PAGE_TAB_LIST, \
                         rolenames.ROLE_FILLER, \
                         rolenames.ROLE_FRAME]
            if self.isDesiredFocusedItem(event.source, rolesList):
                childCount = event.source.childCount

                # As it's possible to get this component hierarchy in other
                # places than the chat room (i.e. the Preferences dialog),
                # we check to see if the name of the frame is the same as one
                # of its children. If it is, then it's a chat room tab event.
                # For a final check, we only announce the new chat tab if the
                # last child has a name.
                #
                nameFound = False
                frameName = event.source.parent.parent.name
                for i in range(0, childCount):
                    child = event.source.child(i)
                    if frameName and (frameName == child.name):
                        nameFound = True
                if nameFound:
                    child = event.source.child(childCount - 1)
                    if child.name:
                        line = _("New chat tab %s") % child.name
                        speech.speak(line)
示例#5
0
文件: script.py 项目: GNOME/orca
    def onTextInserted(self, event):
        """Callback for object:text-changed:insert accessibility events."""

        if not self.utilities.treatEventAsCommand(event):
            super().onTextInserted(event)
            return

        msg = "TERMINAL: Insertion is believed to be due to terminal command"
        debug.println(debug.LEVEL_INFO, msg, True)

        self.updateBraille(event.source)

        newString = self.utilities.insertedText(event)
        if len(newString) == 1:
            self.speakCharacter(newString)
        else:
            voice = self.speechGenerator.voice(string=newString)
            speech.speak(newString, voice)

        if self.flatReviewContext:
            return

        try:
            text = event.source.queryText()
        except:
            pass
        else:
            self._saveLastCursorPosition(event.source, text.caretOffset)
            self.utilities.updateCachedTextSelection(event.source)
示例#6
0
    def onCheckedChanged(self, event):
        """Callback for object:state-changed:checked accessibility events."""

        obj = event.source
        role = obj.getRole()
        parentRole = obj.parent.getRole()
        if not role in [pyatspi.ROLE_TOGGLE_BUTTON, pyatspi.ROLE_PUSH_BUTTON] \
           or not parentRole == pyatspi.ROLE_TOOL_BAR:
            default.Script.onCheckedChanged(self, event)
            return

        sourceWindow = self.utilities.topLevelObject(obj)
        focusWindow = self.utilities.topLevelObject(orca_state.locusOfFocus)
        if sourceWindow != focusWindow:
            return

        # Announce when the toolbar buttons are toggled if we just toggled
        # them; not if we navigated to some text.
        weToggledIt = False
        if isinstance(orca_state.lastInputEvent, input_event.MouseButtonEvent):
            x = orca_state.lastInputEvent.x
            y = orca_state.lastInputEvent.y
            weToggledIt = obj.queryComponent().contains(x, y, 0)
        elif obj.getState().contains(pyatspi.STATE_FOCUSED):
            weToggledIt = True
        else:
            keyString, mods = self.utilities.lastKeyAndModifiers()
            navKeys = [
                "Up", "Down", "Left", "Right", "Page_Up", "Page_Down", "Home",
                "End", "N"
            ]
            wasCommand = mods & keybindings.COMMAND_MODIFIER_MASK
            weToggledIt = wasCommand and keyString not in navKeys
        if weToggledIt:
            speech.speak(self.speechGenerator.generateSpeech(obj))
示例#7
0
    def onChildrenChanged(self, event):
        """Called whenever a child object changes in some way.

        Arguments:
        - event: the text inserted Event
        """

        # Check to see if a new chat room tab has been created and if it
        # has, then announce its name. See bug #469098 for more details.
        #
        if event.type.startswith("object:children-changed:add"):
            rolesList = [rolenames.ROLE_PAGE_TAB_LIST, rolenames.ROLE_FILLER, rolenames.ROLE_FRAME]
            if self.isDesiredFocusedItem(event.source, rolesList):
                childCount = event.source.childCount

                # As it's possible to get this component hierarchy in other
                # places than the chat room (i.e. the Preferences dialog),
                # we check to see if the name of the frame is the same as one
                # of its children. If it is, then it's a chat room tab event.
                # For a final check, we only announce the new chat tab if the
                # last child has a name.
                #
                nameFound = False
                frameName = event.source.parent.parent.name
                for i in range(0, childCount):
                    child = event.source.child(i)
                    if frameName and (frameName == child.name):
                        nameFound = True
                if nameFound:
                    child = event.source.child(childCount - 1)
                    if child.name:
                        line = _("New chat tab %s") % child.name
                        speech.speak(line)
示例#8
0
文件: script.py 项目: rathovarun/orca
    def presentStatusBar(self, obj):
        """Presents information about the metacity status bar."""

        # We have to stop speech, as Metacity has a key grab and we're not
        # getting keys
        #
        speech.stop()

        # If the window was iconified, then obj.name will be surrounded by
        # brackets. If this is the case, remove them before comparing the
        # name against the various window names. See bug #522797 for more
        # details.
        #
        objName = obj.name
        if objName and len(objName):
            if objName[0] == "[" and objName[-1] == "]":
                objName = objName[1:-1]

        try:
            text = obj.name
        except:
            text = objName

        self.displayBrailleMessage(text)
        speech.speak(text)
    def onTextInserted(self, event):
        """Called whenever text is inserted into gcalctool's text display.
        If the object is an instant message or chat, speak the text If we're
        not watching anything, do the default behavior.

        Arguments:
        - event: the text inserted Event
        """

        # This is an attempt to only read the display when enter or equals is
        # pressed - so when we get text insertions to the display, speak
        # them if the last key pressed was enter or equals.
        #
        # Always update the Braille display but only speak if the last
        # key pressed was enter or equals
        #
        if event.source == self._resultsDisplay:
            contents = self.getText(self._resultsDisplay, 0, -1)
            braille.displayMessage(contents)

            if (orca_state.lastInputEvent is None) \
                   or \
                   (not isinstance(orca_state.lastInputEvent,
                                   input_event.KeyboardEvent)):
                return

            if (orca_state.lastNonModifierKeyEvent.event_string == "space") \
                   or (orca_state.lastNonModifierKeyEvent.event_string \
                       == "Return") \
                   or (orca_state.lastNonModifierKeyEvent.event_string == "="):
                speech.speak(contents)
示例#10
0
    def onNameChanged(self, event):
        """Callback for object:property-change:accessible-name events."""

        try:
            ivalue = event.source.queryValue()
            value = ivalue.currentValue
        except NotImplementedError:
            value = -1

        utterances = []
        message = ""
        if value < 0:
            utterances.append(messages.NOTIFICATION)
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))
            message = '%s %s' % (event.source.name, event.source.description)
            utterances.append(message)
            utterances.append(self.voices.get(settings.DEFAULT_VOICE))
        else:
            # A gauge notification, e.g. the Ubuntu volume notification that
            # appears when you press the multimedia keys.
            #
            message = '%s %d' % (event.source.name, value)
            utterances.append(message)
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))

        speech.speak(utterances, None, True)
        self.displayBrailleMessage(message,
                                   flashTime=settings.brailleFlashTime)
        notification_messages.saveMessage(message)
示例#11
0
    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
        """

        # If the new locus of focus has a role of "terminal", then update
        # the braille display accordingly. Also speak the page tab that this
        # terminal is in if it's sensitive (i.e. there are two or more tabs)
        # and if the old locus of focus also had a "terminal role.
        # See bug #518762 for more details.
        #
        if newLocusOfFocus and \
           newLocusOfFocus.getRole() == pyatspi.ROLE_TERMINAL:
            pageTab = event.source.parent.parent.parent
            if oldLocusOfFocus \
               and oldLocusOfFocus.getRole() == pyatspi.ROLE_TERMINAL and \
               pageTab.getRole() == pyatspi.ROLE_PAGE_TAB and \
               pageTab.getState().contains(pyatspi.STATE_SENSITIVE):
                self.updateBraille(newLocusOfFocus)
                utterances = self.speechGenerator.generateSpeech(pageTab)
                speech.speak(utterances)

        gtk.Script.locusOfFocusChanged(self, event,
                                           oldLocusOfFocus, newLocusOfFocus)
示例#12
0
文件: script.py 项目: barichd/orca
    def onNameChanged(self, event):
        """Callback for object:property-change:accessible-name events."""

        if event.source.name == self.spellcheck.getMisspelledWord():
            self.spellcheck.presentErrorDetails()
            return

        obj = event.source

        # If the user has just deleted an open mail message, then we want to
        # try to speak the new name of the open mail message frame and also
        # present the first line of that message to be consistent with what
        # we do when a new message window is opened. See bug #540039 for more
        # details.
        #
        rolesList = [pyatspi.ROLE_DOCUMENT_FRAME,
                     pyatspi.ROLE_INTERNAL_FRAME,
                     pyatspi.ROLE_FRAME,
                     pyatspi.ROLE_APPLICATION]
        if self.utilities.hasMatchingHierarchy(event.source, rolesList):
            lastKey, mods = self.utilities.lastKeyAndModifiers()
            if lastKey == "Delete":
                speech.speak(obj.name)
                [obj, offset] = self.findFirstCaretContext(obj, 0)
                self.setCaretPosition(obj, offset)
                return
示例#13
0
    def onTextInserted(self, event):
        """Callback for object:text-changed:insert accessibility events."""

        if not self.utilities.treatEventAsCommand(event):
            super().onTextInserted(event)
            return

        msg = "TERMINAL: Insertion is believed to be due to terminal command"
        debug.println(debug.LEVEL_INFO, msg, True)

        self.updateBraille(event.source)

        newString = self.utilities.insertedText(event)
        if len(newString) == 1:
            self.speakCharacter(newString)
        else:
            voice = self.speechGenerator.voice(string=newString)
            speech.speak(newString, voice)

        if self.flatReviewContext:
            return

        try:
            text = event.source.queryText()
        except:
            pass
        else:
            self._saveLastCursorPosition(event.source, text.caretOffset)
            self.utilities.updateCachedTextSelection(event.source)
示例#14
0
    def onTextInserted(self, event):
        """Called whenever text is inserted into an object.

        Arguments:
        - event: the Event
        """
        obj = event.source
        parent = obj.parent

        # Try to stop unwanted chatter when a new message is being
        # replied to. See bgo#618484.
        #
        if event.source.getRole() == pyatspi.ROLE_DOCUMENT_FRAME \
           and event.source.getState().contains(pyatspi.STATE_EDITABLE) \
           and event.type.endswith("system"):
            return

        # Speak the autocompleted text, but only if it is different
        # address so that we're not too "chatty." See bug #533042.
        #
        if parent.getRole() == pyatspi.ROLE_AUTOCOMPLETE:
            if event.type.endswith("system") and event.any_data:
                # The autocompleted address may start with the name,
                # or it might start with the text typed by the user
                # followed by ">>" followed by the address. Therefore
                # we'll look at whatever follows the ">>" should it
                # exist.
                #
                address = event.any_data.split(">>")[-1]
                if self._lastAutoComplete != address:
                    speech.speak(address)
                self._lastAutoComplete = address
                return

        Gecko.Script.onTextInserted(self, event)
示例#15
0
def decirInfoBateria(script, inputEvent=None):
    f = os.popen("acpi")
    speech.speak(f.read())
    f = os.popen("acpi")
    braille.displayMessage(f.read(80))
    f.close()
    return True
示例#16
0
    def onFocus(self, event):
        """Called whenever an object gets focus.

        Arguments:
        - event: the Event
        """

        # This seems to be the most reliable way to identify that the
        # active chatroom was changed via keyboard from within the entry.
        # In this case, speak and flash braille the new room name.
        #
        if orca_state.locusOfFocus and event.source \
           and orca_state.locusOfFocus.getRole() == pyatspi.ROLE_ENTRY \
           and event.source.getRole() == pyatspi.ROLE_ENTRY \
           and orca_state.locusOfFocus != event.source:
            room1 = self.chat.getChatRoomName(orca_state.locusOfFocus)
            room2 = self.chat.getChatRoomName(event.source)
            if room1 != room2:
                speech.speak(room2)
                flashTime = _settingsManager.getSetting('brailleFlashTime')
                self.displayBrailleMessage(room2, flashTime)
                orca.setLocusOfFocus(event, event.source)
                return

        if self.inDocumentContent(event.source):
            Gecko.Script.onFocus(self, event)
        else:
            default.Script.onFocus(self, event)
示例#17
0
    def presentStatusBar(self, obj):
        """Presents information about the metacity status bar."""

        # We have to stop speech, as Metacity has a key grab and we're not
        # getting keys
        #
        speech.stop()

        # If the window was iconified, then obj.name will be surronded by
        # brackets. If this is the case, remove them before comparing the
        # name against the various window names. See bug #522797 for more
        # details.
        #
        objName = obj.name
        if objName and len(objName):
            if objName[0] == "[" and objName[-1] == "]":
                objName = objName[1:-1]

        try:
            text = obj.name
        except:
            text = objName

        self.displayBrailleMessage(text)
        speech.speak(text)
示例#18
0
    def presentObject(self, obj, **args):
        if not self._lastCommandWasStructNav:
            super().presentObject(obj, **args)
            return

        utterances = self.speechGenerator.generateSpeech(obj, **args)
        speech.speak(utterances)
示例#19
0
    def sayPhrase(self, obj, startOffset, endOffset):
        """Speaks the text of an Accessible object between the given offsets.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        - startOffset: the start text offset.
        - endOffset: the end text offset.
        """

        if obj.getRole() == pyatspi.ROLE_ENTRY:
            default.Script.sayPhrase(self, obj, startOffset, endOffset)
            return

        phrase = self.utilities.substring(obj, startOffset, endOffset)
        if len(phrase) and phrase != "\n":
            if phrase.isupper():
                voice = self.voices[settings.UPPERCASE_VOICE]
            else:
                voice = self.voices[settings.DEFAULT_VOICE]

            phrase = self.utilities.adjustForRepeats(phrase)
            links = [x for x in obj if x.getRole() == pyatspi.ROLE_LINK]
            if links:
                phrase = self.utilities.adjustForLinks(obj, phrase,
                                                       startOffset)
            speech.speak(phrase, voice)
        else:
            # Speak blank line if appropriate.
            #
            self.sayCharacter(obj)
示例#20
0
    def onNameChanged(self, event):
        """Callback for object:property-change:accessible-name events."""

        if event.source.name == self.spellcheck.getMisspelledWord():
            self.spellcheck.presentErrorDetails()
            return

        obj = event.source

        # If the user has just deleted an open mail message, then we want to
        # try to speak the new name of the open mail message frame and also
        # present the first line of that message to be consistent with what
        # we do when a new message window is opened. See bug #540039 for more
        # details.
        #
        rolesList = [
            pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_INTERNAL_FRAME,
            pyatspi.ROLE_FRAME, pyatspi.ROLE_APPLICATION
        ]
        if self.utilities.hasMatchingHierarchy(event.source, rolesList):
            lastKey, mods = self.utilities.lastKeyAndModifiers()
            if lastKey == "Delete":
                speech.speak(obj.name)
                [obj, offset] = self.utilities.findFirstCaretContext(obj, 0)
                self.utilities.setCaretPosition(obj, offset)
                return
示例#21
0
    def onWindowCreate(self, event):
        """Called whenever a window is created in the notify-osd
        application.

        Arguments:
        - event: the Event.
        """
        try:
            ivalue = event.source.queryValue()
            value = ivalue.currentValue
        except NotImplementedError:
            value = -1
            
        utterances = []
        message = ""
        if value < 0:
            # Translators: This denotes a notification to the user of some sort.
            #
            utterances.append(_('Notification'))
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))
            message = '%s %s' % (event.source.name, event.source.description)
            utterances.append(message)
            utterances.append(self.voices.get(settings.DEFAULT_VOICE))
        else:
            # A gauge notification, e.g. the Ubuntu volume notification that
            # appears when you press the multimedia keys.
            #
            message = '%s %d' % (event.source.name, value)
            utterances.append(message)
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))

        speech.speak(utterances, None, True)
        self.displayBrailleMessage(message, flashTime=settings.brailleFlashTime)
        notification_messages.saveMessage(message)
示例#22
0
文件: script.py 项目: barichd/orca
    def onWindowCreated(self, event):
        """Callback for window:create accessibility events."""

        a = self.utilities.descendantsWithRole(event.source, pyatspi.ROLE_LABEL)
        texts = [self.utilities.displayedText(acc) for acc in a]
        text = '%s %s' % (messages.NOTIFICATION, ' '.join(texts))
        speech.speak(text, None, True)
示例#23
0
    def onCheckedChanged(self, event):
        """Callback for object:state-changed:checked accessibility events."""

        obj = event.source
        role = obj.getRole()
        parentRole = obj.parent.getRole()
        if not role in [pyatspi.ROLE_TOGGLE_BUTTON, pyatspi.ROLE_PUSH_BUTTON] \
           or not parentRole == pyatspi.ROLE_TOOL_BAR:
            default.Script.onCheckedChanged(self, event)
            return
 
        # Announce when the toolbar buttons are toggled if we just toggled
        # them; not if we navigated to some text.
        weToggledIt = False
        if isinstance(orca_state.lastInputEvent, input_event.MouseButtonEvent):
            x = orca_state.lastInputEvent.x
            y = orca_state.lastInputEvent.y
            weToggledIt = obj.queryComponent().contains(x, y, 0)
        else:
            keyString, mods = self.utilities.lastKeyAndModifiers()
            navKeys = ["Up", "Down", "Left", "Right", "Page_Up", "Page_Down",
                       "Home", "End"]
            wasCommand = mods & settings.COMMAND_MODIFIER_MASK
            weToggledIt = wasCommand and keyString not in navKeys
        if weToggledIt:
            speech.speak(self.speechGenerator.generateSpeech(obj))
示例#24
0
文件: script.py 项目: h4ck3rm1k3/orca
    def onNameChanged(self, event):
        """Callback for object:property-change:accessible-name events."""

        try:
            ivalue = event.source.queryValue()
            value = ivalue.currentValue
        except NotImplementedError:
            value = -1

        utterances = []
        message = ""
        if value < 0:
            utterances.append(messages.NOTIFICATION)
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))
            message = '%s %s' % (event.source.name, event.source.description)
            utterances.append(message)
            utterances.append(self.voices.get(settings.DEFAULT_VOICE))
        else:
            # A gauge notification, e.g. the Ubuntu volume notification that
            # appears when you press the multimedia keys.
            #
            message = '%s %d' % (event.source.name, value)
            utterances.append(message)
            utterances.append(self.voices.get(settings.SYSTEM_VOICE))

        speech.speak(utterances, None, True)
        self.displayBrailleMessage(
            message, flashTime=settings.brailleFlashTime)
        notification_messages.saveMessage(message)
def decirInfoBateria(script, inputEvent=None):
  f=os.popen("acpi")
  speech.speak(f.read())
  f=os.popen("acpi")
  braille.displayMessage(f.read(80))
  f.close()
  return True
示例#26
0
    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
        """

        # If the new locus of focus has a role of "terminal", then update
        # the braille display accordingly. Also speak the page tab that this
        # terminal is in if it's sensitive (i.e. there are two or more tabs)
        # and if the old locus of focus also had a "terminal role.
        # See bug #518762 for more details.
        #
        if newLocusOfFocus and \
           newLocusOfFocus.getRole() == pyatspi.ROLE_TERMINAL:
            pageTab = event.source.parent.parent.parent
            if oldLocusOfFocus \
               and oldLocusOfFocus.getRole() == pyatspi.ROLE_TERMINAL and \
               pageTab.getRole() == pyatspi.ROLE_PAGE_TAB and \
               pageTab.getState().contains(pyatspi.STATE_SENSITIVE):
                self.updateBraille(newLocusOfFocus)
                utterances = self.speechGenerator.generateSpeech(pageTab)
                speech.speak(utterances)

        gtk.Script.locusOfFocusChanged(self, event,
                                           oldLocusOfFocus, newLocusOfFocus)
示例#27
0
    def presentObject(self, obj, **args):
        if not self._lastCommandWasStructNav:
            super().presentObject(obj, **args)
            return

        utterances = self.speechGenerator.generateSpeech(obj, **args)
        speech.speak(utterances)
示例#28
0
    def sayLine(self, obj):
        """Speaks the line at the caret.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        """

        if obj.getRole() == pyatspi.ROLE_ENTRY:
            default.Script.sayLine(self, obj)
            return

        boundary = pyatspi.TEXT_BOUNDARY_LINE_START
        objects = self.utilities.getObjectsFromEOCs(obj, boundary=boundary)
        for (obj, start, end, string) in objects:
            self.sayPhrase(obj, start, end)

            # TODO: Move these next items into the speech generator.
            if obj.getRole() == pyatspi.ROLE_PANEL \
               and obj.getIndexInParent() == 0:
                obj = obj.parent

            rolesToSpeak = [pyatspi.ROLE_HEADING, pyatspi.ROLE_LINK]
            if obj.getRole() in rolesToSpeak:
                speech.speak(self.speechGenerator.getRoleName(obj))

        self.pointOfReference["lastTextUnitSpoken"] = "line"
示例#29
0
    def sayPhrase(self, obj, startOffset, endOffset):
        """Speaks the text of an Accessible object between the given offsets.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        - startOffset: the start text offset.
        - endOffset: the end text offset.
        """

        if obj.getRole() == pyatspi.ROLE_ENTRY:
            default.Script.sayPhrase(self, obj, startOffset, endOffset)
            return

        phrase = self.utilities.substring(obj, startOffset, endOffset)
        if len(phrase) and phrase != "\n":
            voice = self.speechGenerator.voice(string=phrase)
            phrase = self.utilities.adjustForRepeats(phrase)
            links = [x for x in obj if x.getRole() == pyatspi.ROLE_LINK]
            if links:
                phrase = self.utilities.adjustForLinks(obj, phrase,
                                                       startOffset)
            speech.speak(phrase, voice)
        else:
            # Speak blank line if appropriate.
            #
            self.sayCharacter(obj)

        self.pointOfReference["lastTextUnitSpoken"] = "phrase"
示例#30
0
    def onChildrenChanged(self, event):
        """Called whenever a child object changes in some way.

        Arguments:
        - event: the text inserted Event
        """

        # Check to see if a new chat room tab has been created and if it
        # has, then announce its name. See bug #469098 for more details.
        #
        if event.type.startswith("object:children-changed:add"):
            rolesList = [
                pyatspi.ROLE_PAGE_TAB_LIST, pyatspi.ROLE_FILLER,
                pyatspi.ROLE_FRAME
            ]
            if self.utilities.hasMatchingHierarchy(event.source, rolesList):
                # As it's possible to get this component hierarchy in other
                # places than the chat room (i.e. the Preferences dialog),
                # we check to see if the name of the frame is the same as one
                # of its children. If it is, then it's a chat room tab event.
                # For a final check, we only announce the new chat tab if the
                # last child has a name.
                #
                nameFound = False
                frameName = event.source.parent.parent.name
                for child in event.source:
                    if frameName and (frameName == child.name):
                        nameFound = True
                if nameFound:
                    child = event.source[-1]
                    if child.name:
                        line = messages.CHAT_NEW_TAB % child.name
                        speech.speak(line)
示例#31
0
    def onNameChanged(self, event):
        """Called whenever a property on an object changes.

        Arguments:
        - event: the Event
        """

        obj = event.source

        # If the user has just deleted an open mail message, then we want to
        # try to speak the new name of the open mail message frame and also
        # present the first line of that message to be consistent with what
        # we do when a new message window is opened. See bug #540039 for more
        # details.
        #
        rolesList = [pyatspi.ROLE_DOCUMENT_FRAME,
                     pyatspi.ROLE_INTERNAL_FRAME,
                     pyatspi.ROLE_FRAME,
                     pyatspi.ROLE_APPLICATION]
        if self.utilities.hasMatchingHierarchy(event.source, rolesList):
            lastKey, mods = self.utilities.lastKeyAndModifiers()
            if lastKey == "Delete":
                speech.speak(obj.name)
                [obj, offset] = self.findFirstCaretContext(obj, 0)
                self.setCaretPosition(obj, offset)
                return

        # If we get a "object:property-change:accessible-name" event for 
        # the first item in the Suggestions lists for the spell checking
        # dialog, then speak the first two labels in that dialog. These
        # will by the "Misspelled word:" label and the currently misspelled
        # word. See bug #535192 for more details.
        #
        rolesList = [pyatspi.ROLE_LIST_ITEM,
                     pyatspi.ROLE_LIST,
                     pyatspi.ROLE_DIALOG,
                     pyatspi.ROLE_APPLICATION]
        if self.utilities.hasMatchingHierarchy(obj, rolesList):
            dialog = obj.parent.parent

            # Translators: this is what the name of the spell checking 
            # dialog in Thunderbird begins with. The translated form
            # has to match what Thunderbird is using.  We hate keying
            # off stuff like this, but we're forced to do so in this case.
            #
            if dialog.name.startswith(_("Check Spelling")):
                if obj.getIndexInParent() == 0:
                    badWord = self.utilities.displayedText(dialog[1])

                    if self.textArea != None:
                        # If we have a handle to the Thunderbird message text
                        # area, then extract out all the text objects, and
                        # create a list of all the words found in them.
                        #
                        allTokens = []
                        text = self.utilities.substring(self.textArea, 0, -1)
                        tokens = text.split()
                        allTokens += tokens
                        self.speakMisspeltWord(allTokens, badWord)
示例#32
0
    def presentStatusBar(self, obj):
        """Presents information about the metacity status bar."""

        # We have to stop speech, as Metacity has a key grab and we're not
        # getting keys
        #
        speech.stop()

        # If the window was iconified, then obj.name will be surronded by
        # brackets. If this is the case, remove them before comparing the
        # name against the various window names. See bug #522797 for more
        # details.
        #
        objName = obj.name
        if objName and len(objName):
            if objName[0] == "[" and objName[-1] == "]":
                objName = objName[1:-1]

        # Do we know about this window?  Traverse through our list of apps
        # and go through the toplevel windows in each to see if we know
        # about this one.  If we do, it's accessible.  If we don't, it is
        # not.
        #
        found = False
        for app in self.utilities.knownApplications():
            i = 0
            try:
                childCount = app.childCount
            except:
                continue
            while i < childCount:
                try:
                    win = app.getChildAtIndex(i)
                except:
                    win = None
                if win is None:
                    print("app error " + app.name)
                elif win.name == objName:
                    found = True
                i = i + 1

        try:
            text = obj.name
        except:
            text = objName

        # Translators: the "Workspace " and "Desk " strings are
        # the prefix of what metacity shows when you press
        # Ctrl+Alt and the left or right arrow keys to switch
        # between workspaces.  The goal here is to find a match
        # with that prefix.
        #
        if text.startswith(_("Workspace ")) or text.startswith(_("Desk ")):
            pass
        elif not found:
            text += ". " + messages.INACCESSIBLE

        self.displayBrailleMessage(text)
        speech.speak(text)
示例#33
0
    def onWindowActivated(self, event):
        if self.currentTab:  #Speak current open tab
            obj = self.currentTab.child(0)
            for n in range(obj.childCount):
                if util.getDisplayedText(obj.child(n)):
                    speech.speak(util.getDisplayedText(obj.child(n)))

        default.Script.onWindowActivated(self, event)
示例#34
0
    def onWindowCreated(self, event):
        """Callback for window:create accessibility events."""

        hasRole = lambda x: x and x.getRole() == pyatspi.ROLE_LABEL
        allLabels = pyatspi.findAllDescendants(event.source, hasRole)
        texts = [self.utilities.displayedText(acc) for acc in allLabels]
        text = '%s %s' % (messages.NOTIFICATION, ' '.join(texts))
        speech.speak(text, None, True)
	def onWindowActivated(self, event):
		if self.currentTab:#Speak current open tab
			obj = self.currentTab.child(0)			
			for n in range(obj.childCount):					
				if  util.getDisplayedText(obj.child(n)):				
					speech.speak(util.getDisplayedText(obj.child(n)))
		
		default.Script.onWindowActivated(self, event)
示例#36
0
文件: script.py 项目: GNOME/orca
    def onWindowCreated(self, event):
        """Callback for window:create accessibility events."""

        hasRole = lambda x: x and x.getRole() == pyatspi.ROLE_LABEL
        allLabels = pyatspi.findAllDescendants(event.source, hasRole)
        texts = [self.utilities.displayedText(acc) for acc in allLabels]
        text = "%s %s" % (messages.NOTIFICATION, " ".join(texts))
        speech.speak(text, None, True)
        self.displayBrailleMessage(text, flashTime=settings.brailleFlashTime)
        notification_messages.saveMessage(text)
示例#37
0
    def onValueChanged(self, event):
        try:
            ivalue = event.source.queryValue()
            value = int(ivalue.currentValue)
        except NotImplementedError:
            value = -1

        if value >= 0:
            speech.speak(str(value), None, True)
            self.displayBrailleMessage("%s" % value,
                                       flashTime=settings.brailleFlashTime)
示例#38
0
    def onValueChange(self, event):
        try:
            ivalue = event.source.queryValue()
            value = int(ivalue.currentValue)
        except NotImplementedError:
            value = -1

        if value >= 0:
            speech.speak(str(value), None, True)
            self.displayBrailleMessage("%s" % value,
                                       flashTime=settings.brailleFlashTime)
示例#39
0
 def addBookmark(self, inputEvent):
     """ Add an in-page accessible object bookmark for this key and
     webpage URI. """
     # form bookmark dictionary key
     index = (inputEvent.hw_code, self.getURIKey())
     # convert the current object to a path and bookmark it
     obj, characterOffset = self._script.getCaretContext()
     path = self._objToPath()
     self._bookmarks[index] = path, characterOffset
     utterances = [(messages.BOOKMARK_ENTERED)]
     utterances.extend(self._script.speechGenerator.generateSpeech(obj))
     speech.speak(utterances)
示例#40
0
    def onExpandedChanged(self, event):
        """Callback for object:state-changed:expanded accessibility events."""

        # Overridden here because the event.source is in a hidden column.
        obj = event.source
        if self.chat.isInBuddyList(obj):
            obj = obj.parent[obj.getIndexInParent() + 1]
            self.updateBraille(obj)
            speech.speak(self.speechGenerator.generateSpeech(obj, alreadyFocused=True))
            return
            
        default.Script.onExpandedChanged(self, event)
示例#41
0
    def onShowingChanged(self, event):
        """Callback for object:state-changed:showing accessibility events."""

        obj = event.source
        if not self.utilities._isNonModalPopOver(obj):
            default.Script.onShowingChanged(self, event)
            return

        if event.detail1:
            speech.speak(self.speechGenerator.generateSpeech(obj))
            labels = self.utilities.unrelatedLabels(obj)
            msg = ' '.join(map(self.utilities.displayedText, labels))
            self.presentMessage(msg)
示例#42
0
    def onExpandedChanged(self, event):
        """Callback for object:state-changed:expanded accessibility events."""

        # Overridden here because the event.source is in a hidden column.
        obj = event.source
        if self.chat.isInBuddyList(obj):
            obj = obj.parent[obj.getIndexInParent() + 1]
            self.updateBraille(obj)
            speech.speak(
                self.speechGenerator.generateSpeech(obj, alreadyFocused=True))
            return

        GAIL.Script.onExpandedChanged(self, event)
示例#43
0
def _changeControl(ac):
    increment = 1 if ac == 'r' else -1
    control = _speechControl
    index = (_speechControls.index(control)
             if control in _speechControls else -1) + increment
    if index < 0:
        index = len(_speechControls) - 1
    elif index >= len(_speechControls):
        index = 0
    control = _speechControls[index]
    _saveControl(control)
    msg = control
    speak(msg)
示例#44
0
    def onWindowCreate(self, event):
        """Called whenever a window is created in the notification-daemon
        application.

        Arguments:
        - event: the Event.
        """
        a = self.findByRole(event.source, rolenames.ROLE_LABEL)
        texts = [self.getDisplayedText(acc) for acc in a]
        # Translators: This denotes a notification to the user of some sort.
        #
        text = _('Notification %s') % ' '.join(texts)
        speech.speak(text, None, True)
    def onWindowCreate(self, event):
        """Called whenever a window is created in the notification-daemon
        application.

        Arguments:
        - event: the Event.
        """
        a = self.findByRole(event.source, rolenames.ROLE_LABEL)
        texts = [self.getDisplayedText(acc) for acc in a]
        # Translators: This denotes a notification to the user of some sort.
        #
        text = _('Notification %s') % ' '.join(texts)
        speech.speak(text, None, True)
示例#46
0
    def onShowingChanged(self, event):
        """Callback for object:state-changed:showing accessibility events."""

        obj = event.source
        if not self.utilities._isNonModalPopOver(obj):
            default.Script.onShowingChanged(self, event)
            return

        if event.detail1:
            speech.speak(self.speechGenerator.generateSpeech(obj))
            labels = self.utilities.unrelatedLabels(obj)
            msg = ' '.join(map(self.utilities.displayedText, labels))
            self.presentMessage(msg)
示例#47
0
    def sayCharacter(self, obj):
        """Speak the character at the caret.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText
          interface
        """

        if obj.getRole() == pyatspi.ROLE_SEPARATOR:
            speech.speak(self.speechGenerator.generateSpeech(obj))
            return

        default.Script.sayCharacter(self, obj)
示例#48
0
    def onNameChanged(self, event):
        """Callback for object:property-change:accessible-name events."""

        if event.source.name == self.spellcheck.getMisspelledWord():
            self.spellcheck.presentErrorDetails()
            return

        if not self.utilities.lastInputEventWasDelete() \
           or not self.utilities.isDocument(event.source):
            return

        speech.speak(obj.name)
        [obj, offset] = self.utilities.findFirstCaretContext(obj, 0)
        self.utilities.setCaretPosition(obj, offset)
示例#49
0
    def sayLine(self, obj):
        """Speaks the line of an AccessibleText object that contains the
        caret.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText
               interface
        """

        default.Script.sayLine(self, obj)

        rolesToSpeak = [pyatspi.ROLE_HEADING]
        if obj.getRole() in rolesToSpeak:
            speech.speak(self.speechGenerator.getRoleName(obj))
示例#50
0
    def sayCharacter(self, obj):
        """Speak the character at the caret.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        """

        boundary = pyatspi.TEXT_BOUNDARY_CHAR
        objects = self.utilities.getObjectsFromEOCs(obj, boundary)
        for (obj, start, end, string) in objects:
            if string:
                speech.speakCharacter(string)
            else:
                speech.speak(self.speechGenerator.generateSpeech(obj))
示例#51
0
    def onTextInserted(self, event):
        """Callback for object:text-changed:insert accessibility events."""

        obj = event.source
        try:
            role = obj.getRole()
            parentRole = obj.parent.getRole()
        except:
            return

        if role == pyatspi.ROLE_LABEL and parentRole == pyatspi.ROLE_STATUS_BAR:
            return

        if len(event.any_data) > 1 and obj == self.spellcheck.getChangeToEntry(
        ):
            return

        isSystemEvent = event.type.endswith("system")

        # Try to stop unwanted chatter when a message is being replied to.
        # See bgo#618484.
        if isSystemEvent and self.isEditableMessage(obj):
            return

        # Speak the autocompleted text, but only if it is different
        # address so that we're not too "chatty." See bug #533042.
        if parentRole == pyatspi.ROLE_AUTOCOMPLETE:
            if len(event.any_data) == 1:
                default.Script.onTextInserted(self, event)
                return

            if self._lastAutoComplete and self._lastAutoComplete in event.any_data:
                return

            # Mozilla cannot seem to get their ":system" suffix right
            # to save their lives, so we'll add yet another sad hack.
            try:
                text = event.source.queryText()
            except:
                hasSelection = False
            else:
                hasSelection = text.getNSelections() > 0
            if hasSelection or isSystemEvent:
                speech.speak(event.any_data)
                self._lastAutoComplete = event.any_data
                self.pointOfReference['lastAutoComplete'] = hash(obj)
                return

        Gecko.Script.onTextInserted(self, event)
示例#52
0
    def onCheckedChanged(self, event):
        """Callback for object:state-changed:checked accessibility events."""

        obj = event.source
        if self.utilities.isSameObject(obj, orca_state.locusOfFocus):
            default.Script.onCheckedChanged(self, event)
            return

        # Present changes of child widgets of GtkListBox items
        isListBox = lambda x: x and x.getRole() == pyatspi.ROLE_LIST_BOX
        if not pyatspi.findAncestor(obj, isListBox):
            return

        self.updateBraille(obj)
        speech.speak(self.speechGenerator.generateSpeech(obj, alreadyFocused=True))
示例#53
0
    def _speakSearching(self):
        """If we are still searching, let the user know. Then start another
        timer to go off again and repeat this process.
        """

        if not self.searching:
            return False

        currentTime = time.time()
        if not self.startTime or \
           (currentTime > (self.startTime + self.searchInterval)):
            speech.speak(_("Searching."))
            self.startTime = time.time()

        return True
示例#54
0
    def readPreviousMessage(self, inputEvent):
        #This function speaks the latest n messages. Orca+F1 the latest one,
        #Orca+F2 the latest two and so.

        debug.println(self.debugLevel, "gnome-mud.readPreviousMessage.")

        i = int(inputEvent.event_string[1:])
        messageNo = Script.MESSAGE_LIST_LENGTH - i

        text = ""
        messages = self.previousMessages.get()
        for i in range(messageNo, Script.MESSAGE_LIST_LENGTH):
            message = messages[i]
            text += message

        speech.speak(text)
示例#55
0
    def checkForTableBoundary(self, oldFocus, newFocus):
        """Check to see if we've crossed any table boundaries,
        speaking the appropriate details when we have.

        Arguments:
        - oldFocus: Accessible that is the old locus of focus
        - newFocus: Accessible that is the new locus of focus
        """

        if oldFocus == None or newFocus == None:
            return

        [oldFocusIsTable, oldFocusRows, oldFocusColumns] = \
                   self.getTableAndDimensions(oldFocus)
        [newFocusIsTable, newFocusRows, newFocusColumns] = \
                   self.getTableAndDimensions(newFocus)

        # [[[TODO: JD - It is possible to move focus into the object
        # that contains the object that contains the text object. We
        # need to detect this and adjust accordingly.]]]

        if not oldFocusIsTable and newFocusIsTable:
            # We've entered a table.  Announce the dimensions.
            #
            line = _("table with %d rows and %d columns.") % \
                    (newFocusRows, newFocusColumns)
            speech.speak(line)

        elif oldFocusIsTable and not newFocusIsTable:
            # We've left a table.  Announce this fact.
            #
            speech.speak(_("leaving table."))

        elif oldFocusIsTable and newFocusIsTable:
            # See if we've crossed a cell boundary.  If so, speak
            # what has changed (per Mike).
            #
            [oldRow, oldCol] = \
                   self.getCellCoordinates(oldFocusIsTable, oldFocus)
            [newRow, newCol] = \
                   self.getCellCoordinates(newFocusIsTable, newFocus)
            # We can't count on being in the first/last cell
            # of the new row -- only the first/last cell of
            # the new row that contains data.
            #
            if newRow != oldRow:
                # Translators: this represents the row and column we're
                # on in a table.
                #
                line = _("row %d, column %d") % (newRow, newCol)
                speech.speak(line)
            elif newCol != oldCol:
                # Translators: this represents the column we're
                # on in a table.
                #
                line = _("column %d") % newCol
                speech.speak(line)
示例#56
0
    def sayCharacter(self, obj):
        """Speak the character at the caret.

        Arguments:
        - obj: an Accessible object that implements the AccessibleText interface
        """

        if obj.getRole() == pyatspi.ROLE_ENTRY:
            default.Script.sayCharacter(self, obj)
            return

        boundary = pyatspi.TEXT_BOUNDARY_CHAR
        objects = self.utilities.getObjectsFromEOCs(obj, boundary=boundary)
        for (obj, start, end, string) in objects:
            if string:
                self.speakCharacter(string)
            else:
                speech.speak(self.speechGenerator.generateSpeech(obj))
示例#57
0
def _change_language(ac):
    _createLanguageProfiles()
    increment = 1 if ac == 'u' else -1
    languages = _getCurrentLanguages()
    profile = _getProfile()
    new = [x[1] for x in languages].index(profile) + increment
    if new < 0:
        new = len(languages) - 1
    elif new >= len(languages):
        new = 0
    newProfile = languages[new][1]
    language = None
    if profile != newProfile:
        _settingsManager.setProfile(newProfile)
    language = languages[new][0]
    if language:
        msg = language
        speak(msg)
示例#58
0
    def readPreviousMessage(self, inputEvent):
        #This function speaks the latest n messages. Alt+1 the latest one, 
        #alt+2 the latest two and so.

        debug.println(self.debugLevel, "gnome-mud.readPreviousMessage.")

        if inputEvent.event_string == "0":
           inputEvent.event_string="10"
        i = int(inputEvent.event_string)
        messageNo = self.MESSAGE_LIST_LENGTH-i
     
        text=""
        messages = self.previousMessages.get()
        for i in range (messageNo, self.MESSAGE_LIST_LENGTH):
            message = messages[i]
            text += message

        speech.speak(text)
示例#59
0
    def onFocusedChanged(self, event):
        """Callback for object:state-changed:focused accessibility events."""

        obj = event.source

        # If we are focused in a password text area, we need to check if
        # there are any useful messages displayed in a couple of labels that
        # are visually below that password area. If there are, then speak
        # them for the user. See bug #529655 for more details.
        #
        if obj.getRole() == pyatspi.ROLE_PASSWORD_TEXT:
            obj = obj.parent.parent.parent
            for child in obj:
                if child.getRole() == pyatspi.ROLE_LABEL and child.name:
                    speech.speak(child.name)
                return

        gtk.Script.onFocusedChanged(self, event)