@@ -29,7 +29,7 @@ limitations under the License.
29
29
/******************************************************************************
30
30
Base classes and constants.
31
31
******************************************************************************/
32
- class Plugin {
32
+ class PyScriptPlugin {
33
33
/*
34
34
Defines a "plugin" in PyScript.
35
35
*/
@@ -91,7 +91,7 @@ class Runtime {
91
91
Dispatch the py-runtime-ready event (for when the runtime has
92
92
eventually started and is ready to evaluate code).
93
93
*/
94
- const pyRuntimeReady = new CustomEvent ( "py-runtime-ready" ) ;
94
+ const pyRuntimeReady = new CustomEvent ( "py-runtime-ready" , this ) ;
95
95
document . dispatchEvent ( pyRuntimeReady ) ;
96
96
}
97
97
@@ -124,14 +124,15 @@ class Runtime {
124
124
125
125
126
126
// The innerHTML of the default splash screen to show while PyScript is
127
- // starting up. Currently a simple SVG animation above the word "PyScript".
127
+ // starting up. Currently the page is greyed out and the words
128
+ // "Loading PyScript...".
128
129
const defaultSplash = '<div style="position:fixed;width:100%;height:100%;top:0;left:0;right:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:99999;"><div style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);color:white;font-family:monospace;font-size:10px;">Loading PyScript...</div></div>' ;
129
130
130
131
131
132
/******************************************************************************
132
133
Built-in plugins and runtimes.
133
134
******************************************************************************/
134
- class PyScriptTag extends Plugin {
135
+ class PyScriptTag extends PyScriptPlugin {
135
136
start ( config ) {
136
137
// Define the PyScript element.
137
138
class PyScript extends HTMLElement {
@@ -268,13 +269,11 @@ class PyodideRuntime extends Runtime {
268
269
The core PyScript app definition.
269
270
******************************************************************************/
270
271
const main = function ( ) {
271
- // Used to measure start-up times.
272
- const start = new Date ( ) ;
273
272
// Really simple logging. Emoji 🐍 highlights PyScript app logs. ;-)
274
273
const logger = function ( ) {
275
274
return Function . prototype . bind . call ( console . log , console , "🐍 " , ...arguments ) ;
276
275
} ( ) ;
277
- logger ( "Starting PyScript. 👋" , start ) ;
276
+ logger ( "Starting PyScript. 👋" ) ;
278
277
279
278
// Default configuration settings for PyScript. These may be overridden by
280
279
// the app.loadConfig function.
@@ -301,8 +300,6 @@ const main = function() {
301
300
"cpython" : CPythonRuntime ,
302
301
"pyodide" : PyodideRuntime
303
302
}
304
- // Default to smallest/fastest runtime.
305
- runtimes [ "default" ] = runtimes [ "micropython" ]
306
303
307
304
// Eventually references an instance of the Runtime class, representing the
308
305
// started runtime.
@@ -377,28 +374,25 @@ const main = function() {
377
374
378
375
TL;DR - a new script tag with the correct src is added to the head.
379
376
*/
380
- const runtimeName = config . runtime ? config . runtime : "default" ;
381
- if ( ! runtimes . hasOwnProperty ( runtimeName ) ) {
382
- throw `💥 Unknown runtime: "${ runtimeName } " (known runtimes: ${ Object . keys ( runtimes ) } )` ;
377
+ if ( ! runtimes . hasOwnProperty ( config . runtime ) ) {
378
+ throw `💥 Unknown runtime: "${ config . runtime } " (known runtimes: ${ Object . keys ( runtimes ) } )` ;
383
379
}
384
380
const runtimeElement = document . createElement ( "script" ) ;
385
- runtimeElement . src = runtimes [ runtimeName . toLowerCase ( ) ] . url ;
381
+ runtimeElement . src = runtimes [ config . runtime . toLowerCase ( ) ] . url ;
386
382
runtimeElement . onload = function ( e ) {
387
- let duration = new Date ( ) - start ;
388
- logger ( `Runtime "${ runtimeName } " loaded (${ duration } ms). 👍` ) ;
389
- const pyRuntimeLoaded = new CustomEvent ( "py-runtime-loaded" , { detail : runtimeName } ) ;
383
+ logger ( `Runtime "${ config . runtime } " loaded. 👍` ) ;
384
+ const pyRuntimeLoaded = new CustomEvent ( "py-runtime-loaded" , { detail : config . runtime } ) ;
390
385
document . dispatchEvent ( pyRuntimeLoaded ) ;
391
386
} ;
392
387
var head = document . getElementsByTagName ( 'head' ) [ 0 ] ;
393
- logger ( `Loading runtime "${ runtimeName } ". 🚀` )
388
+ logger ( `Loading runtime "${ config . runtime } ". 🚀` )
394
389
head . appendChild ( runtimeElement ) ;
395
390
} ,
396
391
startRuntime : function ( ) {
397
392
/*
398
393
Congigure and start the Python runtime.
399
394
*/
400
- const runtimeName = config . runtime ? config . runtime : "default" ;
401
- runtime = new runtimes [ runtimeName . toLowerCase ( ) ] ( ) ;
395
+ runtime = new runtimes [ config . runtime . toLowerCase ( ) ] ( ) ;
402
396
runtime . start ( config ) ;
403
397
} ,
404
398
runtimeStarted : function ( ) {
@@ -407,8 +401,7 @@ const main = function() {
407
401
through each registered plugin's onRuntimeReady method, and begin
408
402
evaluating any code in the pendingScripts queue.
409
403
*/
410
- let duration = new Date ( ) - start ;
411
- logger ( `Runtime started (${ duration } ms). 🎬` ) ;
404
+ logger ( `Runtime started. 🎬` ) ;
412
405
runtimeReady = true ;
413
406
plugins . forEach ( function ( plugin ) {
414
407
plugin . onRuntimeReady ( config , runtime ) ;
0 commit comments