Class: QgsCodeEditorPython

A Python editor based on QScintilla2.

Adds syntax highlighting and code autocompletion.

Note

may not be available in Python bindings, depending on platform support

QgsCodeEditorPython containing sample Python

QgsCodeEditorPython containing sample Python

Class Hierarchy

Inheritance diagram of qgis.gui.QgsCodeEditorPython

Base classes

QgsCodeEditor

A text editor based on QScintilla2.

QsciScintilla

QsciScintillaBase

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

Methods

autoComplete

Triggers the autocompletion popup.

characterAfterCursor

Returns the character after the cursor, or an empty string if the cursor is set at end

characterBeforeCursor

Returns the character before the cursor, or an empty string if cursor is set at start

isCursorInsideStringLiteralOrComment

Check whether the current cursor position is inside a string literal or a comment

loadAPIs

Load APIs from one or more files

loadScript

Loads a script file.

searchSelectedTextInPyQGISDocs

Searches the selected text in the official PyQGIS online documentation.

updateCapabilities

Updates the editor capabilities.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsCodeEditorPython. See the FAQ for more details.

showApiDocumentation

Displays the given text in the official APIs (PyQGIS, C++ QGIS or Qt) documentation.

toggleComment

Toggle comment for the selected text.

class qgis.gui.QgsCodeEditorPython[source]

Bases: QgsCodeEditor

__init__(parent: QWidget | None = None, filenames: Iterable[str | None] = [], mode: QgsCodeEditor.Mode = QgsCodeEditor.Mode.ScriptEditor, flags: QgsCodeEditor.Flags | QgsCodeEditor.Flag = QgsCodeEditor.Flag.CodeFolding)

Construct a new Python editor.

Parameters:
  • parent (Optional[QWidget] = None) – The parent QWidget

  • filenames (Iterable[Optional[str]] = []) – The list of apis files to load for the Python lexer

  • mode (QgsCodeEditor.Mode = QgsCodeEditor.Mode.ScriptEditor) – code editor mode (since QGIS 3.30)

  • flags (Union[QgsCodeEditor.Flags, QgsCodeEditor.Flag] = QgsCodeEditor.Flag.CodeFolding) – code editor flags (since QGIS 3.32)

autoComplete(self)[source]

Triggers the autocompletion popup.

Added in version 3.16.

characterAfterCursor(self) str[source]

Returns the character after the cursor, or an empty string if the cursor is set at end

Added in version 3.30.

Return type:

str

characterBeforeCursor(self) str[source]

Returns the character before the cursor, or an empty string if cursor is set at start

Added in version 3.30.

Return type:

str

isCursorInsideStringLiteralOrComment(self) bool[source]

Check whether the current cursor position is inside a string literal or a comment

Added in version 3.30.

Return type:

bool

loadAPIs(self, filenames: Iterable[str | None])[source]

Load APIs from one or more files

Parameters:

filenames (Iterable[Optional[str]]) – The list of apis files to load for the Python lexer

loadScript(self, script: str | None) bool[source]

Loads a script file.

Parameters:

script (Optional[str])

Return type:

bool

searchSelectedTextInPyQGISDocs(self)[source]

Searches the selected text in the official PyQGIS online documentation.

Added in version 3.16.

virtual showApiDocumentation(self, item: str | None)[source]

Displays the given text in the official APIs (PyQGIS, C++ QGIS or Qt) documentation.

Added in version 3.42.

Parameters:

item (Optional[str])

virtual toggleComment(self)[source]

Toggle comment for the selected text.

Added in version 3.30.

updateCapabilities(self)[source]

Updates the editor capabilities.

Added in version 3.32.