From b55f5f8881687c1c3f31b832b988fdd09e9f61cf Mon Sep 17 00:00:00 2001 From: Brad Taylor Date: Wed, 22 Apr 2009 06:10:17 -0400 Subject: [PATCH] Make sure that we always return an Accessible when we're supposed to, and be more explicit with method parameters. --- pyatspi/component.py | 5 ++-- pyatspi/hyperlink.py | 3 ++- pyatspi/hypertext.py | 4 +-- pyatspi/selection.py | 7 +++-- pyatspi/table.py | 22 +++++++++------- pyatspi/text.py | 74 ++++++++++++++++++++++++++++++++-------------------- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/pyatspi/component.py b/pyatspi/component.py index dc8fc45..335b30a 100644 --- a/pyatspi/component.py +++ b/pyatspi/component.py @@ -100,9 +100,10 @@ class Component(Accessible): @return the Accessible child whose bounding box contains the specified point. """ - #TODO Need to return an actual accessible object rather than a random string. func = self.get_dbus_method("getAccessibleAtPoint", dbus_interface=ATSPI_COMPONENT) - return func(x, y, coord_type) + return self._cache.create_accessible(self._app_name, + func(x, y, coord_type), + interfaces.ATSPI_COMPONENT) def getAlpha(self): """ diff --git a/pyatspi/hyperlink.py b/pyatspi/hyperlink.py index c92eebd..de7a6db 100644 --- a/pyatspi/hyperlink.py +++ b/pyatspi/hyperlink.py @@ -51,7 +51,8 @@ class Hyperlink(Accessible): ith anchor can be accessed. """ func = self.get_dbus_method("getObject", dbus_interface=ATSPI_HYPERLINK) - return func(index) + return self._cache.create_accessible(self._app_name, func(index), + interfaces.ATSPI_HYPERLINK) def getURI(self, index): """ diff --git a/pyatspi/hypertext.py b/pyatspi/hypertext.py index c8a1a84..6e7332f 100644 --- a/pyatspi/hypertext.py +++ b/pyatspi/hypertext.py @@ -40,8 +40,8 @@ class Hypertext(Accessible): @return the Hyperlink in this Hypertext object. """ func = self.get_dbus_method("getLink", dbus_interface=ATSPI_HYPERTEXT) - #TODO Lookup the accessible object and call queryHyperlink on it. - return func(index) + return self._cache.create_accessible(self._app_name, func(index), + interfaces.ATSPI_HYPERTEXT) def getLinkIndex(self, character_index): """ diff --git a/pyatspi/selection.py b/pyatspi/selection.py index 7b56b4a..4751ba5 100644 --- a/pyatspi/selection.py +++ b/pyatspi/selection.py @@ -46,7 +46,7 @@ class Selection(Accessible): func = self.get_dbus_method("clearSelection", dbus_interface=ATSPI_SELECTION) return func() - def deselectChild(self, *args, **kwargs): + def deselectChild(self, childIndex): """ Remove a child from the selected children list of a Selection, if the child is currently selected. @@ -57,7 +57,7 @@ class Selection(Accessible): @return True if the child was successfully selected, False otherwise. """ func = self.get_dbus_method("deselectChild", dbus_interface=ATSPI_SELECTION) - return func(*args, **kwargs) + return func(childIndex) def deselectSelectedChild(self, index): """ @@ -83,8 +83,7 @@ class Selection(Accessible): by selectedChildIndex. """ func = self.get_dbus_method("getSelectedChild", dbus_interface=ATSPI_SELECTION) - return self._cache.create_accessible(self._app_name, - func(index), + return self._cache.create_accessible(self._app_name, func(index), interfaces.ATSPI_ACCESSIBLE) def isChildSelected(self, index): diff --git a/pyatspi/table.py b/pyatspi/table.py index 80127a0..dd8879f 100644 --- a/pyatspi/table.py +++ b/pyatspi/table.py @@ -72,9 +72,9 @@ class Table(Accessible): @return an Accessible object representing the specified table cell. """ - #TODO Return an accessible object instead of a path. func = self.get_dbus_method("getAccessibleAt", dbus_interface=ATSPI_TABLE) - return func(row, column) + return self._cache.create_accessible(self._app_name, func(row, column), + interfaces.ATSPI_ACCESSIBLE) def getColumnAtIndex(self, index): """ @@ -126,8 +126,8 @@ class Table(Accessible): if available. """ func = self.get_dbus_method("getColumnHeader", dbus_interface=ATSPI_TABLE) - #TODO Return an accessible object - return func(index) + return self._cache.create_accessible(self._app_name, func(index), + interfaces.ATSPI_ACCESSIBLE) def getIndexAt(self, row, column): """ @@ -231,8 +231,8 @@ class Table(Accessible): if available. """ func = self.get_dbus_method("getRowHeader", dbus_interface=ATSPI_TABLE) - #TODO Return an accessible object - return func(row) + return self._cache.create_accessible(self._app_name, func(row), + interfaces.ATSPI_ACCESSIBLE) def getSelectedColumns(self): """ @@ -310,8 +310,9 @@ class Table(Accessible): return func(row) def get_caption(self): - #TODO Return an accessible object - return self._pgetter(self._dbus_interface, "caption") + accessible = self._pgetter(self._dbus_interface, "caption") + return self._cache.create_accessible(self._app_name, accessible, + interfaces.ATSPI_ACCESSIBLE) _captionDoc = \ """ An Accessible which represents of a caption for a Table. @@ -358,8 +359,9 @@ class Table(Accessible): nSelectedRows = property(fget=get_nSelectedRows, doc=_nSelectedRowsDoc) def get_summary(self): - #TODO Return an accessible object - return self._pgetter(self._dbus_interface, "summary") + accessible = self._pgetter(self._dbus_interface, "summary") + return self._cache.create_accessible(self._app_name, accessible, + interfaces.ATSPI_ACCESSIBLE) _summaryDoc = \ """ An accessible object which summarizes the contents of a Table. diff --git a/pyatspi/text.py b/pyatspi/text.py index 90a9240..1a46e8e 100644 --- a/pyatspi/text.py +++ b/pyatspi/text.py @@ -101,7 +101,7 @@ class Text(Accessible): and the set returned at a particular character offset via Text::getAttributeRun. """ - def addSelection(self, *args, **kwargs): + def addSelection(self, index): """ The result of calling addSelection on objects which already have one selection present, and which do not include STATE_MULTISELECTABLE, @@ -114,7 +114,7 @@ class Text(Accessible): to copy the text into the relevant selection buffer). """ func = self.get_dbus_method("addSelection", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(index) def getAttributeRun(self, offset, startOffset, endOffset, includeDefaults): """ @@ -169,7 +169,7 @@ class Text(Accessible): attr = func(offset, startOffset, endOffset, includeDefaults) return [key + ':' + value for key, value in attr.values()] - def getAttributeValue(self, *args, **kwargs): + def getAttributeValue(self, offset, attributeName, startOffset, endOffset, defined): """ Get the string value of a named attribute at a given offset, if defined. @@ -192,7 +192,7 @@ class Text(Accessible): to "name", if defined. """ func = self.get_dbus_method("getAttributeValue", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset, attributeName, startOffset, endOffset, defined) def getAttributes(self, offset): """ @@ -203,7 +203,7 @@ class Text(Accessible): func = self.get_dbus_method("getAttributes", dbus_interface=ATSPI_TEXT) return [key + ':' + value for key, value in func(dbus.Int32(offset)).values()] - def getBoundedRanges(self, *args, **kwargs): + def getBoundedRanges(self, x, y, width, height, coordType, xClipType, yClipType): #TODO Return a list of range structures """ Return the text content within a bounding box, as a list of Range @@ -233,18 +233,20 @@ class Text(Accessible): the y direction is included. """ func = self.get_dbus_method("getBoundedRanges", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(x, y, width, height, coordType, xClipType, yClipType) - def getCharacterAtOffset(self, *args, **kwargs): + def getCharacterAtOffset(self, offset): """ + @param : offset + position @return an unsigned long integer whose value corresponds to the UCS-4 representation of the character at the specified text offset, or 0 if offset is out of range. """ func = self.get_dbus_method("getCharacterAtOffset", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset) - def getCharacterExtents(self, *args, **kwargs): + def getCharacterExtents(self, offset, x, y, width, height, coordType): """ Obtain a the bounding box, as x, y, width, and height, of the character or glyph at a particular character offset in this object's @@ -276,7 +278,7 @@ class Text(Accessible): down. """ func = self.get_dbus_method("getCharacterExtents", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset, x, y, width, height, coordType) def getDefaultAttributeSet(self): """ @@ -301,7 +303,7 @@ class Text(Accessible): func = self.get_dbus_method("getDefaultAttributes", dbus_interface=ATSPI_TEXT) return [key + ':' + value for key, value in func().values()] - def getNSelections(self, *args, **kwargs): + def getNSelections(self): """ Obtain the number of separate, contiguous selections in the current Text object. Text objects which do not implement selection of @@ -314,9 +316,9 @@ class Text(Accessible): object. """ func = self.get_dbus_method("getNSelections", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func() - def getOffsetAtPoint(self, *args, **kwargs): + def getOffsetAtPoint(self, x, y, coordType): """ Get the offset of the character at a given onscreen coordinate. The coordinate system used to interpret x and y is determined @@ -332,9 +334,9 @@ class Text(Accessible): -1 if the point is outside the bounds of any glyph. """ func = self.get_dbus_method("getOffsetAtPoint", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(x, y, coordType) - def getRangeExtents(self, *args, **kwargs): + def getRangeExtents(self, startOffset, endOffset, x, y, width, height, coordType): """ Obtain the bounding box which entirely contains a given text range. Negative values may be returned for the bounding box parameters @@ -363,22 +365,36 @@ class Text(Accessible): to the corner of the containing toplevel window. """ func = self.get_dbus_method("getRangeExtents", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(startOffset, endOffset, x, y, width, height, coordType) - def getSelection(self, *args, **kwargs): + def getSelection(self, selectionNum, startOffset, endOffset): """ The result of calling getSelection with an out-of-range selectionNum (i.e. for a selection which does not exist) is not strictly defined, but should set endOffset equal to startOffset. + @param : selectionNum + indicates which of a set of non-contiguous selections to modify. + @param : startOffset + back-filled with the starting offset of the resulting substring, + if one exists. + @param : endOffset + back-filled with the offset of the character immediately following + the resulting substring, if one exists. """ func = self.get_dbus_method("getSelection", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(selectionNum, startOffset, endOffset) def getText(self, startOffset, endOffset): """ Obtain all or part of the onscreen textual content of a Text object. If endOffset is specified as "-1", then this method will return the entire onscreen textual contents of the Text object. + @param : startOffset + back-filled with the starting offset of the resulting substring, + if one exists. + @param : endOffset + back-filled with the offset of the character immediately following + the resulting substring, if one exists. @return the textual content of the current Text object beginning startOffset (inclusive) up to but not including the character at endOffset. @@ -388,7 +404,7 @@ class Text(Accessible): endOffset = -1 return func(dbus.Int32(startOffset), dbus.Int32(endOffset)) - def getTextAfterOffset(self, *args, **kwargs): + def getTextAfterOffset(self, offset, type, startOffset, endOffset): """ Obtain a subset of the text content of an object which entirely follows offset, delimited by character, word, line, or sentence @@ -414,7 +430,7 @@ class Text(Accessible): the object, delimited by the specified boundary condition. """ func = self.get_dbus_method("getTextAfterOffset", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset, type, startOffset, endOffset) def getTextAtOffset(self, offset, type): """ @@ -443,7 +459,7 @@ class Text(Accessible): func = self.get_dbus_method("getTextAtOffset", dbus_interface=ATSPI_TEXT) return _repack_tuple(func(offset, type)) - def getTextBeforeOffset(self, *args, **kwargs): + def getTextBeforeOffset(self, offset, type, startOffset, endOffset): """ Obtain a subset of the text content of an object which entirely precedes offset, delimited by character, word, line, or sentence @@ -468,20 +484,22 @@ class Text(Accessible): the object, delimited by the specified boundary condition. """ func = self.get_dbus_method("getTextBeforeOffset", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset, type, startOffset, endOffset) - def removeSelection(self, *args, **kwargs): + def removeSelection(self, selectionNum): """ Deselect the text contained in the specified selectionNum, if such a selection exists, otherwise do nothing. Removal of a non-existant selectionNum has no effect. + @param : selectionNum + indicates which of a set of non-contiguous selections to modify. @return True if the selection was successfully removed, False otherwise. """ func = self.get_dbus_method("removeSelection", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(selectionNum) - def setCaretOffset(self, *args, **kwargs): + def setCaretOffset(self, offset): """ Programmatically move the text caret (visible or virtual, as above) to a given position. @@ -493,9 +511,9 @@ class Text(Accessible): caret could not be moved to the requested position. """ func = self.get_dbus_method("setCaretOffset", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(offset) - def setSelection(self, *args, **kwargs): + def setSelection(self, selectionNum, startOffset, endOffset): """ Modify an existing selection's start or ending offset. Calling setSelection for a selectionNum that is not already defined @@ -512,7 +530,7 @@ class Text(Accessible): successfully modified, False otherwise. """ func = self.get_dbus_method("setSelection", dbus_interface=ATSPI_TEXT) - return func(*args, **kwargs) + return func(selectionNum, startOffset, endOffset) def get_caretOffset(self): return dbus.Int32(self._pgetter(self._dbus_interface, "caretOffset")) -- 2.7.4