Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70d4014

Browse files
authored
Merge pull requestpyscript#150 from pyscript/quickfix/pyscript_loading_sequence
Hotfix for py-script/py-repl loading
2 parentsb77b8ca +f957fda commit70d4014

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

‎pyscriptjs/examples/pylist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ def on_click(self, evt=None):
99

1010
classPyList(PyListTemplate):
1111
item_class=PyItem
12+
13+
defadd(self,item):
14+
ifisinstance(item,str):
15+
item= {"content":item,"done":False,"created_at":dt.now() }
16+
17+
super().add(item,labels=['content'],state_key="done")

‎pyscriptjs/examples/repl2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<metacharset="utf-8"/>
55
<metaname="viewport"content="width=device-width,initial-scale=1"/>
66

7-
<title>Svelte app</title>
7+
<title>Custom REPL Example</title>
88

99
<linkrel="icon"type="image/png"href="favicon.png"/>
1010
<linkrel="stylesheet"href="../build/pyscript.css"/>
@@ -23,7 +23,7 @@
2323

2424
<body>
2525
<h1class="font-semibold text-2xl ml-5">Custom REPL</h1>
26-
<py-boxwidths="2/3;1/3">
26+
<py-boxwidths="1/2;1/2">
2727
<py-replid="my-repl"auto-generate="true"std-out="output"std-err="err-div"></py-repl>
2828
<divid="output"class="p-4"></div>
2929
</py-box>

‎pyscriptjs/examples/simple_clock.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<metacharset="utf-8"/>
55
<metaname="viewport"content="width=device-width,initial-scale=1"/>
66

7-
<title>Svelte app</title>
7+
<title>Simple Clock Demo</title>
88

99
<linkrel="icon"type="image/png"href="favicon.png"/>
1010
<linkrel="stylesheet"href="../build/pyscript.css"/>

‎pyscriptjs/examples/todo-pylist.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# add a new task to the list and tell it to use the `content` key to show in the UI
2424
# and to use the key `done` to sync the task status with a checkbox element in the UI
25-
myList.add(task, labels=['content'], state_key="done")
25+
myList.add(task)
2626

2727
# clear the inputbox element used to create the new task
2828
new_task_content.clear()

‎pyscriptjs/src/components/base.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import{loadedEnvironments,mode,pyodideLoaded}from'../stores';
22
import{guidGenerator,addClasses}from'../utils';
33
// Premise used to connect to the first available pyodide interpreter
4-
letpyodideReadyPromise;
4+
letruntime;
55
letenvironments;
66
letcurrentMode;
77
letElement;
88

9+
910
pyodideLoaded.subscribe(value=>{
10-
pyodideReadyPromise=value;
11+
runtime=value;
1112
});
1213
loadedEnvironments.subscribe(value=>{
1314
environments=value;
@@ -63,7 +64,7 @@ export class BaseEvalElement extends HTMLElement {
6364
}
6465

6566
asyncgetSourceFromFile(s:string):Promise<string>{
66-
constpyodide=awaitpyodideReadyPromise;
67+
constpyodide=runtime;
6768
constresponse=awaitfetch(s);
6869
this.code=awaitresponse.text();
6970
returnthis.code;
@@ -101,7 +102,7 @@ export class BaseEvalElement extends HTMLElement {
101102

102103
asyncevaluate():Promise<void>{
103104
console.log('evaluate');
104-
constpyodide=awaitpyodideReadyPromise;
105+
constpyodide=runtime;
105106
letsource:string;
106107
letoutput;
107108
try{
@@ -154,7 +155,7 @@ export class BaseEvalElement extends HTMLElement {
154155

155156
asynceval(source:string):Promise<void>{
156157
letoutput;
157-
constpyodide=awaitpyodideReadyPromise;
158+
constpyodide=runtime;
158159

159160
try{
160161
output=awaitpyodide.runPythonAsync(source);
@@ -193,25 +194,39 @@ function createWidget(name: string, code: string, klass: string) {
193194
// ideally we can just wait for it to load and then run. To do
194195
// so we need to replace using the promise and actually using
195196
// the interpreter after it loads completely
196-
setTimeout(()=>{
197-
this.eval(this.code).then(()=>{
198-
this.proxy=this.proxyClass(this);
199-
console.log('proxy',this.proxy);
200-
this.proxy.connect();
201-
this.registerWidget();
202-
});
203-
},2000);
197+
// setTimeout(() => {
198+
// this.eval(this.code).then(() => {
199+
// this.proxy = this.proxyClass(this);
200+
// console.log('proxy', this.proxy);
201+
// this.proxy.connect();
202+
// this.registerWidget();
203+
// });
204+
// }, 2000);
205+
pyodideLoaded.subscribe(value=>{
206+
console.log("RUNTIME READY",value)
207+
if("runPythonAsync"invalue){
208+
runtime=value;
209+
setTimeout(()=>{
210+
this.eval(this.code).then(()=>{
211+
this.proxy=this.proxyClass(this);
212+
console.log('proxy',this.proxy);
213+
this.proxy.connect();
214+
this.registerWidget();
215+
});
216+
},1000);
217+
}
218+
});
204219
}
205220

206-
asyncregisterWidget(){
207-
constpyodide=awaitpyodideReadyPromise;
221+
registerWidget(){
222+
constpyodide=runtime;
208223
console.log('new widget registered:',this.name);
209224
pyodide.globals.set(this.id,this.proxy);
210225
}
211226

212227
asynceval(source:string):Promise<void>{
213228
letoutput;
214-
constpyodide=awaitpyodideReadyPromise;
229+
constpyodide=runtime;
215230
try{
216231
output=awaitpyodide.runPythonAsync(source);
217232
this.proxyClass=pyodide.globals.get(this.klass);
@@ -306,14 +321,14 @@ export class PyWidget extends HTMLElement {
306321
}
307322

308323
asyncgetSourceFromFile(s:string):Promise<string>{
309-
constpyodide=awaitpyodideReadyPromise;
324+
constpyodide=runtime;
310325
constresponse=awaitfetch(s);
311326
returnawaitresponse.text();
312327
}
313328

314329
asynceval(source:string):Promise<void>{
315330
letoutput;
316-
constpyodide=awaitpyodideReadyPromise;
331+
constpyodide=runtime;
317332
try{
318333
output=awaitpyodide.runPythonAsync(source);
319334
if(output!==undefined){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp