KDE 4.9 PyKDE API Reference

- KDE's Python API

# CodeCompletionInterface Class Reference

`from PyKDE4.ktexteditor import *`

Namespace: KTextEditor

## Detailed Description

Code completion extension interface for the View.

Introduction

The CodeCompletionInterface is designed to provide code completion functionality for a KTextEditor.View. This interface provides the basic mechanisms to display a list of completions, update this list according to user input, and allow the user to select a completion.

Essentially, this provides an item view for the available completions. In order to use this interface, you will need to implement a CodeCompletionModel that generates the relevant completions given the current input.

Accessing the CodeCompletionInterface

The CodeCompletionInterface is an extension interface for a View, i.e. the View inherits the interface provided that the used KTextEditor library implements the interface. Use qobject_cast to access the interface:

     // view is of type KTextEditor.View*
     KTextEditor.CodeCompletionInterface *iface =
         qobject_cast<KTextEditor.CodeCompletionInterface*>( view );

     if( iface ) {
         // the implementation supports the interface
         // do stuff
     }

Using the CodeCompletionInterface

The CodeCompletionInterface can be used in different ways, which we will call "automatic", and "manual".

In automatic mode, the CodeCompletionInterface will take care of starting and aborting the generation of code completions as appropriate, when the users inserts or changes text.

To use the interface in this way, first register a CodeCompletionModel using registerCompletionModel(). Now call setAutomaticCompletionEnabled() to enabled automatic completions.

If you need more control over when code completions get shown or not, or which fragment of the text should be considered as the basis for generated completions, proceed as follows:

Call setAutomaticCompletionEnabled(false) to disable automatic completions. To start the generation of code completions for the current word, call startCompletion(), with the appropriate parameters. To hide the generated completions, use abortCompletion().

See also:
  KTextEditor.View, KTextEditor.CodeCompletionModel

## Methods
| abortCompletion (self)
| forceCompletion (self)
bool | isAutomaticInvocationEnabled (self)
bool | isCompletionActive (self)
| registerCompletionModel (self, KTextEditor.CodeCompletionModel model)
| setAutomaticInvocationEnabled (self, bool enabled=1)
| startCompletion (self, KTextEditor.Range word, KTextEditor.CodeCompletionModel model)
| unregisterCompletionModel (self, KTextEditor.CodeCompletionModel model)

## Method Documentation

abortCompletion | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Abort the currently displayed code completion without executing any currently selected completion. This is safe, even when the completion box is not currently active.

See also:
  isCompletionActive()

forceCompletion | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Force execution of the currently selected completion, and hide the code completion box.

bool isAutomaticInvocationEnabled | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Determine the status of automatic code completion invocation.

bool isCompletionActive | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Query whether the code completion box is currently displayed.

registerCompletionModel | ( | self, |
|  | KTextEditor.CodeCompletionModel | model
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Register a new code completion model.

Parameters:

  | model | new completion model

See also:
  unregisterCompletionModel()

setAutomaticInvocationEnabled | ( | self, |
|  | bool | enabled=1
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Enable or disable automatic code completion invocation.

startCompletion | ( | self, |
|  | KTextEditor.Range | word,
|  | KTextEditor.CodeCompletionModel | model
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Invoke code completion over a given range, with a specific model.

unregisterCompletionModel | ( | self, |
|  | KTextEditor.CodeCompletionModel | model
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Unregister a code completion model.

Parameters:

  | model | the model that should be unregistered

See also:
  registerCompletionModel()