Skip to content

Commit b8d1f47

Browse files
authored
Merge pull request #15 from wade-cheng/patch-1
thanks for contribution !
2 parents 35871d2 + 3126b33 commit b8d1f47

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

wiki/pygbag-code/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ print( json.dumps(repo["packages"], sort_keys=True, indent=4) )
8888
implemented, event based, TODO sample
8989

9090
### downloading files created by python
91-
92-
( you can use cd/ls/pwd to navigate filesystem)
93-
type in the repl:
94-
```
95-
rx /path/of/file_to_download/name_of_file
91+
Python files can still be created normally and will appear in the browser's filesystem. They can then be downloaded from the browser's filesystem to a user's filesystem with `platform.window.MM.download(filepath)`.
92+
```py
93+
import sys, platform
94+
with open("file.txt", "w") as f:
95+
f.write("newly created example file")
96+
if sys.platform == "emscripten":
97+
platform.window.MM.download("file.txt")
9698
```
99+
`platform.window.MM.download("file.txt")` is code taken from the debug REPL's shell implementation. Read about the debug REPL [here](https://pygame-web.github.io/wiki/pygbag-debug/).
97100

98101
### editing local files
99102

wiki/pygbag-debug/README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1-
For using repl and debugging pygbag games
2-
just use http://localhost:8000/#debug instead of just http://localhost:8000
1+
pygbag comes with an interactive Python-like REPL that can be used for debugging.
2+
3+
## to open
4+
To open the REPL, visit `http://localhost:8000/#debug` instead of just `http://localhost:8000`.
5+
6+
To get debugger at runtime, open the [javascript console](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/What_are_browser_developer_tools#the_javascript_console) and run `debug()` by typing in `debug()` followed by pressing enter.
7+
8+
## to use
9+
The REPL is a Python REPL that has loaded the project. This means if your pygbag main file includes a `main() function`, calling `type(main)` will return `<class 'function'>` instead of a `NameError`.
10+
11+
It also implements a variety of shell-like commands, defined in the [shell](https://github.com/pygame-web/pygbag/blob/72b34546e23086c78f5b193c05e3e961b807f214/src/pygbag/support/cpythonrc.py#L266) class, that are reminiscent of shell languages common on Linux systems. These can be used in the REPL.
12+
For example,
13+
```bash
14+
>>> cat main.py
15+
```
16+
will dump the binary contents of `main.py` into the REPL, if `main.py` exists in your pygbag project directory.
17+
18+
Other helpful commands are available. For example,`rx` takes a list of files and downloads them from the browser's filesystem to a user's filesystem. For example,
19+
```bash
20+
>>> rx main.py assets/image.png assets/otherimage.png
21+
```
22+
will try to download the given three files.
23+
24+
## Python versus browser logging
25+
`print` statements will write to this REPL instead of the browser's console.
26+
27+
To write to the browser's console instead, use `platform.console.log`. For example,
28+
```py
29+
import sys, platform
30+
if sys.platform == "emscripten":
31+
platform.console.log("logged message")
32+
```
33+
34+
35+
336

4-
to get debugger at runtime use ctrl+shift+i to pop up javascript console from pygbag page tab and type : debug()
5-
followed by enter.
637

738

839
[edit this page](https://github.com/pygame-web/pygame-web.github.io/edit/main/wiki/pygbag-debug/README.md)

0 commit comments

Comments
 (0)