PyScript master READ ONLY 0
  • explorer
  • search
a [App]
a CG.PyScript
a README.md
a app.ts
a [Test]
a test
  • README.md

PyScript

Integrate Py-Script into your CG project. Run py-script on web.

Getting Started

Run a py-script

CG.PyScript.runScriptFromSource('CG.PyScript/test.py');

Open a py-editor

CG.PyScript.addRepl('User Script Editor');

Customize the looks

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:

url = getAppSourceUrl('CG/PyScript/README.md')
print(url)

To hide or show python console

# hide
js.hidePythonConsole()
# show
js.showPythonConsole()

To open dialogs:

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:

# 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}])
READ ONLY
  • problem
  • console
No problems have been detected so far.
Ln 1, Col 1, Sel 0
Markdown