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)
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)