Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
berinhard committed Mar 4, 2021
2 parents 10f2e20 + d80e94d commit ff2355e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.6, 3.7, 3.8]

steps:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## pyp5js: Python to P5.js Transcriptor
## pyp5js: drawing with Python 3

[![PyPI version](https://badge.fury.io/py/pyp5js.svg)](https://badge.fury.io/py/pyp5js)
![Continuous Integration](https://github.com/berinhard/pyp5js/workflows/Continuous%20Integration/badge.svg?branch=develop&event=push)
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/berinhard/pyp5js/tree/main)

> [Processing](https://processing.org) ideas and Python 3 together with [P5.js](https://p5js.org) in the browser.
Python 3 drawing in the web 🐍 🐍 🐍 Try it [here](https://berinhard.github.io/pyp5js/pyodide/)!
Python 3 drawing in the web! Try it [here](https://berinhard.github.io/pyp5js/pyodide/)!

Here's an example of a valid Python code using P5.js API:

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pyp5js: Python to P5.js Transcriptor
## pyp5js: drawing with Python 3

[![PyPI version](https://badge.fury.io/py/pyp5js.svg)](https://badge.fury.io/py/pyp5js)
![Continuous Integration](https://github.com/berinhard/pyp5js/workflows/Continuous%20Integration/badge.svg?branch=develop&event=push)
Expand Down
39 changes: 32 additions & 7 deletions docs/pyodide/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

<div id="text-editor"></div>
<div class="clearfix">
<input disabled id="executeBtn" class="btn rounded py1 px2 mb1" type="submit" value="Execute">
<input id="clearBtn" class="btn rounded py1 px2 mb1" type="submit" value="Clear">
<input disabled id="executeBtn" class="btn rounded py1 px2 mb1" type="submit" value="Run" title="(Ctrl/Cmd + Enter) to run the sketch">
<input id="clearBtn" class="btn rounded py1 px2 mb1" type="submit" value="Clear" title="(Ctrl/Cmd + .) to clear the sketch">
</div>
</div>

Expand Down Expand Up @@ -1256,15 +1256,28 @@
script.onload = logOnloaded
script.src = src
document.head.appendChild(script)
`
`;

let placeholder = `
def setup():
pass
def draw():
pass
`
`;

const initialSketch = `
def setup():
createCanvas(200, 200)
background(160)
def draw():
fill("blue")
background(200)
radius = sin(frameCount / 60) * 50 + 50
ellipse(100, 100, radius, radius)
`;

languagePluginLoader.then(() => {
pyodide.runPython(`
import io, code, sys
Expand Down Expand Up @@ -1297,6 +1310,8 @@
editor.session.setOptions({
tabSize: 4,
});
editor.setValue(initialSketch, -1);
document.getElementById("id_py_code").innerHTML = initialSketch;

editor.session.on('change', function(){
document.getElementById("id_py_code").innerHTML = editor.getSession().getValue();
Expand All @@ -1307,12 +1322,22 @@

$("body").bind("keydown",keyDown);

function cleanKeyCode(e) {
// Shortcuts work for Ctrl or Cmd
if (e.ctrlKey || e.metaKey) {
return e.keyCode;
}
}

function keyDown(e){
if((e.ctrlKey) && (e.keyCode == 13)){
runCode();
if (cleanKeyCode(e) === 13) { // Ctrl + Enter to run
e.preventDefault();
$("#executeBtn").click();
} else if(cleanKeyCode(e) === 190){ // Ctrl + . to clear
e.preventDefault();
$("#clearBtn").click();
}
}

</script>


Expand Down

0 comments on commit ff2355e

Please sign in to comment.