Update: Python Online板卡下在载入Python3内核时增加提示信息

This commit is contained in:
王立帮
2024-11-26 18:11:32 +08:00
parent fca27cd589
commit 5411a188f7
8 changed files with 85 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
export const EnMsg = { export const EnMsg = {
'PYTHON_PYODIDE_IMAGE': 'Image' 'PYTHON_PYODIDE_IMAGE': 'Image',
'PYTHON_PYODIDE_LOADING': 'Python3 kernel loading...'
}; };
export const EnCatgories = {}; export const EnCatgories = {};

View File

@@ -1,5 +1,6 @@
export const ZhHansMsg = { export const ZhHansMsg = {
'PYTHON_PYODIDE_IMAGE': '图像' 'PYTHON_PYODIDE_IMAGE': '图像',
'PYTHON_PYODIDE_LOADING': 'Python3内核载入中...'
}; };
export const ZhHansCatgories = {}; export const ZhHansCatgories = {};

View File

@@ -1,5 +1,6 @@
export const ZhHantMsg = { export const ZhHantMsg = {
'PYTHON_PYODIDE_IMAGE': '影像' 'PYTHON_PYODIDE_IMAGE': '影像',
'PYTHON_PYODIDE_LOADING': 'Python3核心載入...'
}; };
export const ZhHantCatgories = {}; export const ZhHantCatgories = {};

View File

@@ -1,3 +1,3 @@
import NavExt from './nav-ext'; import NavExt from './nav-ext';
NavExt.init(); await NavExt.init();

View File

@@ -1,19 +1,38 @@
import * as Blockly from 'blockly/core';
import * as path from 'path'; import * as path from 'path';
// import * as dayjs from 'dayjs'; import $ from 'jquery';
import { import {
Workspace, Workspace,
Debug, Debug,
Env, Env,
Msg Msg,
HTMLTemplate,
app
} from 'mixly'; } from 'mixly';
import { KernelLoader } from '@basthon/kernel-loader'; import { KernelLoader } from '@basthon/kernel-loader';
import StatusBarImage from './statusbar-image'; import StatusBarImage from './statusbar-image';
import LOADER_TEMPLATE from '../templates/html/loader.html';
class PythonShell { class PythonShell {
static { static {
HTMLTemplate.add(
'html/statusbar/loader.html',
new HTMLTemplate(LOADER_TEMPLATE)
);
this.pythonShell = null; this.pythonShell = null;
this.kernelLoaded = false;
this.$loader = $(HTMLTemplate.get('html/statusbar/loader.html').render({
msg: {
loading: Blockly.Msg.PYTHON_PYODIDE_LOADING
}
}));
this.init = async function () { this.init = async function () {
const footerBar = app.getFooterBar();
const $content = footerBar.getContent();
$content.after(this.$loader);
StatusBarImage.init(); StatusBarImage.init();
const projectPath = path.relative(Env.indexDirPath, Env.boardDirPath); const projectPath = path.relative(Env.indexDirPath, Env.boardDirPath);
const loader = new KernelLoader({ const loader = new KernelLoader({
@@ -34,6 +53,9 @@ class PythonShell {
this.pyodide = window.pyodide; this.pyodide = window.pyodide;
this.interruptBuffer = new Uint8Array(new ArrayBuffer(1)); this.interruptBuffer = new Uint8Array(new ArrayBuffer(1));
this.pyodide.setInterruptBuffer(this.interruptBuffer); this.pyodide.setInterruptBuffer(this.interruptBuffer);
this.kernelLoaded = true;
this.$loader.remove();
this.$loader = null;
} }
this.run = function () { this.run = function () {
@@ -94,6 +116,7 @@ class PythonShell {
} }
} }
]; ];
constructor() { constructor() {
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
this.#statusBarsManager_ = mainWorkspace.getStatusBarsManager(); this.#statusBarsManager_ = mainWorkspace.getStatusBarsManager();
@@ -170,6 +193,9 @@ class PythonShell {
} }
run(code) { run(code) {
if (!PythonShell.kernelLoaded) {
return;
}
this.stop() this.stop()
.then(() => { .then(() => {
if (code.indexOf('import turtle') !== -1) { if (code.indexOf('import turtle') !== -1) {
@@ -191,6 +217,9 @@ class PythonShell {
} }
async stop() { async stop() {
if (!PythonShell.kernelLoaded) {
return;
}
if (this.#waittingForInput_) { if (this.#waittingForInput_) {
this.#exitInput_(); this.#exitInput_();
} }

View File

@@ -0,0 +1,24 @@
<style>
div[m-id="{{d.mId}}"] {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
position: absolute;
background-color: transparent !important;
font-size: 12px;
line-height: 12px;
color: #fff;
bottom: 0;
height: var(--footer-height);
width: 100%;
}
div[m-id="{{d.mId}}"] > p {
margin-left: 5px;
}
</style>
<div m-id="{{d.mId}}">
<div class="ui mini active inline slow loader"></div>
<p>{{d.msg.loading}}</p>
</div>

View File

@@ -14,6 +14,4 @@
background-color: #1e1e1e; background-color: #1e1e1e;
} }
</style> </style>
<div m-id="{{d.mId}}" class="page-item"> <div m-id="{{d.mId}}" class="page-item"></div>
</div>