Package textInfos :: Class TextInfo
[hide private]
[frames] | no frames]

Class TextInfo

source code

                   object --+    
                            |    
baseObject.AutoPropertyObject --+
                                |
                               TextInfo

Provides information about a range of text in an object and facilitates access to all text in the widget.
A TextInfo represents a specific range of text, providing access to the text itself, as well as information about the text such as its formatting and any associated controls.
This range can be moved within the object's text relative to the initial position.

At a minimum, subclasses must:
        * Extend the constructor so that it can set up the range at the specified position.
        * Implement the L{move}, L{expand}, L{compareEndPoints}, L{setEndPoint} and L{copy} methods.
        * Implement the L{text} and L{bookmark} attributes.
        * Support at least the L{UNIT_CHARACTER}, L{UNIT_WORD} and L{UNIT_LINE} units.
        * Support at least the L{POSITION_FIRST}, L{POSITION_LAST} and L{POSITION_ALL} positions.
If an implementation should support tracking with the mouse,
L{Points} must be supported as a position.
To support routing to a screen point from a given position, L{pointAtStart} must be implemented.
In order to support text formatting or control information, L{getTextWithFields} should be overridden.

@ivar bookmark: A unique identifier that can be used to make another textInfo object at this position.
@type bookmark: L{Bookmark}

Nested Classes [hide private]

Inherited from baseObject.AutoPropertyObject: __metaclass__

Instance Methods [hide private]
 
__init__(self, obj, position)
Constructor.
source code
 
_get_obj(self)
The object containing the range of text being represented.
source code
 
_get_unit_mouseChunk(self) source code
unicode
_get_text(self)
The text with in this range.
source code
list of unicode and FieldCommand
getTextWithFields(self, formatConfig=None)
Retreaves the text in this range, as well as any control/format fields associated therewith.
source code
int
unitIndex(self, unit)
Returns: The 1-based index of this unit, out of all the units of this type in the object
source code
int
unitCount(self, unit)
Returns: the number of units of this type in the object
source code
int
compareEndPoints(self, other, which)
compares one end of this range to one end of another range.
source code
bool
isOverlapping(self, other)
Determines whether this object overlaps another object in any way.
source code
 
setEndPoint(self, other, which)
Sets one end of this range to one end of another range.
source code
bool
_get_isCollapsed(self)
Returns: True if representing a collapsed range, False if the range is expanded to cover one or more characters.
source code
 
expand(self, unit)
Expands the start and end of this text info object to a given unit
source code
 
collapse(self, end=False)
Collapses this text info object so that both endpoints are the same.
source code
 
copy(self)
duplicates this text info object so that changes can be made to either one with out afecting the other
source code
 
updateCaret(self)
Moves the system caret to the position of this text info object
source code
 
updateSelection(self)
Moves the selection (usually the system caret) to the position of this text info object
source code
 
_get_bookmark(self) source code
int
move(self, unit, direction, endPoint=None)
Moves one or both of the endpoints of this object by the given unit and direction.
source code
bool
find(self, text, caseSensitive=False, reverse=False)
Locates the given text and positions this TextInfo object at the start.
source code
 
_get_NVDAObjectAtStart(self)
retreaves the NVDAObject related to the start of the range.
source code
 
_get_pointAtStart(self)
Retrieves x and y coordinates corresponding with the textInfo start.
source code
 
_get_clipboardText(self)
Text suitably formatted for copying to the clipboard.
source code
bool
copyToClipboard(self)
Copy the content of this instance to the clipboard.
source code
generator of str
getTextInChunks(self, unit)
Retrieve the text of this instance in chunks of a given unit.
source code
 
getControlFieldSpeech(self, attrs, ancestorAttrs, fieldType, formatConfig=None, extraDetail=False, reason=None) source code
 
getControlFieldBraille(self, field, ancestors, reportStart, formatConfig) source code
NVDAObjects.NVDAObject
getEmbeddedObject(self, offset=0)
Retrieve the embedded object associated with a particular embedded object character.
source code

Inherited from baseObject.AutoPropertyObject: invalidateCache

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]

Inherited from baseObject.AutoPropertyObject: invalidateCaches

Class Variables [hide private]

Inherited from baseObject.AutoPropertyObject: cachePropertiesByDefault

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, obj, position)
(Constructor)

source code 

Constructor. Subclasses must extend this, calling the superclass method first.

Parameters:
  • position (int, tuple or string) - The initial position of this range; one of the POSITION_* constants or a position object supported by the implementation.
  • obj - The object containing the range of text being represented.
Overrides: object.__init__

_get_text(self)

source code 

The text with in this range. Subclasses must implement this.

Returns: unicode
The text.

Note: The text is not guaranteed to be the exact length of the range in offsets.

getTextWithFields(self, formatConfig=None)

source code 

Retreaves the text in this range, as well as any control/format fields associated therewith. Subclasses may override this. The base implementation just returns the text.

Parameters:
  • formatConfig (dict) - Document formatting configuration, useful if you wish to force a particular configuration for a particular task.
Returns: list of unicode and FieldCommand
A sequence of text strings interspersed with associated field commands.

unitIndex(self, unit)

source code 
Parameters:
  • unit - a unit constant for which you want to retreave an index
Returns: int
The 1-based index of this unit, out of all the units of this type in the object

unitCount(self, unit)

source code 
Parameters:
  • unit (string) - a unit constant
Returns: int
the number of units of this type in the object

compareEndPoints(self, other, which)

source code 

compares one end of this range to one end of another range. Subclasses must implement this.

Parameters:
  • other (TextInfo) - the text range to compare with.
  • which - The ends to compare; one of "startToStart", "startToEnd", "endToStart", "endToEnd".
Returns: int
-1 if this end is before other end, 1 if this end is after other end or 0 if this end and other end are the same.

isOverlapping(self, other)

source code 

Determines whether this object overlaps another object in any way. Note that collapsed objects can cause some confusion. For example, in terms of offsets, (4, 4) and (4, 5) are not considered as overlapping. Therefore, collapsed objects should probably be expanded to at least 1 character when using this method.

Parameters:
  • other (TextInfo) - The TextInfo object being compared.
Returns: bool
True if the objects overlap, False if not.

setEndPoint(self, other, which)

source code 

Sets one end of this range to one end of another range. Subclasses must implement this.

Parameters:
  • other (TextInfo) - The range from which an end is being obtained.
  • which - The ends to use; one of "startToStart", "startToEnd", "endToStart", "endToEnd".

_get_isCollapsed(self)

source code 
Returns: bool
True if representing a collapsed range, False if the range is expanded to cover one or more characters.

expand(self, unit)

source code 

Expands the start and end of this text info object to a given unit

Parameters:
  • unit (string) - a unit constant

collapse(self, end=False)

source code 

Collapses this text info object so that both endpoints are the same.

Parameters:
  • end (bool) - Whether to collapse to the end; True to collapse to the end, False to collapse to the start.

move(self, unit, direction, endPoint=None)

source code 

Moves one or both of the endpoints of this object by the given unit and direction.

Parameters:
  • unit - the unit to move by; one of the UNIT_* constants.
  • direction - a positive value moves forward by a number of units, a negative value moves back a number of units
  • endPoint - Either None, "start" or "end". If "start" then the start of the range is moved, if "end" then the end of the range is moved, if None - not specified then collapse to start and move both start and end.
Returns: int
The number of units moved; negative indicates backward movement, positive indicates forward movement, 0 means no movement.

find(self, text, caseSensitive=False, reverse=False)

source code 

Locates the given text and positions this TextInfo object at the start.

Parameters:
  • text (string) - the text to search for
  • caceSensitive - true if case sensitivity search should be used, False if not
  • reverse (bool) - true then the search will go from current position towards the start of the text, if false then towards the end.
  • caseSensitive (bool)
Returns: bool
True if text is found, false otherwise

_get_NVDAObjectAtStart(self)

source code 

retreaves the NVDAObject related to the start of the range. Usually it is just the owner NVDAObject, but in the case of virtualBuffers it may be a descendant object.

Returns:
the NVDAObject at the start

_get_pointAtStart(self)

source code 

Retrieves x and y coordinates corresponding with the textInfo start. It should return Point

_get_clipboardText(self)

source code 

Text suitably formatted for copying to the clipboard. E.g. crlf characters inserted between lines.

copyToClipboard(self)

source code 

Copy the content of this instance to the clipboard.

Returns: bool
True if successful, False otherwise.

getTextInChunks(self, unit)

source code 

Retrieve the text of this instance in chunks of a given unit.

Parameters:
  • unit - The unit at which chunks should be split.
Returns: generator of str
Chunks of text.

getEmbeddedObject(self, offset=0)

source code 

Retrieve the embedded object associated with a particular embedded object character. Where a text implementation allows other objects to be embedded in the text, embedded objects are represented by an embedded object character (\uFFFC). When these characters are encountered, this method can be used to retrieve the associated embedded object.

Parameters:
  • offset (int) - The offset of the embedded object character in question relative to the start of this instance.
Returns: NVDAObjects.NVDAObject
The embedded object.