Skip to main content

QPPTE - QPythonPlainTextEdit

A poor-main embeddable code editor for python. Written in Python with PySide6 it is created with intent to be used within larger application where code editor is required. For example if you application supports plugins in Python and you want to give users ability to create and edit such plugins, then you can make this library a dependency in your project and embed this editor.

More information can be found here.

A poor-main text editor for editing and viewing Python code to be used with PySide6 library. It supports basic syntax highlighting using tree-sitter and keystrokes common to code editors. Highlighting styles can be customized and expanded. Likewise, keystrokes can be customized by the user.

When syntax highlighting is enabled we synchronously reparse the whole source code tree and re-highlight entire text. This is suboptimal and could result in slowing down of the text update but is adequate for relatively small files.

Adding qptte to your code

uv add git+https://github.com/priimak/qppte.git@v0.5.0

Running demo GUI

uv tool run --from git+https://github.com/priimak/qppte.git@v0.5.0 qppte_demo

Supported additional editor operations

  • Line or block indent
    • Press Tab to indent a line or a selected block by a Tab width number of spaces. Tab is always converted into space (default 4).
  • Undo and Redo
    • Ctrl-Z and Ctrl-R for undo and redo respectively.
  • Unindent line or block
    • Press Shift-Tab to unindent a line or a selected block by a Tab width number of spaces.
  • Delete line or block.
    • Ctrl-Y will delete a line or all lines in a selected block.
  • Duplicate line
    • Ctrl-D will duplicate current line and move cursor down.
  • Move line up and down
    • Ctrl-Shift-ArrowUp and Ctrl-Shift-ArrowDown will move current line up and down respectively.
  • Toggle commenting line or block.
    • Ctrl-/ will toggle commenting out a line or all lines included in the selected block.
  • Increment/decrement font size
    • Ctrl-+ will increase font size. Ctrl+_ decrease.

Using QPythonPlainTextEdit in your code.

from qppte import QPythonPlainTextEdit
from PySide6.QtWidgets import QMainWindow, QVBoxLayout, QWidget


class TextEditorWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        root_panel = QWidget()

        layout = QVBoxLayout()
        root_panel.setLayout(layout)

        code_editor = QPythonPlainTextEdit()
        layout.addWidget(code_editor)

        self.setCentralWidget(root_panel)

        ...

Methods specific to QPythonPlainTextEdit

  • getTabWidth() -> int - returns number of spaces to be used when Tab is pressed on the keyboard
  • setTabWidth(tabWidthSpaces: int) - sets number of spaces to be used when Tab is pressed on the keyboard. Will not affect already entered text/code in the editor.
  • getHighlightStyle() -> str - returns current name of highlight style.
  • setHighlightStyle(highlightStyle: str) - sets highlight style to a new one.
  • listAvailableHighlightStyles() -> list[str] - returns list of available highlight styles.
  • setEnableSyntaxHighlighting(enableSyntaxHighlighting: bool) - enables or disables syntax highlighting.
  • recordStateForUndoOperation() - method to be used when extending QPythonPlainTextEdit

Adding and modifying new custom highlight styles.

TBD

Changing keyboard shortcuts

TBD

Metadata

Release files for qppte 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qppte 0.7.0
File Size Uploaded
qppte-0.7.0.tar.gz 20.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qppte 0.7.0
File Interpreter ABI Platform
qppte-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.1 kB

Release files / qppte-0.7.0.tar.gz

Download URL qppte-0.7.0.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6889ff31e5b140e33d0e530c4eedb7fee8fb77a197ea174853b5f3e90f3aab93
BLAKE2b-256 checksum
How to use checksums
124bfe46effc14d6d576e6d0e12c1a668315785d8191ae1f4a74912039476580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / qppte-0.7.0-py3-none-any.whl

Download URL qppte-0.7.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f85acb04c889fcf7c88647cb08dc48d656faf72b934a4bbd8261ad03624cdb5
BLAKE2b-256 checksum
How to use checksums
bceaff520bacceffecf86d0334387cb90af5750051c4e2601ec7af8790339dd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release history Release notifications | RSS feed

0.7.2

2 release files

0.7.1

2 release files

This release

0.7.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page