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:
@@ -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){
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user