8000 Merge pull request #7 from anaconda/pys-6/remove-old-code · rmyers/pyscript@6f2f6ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f2f6ac

Browse files
authored
Merge pull request pyscript#7 from anaconda/pys-6/remove-old-code
[PYS-6] remove old code
2 parents b245e5a + bef7d43 commit 6f2f6ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+230
-476
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
.DS_Store
56

67
# C extensions
78
*.so
@@ -117,6 +118,9 @@ venv.bak/
117118
# Rope project settings
118119
.ropeproject
119120

121+
# VS Code Files
122+
.vscode/
123+
120124
# mkdocs documentation
121125
/site
122126

pyscriptjs/public/bokeh.html renamed to pyscriptjs/examples/bokeh.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<script type="text/javascript">
1111
Bokeh.set_log_level("info");
1212
</script>
13-
<link rel="stylesheet" href="build/pyscript.css" />
13+
<link rel="stylesheet" href="../build/pyscript.css" />
1414

15-
<script defer src="build/pyscript.js"></script>
15+
<script defer src="../build/pyscript.js"></script>
1616

1717
</head>
1818
<body>
@@ -22,7 +22,6 @@
2222
</py-env>
2323
<h1>Bokeh Example</h1>
2424
<div id="myplot"></div>
25-
<py-repl id="my-repl"></py-repl>
2625

2726
<py-script>
2827
import json

pyscriptjs/public/bokeh_interactive.html renamed to pyscriptjs/examples/bokeh_interactive.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<script type="text/javascript">
1111
Bokeh.set_log_level("info");
1212
</script>
13-
<link rel="stylesheet" href="build/pyscript.css" />
13+
<link rel="stylesheet" href="../build/pyscript.css" />
1414

15-
<script defer src="build/pyscript.js"></script>
15+
<script defer src="../build/pyscript.js"></script>
1616

1717
</head>
1818
<body>

pyscriptjs/examples/favicon.png

4.19 KB
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
7+
<title>Svelte app</title>
8+
9+
<link rel="icon" type="image/png" href="favicon.png" />
10+
<link rel="stylesheet" href="../../build/pyscript.css" />
11+
12+
<script defer src="../../build/pyscript.js"></script>
13+
</head>
14+
15+
<body>
16+
<py-script>
17+
from js import handTrack, setTimeout, requestAnimationFrame
18+
from pyodide import create_once_callable
19+
import asyncio
20+
21+
context = canvas.element.getContext("2d")
22+
23+
isVideo = False
24+
model = None
25+
26+
modelParams = {
27+
"flipHorizontal": True, # flip e.g for video
28+
"maxNumBoxes": 20, # maximum number of boxes to detect
29+
"iouThreshold": 0.5, # ioU threshold for non-max suppression
30+
"scoreThreshold": 0.6, # confidence threshold for predictions.
31+
}
32+
33+
def toggle_video(evt):
34+
global isVideo
35+
if (not isVideo):
36+
update_note.write("Starting video")
37+
pyscript.run_until_complete(start_video())
38+
else:
39+
update_note.write("Stopping video")
40+
handTrack.stopVideo(video.element)
41+
isVideo = False
42+
update_note.write("Video stopped")
43+
44+
async def start_video():
45+
global isVideo
46+
update_note.write("Inside sstart video")
47+
status = await handTrack.startVideo(video.element)
48+
console.log("video started", status)
49+
if status:
50+
update_note.write("Video started. Now tracking")
51+
isVideo = True
52+
console.log( "Calling RUN DETECTION")
53+
y = await run_detection()
54+
else:
55+
update_note.write( "Please enable video")
56+
57+
def sync_run_detection(evt):
58+
pyscript.run_until_complete(run_detection())
59+
60+
async def run_detection():
61+
console.log("in RUN DETECTION: ");
62+
global model
63+
global isVideo
64+
65+
console.log("...1")
66+
67+
predictions = await model.detect(video.element)
68+
console.log("done...1")
69+
console.log("Predictions: ", predictions);
70+
model.renderPredictions(predictions, canvas.element, context, video.element);
71+
console.log("is Video?", isVideo)
72+
if (isVideo):
73+
console.log("requestingAnimation!")
74+
await requestAnimationFrame(create_once_callable(sync_run_detection));
75+
console.log("...2")
76+
77+
def run_detection_image(img):
78+
console.log("in RUN DETECTION IMAGE", predictions);
79+
global model
80+
def detect(predition):
81+
console.log("Predictions: ", predictions);
82+
model.renderPredictions(predictions, canvas, context, img);
83+
console.log("...3")
84+
model.detect(img).then(detect)
85+
console.log("...4")
86+
87+
def handle_model(lmodel):
88+
global model
89+
model = lmodel
90+
update_note.write("Loaded Model!")
91+
92+
async def start():
93+
console.log("creating x")
94+
console.log("calling x")
95+
model = await handTrack.load(modelParams)#.then(handle_model)
96+
console.log("loaded model!")
97+
console.log(model)
98+
handle_model(model)
99+
print(dir(x))
100+
print(x)
101+
102+
pyscript.run_until_complete(start())
103+
104+
#});
105+
106+
</py-script>
107+
108+
<div class="mb10">
109+
<button id="trackbutton" class="bx--btn bx--btn--secondary" type="button" pys-onClick="toggle_video">
110+
Toggle Video
111+
</button>
112+
<button id="nextimagebutton" class="mt10 bx--btn bx--btn--secondary" type="button" disabled>
113+
Next Image
114+
</button>
115+
<div id="update-note" py-mount class="updatenote mt10">loading model ..</div>
116+
</div>
117+
<div>
118+
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
119+
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
120+
</div>
121+
<script src="lib/handtrack.min.js"> </script>
122+
</html>
File renamed without changes.

pyscriptjs/public/mario/play_mario.html renamed to pyscriptjs/examples/mario/play_mario.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<title>Svelte app</title>
88

99
<link rel="icon" type="image/png" href="../favicon.png" />
10-
<link rel="stylesheet" href="../build/pyscript.css" />
10+
<link rel="stylesheet" href="../../build/pyscript.css" />
1111

12-
<script defer src="../build/pyscript.js"></script>
12+
<script defer src="../../build/pyscript.js"></script>
1313
</head>
1414

1515
<body>
@@ -140,5 +140,5 @@
140140
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
141141
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
142142
</div>
143-
<script src="../lib/handtrack.min.js"> </script>
143+
<script src="../handtrack/lib/handtrack.min.js"> </script>
144144
</html>

pyscriptjs/public/panel.html renamed to pyscriptjs/examples/panel.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>
99
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js"></script>
1010
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@holoviz/panel@0.13.0-rc.5/dist/panel.min.js"></script>
11-
<link rel="stylesheet" href="build/pyscript.css" />
12-
<script defer src="build/pyscript.js"></script>
11+
<link rel="stylesheet" href="../build/pyscript.css" />
12+
<script defer src="../build/pyscript.js"></script>
1313
</head>
1414
<body>
1515
<py-env>

pyscriptjs/public/panel_kmeans.html renamed to pyscriptjs/examples/panel_kmeans.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
3939
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
4040

41-
<link rel="stylesheet" href="build/pyscript.css" />
42-
<script defer src="build/pyscript.js"></script>
41+
<link rel="stylesheet" href="../build/pyscript.css" />
42+
<script defer src="../build/pyscript.js"></script>
4343
</head>
4444
<body>
4545
<py-env>

pyscriptjs/public/repl.html renamed to pyscriptjs/examples/repl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<title>Svelte app</title>
88

99
<link rel="icon" type="image/png" href="favicon.png" />
10-
<link rel="stylesheet" href="build/bundle.css" />
10+
<link rel="stylesheet" href="../build/bundle.css" />
1111

12-
<script defer src="build/pyscript.js"></script>
12+
<script defer src="../build/pyscript.js"></script>
1313
</head>
1414

1515
<body>

pyscriptjs/public/repl2.html renamed to pyscriptjs/examples/repl2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<title>Svelte app</title>
88

99
<link rel="icon" type="image/png" href="favicon.png" />
10-
<link rel="stylesheet" href="build/bundle.css" />
10+
<link rel="stylesheet" href="../build/bundle.css" />
1111

12-
<script defer src="build/pyscript.js"></script>
12+
<script defer src="../build/pyscript.js"></script>
1313
</head>
1414

1515
<body>

pyscriptjs/public/simple_script.html renamed to pyscriptjs/examples/simple_script.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<title>Svelte app</title>
88

99
<link rel="icon" type="image/png" href="favicon.png" />
10-
<link rel="stylesheet" href="build/bundle.css" />
10+
<link rel="stylesheet" href="../build/pyscript.css" />
1111

12-
<script defer src="build/pyscript.js"></script>
12+
<script defer src="../build/pyscript.js"></script>
1313
</head>
1414

1515
<body>

pyscriptjs/public/simple_script2.html renamed to pyscriptjs/examples/simple_script2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<title>Svelte app</title>
88

99
<link rel="icon" type="image/png" href="favicon.png" />
10-
<link rel="stylesheet" href="build/bundle.css" />
10+
<link rel="stylesheet" href="../build/bundle.css" />
1111

12-
<script defer src="build/pyscript.js"></script>
12+
<script defer src="../build/pyscript.js"></script>
1313
</head>
1414

1515
<body>

pyscriptjs/examples/todo.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
7+
<title>Todo App</title>
8+
9+
<link rel="icon" type="image/png" href="favicon.png" />
10+
<link rel="stylesheet" href="../build/bundle.css" />
11+
12+
<script defer src="../build/pyscript.js"></script>
13+
</head>
14+
15+
<py-script>
16+
from datetime import datetime as dt
17+
18+
tasks = []
19+
20+
# define the task template that will be use to render new templates to the page
21+
task_template = Element("task-template").select('.task', from_content=True)
22+
task_list = Element("list-tasks-container")
23+
new_task_content = Element("new-task-content")
24+
25+
def add_task(*ags, **kws):
26+
# create task
27+
task_id = f"task-{len(tasks)}"
28+
task = {"id": task_id, "content": new_task_content.element.value, "done": False, "created_at": dt.now()}
29+
tasks.append(task)
30+
31+
# add the task element to the page as new node in the list by cloning from a template
32+
taskHtml = task_template.clone(task_id, to=task_list)
33+
taskHtmlContent = taskHtml.select('p')
34+
taskHtmlContent.element.innerText = task['content']
35+
taskHtmlCheck = taskHtml.select('input')
36+
task_list.element.appendChild(taskHtml.element)
37+
38+
def check_task(evt=None):
39+
task['done'] = not task['done']
40+
if task['done']:
41+
taskHtmlContent.element.classList.add("line-through")
42+
else:
43+
taskHtmlContent.element.classList.remove("line-through")
44+
45+
new_task_content.clear()
46+
taskHtmlCheck.element.onclick = check_task
47+
48+
def add_task_event(e):
49+
console.log("im in")
50+
if (e.key == "Enter"):
51+
add_task()
52+
53+
</py-script>
54+
55+
<main class="max-w-xs mx-auto mt-4">
56+
<section>
57+
58+
<div class="text-center w-full mb-8">
59+
<h1 class="text-3xl font-bold text-gray-800 uppercase tracking-tight">To Do List</h1>
60+
</div>
61+
62+
<div>
63+
<input id="new-task-content" class="border flex-1 mr-3 border-gray-300 p-2 rounded" type="text">
64+
<button id="new-task-btn" class="p-2 text-white bg-blue-600 border border-blue-600 rounded" type="submit" pys-onClick="add_task">
65+
Add task
66+
</button>
67+
</div>
68+
69+
<div id="list-tasks-container" class="flex flex-col-reverse mt-4">
70+
</div>
71+
72+
<template id="task-template">
73+
<section class="task bg-white my-1">
74+
<label for="flex items-center p-2 ">
75+
<input class="mr-2" type="checkbox" class="task-check">
76+
<p class="m-0 inline"></p>
77+
</label>
78+
</section>
79+
</template>
80+
81+
</section>
82+
</main>
83+
</html>

pyscriptjs/public/favicon.png

-3.05 KB
Binary file not shown.

pyscriptjs/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
sourcemap: true,
4141
format: "iife",
4242
name: "app",
43-
file: "public/build/pyscript.js",
43+
file: "build/pyscript.js",
4444
},
4545
plugins: [
4646
svelte({

0 commit comments

Comments
 (0)
0