File tree 3 files changed +20
-8
lines changed 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change 20
20
< body >
21
21
< py-title > To Do List</ py-title >
22
22
< py-box widths ="2/3;1/3 ">
23
- < py-inputbox id ="new-task-content "> </ py-inputbox >
23
+ < py-inputbox id ="new-task-content ">
24
+ def on_keypress(e):
25
+ if (e.code == "Enter"):
26
+ add_task()
27
+ </ py-inputbox >
24
28
< py-button id ="new-task-btn " label ="Add Task! ">
25
29
def on_click(evt):
26
30
task = { "content": new_task_content.value, "done": False, "created_at": dt.now() }
30
34
</ py-box >
31
35
32
36
< py-list id ="myList "> </ py-list >
33
-
34
37
< py-repl id ="my-repl " auto-generate ="true "> </ py-repl >
35
38
</ body >
36
39
</ html >
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export class PyInputBox extends BaseEvalElement {
23
23
24
24
25
25
connectedCallback ( ) {
26
- this . label = htmlDecode ( this . innerHTML ) ;
26
+ this . code = htmlDecode ( this . innerHTML ) ;
27
27
this . mount_name = this . id . split ( "-" ) . join ( "_" ) ;
28
28
this . innerHTML = '' ;
29
29
@@ -37,14 +37,23 @@ export class PyInputBox extends BaseEvalElement {
37
37
38
38
// now that we appended and the element is attached, lets connect with the event handlers
39
39
// defined for this widget
40
- this . code = `${ this . mount_name } = Element("${ mainDiv . id } ")` ;
40
+ this . appendChild ( mainDiv ) ;
41
+ this . code = this . code . split ( "self" ) . join ( this . mount_name ) ;
42
+ let registrationCode = `${ this . mount_name } = Element("${ mainDiv . id } ")` ;
43
+ if ( this . code . includes ( "def on_keypress" ) ) {
44
+ this . code = this . code . replace ( "def on_keypress" , `def on_keypress_${ this . mount_name } ` ) ;
45
+ registrationCode += `\n${ this . mount_name } .element.onkeypress = on_keypress_${ this . mount_name } `
46
+ }
47
+
41
48
setTimeout ( ( ) => {
42
49
this . eval ( this . code ) . then ( ( ) => {
43
- console . log ( 'registered handlers' ) ;
50
+ this . eval ( registrationCode ) . then ( ( ) => {
51
+ console . log ( 'registered handlers' ) ;
52
+ } ) ;
44
53
} ) ;
45
54
} , 4000 ) ;
46
-
47
- console . log ( 'py-title connected' ) ;
55
+
56
+ console . log ( 'py-inputbox connected' ) ;
48
57
}
49
58
}
50
59
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ class PyWidgetTheme:
140
140
141
141
142
142
class PyListTemplate:
143
- theme = PyWidgetTheme("flex flex-col-reverse mt-4")
143
+ theme = PyWidgetTheme("flex flex-col-reverse mt-8 mx- 4")
144
144
145
145
146
146
def __init__(self, parent):
You can’t perform that action at this time.
0 commit comments