1
0
mirror of https://github.com/pyscript/pyscript.git synced 2022-05-01 19:47:48 +03:00

add better support for new widgets

This commit is contained in:
Fabio Pliger
2022-04-20 15:41:28 -05:00
parent 28efe8a1c9
commit f5b168a45e
3 changed files with 30 additions and 7 deletions

View File

@@ -149,7 +149,23 @@ export class BaseEvalElement extends HTMLElement {
this.errorElement.hidden = false;
this.errorElement.style.display = 'block';
}
}
} // end evaluate
async eval(source: string): Promise<void> {
let output;
let pyodide = await pyodideReadyPromise;
try{
output = await pyodide.runPythonAsync(source);
if (output !== undefined){
console.log(output);
}
} catch (err) {
console.log(err);
}
} // end eval
}
function createWidget(name: string, code: string, klass: string){

View File

@@ -7,7 +7,7 @@ import { defaultKeymap } from "@codemirror/commands";
import { oneDarkTheme } from "@codemirror/theme-one-dark";
import { pyodideLoaded, loadedEnvironments, componentDetailsNavOpen, currentComponentDetails, mode, addToScriptsQueue, addInitializer, addPostInitializer } from '../stores';
import { addClasses } from '../utils';
import { addClasses, htmlDecode } from '../utils';
import { BaseEvalElement } from './base';
// Premise used to connect to the first available pyodide interpreter
@@ -41,11 +41,6 @@ function createCmdHandler(el){
return toggleCheckbox
}
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
// TODO: use type declaractions
type PyodideInterface = {
registerJsModule(name: string, module: object): void

View File

@@ -148,6 +148,18 @@ class PyListTemplate:
self._children = []
self._id = self.parent.id
@property
def children(self):
return self._children
@property
def data(self):
return [c.data for c in self._children]
@property
def render_children(self):
return [c.element.innerHTML.replace("\\n", "") for c in self._children]
def connect(self):
self.md = main_div = document.createElement('div');
main_div.id = self._id + "-list-tasks-container"