Package textInfos :: Module offsets :: Class OffsetsTextInfo
[hide private]
[frames] | no frames]

Class OffsetsTextInfo

source code

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

An abstract TextInfo for text implementations which represent ranges using numeric offsets relative to the start of the text.
In such implementations, the start of the text is represented by 0 and the end is the length of the entire text.

All subclasses must implement L{_getStoryLength}.
Aside from this, there are two possible implementations:
        * If the underlying text implementation does not support retrieval of line offsets, L{_getStoryText} should be implemented.
        In this case, the base implementation of L{_getLineOffsets} will retrieve the entire text of the object and use text searching algorithms to find line offsets.
        This is very inefficient and should be avoided if possible.
        * Otherwise, subclasses must implement at least L{_getTextRange} and L{_getLineOffsets}.
        Retrieval of other offsets (e.g. L{_getWordOffsets}) should also be implemented if possible for greatest accuracy and efficiency.

If a caret and/or selection should be supported, L{_getCaretOffset} and/or L{_getSelectionOffsets} should be implemented, respectively.
To support conversion from/to screen points (e.g. for mouse tracking), L{_getOffsetFromPoint}/L{_getPointFromOffset} should be implemented.

Nested Classes [hide private]

Inherited from baseObject.AutoPropertyObject: __metaclass__

Instance Methods [hide private]
 
__eq__(self, other) source code
 
_getCaretOffset(self) source code
 
_setCaretOffset(self, offset) source code
 
_getSelectionOffsets(self) source code
 
_setSelectionOffsets(self, start, end) source code
 
_getStoryLength(self) source code
unicode
_getStoryText(self)
Retrieve the entire text of the object.
source code
unicode
_getTextRange(self, start, end)
Retrieve the text in a given offset range.
source code
 
_getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)
Retrieve the formatting information for a given offset and the offsets spanned by that field.
source code
 
_getCharacterOffsets(self, offset) source code
 
_getWordOffsets(self, offset) source code
 
_getLineNumFromOffset(self, offset) source code
 
_getLineOffsets(self, offset) source code
 
_getParagraphOffsets(self, offset) source code
 
_getReadingChunkOffsets(self, offset) source code
 
_getPointFromOffset(self, offset) source code
 
_getOffsetFromPoint(self, x, y) source code
 
_getNVDAObjectFromOffset(self, offset) source code
 
_getOffsetsFromNVDAObject(self, obj) source code
 
__init__(self, obj, position)
Constructor.
source code
 
_get_NVDAObjectAtStart(self)
retreaves the NVDAObject related to the start of the range.
source code
 
_getUnitOffsets(self, unit, offset) source code
 
_get_pointAtStart(self)
Retrieves x and y coordinates corresponding with the textInfo start.
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
 
collapse(self, end=False)
Collapses this text info object so that both endpoints are the same.
source code
 
expand(self, unit)
Expands the start and end of this text info object to a given unit
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
int
compareEndPoints(self, other, which)
compares one end of this range to one end of another range.
source code
 
setEndPoint(self, other, which)
Sets one end of this range to one end of another 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
unicode
_get_text(self)
The text with in this range.
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
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
 
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

Inherited from TextInfo: copyToClipboard, getControlFieldBraille, getControlFieldSpeech, getEmbeddedObject, getTextInChunks, isOverlapping

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]
  detectFormattingAfterCursorMaybeSlow = True
honours documentFormatting config option if true - set to false if this is not at all slow.
  useUniscribe = True

Inherited from baseObject.AutoPropertyObject: cachePropertiesByDefault

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_getStoryText(self)

source code 

Retrieve the entire text of the object.

Returns: unicode
The entire text of the object.

_getTextRange(self, start, end)

source code 

Retrieve the text in a given offset range.

Parameters:
  • start (int) - The start offset.
  • end (int) - The end offset (exclusive).
Returns: unicode
The text contained in the requested range.

_getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)

source code 

Retrieve the formatting information for a given offset and the offsets spanned by that field. Subclasses must override this if support for text formatting is desired. The base implementation associates text with line numbers if possible.

__init__(self, obj, position)
(Constructor)

source code 

Constructor. Subclasses may extend this to perform implementation specific initialisation, calling their superclass method afterwards.

Parameters:
  • position - 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_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
Overrides: TextInfo._get_NVDAObjectAtStart
(inherited documentation)

_get_pointAtStart(self)

source code 

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

Overrides: TextInfo._get_pointAtStart
(inherited documentation)

_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.
Overrides: TextInfo._get_isCollapsed
(inherited documentation)

collapse(self, end=False)

source code 

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

Parameters:
  • end - Whether to collapse to the end; True to collapse to the end, False to collapse to the start.
Overrides: TextInfo.collapse
(inherited documentation)

expand(self, unit)

source code 

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

Parameters:
  • unit - a unit constant
Overrides: TextInfo.expand
(inherited documentation)

copy(self)

source code 

duplicates this text info object so that changes can be made to either one with out afecting the other

Overrides: TextInfo.copy
(inherited documentation)

compareEndPoints(self, other, which)

source code 

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

Parameters:
  • other - 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.
Overrides: TextInfo.compareEndPoints
(inherited documentation)

setEndPoint(self, other, which)

source code 

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

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

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 - 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.
Overrides: TextInfo.getTextWithFields
(inherited documentation)

_get_text(self)

source code 

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

Returns: unicode
The text.
Overrides: TextInfo._get_text
(inherited documentation)

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
Overrides: TextInfo.unitIndex
(inherited documentation)

unitCount(self, unit)

source code 
Parameters:
  • unit - a unit constant
Returns: int
the number of units of this type in the object
Overrides: TextInfo.unitCount
(inherited documentation)

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.
Overrides: TextInfo.move
(inherited documentation)

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

source code 

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

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

updateCaret(self)

source code 

Moves the system caret to the position of this text info object

Overrides: TextInfo.updateCaret
(inherited documentation)

updateSelection(self)

source code 

Moves the selection (usually the system caret) to the position of this text info object

Overrides: TextInfo.updateSelection
(inherited documentation)

_get_bookmark(self)

source code 
Overrides: TextInfo._get_bookmark