toga-code-editor
A Toga widget for editing code, with line numbers and syntax highlighting. CodeEditor is a toga.MultilineTextInput that colors its text with Pygments and shows a line-number gutter. It supports macOS, iOS, and Android.
Installation
pip install toga-code-editor
The package depends on toga-core and pygments. Your app installs the Toga backend for its platform as usual; toga-code-editor contributes its implementation for that backend through entry points, the same way Toga's own widgets are found.
Usage
import toga
from toga_code_editor import CodeEditor, language_for_filename
editor = CodeEditor(
value=source,
language="python", # any Pygments lexer alias; None turns highlighting off
show_line_numbers=True,
on_change=handle_edit,
flex=1,
)
# Pick the language from a file name. Unknown files get None, which means no highlighting.
editor.language = language_for_filename(path)
CodeEditor inherits everything from toga.MultilineTextInput, including value, readonly, placeholder, on_change, scroll_to_top, and scroll_to_bottom. It adds three properties:
language: a Pygments lexer alias such as"python","rust", or"json". Setting an unknown alias raisesValueError.Nonedisables highlighting. The default isNone.show_line_numbers: shows or hides the gutter. DefaultTrue.theme: a mapping fromTokenKindtoStyle.Noneselects the built-inDEFAULT_THEME.
Unless you give the widget a font family, it uses a monospace font. Autocorrect, smart quotes, smart dashes, auto-capitalization, and spell checking are always off.
Themes
A theme is a plain mapping. Kinds you leave out are drawn in the widget's normal text color.
from toga_code_editor import DEFAULT_THEME, Style, TokenKind
theme = {
**DEFAULT_THEME,
TokenKind.COMMENT: Style("#6a737d", italic=True),
TokenKind.KEYWORD: Style("rebeccapurple", bold=True),
}
editor.theme = theme
Style.color accepts anything Toga's color properties accept. The token kinds are KEYWORD, BUILTIN, DEFINITION, DECORATOR, STRING, NUMBER, COMMENT, OPERATOR, PUNCTUATION, TAG, ATTRIBUTE, and VARIABLE.
Platform notes
- macOS uses an
NSRulerViewfor the gutter and the system's adaptive color mapping, so theme colors follow dark mode. - iOS and Android draw the gutter themselves. Theme colors do not change with the system appearance; the default theme is chosen to be legible on both light and dark backgrounds.
- Highlighting re-lexes the whole buffer after a short pause in typing. Files of a few thousand lines are fine on a desktop; very large files are slower on phones.
- Some third-party Android keyboards ignore the flag that disables suggestions.
- On Android, the widget asks the window to shrink its content when the soft keyboard appears, so the editor scrolls internally and the rest of the layout stays put. It only does this when the app has not chosen a soft-input mode itself.
Developing
uv venv
uv pip install -e . --group dev
.venv/bin/tox -m test
The test suite runs against Toga's dummy backend. Real backends are checked with the example app in examples/editor:
cd examples/editor
briefcase dev # macOS
briefcase run iOS
briefcase run android
On macOS and iOS the example installs the widget straight from this repository; add -r after changing the widget source so Briefcase reinstalls it. On Android the example installs the widget from a wheel in dist/, because Gradle rejects a path requirement whose directory contains the Android build tree. Build the wheel before each Android run that should pick up widget changes:
uv build --wheel
cd examples/editor
briefcase run android -r
Every user-visible change needs a fragment in changes/, named <issue>.<kind>.md where kind is feature, bugfix, doc, or misc. Release notes are assembled with towncrier build.
Community
toga-code-editor is part of the BeeWare suite. You can talk to the community through:
We foster a welcoming and respectful community as described in our BeeWare Community Code of Conduct.
Contributing
If you experience problems with the CodeEditor widget, log them on GitHub. If you want to contribute code, please fork the code and submit a pull request.
Metadata
Release files for toga-code-editor 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toga_code_editor-0.1.1.tar.gz | 36.2 kB | With provenance | Details for toga_code_editor-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toga_code_editor-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for toga_code_editor-0.1.1-py3-none-any.whl |
Total release size: 56.5 kB
Release files / toga_code_editor-0.1.1.tar.gz
| Download URL | toga_code_editor-0.1.1.tar.gz |
|---|---|
| Size | 36.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38d85ff55ba32295c467185c6d1f5e6b1d4a9619050290660d27222d2ab1971c
|
|
BLAKE2b-256 checksum How to use checksums |
09452c6c35dd89fe11c35b94a30ed08b4a94081937983d7d9ee645bd7d349be7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logRelease files / toga_code_editor-0.1.1-py3-none-any.whl
| Download URL | toga_code_editor-0.1.1-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a20429052cb8f5ba72103e4c5f9742903349128350ceae1a05556f44a8b5ccee
|
|
BLAKE2b-256 checksum How to use checksums |
64a4feb7ab67713c18099840df61ec8a1b6290d7a1bd260bdb22c0a22ed7c96c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logSecurity for toga-code-editor 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for toga_code_editor-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.