KDE 4.9 PyKDE API Reference

- KDE's Python API

# Cursor Class Reference

`from PyKDE4.ktexteditor import *`

Namespace: KTextEditor

## Detailed Description

An object which represents a position in a Document.

A Cursor is a basic class which contains the line() and column() a position in a Document. It is very lightweight and maintains no affiliation with a particular Document.

If you want additional functionality such as the ability to maintain position in a document, see SmartCursor.

Note:
  The Cursor class is designed to be passed via value, while SmartCursor and derivatives must be passed via pointer or reference as they maintain a connection with their document internally and cannot be copied.

Note:
  Lines and columns start at 0.

Note:
  Think of cursors as having their position at the start of a character, not in the middle of one.

Note:
  If a Cursor is associated with a Range the Range will be notified whenever the cursor (i.e. start or end position) changes its position. Read the class documentation about Range%s for further details.

\sa SmartCursor

## Methods

| __init__ (self)
| __init__ (self, int line, int column)
| __init__ (self, KTextEditor.Cursor copy)
bool | atStartOfDocument (self)
bool | atStartOfLine (self)
int | column (self)
| cursorChangedDirectly (self, KTextEditor.Cursor from)
bool | isSmartCursor (self)
bool | isValid (self)
int | line (self)
| position (self, int line, int column)
KTextEditor.Range | range (self)
| setColumn (self, int column)
| setLine (self, int line)
| setPosition (self, KTextEditor.Cursor position)
| setPosition (self, int line, int column)
| setRange (self, KTextEditor.Range range)
KTextEditor.SmartCursor | toSmartCursor (self)

## Static Methods

KTextEditor.Cursor | invalid ()
KTextEditor.Cursor | start ()

## Method Documentation

__init__ | ( |  | self ) |

The default constructor creates a cursor at position (0,0).

__init__ | ( | self, |
|  | int | line,
|  | int | column
| ) |  |  |

This constructor creates a cursor initialized with line and column.

Parameters:

  | line | line for cursor

Parameters:

  | column | column for cursor

__init__ | ( | self, |
|  | KTextEditor.Cursor | copy
| ) |  |  |

Copy constructor. Does not copy the owning range, as a range does not have any association with copies of its cursors.

Parameters:

  | copy | the cursor to copy.

bool atStartOfDocument | ( |  | self ) |

Determine if this cursor is located at the start of a document.

Returns:
  true if the cursor is situated at the start of the document, false if it isn't.

bool atStartOfLine | ( |  | self ) |

Determine if this cursor is located at the start of a line.

Returns:
  true if the cursor is situated at the start of the line, false if it isn't.

int column | ( |  | self ) |

Retrieve the column on which this cursor is situated.

Returns:
  column number, where 0 is the first column.

cursorChangedDirectly | ( | self, |
|  | KTextEditor.Cursor | from
| ) |  |  |

Internal:

Notify the owning range, if any, that this cursor has changed directly.

bool isSmartCursor | ( |  | self ) |

Returns whether this cursor is a SmartCursor.

bool isValid | ( |  | self ) |

Returns whether the current position of this cursor is a valid position (line + column must both be >= 0).

Smart cursors should override this to return whether the cursor is valid within the linked document.

int line | ( |  | self ) |

Retrieve the line on which this cursor is situated.

Returns:
  line number, where 0 is the first line.

position | ( | self, |
|  | int | line,
|  | int | column
| ) |  |  |

Get both the line and column of the cursor position.

Parameters:

  | line | will be filled with current cursor line

Parameters:

  | column | will be filled with current cursor column

KTextEditor.Range range | ( |  | self ) |

Returns the range that this cursor belongs to, if any.

setColumn | ( | self, |
|  | int | column
| ) |  |  |

Set the cursor column to column.

Parameters:

  | column | new cursor column

setLine | ( | self, |
|  | int | line
| ) |  |  |

Set the cursor line to line.

Parameters:

  | line | new cursor line

setPosition | ( | self, |
|  | KTextEditor.Cursor | position
| ) |  |  |

Set the cursor position to line and column.

Parameters:

  | line | new cursor line

Parameters:

  | column | new cursor column

setPosition | ( | self, |
|  | int | line,
|  | int | column
| ) |  |  |

Set the cursor position to line and column.

Parameters:

  | line | new cursor line

Parameters:

  | column | new cursor column

setRange | ( | self, |
|  | KTextEditor.Range | range
| ) |  |  |

Internal:

Sets the range that this cursor belongs to.

Parameters:

  | range | the range that this cursor is referenced from.

KTextEditor.SmartCursor toSmartCursor | ( |  | self ) |

Returns this cursor as a SmartCursor, if it is one.

## Static Method Documentation

KTextEditor.Cursor invalid | ( |  | ) |

Returns an invalid cursor.

KTextEditor.Cursor start | ( |  | ) |

Returns a cursor representing the start of any document - i.e., line 0, column 0.