8000 Merge pull request #59 from pyscript/fpliger/fix_lint · forrestzhang/pyscript@3b22aa8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b22aa8

Browse files
authored
Merge pull request pyscript#59 from pyscript/fpliger/fix_lint
remove old code and bypass some warning
2 parents e8d1067 + 4e66764 commit 3b22aa8

16 files changed

+40
-145
lines changed

pyscriptjs/examples/bokeh.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html><head>
22
<title>Bokeh Example</title>
33
<meta charset="iso-8859-1">
4+
<link rel="icon" type="image/x-icon" href="./favicon.png">
45
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js"></script>
56
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js"></script>
67
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
@@ -40,11 +41,7 @@ <h1>Bokeh Example</h1>
4041
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=15, line_color="navy", fill_color="orange", fill_alpha=0.5)
4142
p_json = json.dumps(json_item(p, "myplot"))
4243

43-
print("about to embed")
44-
4544
Bokeh.embed.embed_item(JSON.parse(p_json))
46-
47-
print ("Done embedding...")
4845
</py-script>
4946

5047
</body>

pyscriptjs/examples/bokeh_interactive.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html><head>
22
<title>Bokeh Example</title>
33
<meta charset="iso-8859-1">
4+
<link rel="icon" type="image/x-icon" href="./favicon.png">
45
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.js"></script>
56
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js"></script>
67
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>

pyscriptjs/examples/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ <h2 class="text-2xl font-bold text-blue-600"><a href="./panel.html" target=”_b
9090
WARNING: This examples takes a little longer to load. So be patient :)
9191
</p>
9292

93+
<h2 class="text-2xl font-bold text-blue-600"><a href="./panel_deckgl.html" target=”_blank”>NYC Taxi Data Panel DeckGL Demo</a></h2>
94+
<p>Interactive application exploring the NYC Taxi dataset using Panel and DeckGL
95+
96+
WARNING: This examples takes a little longer to load. So be patient :)
97+
</p>
98+
9399
<h2 class="text-2xl font-bold text-blue-600"><a href="./toga/freedom.html" target=”_blank”>Freedom Units!</a></h2>
94100
<p>A Toga application (a Fahrenheit to Celsius converter), rendered as a Single Page App</p>
95101

pyscriptjs/examples/panel.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<head>
33
<title>Panel Example</title>
44
<meta charset="iso-8859-1">
5+
<link rel="icon" type="image/x-icon" href="./favicon.png">
56
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.js"></script>
67
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
78
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>

pyscriptjs/examples/panel_deckgl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<link rel="icon" type="image/x-icon" href="./favicon.png">
56
<meta name="apple-mobile-web-app-capable" content="yes">
67
<meta name="apple-mobile-web-app-status-bar-style" content="default">
78
<meta name="theme-color" content="#0072b5">

pyscriptjs/examples/panel_kmeans.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<link rel="icon" type="image/x-icon" href="./favicon.png">
56
<meta name="apple-mobile-web-app-capable" content="yes">
67
<meta name="apple-mobile-web-app-status-bar-style" content="default">
78
<meta name="theme-color" content="#000000">

pyscriptjs/examples/panel_stream.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta charset="utf-8">
5+
<link rel="icon" type="image/x-icon" href="./favicon.png">
66
<meta name="apple-mobile-web-app-capable" content="yes">
77
<meta name="apple-mobile-web-app-status-bar-style" content="default">
88
<meta name="theme-color" content="#000000">

pyscriptjs/src/App.svelte

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,31 @@
22
import Tailwind from './Tailwind.svelte';
33
import { loadInterpreter } from './interpreter';
44
import {
5-
componentsNavOpen,
65
initializers,
76
loadedEnvironments,
87
mode,
9-
navBarOpen,
108
postInitializers,
119
pyodideLoaded,
1210
scriptsQueue,
1311
} from './stores';
1412
15-
let iconSize = 2;
1613
let pyodideReadyPromise;
1714
18-
function bumpSize(evt) {
19-
iconSize = 4;
20-
}
21-
22-
function downSize(evt) {
23-
iconSize = 2;
24-
}
25-
2615
const initializePyodide = async () => {
2716
pyodideReadyPromise = loadInterpreter();
17+
const pyodide = await pyodideReadyPromise;
2818
let newEnv = {
2919
id: 'a',
3020
promise: pyodideReadyPromise,
21+
runtime: pyodide,
3122
state: 'loading',
3223
};
33-
pyodideLoaded.set(pyodideReadyPromise);
24+
pyodideLoaded.set(pyodide);
25+
3426
loadedEnvironments.update((value: any): any => {
3527
value[newEnv['id']] = newEnv;
3628
});
3729
38-
let showNavBar = false;
39-
let main = document.querySelector('#main');
40-
navBarOpen.subscribe(value => {
41-
showNavBar = value;
42-
});
43-
4430
// now we call all initializers before we actually executed all page scripts
4531
for (let initializer of $initializers) {
4632
await initializer();
@@ -61,10 +47,6 @@
6147
}
6248
}, 3000);
6349
};
64-
65-
function toggleComponentsNavBar(evt) {
66-
componentsNavOpen.set(!$componentsNavOpen);
67-
}
6850
</script>
6951

7052
<svelte:head>

pyscriptjs/src/components/base.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { componentDetailsNavOpen, loadedEnvironments, mode, pyodideLoaded } from '../stores';
1+
import { loadedEnvironments, mode, pyodideLoaded } from '../stores';
22
import { guidGenerator, addClasses } from '../utils';
33
// Premise used to connect to the first available pyodide interpreter
44
let pyodideReadyPromise;
@@ -13,10 +13,6 @@ loadedEnvironments.subscribe(value => {
1313
environments = value;
1414
});
1515

16-
let propertiesNavOpen;
17-
componentDetailsNavOpen.subscribe(value => {
18-
propertiesNavOpen = value;
19-
});
2016

2117
mode.subscribe(value => {
2218
currentMode = value;
@@ -52,7 +48,11 @@ export class BaseEvalElement extends HTMLElement {
5248
this.outputElement.hidden = false;
5349
}
5450

55-
postEvaluate() {}
51+
// subclasses should overwrite this method to define custom logic
52+
// after code has been evaluated
53+
postEvaluate() {
54+
return null;
55+
}
5656

5757
checkId() {
5858
if (!this.id) this.id = this.constructor.name + '-' + guidGenerator();

pyscriptjs/src/components/pybox.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ export class PyBox extends HTMLElement {
4949
this.widths.push(`w-${w}`);
5050
}
5151
} else {
52-
for (const el of mainDiv.childNodes) {
53-
this.widths.push(`w-1/${mainDiv.childNodes.length}`);
54-
}
52+
this.widths = [...this.widths, ...[`w-1/${mainDiv.childNodes.length}`]];
5553
}
5654

5755
this.widths.forEach((width, index)=>{
5856
const node: ChildNode = mainDiv.childNodes[index];
59-
addClasses(node, [width, 'mx-4'])
57+
addClasses(node, [width, 'mx-1'])
6058

6159
})
6260

pyscriptjs/src/components/pybutton.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseEvalElement } from './base';
2-
import { addClasses, ltrim, htmlDecode } from '../utils';
2+
import { addClasses, htmlDecode } from '../utils';
33

44
export class PyButton extends BaseEvalElement {
55
shadow: ShadowRoot;

pyscriptjs/src/components/pyenv.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@ import { loadPackage, loadFromFile } from '../interpreter';
55

66
// Premise used to connect to the first available pyodide interpreter
77
let pyodideReadyPromise;
8-
let environments;
9-
let currentMode;
8+
let runtime;
109

1110
pyodideLoaded.subscribe(value => {
12-
pyodideReadyPromise = value;
13-
});
14-
15-
loadedEnvironments.subscribe(value => {
16-
environments = value;
17-
});
18-
19-
mode.subscribe(value => {
20-
currentMode = value;
11+
runtime = value;
12+
console.log("RUNTIME READY")
2113
});
2214

2315
export class PyEnv extends HTMLElement {
2416
shadow: ShadowRoot;
2517
wrapper: HTMLElement;
2618
code: string;
2719
environment: any;
20+
runtime: any;
21+
env: string[];
22+
paths: string[];
2823

2924
constructor() {
3025
super();
@@ -54,20 +49,20 @@ export class PyEnv extends HTMLElement {
5449
}
5550

5651
async function loadEnv() {
57-
const pyodide = await pyodideReadyPromise;
58-
await loadPackage(env, pyodide);
52+
await loadPackage(env, runtime);
5953
console.log('enviroment loaded');
6054
}
6155

6256
async function loadPaths() {
6357
const pyodide = await pyodideReadyPromise;
6458
for (const singleFile of paths) {
65-
await loadFromFile(singleFile, pyodide);
59+
await loadFromFile(singleFile, runtime);
6660
}
6761
console.log('paths loaded');
6862
}
63+
6964
addInitializer(loadEnv);
7065
addInitializer(loadPaths);
71-
console.log('enviroment loading...', env);
66+
console.log('enviroment loading...', this.env);
7267
}
7368
}

pyscriptjs/src/components/pyinputbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseEvalElement } from './base';
2-
import { addClasses, ltrim, htmlDecode } from '../utils';
2+
import { addClasses, htmlDecode } from '../utils';
33

44
export class PyInputBox extends BaseEvalElement {
55
shadow: ShadowRoot;

pyscriptjs/src/components/pyrepl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { keymap } from '@codemirror/view';
55
import { defaultKeymap } from '@codemirror/commands';
66
import { oneDarkTheme } from '@codemirror/theme-one-dark';
77

8-
import { componentDetailsNavOpen, currentComponentDetails, loadedEnvironments, mode, pyodideLoaded } from '../stores';
8+
import { componentDetailsNavOpen, loadedEnvironments, mode, pyodideLoaded } from '../stores';
99
import { addClasses } from '../utils';
1010
import { BaseEvalElement } from './base';
1111

pyscriptjs/src/components/pyscript.ts

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { EditorState } from '@codemirror/basic-setup';
2-
import { python } from '@codemirror/lang-python';
3-
import { StateCommand } from '@codemirror/state';
4-
import { keymap } from '@codemirror/view';
5-
import { defaultKeymap } from '@codemirror/commands';
6-
import { oneDarkTheme } from '@codemirror/theme-one-dark';
7-
81
import {
92
addInitializer,
103
addPostInitializer,
114
addToScriptsQueue,
12-
componentDetailsNavOpen,
135
loadedEnvironments,
146
mode,
157
pyodideLoaded,
@@ -21,7 +13,6 @@ import { BaseEvalElement } from './base';
2113
let pyodideReadyPromise;
2214
let environments;
2315
let currentMode;
24-
let handlersCollected = false;
2516

2617
pyodideLoaded.subscribe(value => {
2718
pyodideReadyPromise = value;
@@ -30,67 +21,16 @@ loadedEnvironments.subscribe(value => {
3021
environments = value;
3122
});
3223

33-
let propertiesNavOpen;
34-
componentDetailsNavOpen.subscribe(value => {
35-
propertiesNavOpen = value;
36-
});
37-
3824
mode.subscribe(value => {
3925
currentMode = value;
4026
});
4127

42-
function createCmdHandler(el) {
43-
// Creates a codemirror cmd handler that calls the el.evaluate when an event
44-
// triggers that specific cmd
45-
const toggleCheckbox: StateCommand = ({ state, dispatch }) => {
46-
return el.evaluate(state);
47-
};
48-
return toggleCheckbox;
49-
}
5028

5129
// TODO: use type declaractions
5230
type PyodideInterface = {
5331
registerJsModule(name: string, module: object): void;
5432
};
5533

56-
// TODO: This should be used as base for generic scripts that need exectutoin
57-
// from PyScript to initializers, etc...
58-
class Script {
59-
source: string;
60-
state: string;
61-
output: string;
62-
63-
constructor(source: string, output: string) {
64-
this.output = output;
65-
this.source = source;
66-
this.state = 'waiting';
67-
}
68-
69-
async evaluate() {
70-
console.log('evaluate');
71-
const pyodide = await pyodideReadyPromise;
72-
// debugger
73-
try {
74-
// let source = this.editor.state.doc.toString();
75-
let output;
76-
if (this.source.includes('asyncio')) {
77-
output = await pyodide.runPythonAsync(this.source);
78-
} else {
79-
output = pyodide.runPython(this.source);
80-
}
81-
82-
if (this.output) {
83-
// this.editorOut.innerHTML = s;
84-
}
85-
// if (output !== undefined){
86-
// this.addToOutput(output);
87-
// }
88-
} catch (err) {
89-
console.log('OOOPS, this happened: ', err);
90-
// this.addToOutput(err);
91-
}
92-
}
93-
}
9434

9535
export class PyScript extends BaseEvalElement {
9636
constructor() {
@@ -104,25 +44,6 @@ export class PyScript extends BaseEvalElement {
10444
this.checkId();
10545
this.code = this.innerHTML;
10646
this.innerHTML = '';
107-
const startState = EditorState.create({
108-
doc: this.code,
109-
extensions: [
110-
keymap.of([
111-
...defaultKeymap,
112-
{ key: 'Ctrl-Enter', run: createCmdHandler(this) },
113-
{ key: 'Shift-Enter', run: createCmdHandler(this) },
114-
]),
115-
oneDarkTheme,
116-
python(),
117-
// Event listener function that is called every time an user types something on this editor
118-
// EditorView.updateListener.of((v:ViewUpdate) => {
119-
// if (v.docChanged) {
120-
// console.log(v.changes);
121-
122-
// }
123-
// })
124-
],
125-
});
12647

12748
const mainDiv = document.createElement('div');
12849
addClasses(mainDiv, ['parentBox', 'flex', 'flex-col', 'mx-8']);
@@ -234,7 +155,6 @@ async function initHandlers() {
234155
// // pyodide.runPython(handlerCode);
235156
// }
236157
}
237-
handlersCollected = true;
238158

239159
matches = document.querySelectorAll('[pys-onKeyDown]');
240160
for (const el of matches) {
@@ -249,7 +169,7 @@ async function mountElements() {
249169
console.log('Collecting nodes to be mounted into python namespace...');
250170
const pyodide = await pyodideReadyPromise;
251171
const matches: NodeListOf<HTMLElement> = document.querySelectorAll('[py-mount]');
252-
let output;
172+
253173
let source = '';
254174
for (const el of matches) {
255175
let mountName = el.getAttribute('py-mount');

0 commit comments

Comments
 (0)
0