import create_proxy and to_js from pyodide.ffi (#725)

This commit is contained in:
Madhur Tandon
2022-08-26 01:41:18 +05:30
committed by GitHub
parent 0f50f4a9fd
commit edfd4baa1f
8 changed files with 10 additions and 11 deletions

View File

@@ -48,7 +48,7 @@ export class PyButton extends BaseEvalElement {
this.appendChild(mainDiv);
this.code = this.code.split('self').join(this.mount_name);
let registrationCode = `from pyodide import create_proxy`;
let registrationCode = `from pyodide.ffi import create_proxy`;
registrationCode += `\n${this.mount_name} = Element("${mainDiv.id}")`;
if (this.code.includes('def on_focus')) {
this.code = this.code.replace('def on_focus', `def on_focus_${this.mount_name}`);

View File

@@ -31,7 +31,7 @@ export class PyInputBox extends BaseEvalElement {
// defined for this widget
this.appendChild(mainDiv);
this.code = this.code.split('self').join(this.mount_name);
let registrationCode = `from pyodide import create_proxy`;
let registrationCode = `from pyodide.ffi import create_proxy`;
registrationCode += `\n${this.mount_name} = Element("${mainDiv.id}")`;
if (this.code.includes('def on_keypress')) {
this.code = this.code.replace('def on_keypress', `def on_keypress_${this.mount_name}`);

View File

@@ -227,7 +227,7 @@ async function createElementsWithEventListeners(runtime: Runtime, pyAttribute: s
const handlerCode = el.getAttribute(pyAttribute);
const event = pyAttributeToEvent.get(pyAttribute);
const source = `
from pyodide import create_proxy
from pyodide.ffi import create_proxy
Element("${el.id}").element.addEventListener("${event}", create_proxy(${handlerCode}))
`;
await runtime.run(source);