info_outline
# PyScript
Integrate Py-Script into your CG project. Run py-script on web.
- [PyScript home](https://pyscript.net/)
- [Document](https://docs.pyscript.net/latest/)
- [Github](https://github.com/pyscript/pyscript)
## Getting Started
Run a py-script
```typescript
CG.PyScript.runScriptFromSource('CG.PyScript/test.py');
```
Open a py-editor
```typescript
CG.PyScript.addRepl('User Script Editor');
```
Customize the looks
```typescript
CG.PyScript.setPyscriptStyles({
fontSize: '16px',
padding: '10px,
fontFamily: 'Courier',
})
```
## Build-in utils
Some CG related utils are embeded and ready to be used.
To get the URL of a source file:
```py
url = getAppSourceUrl('CG/PyScript/README.md')
print(url)
```
To hide or show python console
```py
# hide
js.hidePythonConsole()
# show
js.showPythonConsole()
```
To open dialogs:
```py
result = await js.dialog.prompt("What's your name?")
print("Your name is " + result)
result = await js.dialog.confirm("Are you a girl?")
print("You are a " + ("Girl" if result else "Boy"))
result = await js.dialog.select(["One", "Two"], "Choose one")
print("You got a " + (result if result else "What?"))
```
To draw shapes:
```py
# draw a line
js.draw.line(10, 400, 300, 100, color=0xFF0000, thickness=5)
# draw a rectangle
js.draw.rect(100, 300, 100, 50, fillColor=0xFFFF00)
# draw a circle
js.draw.circle(400, 300, 30, fillColor=0x00FF00, lineThickness=5, lineColor=0x00FFFF)
# draw a text
js.draw.text(500, 400, "Logo", fontSize=16, color=0xFF9900)
# draw lines
js.draw.lines([{"x":10,"y":10},{"x":200,"y":400},{"x":100,"y":500}], thickness=2)
# draw a polygon
js.draw.polygon([{"x":10,"y":10},{"x":200,"y":400},{"x":100,"y":500}])
```