File tree 2 files changed +7
-5
lines changed
pyscriptjs/src/components 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -51,15 +51,16 @@ export class PyButton extends BaseEvalElement {
51
51
52
52
this . appendChild ( mainDiv ) ;
53
53
this . code = this . code . split ( 'self' ) . join ( this . mount_name ) ;
54
- let registrationCode = `${ this . mount_name } = Element("${ mainDiv . id } ")` ;
54
+ let registrationCode = `from pyodide import create_proxy` ;
55
+ registrationCode += `\n${ this . mount_name } = Element("${ mainDiv . id } ")` ;
55
56
if ( this . code . includes ( 'def on_focus' ) ) {
56
57
this . code = this . code . replace ( 'def on_focus' , `def on_focus_${ this . mount_name } ` ) ;
57
- registrationCode += `\n${ this . mount_name }<
8000
/span> .element.addEventListener('focus', on_focus_${ this . mount_name } )`;
58
+ registrationCode += `\n${ this . mount_name } .element.addEventListener('focus', create_proxy( on_focus_${ this . mount_name } ) )` ;
58
59
}
59
60
60
61
if ( this . code . includes ( 'def on_click' ) ) {
61
62
this . code = this . code . replace ( 'def on_click' , `def on_click_${ this . mount_name } ` ) ;
62
- registrationCode += `\n${ this . mount_name } .element.addEventListener('click', on_click_${ this . mount_name } )` ;
63
+ registrationCode += `\n${ this . mount_name } .element.addEventListener('click', create_proxy( on_click_${ this . mount_name } ) )` ;
63
64
}
64
65
65
66
// now that we appended and the element is attached, lets connect with the event handlers
Original file line number Diff line number Diff line change @@ -34,10 +34,11 @@ export class PyInputBox extends BaseEvalElement {
34
34
// defined for this widget
35
35
this . appendChild ( mainDiv ) ;
36
36
this . code = this . code . split ( 'self' ) . join ( this . mount_name ) ;
37
- let registrationCode = `${ this . mount_name } = Element("${ mainDiv . id } ")` ;
37
+ let registrationCode = `from pyodide import create_proxy` ;
38
+ registrationCode += `\n${ this . mount_name } = Element("${ mainDiv . id } ")` ;
38
39
if ( this . code . includes ( 'def on_keypress' ) ) {
39
40
this . code = this . code . replace ( 'def on_keypress' , `def on_keypress_${ this . mount_name } ` ) ;
40
- registrationCode += `\n${ this . mount_name } .element.addEventListener('keypress', on_keypress_${ this . mount_name } )` ;
41
+ registrationCode += `\n${ this . mount_name } .element.addEventListener('keypress', create_proxy( on_keypress_${ this . mount_name } ) )` ;
41
42
}
42
43
43
44
// TODO: For now we delay execution to allow pyodide to load but in the future this
You can’t perform that action at this time.
0 commit comments