Class: QgsCodeEditorPython

class qgis.gui.QgsCodeEditorPython

Bases: QgsCodeEditor

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(parent: Optional[QWidget] = None, filenames: Iterable[Optional[str]] = [], mode: QgsCodeEditor.Mode = QgsCodeEditor.Mode.ScriptEditor, flags: Union[QgsCodeEditor.Flags, QgsCodeEditor.Flag] = QgsCodeEditor.Flag.CodeFolding) Construct a new Python editor.

Parameters:
actionEvent(self, a0: QActionEvent | None)
autoComplete(self)

Triggers the autocompletion popup.

Added in version 3.16.

canInsertFromMimeData(self, source: QMimeData | None) bool
changeEvent(self, event: QEvent | None)
characterAfterCursor(self) str

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

Added in version 3.30.

Return type:

str

characterBeforeCursor(self) str

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

Added in version 3.30.

Return type:

str

checkSyntax(self) bool
Return type:

bool

childEvent(self, a0: QChildEvent | None)
closeEvent(self, a0: QCloseEvent | None)
connectNotify(self, signal: QMetaMethod)
contextMenuEvent(self, event: QContextMenuEvent | None)
create(self, window: PyQt5.sip.voidptr = None, initializeWindow: bool = True, destroyOldWindow: bool = True)
customEvent(self, a0: QEvent | None)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, signal: QMetaMethod)
dragEnterEvent(self, e: QDragEnterEvent | None)
dragLeaveEvent(self, e: QDragLeaveEvent | None)
dragMoveEvent(self, e: QDragMoveEvent | None)
drawFrame(self, a0: QPainter | None)
dropEvent(self, e: QDropEvent | None)
enterEvent(self, a0: QEvent | None)
event(self, event: QEvent | None) bool
eventFilter(self, watched: QObject | None, event: QEvent | None) bool
focusInEvent(self, e: QFocusEvent | None)
focusNextChild(self) bool
focusNextPrevChild(self, next: bool) bool
focusOutEvent(self, event: QFocusEvent | None)
focusPreviousChild(self) bool
fromMimeData(self, source: QMimeData | None)
hideEvent(self, a0: QHideEvent | None)
initPainter(self, painter: QPainter | None)
initStyleOption(self, option: QStyleOptionFrame | None)
initializeLexer(self)
inputMethodEvent(self, e: QInputMethodEvent | None)
inputMethodQuery(self, query: Qt.InputMethodQuery) Any
isCursorInsideStringLiteralOrComment(self) bool

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

Added in version 3.30.

Return type:

bool

isFixedPitch(font: QFont) bool

Returns True if a font is a fixed pitch font.

isSignalConnected(self, signal: QMetaMethod) bool
keyPressEvent(self, event: QKeyEvent | None)
Parameters:

event (Optional[QKeyEvent])

keyReleaseEvent(self, a0: QKeyEvent | None)
language(self) Qgis.ScriptLanguage
Return type:

Qgis.ScriptLanguage

languageCapabilities(self) Qgis.ScriptLanguageCapabilities
Return type:

Qgis.ScriptLanguageCapabilities

leaveEvent(self, a0: QEvent | None)
lexerColor(self, role: QgsCodeEditorColorScheme.ColorRole) QColor

Returns the color to use in the lexer for the specified role.

Added in version 3.16.

lexerFont(self) QFont

Returns the font to use in the lexer.

Added in version 3.16.

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

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

Loads a script file.

Parameters:

script (Optional[str])

Return type:

bool

metric(self, a0: QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, e: QMouseEvent | None)
mouseMoveEvent(self, e: QMouseEvent | None)
mousePressEvent(self, e: QMouseEvent | None)
mouseReleaseEvent(self, e: QMouseEvent | None)
moveEvent(self, a0: QMoveEvent | None)
nativeEvent(self, eventType: QByteArray | bytes | bytearray, message: PyQt5.sip.voidptr | None)
paintEvent(self, e: QPaintEvent | None)
populateContextMenu(self, menu: QMenu | None)
Parameters:

menu (Optional[QMenu])

receivers(self, signal: PYQT_SIGNAL) int
reformatCodeString(self, string: str | None) str
Parameters:

string (Optional[str])

Return type:

str

resizeEvent(self, e: QResizeEvent | None)
runPostLexerConfigurationTasks(self)

Performs tasks which must be run after a lexer has been set for the widget.

Added in version 3.16.

scrollContentsBy(self, dx: int, dy: int)
searchSelectedTextInPyQGISDocs(self)

Searches the selected text in the official PyQGIS online documentation.

Added in version 3.16.

sender(self) QObject | None
senderSignalIndex(self) int
setViewportMargins(self, left: int, top: int, right: int, bottom: int)
setViewportMargins(self, margins: QMargins) None
sharedPainter(self) QPainter | None
showEvent(self, a0: QShowEvent | None)
showMessage(self, title: str | None, message: str | None, level: Qgis.MessageLevel)

Shows a user facing message (eg a warning message).

The default implementation uses QMessageBox.

Added in version 3.32.

tabletEvent(self, a0: QTabletEvent | None)
timerEvent(self, a0: QTimerEvent | None)
toMimeData(self, text: QByteArray | bytes | bytearray, rectangular: bool) QMimeData | None
toggleComment(self)

Toggle comment for the selected text.

Added in version 3.30.

updateCapabilities(self)

Updates the editor capabilities.

Added in version 3.32.

updateMicroFocus(self)
updatePrompt(self)

Triggers an update of the interactive prompt part of the editor.

Note

Applies to code editors in the QgsCodeEditor.Mode.CommandInput mode only.

Added in version 3.30.

updateSoftHistory(self)

Updates the soft history by storing the current editor text in the history.

Added in version 3.30.

viewportEvent(self, a0: QEvent | None) bool
viewportMargins(self) QMargins
viewportSizeHint(self) QSize
wheelEvent(self, event: QWheelEvent | None)