def onStateChanged(self, event):
        """Called whenever an object's state changes.  Currently, the
        state changes for non-focused objects are ignored.

        Arguments:
        - event: the Event
        """

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

        # This is a workaround for a java-access-bridge bug (Bug 355011)
        # where popup menu events are not sent to Orca.
        #
        # When a root pane gets focus, a popup menu may have been invoked.
        # If there is a popup menu, give locus of focus to the armed menu
        # item.
        #
        if event.source.role == rolenames.ROLE_ROOT_PANE and \
               event.type.startswith("object:state-changed:focused") and \
               event.detail1 == 1:

            for i in range(0, event.source.childCount):
                # search the layered pane for a popup menu
                child = event.source.child(i)
                if child.role == rolenames.ROLE_LAYERED_PANE:
                    popup = self.findByRole(child, rolenames.ROLE_POPUP_MENU, False)
                    if len(popup) > 0:
                        # set the locus of focus to the armed menu item
                        items = self.findByRole(popup[0], rolenames.ROLE_MENU_ITEM, False)
                        for item in items:
                            if item.state.count(Accessibility.STATE_ARMED):
                                orca.setLocusOfFocus(event, item)
                                return


        # In java applications the events are comming in other order:
        # "focus:" event comes before "state-changed:focused" event
        #
        if event.type.startswith("object:state-changed:focused"):
            return

        # Hand state changes when JTree labels become expanded
        # or collapsed.
        #
        if (event.source.role == rolenames.ROLE_LABEL) and \
            event.type.startswith("object:state-changed:expanded"):
            orca.visualAppearanceChanged(event, event.source)
            return

        # Present a value change in case of an focused popup menu.
        # Fix for Swing file chooser.
        #
        if event.type.startswith("object:state-changed:visible") and \
                event.source.role == rolenames.ROLE_POPUP_MENU and \
                event.source.parent.state.count(Accessibility.STATE_FOCUSED):
            orca.setLocusOfFocus(event, event.source.parent)
            return

        default.Script.onStateChanged(self, event)
Exemplo n.º 2
0
    def onSelectionChanged(self, event):
        """Called when an object's selection changes.

        Arguments:
        - event: the Event
        """

        self._debug("onSelectionChanged: %s '%s'" % \
                    (event.source.role, event.source.name))

        if not event.source.state.count(atspi.Accessibility.STATE_FOCUSED):
            return

        if event.source.role == rolenames.ROLE_TABLE:
            return

        if event.source.role == rolenames.ROLE_TREE:
            return

        if event.source.role == rolenames.ROLE_LIST:
            selection = event.source.selection
            if selection.nSelectedChildren <= 0:
                if event.source.childCount > 0:
                    child = event.source.child(0)
                    if child.state.count(atspi.Accessibility.STATE_ACTIVE):
                        return
                else:
                    orca.setLocusOfFocus(event, event.source)
                    return
            else:
                selectedItem = atspi.Accessible.makeAccessible(
                    selection.getSelectedChild(0))

                # If the selected list item is the same with the last focused object,
                # present it only if the item was not selected and has SELECTED state
                # or if the item doesn't have SELECTED state, but SELECTABLE and
                # it was selected.
                #
                if orca_state.activeScript and \
                   orca_state.activeScript.isSameObject(selectedItem,  \
                                                    orca_state.locusOfFocus):
                    if (orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTED) != 0 \
                                and not orca_state.locusOfFocus.was_selected)   \
                        or (orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTED) == 0 \
                                and orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTABLE) != 0 \
                                and orca_state.locusOfFocus.was_selected):
                        orca.visualAppearanceChanged(event, selectedItem)
                    return

        default.Script.onSelectionChanged(self, event)
    def onSelectionChanged(self, event):
        """Called when an object's selection changes.

        Arguments:
        - event: the Event
        """

        self._debug("onSelectionChanged: %s '%s'" % \
                    (event.source.role, event.source.name))

        if not event.source.state.count (atspi.Accessibility.STATE_FOCUSED):
            return

        if event.source.role == rolenames.ROLE_TABLE:
            return

        if event.source.role == rolenames.ROLE_TREE:
            return

        if event.source.role == rolenames.ROLE_LIST:
            selection = event.source.selection
            if selection.nSelectedChildren <= 0:
                if event.source.childCount > 0:
                    child = event.source.child(0)
                    if child.state.count (atspi.Accessibility.STATE_ACTIVE):
                        return
                else:
                    orca.setLocusOfFocus(event, event.source)
                    return
            else:
                selectedItem = atspi.Accessible.makeAccessible(
                                        selection.getSelectedChild(0))

                # If the selected list item is the same with the last focused object,
                # present it only if the item was not selected and has SELECTED state
                # or if the item doesn't have SELECTED state, but SELECTABLE and
                # it was selected.
                #
                if orca_state.activeScript and \
                   orca_state.activeScript.isSameObject(selectedItem,  \
                                                    orca_state.locusOfFocus):
                    if (orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTED) != 0 \
                                and not orca_state.locusOfFocus.was_selected)   \
                        or (orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTED) == 0 \
                                and orca_state.locusOfFocus.state.count(Accessibility.STATE_SELECTABLE) != 0 \
                                and orca_state.locusOfFocus.was_selected):
                        orca.visualAppearanceChanged(event, selectedItem)
                    return

        default.Script.onSelectionChanged(self, event)
Exemplo n.º 4
0
    def visualAppearanceChanged(self, event, obj):
        """Called when the visual appearance of an object changes.  This
        method should not be called for objects whose visual appearance
        changes solely because of focus -- setLocusOfFocus is used for that.
        Instead, it is intended mostly for objects whose notional 'value' has
        changed, such as a checkbox changing state, a progress bar advancing,
        a slider moving, text inserted, caret moved, etc.

        Arguments:
        - event: if not None, the Event that caused this to happen
        - obj: the Accessible whose visual appearance changed.
        """

        self._debug("visualAppearanceChanged: %s '%s', locusOfFocus=%s" % \
                    (obj.role, obj.name, orca_state.locusOfFocus.role))

        # Present to Braille and Speech an object that is the same
        # with the last focused object, only if it is a label.
        # This case is for LISTs which contain labels as items
        # (see Open dialog lists).
        #
        if orca_state.activeScript.isSameObject(obj, orca_state.locusOfFocus):
            if obj.role == rolenames.ROLE_LABEL:
                self.updateBraille(orca_state.locusOfFocus)
                speech.speakUtterances(
                    self.speechGenerator.getSpeech(orca_state.locusOfFocus,
                                                   True))
                return

        if obj.role == rolenames.ROLE_SPIN_BOX:
            # Check for the spinbox text object being null. There appears
            # to be a bug where the text object for some text fields
            # is null.
            if orca_state.locusOfFocus.role == rolenames.ROLE_TEXT and \
               orca_state.locusOfFocus.text == None:
                # Set the locusOfFocus to the spinbox itself.
                orca.setLocusOfFocus(event, obj)

        default.Script.visualAppearanceChanged(self, event, obj)
    def visualAppearanceChanged(self, event, obj):
        """Called when the visual appearance of an object changes.  This
        method should not be called for objects whose visual appearance
        changes solely because of focus -- setLocusOfFocus is used for that.
        Instead, it is intended mostly for objects whose notional 'value' has
        changed, such as a checkbox changing state, a progress bar advancing,
        a slider moving, text inserted, caret moved, etc.

        Arguments:
        - event: if not None, the Event that caused this to happen
        - obj: the Accessible whose visual appearance changed.
        """

        self._debug("visualAppearanceChanged: %s '%s', locusOfFocus=%s" % \
                    (obj.role, obj.name, orca_state.locusOfFocus.role))

        # Present to Braille and Speech an object that is the same
        # with the last focused object, only if it is a label.
        # This case is for LISTs which contain labels as items
        # (see Open dialog lists).
        #
        if orca_state.activeScript.isSameObject(obj, orca_state.locusOfFocus):
            if obj.role == rolenames.ROLE_LABEL:
                self.updateBraille(orca_state.locusOfFocus)
                speech.speakUtterances(self.speechGenerator.getSpeech(orca_state.locusOfFocus, True))
                return

        if obj.role == rolenames.ROLE_SPIN_BOX:
            # Check for the spinbox text object being null. There appears
            # to be a bug where the text object for some text fields
            # is null. 
            if orca_state.locusOfFocus.role == rolenames.ROLE_TEXT and \
               orca_state.locusOfFocus.text == None:
                # Set the locusOfFocus to the spinbox itself.
                orca.setLocusOfFocus(event, obj)

        default.Script.visualAppearanceChanged(self, event, obj)
Exemplo n.º 6
0
    def onFocus(self, event):
        """Called whenever an object gets focus.

        Arguments:
        - event: the Event
        """

        self._debug("onFocus: %s '%s'" % \
                    (event.source.role, event.source.name))

        role = event.source.role
        if role == rolenames.ROLE_LIST:
            selectedItem = None
            selection = event.source.selection
            if selection and selection.nSelectedChildren > 0:
                selectedItem = atspi.Accessible.makeAccessible(
                    selection.getSelectedChild(0))
            elif event.source.childCount > 0:
                selectedItem = event.source.child(0)
            if selectedItem:
                orca.setLocusOfFocus(event, selectedItem)
            else:
                # if impossible to get selection or list has 0 items, present list
                orca.setLocusOfFocus(event, event.source)
        elif role == rolenames.ROLE_LABEL:
            # In FileChooserDemo, when enter in a new folder, a focus event for
            # the top combo box selected item (not SHOWING item) is received.
            # Should this check be more specific ?
            #
            if not event.source.state.count(Accessibility.STATE_SHOWING):
                return
        elif role == rolenames.ROLE_MENU:
            # A JMenu has always selection.nSelectedChildren > 0
            orca.setLocusOfFocus(event, event.source)
        else:
            default.Script.onFocus(self, event)
    def onFocus(self, event):
        """Called whenever an object gets focus.

        Arguments:
        - event: the Event
        """

        self._debug("onFocus: %s '%s'" % \
                    (event.source.role, event.source.name))

        role = event.source.role
        if role == rolenames.ROLE_LIST:
            selectedItem = None
            selection = event.source.selection
            if selection and selection.nSelectedChildren > 0:
                selectedItem = atspi.Accessible.makeAccessible(
                                        selection.getSelectedChild(0))
            elif event.source.childCount > 0:
                selectedItem = event.source.child(0)
            if selectedItem:
                orca.setLocusOfFocus(event, selectedItem)
            else:
                # if impossible to get selection or list has 0 items, present list
                orca.setLocusOfFocus(event, event.source)
        elif role == rolenames.ROLE_LABEL:
            # In FileChooserDemo, when enter in a new folder, a focus event for
            # the top combo box selected item (not SHOWING item) is received.
            # Should this check be more specific ?
            #
            if not event.source.state.count (Accessibility.STATE_SHOWING):
                return
        elif role == rolenames.ROLE_MENU:
            # A JMenu has always selection.nSelectedChildren > 0
            orca.setLocusOfFocus(event, event.source)
        else:
            default.Script.onFocus(self, event)
Exemplo n.º 8
0
    def onStateChanged(self, event):
        """Called whenever an object's state changes.  Currently, the
        state changes for non-focused objects are ignored.

        Arguments:
        - event: the Event
        """

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

        # This is a workaround for a java-access-bridge bug (Bug 355011)
        # where popup menu events are not sent to Orca.
        #
        # When a root pane gets focus, a popup menu may have been invoked.
        # If there is a popup menu, give locus of focus to the armed menu
        # item.
        #
        if event.source.role == rolenames.ROLE_ROOT_PANE and \
               event.type.startswith("object:state-changed:focused") and \
               event.detail1 == 1:

            for i in range(0, event.source.childCount):
                # search the layered pane for a popup menu
                child = event.source.child(i)
                if child.role == rolenames.ROLE_LAYERED_PANE:
                    popup = self.findByRole(child, rolenames.ROLE_POPUP_MENU,
                                            False)
                    if len(popup) > 0:
                        # set the locus of focus to the armed menu item
                        items = self.findByRole(popup[0],
                                                rolenames.ROLE_MENU_ITEM,
                                                False)
                        for item in items:
                            if item.state.count(Accessibility.STATE_ARMED):
                                orca.setLocusOfFocus(event, item)
                                return

        # In java applications the events are comming in other order:
        # "focus:" event comes before "state-changed:focused" event
        #
        if event.type.startswith("object:state-changed:focused"):
            return

        # Hand state changes when JTree labels become expanded
        # or collapsed.
        #
        if (event.source.role == rolenames.ROLE_LABEL) and \
            event.type.startswith("object:state-changed:expanded"):
            orca.visualAppearanceChanged(event, event.source)
            return

        # Present a value change in case of an focused popup menu.
        # Fix for Swing file chooser.
        #
        if event.type.startswith("object:state-changed:visible") and \
                event.source.role == rolenames.ROLE_POPUP_MENU and \
                event.source.parent.state.count(Accessibility.STATE_FOCUSED):
            orca.setLocusOfFocus(event, event.source.parent)
            return

        default.Script.onStateChanged(self, event)
Exemplo n.º 9
0
    def _processObjectEvent(self, event):
        """Handles all object events destined for scripts.

        Arguments:
        - e: an at-spi event.
        """

        debug.printObjectEvent(debug.LEVEL_FINEST, event)
        eType = event.type

        if eType.startswith("object:children-changed:remove"):
            try:
                if event.source == self.registry.getDesktop(0):
                    _scriptManager.reclaimScripts()
                    if settings.debugMemoryUsage:
                        orca.cleanupGarbage()
                    if not event.source.childCount:
                        orca.shutdown()
                    return
            except (LookupError, RuntimeError):
                # If we got this error here, we'll get it again when we
                # attempt to get the state, catch it, and clean up.
                pass
            except:
                debug.printException(debug.LEVEL_WARNING)
                return

        # Clean up any flat review context so that Orca does not get
        # confused (see bgo#609633)
        #
        if (
            eType.startswith("window:deactivate")
            and orca_state.activeScript
            and orca_state.activeScript.flatReviewContext
            and orca_state.activeScript.app == event.host_application
        ):
            orca_state.activeScript.drawOutline(-1, 0, 0, 0)
            orca_state.activeScript.flatReviewContext = None

        try:
            state = event.source.getState()
        except (LookupError, RuntimeError):
            debug.println(debug.LEVEL_WARNING, "Error while processing event: %s" % eType)
            if eType.startswith("window:deactivate"):
                orca.setLocusOfFocus(event, None)
                orca_state.activeWindow = None
            return
        except:
            debug.printException(debug.LEVEL_WARNING)
            return

        if state and state.contains(pyatspi.STATE_DEFUNCT):
            debug.println(debug.LEVEL_FINEST, "IGNORING DEFUNCT OBJECT")
            if eType.startswith("window:deactivate"):
                orca.setLocusOfFocus(event, None)
                orca_state.activeWindow = None
            return

        if state and state.contains(pyatspi.STATE_ICONIFIED):
            debug.println(debug.LEVEL_FINEST, "IGNORING ICONIFIED OBJECT")
            return

        if not debug.eventDebugFilter or debug.eventDebugFilter.match(eType) and not eType.startswith("mouse:"):
            debug.printDetails(debug.LEVEL_FINEST, "    ", event.source)

        script = self._getScriptForEvent(event)
        debug.println(debug.LEVEL_FINEST, "Script for event: %s" % script.name)
        setNewActiveScript, reason = self._isActivatableEvent(event, script)
        if setNewActiveScript:
            app = event.host_application or event.source.getApplication()
            _scriptManager.setActiveScript(script, reason)

        script.processObjectEvent(event)