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

Parameters:
actionEvent(self, QActionEvent)
autoComplete(self)

Triggers the autocompletion popup.

Added in version 3.16.

canInsertFromMimeData(self, QMimeData) bool
changeEvent(self, QEvent)
characterAfterCursor(self) str

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

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, QChildEvent)
closeEvent(self, QCloseEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, event: QContextMenuEvent)
create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
drawFrame(self, QPainter)
dropEvent(self, QDropEvent)
enterEvent(self, QEvent)
event(self, QEvent) bool
eventFilter(self, watched: QObject, event: QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, event: QFocusEvent)
focusPreviousChild(self) bool
fromMimeData(self, QMimeData) Tuple[QByteArray, bool]
hideEvent(self, QHideEvent)
initPainter(self, QPainter)
initStyleOption(self, QStyleOptionFrame)
initializeLexer(self)
inputMethodEvent(self, QInputMethodEvent)
inputMethodQuery(self, 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, QMetaMethod) bool
keyPressEvent(self, event: QKeyEvent)
Parameters:

event (QKeyEvent)

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

Qgis.ScriptLanguage

languageCapabilities(self) Qgis.ScriptLanguageCapabilities
Return type:

Qgis.ScriptLanguageCapabilities

leaveEvent(self, QEvent)
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])

Load APIs from one or more files

Parameters:

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

loadScript(self, script: str) bool

Loads a script file.

Parameters:

script (str)

Return type:

bool

metric(self, QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
populateContextMenu(self, menu: QMenu)
Parameters:

menu (QMenu)

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

string (str)

Return type:

str

resizeEvent(self, QResizeEvent)
runPostLexerConfigurationTasks(self)

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

Added in version 3.16.

scrollContentsBy(self, int, int)
searchSelectedTextInPyQGISDocs(self)

Searches the selected text in the official PyQGIS online documentation.

Added in version 3.16.

sender(self) QObject
senderSignalIndex(self) int
setViewportMargins(self, int, int, int, int)
setViewportMargins(self, QMargins) None
sharedPainter(self) QPainter
showEvent(self, QShowEvent)
showMessage(self, title: str, message: str, level: Qgis.MessageLevel)

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

The default implementation uses QMessageBox.

Added in version 3.32.

tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
toMimeData(self, Union[QByteArray, bytes, bytearray], bool) QMimeData
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, QEvent) bool
viewportMargins(self) QMargins
viewportSizeHint(self) QSize
wheelEvent(self, QWheelEvent)