KDE 4.7 PyKDE API Reference

- KDE's Python API

# Range Class Reference

`from PyKDE4.khtml import *`

Namespace: DOM

## Detailed Description

## Enumerations
CompareHow | { START_TO_START, START_TO_END, END_TO_END, END_TO_START }
## Methods
| __init__ (self)
| __init__ (self, DOM.Document rootContainer)
| __init__ (self, DOM.Range other)
| __init__ (self, DOM.Node startContainer, long startOffset, DOM.Node endContainer, long endOffset)
bool | boundaryPointsValid (self)
DOM.DocumentFragment | cloneContents (self)
DOM.Range | cloneRange (self)
| collapse (self, bool toStart)
bool | collapsed (self)
DOM.Node | commonAncestorContainer (self)
int | compareBoundaryPoints (self, DOM.Range.CompareHow how, DOM.Range sourceRange)
DOM.DocumentFragment | createContextualFragment (self, DOM.DOMString html)
| deleteContents (self)
| detach (self)
DOM.Node | endContainer (self)
long | endOffset (self)
DOM.DocumentFragment | extractContents (self)
| insertNode (self, DOM.Node newNode)
bool | isDetached (self)
bool | isNull (self)
| selectNode (self, DOM.Node refNode)
| selectNodeContents (self, DOM.Node refNode)
| setEnd (self, DOM.Node refNode, long offset)
| setEndAfter (self, DOM.Node refNode)
| setEndBefore (self, DOM.Node refNode)
| setStart (self, DOM.Node refNode, long offset)
| setStartAfter (self, DOM.Node refNode)
| setStartBefore (self, DOM.Node refNode)
DOM.Node | startContainer (self)
long | startOffset (self)
| surroundContents (self, DOM.Node newParent)
DOM.DOMString | toHTML (self)
DOM.DOMString | toString (self)

## Method Documentation

__init__ | ( |  | self ) |

__init__ | ( | self, |
|  | DOM.Document | rootContainer
| ) |  |  |

__init__ | ( | self, |
|  | DOM.Range | other
| ) |  |  |

__init__ | ( | self, |
|  | DOM.Node | startContainer,
|  | long | startOffset,
|  | DOM.Node | endContainer,
|  | long | endOffset
| ) |  |  |

bool boundaryPointsValid | ( |  | self ) |

Internal:
  not part of the DOM

Compare the boundary-points of a range.

Return true if the startContainer is before the endContainer, or if they are equal. Return false if the startContainer is after the endContainer.

DOM.DocumentFragment cloneContents | ( |  | self ) |

Duplicates the contents of a range

Returns:
  A DocumentFragment containing contents equivalent to those of this range.

DOMException HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be extracted into the new DocumentFragment.

DOM.Range cloneRange | ( |  | self ) |

Produces a new range whose end-points are equal to the end-points of the range.

Returns:
  The duplicated range.

collapse | ( | self, |
|  | bool | toStart
| ) |  |  |

Collapse a range onto one of its end-points

Parameters:

  | toStart | If true, collapses the Range onto its start; if false, collapses it onto its end.

Returns:

bool collapsed | ( |  | self ) |

true if the range is collapsed

DOM.Node commonAncestorContainer | ( |  | self ) |

Gets the common ancestor container of the range's two end-points. Also sets it.

int compareBoundaryPoints | ( | self, |
|  | DOM.Range.CompareHow | how,
|  | DOM.Range | sourceRange
| ) |  |  |

Compare the end-points of two ranges in a document.

Parameters:

  | how |
  | sourceRange |

Returns:
  -1, 0 or 1 depending on whether the corresponding end-point of the Range is before, equal to, or after the corresponding end-point of sourceRange .

DOMException WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same document or document fragment.

DOM.DocumentFragment createContextualFragment | ( | self, |
|  | DOM.DOMString | html
| ) |  |  |

deleteContents | ( |  | self ) |

Removes the contents of a range from the containing document or document fragment without returning a reference to the removed content.

Returns:

DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of the range is read-only or any of the nodes that contain any of the content of the range are read-only.

detach | ( |  | self ) |

Called to indicate that the range is no longer in use and that the implementation may relinquish any resources associated with this range. Subsequent calls to any methods or attribute getters on this range will result in a DOMException being thrown with an error code of INVALID_STATE_ERR.

DOM.Node endContainer | ( |  | self ) |

Node within which the range ends

long endOffset | ( |  | self ) |

Offset within the ending node of the range.

DOM.DocumentFragment extractContents | ( |  | self ) |

Moves the contents of a range from the containing document or document fragment to a new DocumentFragment.

Returns:
  A DocumentFragment containing the extracted contents.

DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of the range is read-only or any of the nodes which contain any of the content of the range are read-only.

HIERARCHY_REQUEST_ERR: Raised if a DocumentType node would be extracted into the new DocumentFragment.

insertNode | ( | self, |
|  | DOM.Node | newNode
| ) |  |  |

Inserts a node into the document or document fragment at the start of the range.

Parameters:

  | newNode | The node to insert at the start of the range

Returns:

DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the start of the range is read-only.

WRONG_DOCUMENT_ERR: Raised if newNode and the container of the start of the Range were not created from the same document.

HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that does not allow children of the type of newNode or if newNode is an ancestor of the container .

RangeException INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, Notation, DocumentFragment, or Document node.

bool isDetached | ( |  | self ) |

not part of the DOM true if the range is detached

bool isNull | ( |  | self ) |

selectNode | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Select a node and its contents

Parameters:

  | refNode | The node to select.

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Attr, Entity, Notation or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.

selectNodeContents | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Select the contents within a node

Parameters:

  | refNode | Node to select from

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Attr, Entity, Notation or DocumentType node.

setEnd | ( | self, |
|  | DOM.Node | refNode,
|  | long | offset
| ) |  |  |

Sets the attributes describing the end of a range.

Parameters:

  | refNode | The refNode value. This parameter must be different from null .
  | offset | The endOffset value.

Returns:

RangeException NULL_NODE_ERR: Raised if refNode is null .

INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Attr, Entity, Notation, or DocumentType node.

setEndAfter | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Sets the end of a range to be after a node

Parameters:

  | refNode | Range ends after refNode .

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Attr, Entity, Notation or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.

setEndBefore | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Sets the end position to be before a node.

Parameters:

  | refNode | Range ends before refNode

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Attr, Entity, Notation, or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.

setStart | ( | self, |
|  | DOM.Node | refNode,
|  | long | offset
| ) |  |  |

Sets the attributes describing the start of the range.

Parameters:

  | refNode | The refNode value. This parameter must be different from null .
  | offset | The startOffset value.

Returns:

RangeException NULL_NODE_ERR: Raised if refNode is null .

INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an Attr, Entity, Notation, or DocumentType node.

If an offset is out-of-bounds, should it just be fixed up or should an exception be raised.

setStartAfter | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Sets the start position to be after a node

Parameters:

  | refNode | Range starts after refNode

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Attr, Entity, Notation, or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.

setStartBefore | ( | self, |
|  | DOM.Node | refNode
| ) |  |  |

Sets the start position to be before a node

Parameters:

  | refNode | Range starts before refNode

Returns:

RangeException INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Attr, Entity, Notation, or DocumentType node or if refNode is a Document, DocumentFragment, Attr, Entity, or Notation node.

DOM.Node startContainer | ( |  | self ) |

Node within which the range begins

long startOffset | ( |  | self ) |

Offset within the starting node of the range.

surroundContents | ( | self, |
|  | DOM.Node | newParent
| ) |  |  |

Reparents the contents of the range to the given node and inserts the node at the position of the start of the range.

Parameters:

  | newParent | The node to surround the contents with.

Returns:

DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of either end-point of the range is read-only.

WRONG_DOCUMENT_ERR: Raised if newParent and the container of the start of the Range were not created from the same document.

HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that does not allow children of the type of newParent or if newParent is an ancestor of the container or if node would end up with a child node of a type not allowed by the type of node .

RangeException BAD_ENDPOINTS_ERR: Raised if the range partially selects a non-text node.

INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, Notation, Document, or DocumentFragment node.

DOM.DOMString toHTML | ( |  | self ) |

Internal:
  Not part of DOM

DOM.DOMString toString | ( |  | self ) |

Returns the contents of a range as a string.

Returns:
  The contents of the range.

## Enumeration Documentation

CompareHow

Enumerator:

  START_TO_START = 0 |
  START_TO_END = 1 |
  END_TO_END = 2 |
  END_TO_START = 3 |