SmartInterface Class Reference
from PyKDE4.ktexteditor import *
Namespace: KTextEditor
Detailed Description
- Abstract class:
- This class can be used as a base class for new classes, but can not be instantiated directly.
A Document extension interface for handling SmartCursor%s and SmartRange%s.
Topics: - smartiface_intro - smartiface_creation - smartiface_highlight - smartiface_action - smartiface_access
Introduction Use this interface to:
Creation of SmartCursors and SmartRanges These functions must be used to create SmartCursor%s and SmartRange%s. This means that these objects cannot be derived from by third party applications.
You then own these objects; upon deletion they de-register themselves from the Document with which they were associated. Alternatively, they are all deleted with the deletion of the owning Document.
Arbitrary Highlighting Arbitrary highlighting of text can be achieved by creating SmartRange%s in a tree structure, and assigning appropriate Attributes to these ranges.
To highlight all views, use addHighlightToDocument(); to highlight one or some of the views, use addHighlightToView(). You only need to call this function once per tree; just supply the top range you want to have highlighted. Calling this function more than once with ranges from the same tree may give undefined results.
Action Binding Action binding can be used to associate KAction%s with specific ranges of text. These bound actions are automatically enabled and disabled when the caret enters their associated ranges, and context menus are automatically populated with the relevant actions.
As with the arbitrary highlighting interface, to enable bound actions to be active, call addActionsToDocument() or addActionsToView() on the top SmartRange of a tree. If only small branches of a tree contain actions, it may be more efficient to simply add each of these branches instead (but this is unlikely unless the tree is complex).
Note that actions can be bound either directly to the range via SmartRange.associateAction(), or indirectly via Attribute.associateAction(). Using attributes may be more convenient when you want all ranges of a specific type to have the same action associated with them.
To do: extend this to provide a signal from the action indicating which range was used to activate it (if possible)
Accessing the Interface
The SmartInterface is supposed to be an extension interface for a Document, i.e. the Document inherits the interface provided that the KTextEditor library in use implements the interface. Use dynamic_cast to access the interface:
// doc is of type KTextEditor.Document* KTextEditor.SmartInterface *iface = qobject_cast<KTextEditor.SmartInterface*>( doc ); if( iface ) { // the implementation supports the interface // do stuff }
Thread safety The smart interface is designed to be usable in multithreaded environments. If you use the interface from threads other than the main thread, you must lock the smartMutex() whenever you are making a non-const call to a smart object. This allows the text editor to guarantee that the objects will not change when it locks the mutex (for example, when performing layout or rendering). The useRevision function has only effect for the thread calling it. It will store the selected revision in a thread local storage to allow multiple threads to have different views on the same document in respect to the smart interface.
Method Documentation
__init__ | ( | self ) |
addActionsToDocument | ( | self, | ||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
addActionsToView | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
addHighlightToDocument | ( | self, | ||
KTextEditor.SmartRange | topRange, | |||
bool | supportDynamic=0 | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Register a SmartRange tree as providing arbitrary highlighting information, and that it should be rendered on all of the views of a document.
- Parameters:
-
topRange the top range of the tree to add
- Parameters:
-
supportDynamic support dynamic highlighting attributes
addHighlightToView | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.SmartRange | topRange, | |||
bool | supportDynamic=0 | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Register a SmartRange tree as providing arbitrary highlighting information, and that it should be rendered on the specified view.
- Parameters:
-
view view on which to render the highlight
- Parameters:
-
topRange the top range of the tree to add
- Parameters:
-
supportDynamic support dynamic highlighting attributes
attributeDynamic | ( | self, | ||
KSharedPtr |
a | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
- Internal:
- Used to notify implementations that an Attribute has gained a dynamic component and needs to be included in mouse and/or cursor tracking.
attributeNotDynamic | ( | self, | ||
KSharedPtr |
a | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
- Internal:
- Used to notify implementations that an Attribute has lost all dynamic components and no longer needs to be included in mouse and cursor tracking.
clearDocumentActions | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
clearDocumentHighlights | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Clear the highlight ranges from a Document.
bool clearOnDocumentReload | ( | self ) |
Returns whether the smart interface will be cleared on reload of the document.
Defaults to true.
clearRevision | ( | self ) |
Clear any previous setting to use a specific revision. Convenience wrapper for useRevision (-1).
clearSmartInterface | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Clears or deletes all instances of smart objects, ie:
Deletion occurs without modification to the underlying text.
clearViewActions | ( | self, | ||
KTextEditor.View | view | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
clearViewHighlights | ( | self, | ||
KTextEditor.View | view | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Clear the highlight ranges from a View.
- Parameters:
-
view view to clear highlights from
int currentRevision | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Retrieve a token representing the current version of the document. This can be used later to create cursors and ranges as they would have been at this revision.
Once you have finished with the token, release it with releaseRevision().
deleteCursors | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Delete all SmartCursor%s from this document, with the exception of those cursors currently bound to ranges.
deleteRanges | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Delete all SmartRange%s from this document. This will also delete all cursors currently bound to ranges.
This will not affect any underlying text.
[KTextEditor.SmartRange] documentActions | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
[KTextEditor.SmartRange] documentHighlights | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Return a list of SmartRange%s which are currently registered as providing arbitrary highlighting information to all of the views of a document.
KTextEditor.SmartCursor newSmartCursor | ( | self, | ||
KTextEditor.Cursor | position=KTextEditor.Cursor.start(), | |||
KTextEditor.SmartCursor.InsertBehavior | insertBehavior=KTextEditor.SmartCursor.MoveOnInsert | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Creates a new SmartCursor.
You own this object, and may delete it when you are finished with it. Alternatively, you may call the various clear methods, or wait for the Document to be destroyed.
- Parameters:
-
line the line number of the cursor's initial position
- Parameters:
-
column the line number of the cursor's initial position
- Parameters:
-
insertBehavior Define whether the cursor should move when text is inserted at the cursor position.
KTextEditor.SmartCursor newSmartCursor | ( | self, | ||
int | line, | |||
int | column, | |||
KTextEditor.SmartCursor.InsertBehavior | insertBehavior=KTextEditor.SmartCursor.MoveOnInsert | |||
) |
Creates a new SmartCursor.
You own this object, and may delete it when you are finished with it. Alternatively, you may call the various clear methods, or wait for the Document to be destroyed.
- Parameters:
-
line the line number of the cursor's initial position
- Parameters:
-
column the line number of the cursor's initial position
- Parameters:
-
insertBehavior Define whether the cursor should move when text is inserted at the cursor position.
KTextEditor.SmartRange newSmartRange | ( | self, | ||
KTextEditor.Range | range=KTextEditor.Range(), | |||
KTextEditor.SmartRange | parent=0, | |||
KTextEditor.SmartRange.InsertBehaviors | insertBehavior=KTextEditor.SmartRange.DoNotExpand | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Creates a new SmartRange from pre-existing SmartCursor%s. The cursors must not be part of any other range.
- Parameters:
-
start Start SmartCursor
- Parameters:
-
end End SmartCursor
- Parameters:
-
parent The parent SmartRange, if this is to be the child of an existing range.
- Parameters:
-
insertBehavior Define whether the range should expand when text is inserted at ends of the range.
KTextEditor.SmartRange newSmartRange | ( | self, | ||
KTextEditor.Cursor | startPosition, | |||
KTextEditor.Cursor | endPosition, | |||
KTextEditor.SmartRange | parent=0, | |||
KTextEditor.SmartRange.InsertBehaviors | insertBehavior=KTextEditor.SmartRange.DoNotExpand | |||
) |
Creates a new SmartRange from pre-existing SmartCursor%s. The cursors must not be part of any other range.
- Parameters:
-
start Start SmartCursor
- Parameters:
-
end End SmartCursor
- Parameters:
-
parent The parent SmartRange, if this is to be the child of an existing range.
- Parameters:
-
insertBehavior Define whether the range should expand when text is inserted at ends of the range.
KTextEditor.SmartRange newSmartRange | ( | self, | ||
int | startLine, | |||
int | startColumn, | |||
int | endLine, | |||
int | endColumn, | |||
KTextEditor.SmartRange | parent=0, | |||
KTextEditor.SmartRange.InsertBehaviors | insertBehavior=KTextEditor.SmartRange.DoNotExpand | |||
) |
Creates a new SmartRange from pre-existing SmartCursor%s. The cursors must not be part of any other range.
- Parameters:
-
start Start SmartCursor
- Parameters:
-
end End SmartCursor
- Parameters:
-
parent The parent SmartRange, if this is to be the child of an existing range.
- Parameters:
-
insertBehavior Define whether the range should expand when text is inserted at ends of the range.
KTextEditor.SmartRange newSmartRange | ( | self, | ||
KTextEditor.SmartCursor | start, | |||
KTextEditor.SmartCursor | end, | |||
KTextEditor.SmartRange | parent=0, | |||
KTextEditor.SmartRange.InsertBehaviors | insertBehavior=KTextEditor.SmartRange.DoNotExpand | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Creates a new SmartRange from pre-existing SmartCursor%s. The cursors must not be part of any other range.
- Parameters:
-
start Start SmartCursor
- Parameters:
-
end End SmartCursor
- Parameters:
-
parent The parent SmartRange, if this is to be the child of an existing range.
- Parameters:
-
insertBehavior Define whether the range should expand when text is inserted at ends of the range.
releaseRevision | ( | self, | ||
int | revision | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Release a revision token provided by currentRevision(). You will no longer be able to create cursors and ranges against this revision.
removeActionsFromDocument | ( | self, | ||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
removeActionsFromView | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
removeHighlightFromDocument | ( | self, | ||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Remove a SmartRange tree from providing arbitrary highlighting information to all of the views of a document.
- Parameters:
-
topRange the top range of the tree to remove
removeHighlightFromView | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.SmartRange | topRange | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Remove a SmartRange tree from providing arbitrary highlighting information to a specific view of a document.
- Note:
- implementations should not take into account document-bound highlighting ranges when calling this function; it is intended solely to be the counter of addHighlightToView()
- Parameters:
-
view view on which the highlight was previously rendered
- Parameters:
-
topRange the top range of the tree to remove
setClearOnDocumentReload | ( | self, | ||
bool | clearOnReload | |||
) |
Specify whether the smart interface should be cleared on reload of the document.
- Parameters:
-
clearOnReload set to true to enable clearing of the smart interface on reload (the default).
QMutex smartMutex | ( | self ) |
Provides access to the recursive mutex used to protect write access to smart interface objects (cursors + ranges and their associated properties). If you use this interface from a thread other than the main thread, you must lock this mutex whenever you call a non-const function on a smart object.
KTextEditor.Cursor translateFromRevision | ( | self, | ||
KTextEditor.Cursor | cursor, | |||
KTextEditor.SmartCursor.InsertBehavior | insertBehavior=KTextEditor.SmartCursor.StayOnInsert | |||
) |
Translate the given range against the revision specified through useRevision(), using the given insertBehavior.
If no revision is set, simply returns the range.
KTextEditor.Range translateFromRevision | ( | self, | ||
KTextEditor.Range | range, | |||
KTextEditor.SmartRange.InsertBehaviors | insertBehavior=KTextEditor.SmartRange.ExpandLeft|KTextEditor.SmartRange.ExpandRight | |||
) |
Translate the given range against the revision specified through useRevision(), using the given insertBehavior.
If no revision is set, simply returns the range.
unbindSmartRange | ( | self, | ||
KTextEditor.SmartRange | range | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Delete a SmartRange without deleting the SmartCursor%s which make up its start() and end().
First, extract the cursors yourself using:
SmartCursor* start = &range->smartStart(); SmartCursor* end = &range->smartEnd();
Then, call this function to delete the SmartRange instance. The underlying text will not be affected.
- Parameters:
-
range the range to dissociate from its smart cursors, and delete
useRevision | ( | self, | ||
int | revision | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Tell the smart interface to work against the given revision when creating cursors and ranges. This has only an effect for the thread calling this function, as this property is stored thread locally. This is not allowed to be called in the main gui thread. If you call it in the main gui thread, fatal error will occur.
- Parameters:
-
revision the token representing a revision retrieved by currentRevision(), or -1 to clear any previous setting and use the current document revision.
[KTextEditor.SmartRange] viewActions | ( | self, | ||
KTextEditor.View | view | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
[KTextEditor.SmartRange] viewHighlights | ( | self, | ||
KTextEditor.View | view | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Return a list of SmartRange%s which are currently registered as providing arbitrary highlighting information to a specific view of a document.
- Note:
- implementations should not take into account document-bound highlighting ranges when returning the list; it is intended solely to show highlights added via addHighlightToView()
- Parameters:
-
view view to query for the highlight list