Skip to content

Commit 7a96169

Browse files
committed
Update terminal docs, add Python editor plugin docs.
1 parent 87e39f8 commit 7a96169

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

docs/assets/images/pyeditor1.gif

256 KB
Loading

docs/assets/images/pyterm2.gif

-46.1 KB
Loading

docs/assets/images/pyterm3.gif

58.5 KB
Loading

docs/user-guide/editor.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Python editor
2+
3+
The PyEditor is a core plugin.
4+
5+
!!! warning
6+
7+
Work on the Python editor is in its early stages. We have made it available
8+
in this version of PyScript to give the community an opportunity to play,
9+
experiment and provide feedback.
10+
11+
Future versions of PyScript will include a more refined, robust and perhaps
12+
differently behaving version of the Python editor.
13+
14+
If you specify the type of a `<script>` tag as either `py-editor` (for Pyodide)
15+
or `mpy-editor` (for MicroPython), the plugin creates a visual code editor,
16+
with code highlighting and a "run" button to execute the editable code
17+
contained therein in a non-blocking worker.
18+
19+
The interpreter is not loaded onto the page until the run button is clicked. By
20+
default each editor has its own independent instance of the specified
21+
interpreter:
22+
23+
```html title="Two editors, one with Pyodide, the other with MicroPython."
24+
<script type="py-editor">
25+
import sys
26+
print(sys.version)
27+
</script>
28+
<script type="mpy-editor">
29+
import sys
30+
print(sys.version)
31+
a = 42
32+
print(a)
33+
</script>
34+
```
35+
36+
However, different editors can share the same interpreter if they share the
37+
same `env` attribute value.
38+
39+
```html title="Two editors sharing the same MicroPython environment."
40+
<script type="mpy-editor" env="shared">
41+
if not 'a' in globals():
42+
a = 1
43+
else:
44+
a += 1
45+
print(a)
46+
</script>
47+
<script type="mpy-editor" env="shared">
48+
# doubled a
49+
print(a * 2)
50+
</script>
51+
```
52+
53+
The outcome of these code fragments should look something like this:
54+
55+
<img src="../../assets/images/pyeditor1.gif" style="border: 1px solid black; border-radius: 0.2rem; box-shadow: var(--md-shadow-z1);"/>
56+
57+
!!! info
58+
59+
Notice that the interpreter type, and optional environment name is shown
60+
at the top right above the Python editor.
61+
62+
Hovering over the Python editor reveals the "run" button.
63+
64+
Finally, it is possible to specify a target node into which the code editor is
65+
created:
66+
67+
```html title="Specify a target for the Python editor."
68+
<script type="mpy-editor" target="editor">
69+
import sys
70+
print(sys.version)
71+
</script>
72+
<div id="editor"></div> <!-- will eventually contain the Python editor -->
73+
```

docs/user-guide/terminal.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ name = input("What is your name? ")
4545
print(f"Hello, {name}")
4646
</script>
4747
```
48+
<img src="../../assets/images/pyterm2.gif" style="border: 1px solid black; border-radius: 0.2rem; box-shadow: var(--md-shadow-z1);"/>
4849

49-
Once the Python code has finished you are automatically dropped into the
50-
Python REPL, like this:
50+
To use the interactive Python REPL in the terminal, use Python's
51+
[code](https://docs.python.org/3/library/code.html) module like this:
5152

52-
<img src="../../assets/images/pyterm2.gif" style="border: 1px solid black; border-radius: 0.2rem; box-shadow: var(--md-shadow-z1);"/>
53+
```python
54+
import code
55+
56+
code.interact()
57+
```
5358

59+
The end result should look something like this:
5460

61+
<img src="../../assets/images/pyterm3.gif" style="border: 1px solid black; border-radius: 0.2rem; box-shadow: var(--md-shadow-z1);"/>

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ nav:
7575
- Workers: user-guide/workers.md
7676
- Builtin helpers: user-guide/builtins.md
7777
- Python terminal: user-guide/terminal.md
78+
- Python editor: user-guide/editor.md
7879
- Plugins: user-guide/plugins.md
7980
- Example apps: user-guide/examples.md

0 commit comments

Comments
 (0)