toga-code-editor 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: toga-code-editor
3
+ Version: 0.1.1
4
+ Summary: A Toga widget for editing code, with line numbers and syntax highlighting.
5
+ Author-email: Kattni <hello@kattni.com>
6
+ Maintainer-email: BeeWare Team <team@beeware.org>
7
+ License-Expression: BSD-3-Clause
8
+ Keywords: gui,widget,toga,code,editor,syntax-highlighting
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: User Interfaces
19
+ Classifier: Topic :: Software Development :: Widget Sets
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: toga-core>=0.5.7
24
+ Requires-Dist: pygments>=2.19
25
+ Dynamic: license-file
26
+
27
+ # toga-code-editor
28
+
29
+ A [Toga](https://toga.beeware.org) widget for editing code, with line numbers and syntax highlighting. `CodeEditor` is a `toga.MultilineTextInput` that colors its text with [Pygments](https://pygments.org) and shows a line-number gutter. It supports macOS, iOS, and Android.
30
+
31
+ ## Installation
32
+
33
+ ```console
34
+ pip install toga-code-editor
35
+ ```
36
+
37
+ 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.
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import toga
43
+ from toga_code_editor import CodeEditor, language_for_filename
44
+
45
+ editor = CodeEditor(
46
+ value=source,
47
+ language="python", # any Pygments lexer alias; None turns highlighting off
48
+ show_line_numbers=True,
49
+ on_change=handle_edit,
50
+ flex=1,
51
+ )
52
+
53
+ # Pick the language from a file name. Unknown files get None, which means no highlighting.
54
+ editor.language = language_for_filename(path)
55
+ ```
56
+
57
+ `CodeEditor` inherits everything from `toga.MultilineTextInput`, including `value`, `readonly`, `placeholder`, `on_change`, `scroll_to_top`, and `scroll_to_bottom`. It adds three properties:
58
+
59
+ - `language`: a Pygments lexer alias such as `"python"`, `"rust"`, or `"json"`. Setting an unknown alias raises `ValueError`. `None` disables highlighting. The default is `None`.
60
+ - `show_line_numbers`: shows or hides the gutter. Default `True`.
61
+ - `theme`: a mapping from `TokenKind` to `Style`. `None` selects the built-in `DEFAULT_THEME`.
62
+
63
+ 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.
64
+
65
+ ### Themes
66
+
67
+ A theme is a plain mapping. Kinds you leave out are drawn in the widget's normal text color.
68
+
69
+ ```python
70
+ from toga_code_editor import DEFAULT_THEME, Style, TokenKind
71
+
72
+ theme = {
73
+ **DEFAULT_THEME,
74
+ TokenKind.COMMENT: Style("#6a737d", italic=True),
75
+ TokenKind.KEYWORD: Style("rebeccapurple", bold=True),
76
+ }
77
+ editor.theme = theme
78
+ ```
79
+
80
+ `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`.
81
+
82
+ ## Platform notes
83
+
84
+ - **macOS** uses an `NSRulerView` for the gutter and the system's adaptive color mapping, so theme colors follow dark mode.
85
+ - **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.
86
+ - 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.
87
+ - Some third-party Android keyboards ignore the flag that disables suggestions.
88
+ - 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.
89
+
90
+ ## Developing
91
+
92
+ ```console
93
+ uv venv
94
+ uv pip install -e . --group dev
95
+ .venv/bin/tox -m test
96
+ ```
97
+
98
+ The test suite runs against Toga's dummy backend. Real backends are checked with the example app in `examples/editor`:
99
+
100
+ ```console
101
+ cd examples/editor
102
+ briefcase dev # macOS
103
+ briefcase run iOS
104
+ briefcase run android
105
+ ```
106
+
107
+ 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:
108
+
109
+ ```console
110
+ uv build --wheel
111
+ cd examples/editor
112
+ briefcase run android -r
113
+ ```
114
+
115
+ 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`.
116
+
117
+ ## Community
118
+
119
+ `toga-code-editor` is part of the [BeeWare suite](http://beeware.org). You can talk to the community through:
120
+
121
+ - [@beeware@fosstodon.org on Mastodon](https://fosstodon.org/@beeware)
122
+ - [Discord](https://beeware.org/bee/chat/)
123
+
124
+ We foster a welcoming and respectful community as described in our [BeeWare Community Code of Conduct](http://beeware.org/community/behavior/).
125
+
126
+ ## Contributing
127
+
128
+ If you experience problems with the `CodeEditor` widget, [log them on GitHub](https://github.com/beeware/toga-code-editor/issues). If you want to contribute code, please [fork the code](https://github.com/beeware/toga-code-editor) and [submit a pull request](https://github.com/beeware/toga-code-editor/pulls).
@@ -0,0 +1,14 @@
1
+ toga_code_editor/__init__.py,sha256=4O8bQ_gVrrVYHyI3QZZQwtpxOVc1qkF_6yJebnH-KbY,350
2
+ toga_code_editor/code_editor.py,sha256=KGdpFRqn6zukBh3_2NRdLdRiTt7pbp1NSpN4FNI1Of8,6133
3
+ toga_code_editor/highlighting.py,sha256=C0C9Eyy6Bu5ZXU4IW3zNZk0Gbi0i-4vWFMFyoXIWiuI,6106
4
+ toga_code_editor/platforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ toga_code_editor/platforms/android.py,sha256=aWx63Lj4HlGNLqDbI3fo2tVzUwelxTmRYyGj9b_9XIk,8676
6
+ toga_code_editor/platforms/cocoa.py,sha256=FtQotsX0XZM7YDx1jupg5KKfrd-XjhWwkWKABacq4e0,9866
7
+ toga_code_editor/platforms/dummy.py,sha256=1vtlDM1HO4a1Jm2WyOCzP1YfypSBZ-SYpCoD48hxKK4,648
8
+ toga_code_editor/platforms/iOS.py,sha256=s5Pb4CReK-bdabg4Q2oOUZ5Ie6th_osIkGUuBzGiYK4,11792
9
+ toga_code_editor-0.1.1.dist-info/licenses/LICENSE,sha256=LZFBFf-4Wc8AA73Jms6mPJOZxzRk6_bA-u92jQ-CDME,1501
10
+ toga_code_editor-0.1.1.dist-info/METADATA,sha256=PJPlhLy1s3MHZ0-0nH9g4Ty5EbN32Fj2l7uw-yIJLV4,5867
11
+ toga_code_editor-0.1.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
12
+ toga_code_editor-0.1.1.dist-info/entry_points.txt,sha256=L-uapfZ1foowkY7_r3BuWOisd96g7Om3PD58TPsHnYg,383
13
+ toga_code_editor-0.1.1.dist-info/top_level.txt,sha256=NaP31teLbDeXb1cu667SvBDKw890Iyeu2uY4hWuoDoE,17
14
+ toga_code_editor-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,11 @@
1
+ [toga_code_editor.backend.toga_android]
2
+ CodeEditor = toga_code_editor.platforms.android:CodeEditor
3
+
4
+ [toga_code_editor.backend.toga_cocoa]
5
+ CodeEditor = toga_code_editor.platforms.cocoa:CodeEditor
6
+
7
+ [toga_code_editor.backend.toga_dummy]
8
+ CodeEditor = toga_code_editor.platforms.dummy:CodeEditor
9
+
10
+ [toga_code_editor.backend.toga_iOS]
11
+ CodeEditor = toga_code_editor.platforms.iOS:CodeEditor
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2026, Russell Keith-Magee
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of toga-code-editor nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ toga_code_editor