55DELIVERY_OPTIONS = ["1-day" , "2-day" , "pickup" ]
66
77class Product (ltk .Model ):
8- name : str = "Wrench"
9- price : float = 50.0
108 count : int = 10
9+ name : str = "Screwdriver"
10+ price : float = 50.0
1111 warranty : bool = False
1212 service : bool = True
1313 delivery : int = 1
@@ -24,10 +24,21 @@ def changed(self, name, value):
2424 - Delivery: { DELIVERY_OPTIONS [self .delivery ]}
2525 """
2626
27- product = Product (count = 60 )
27+ product1 = Product (name = "Wrench" , delivery = 0 )
28+ product2 = Product (name = "Drill" , count = 6 , price = 500 , service = False )
2829
29- def create ():
30- form = ltk .VBox (
30+ def order_hammers (event ):
31+ product2 .name = "Hammer"
32+ product2 .count = 10
33+ product2 .price = 100.0
34+ product2 .warranty = True
35+ product2 .delivery = 2
36+ product2 .service = False
37+
38+ def create_form (name , product ):
39+ print ("Create form for" , product )
40+ return ltk .VBox (
41+ ltk .Label (name ),
3142 row (
3243 "Name:" ,
3344 ltk .Input (product .name ).width (300 )
@@ -65,31 +76,30 @@ def create():
6576 ltk .Text (product .summary )
6677 )
6778 )
79+
80+ def create ():
6881 return (
6982 ltk .VBox (
7083 ltk .Heading2 ("Reactive LTK Demo" ),
71- form
84+ create_form ("Product 1" , product1 )
85+ .css ("border" , "2px solid green" )
86+ .css ("padding" , 12 )
87+ .css ("margin-bottom" , 12 )
88+ .css ("font-size" , 24 ),
89+ create_form ("Product 1" , product2 )
7290 .css ("border" , "2px solid green" )
7391 .css ("padding" , 12 )
7492 .css ("font-size" , 24 )
7593 .attr ("name" , "Reactive" ),
76- ltk .Button ("Buy Hammers " , order_hammers )
94+ ltk .Button ("Set Product 2 to Hammer " , order_hammers )
7795 .css ("margin-top" , 24 )
7896 .css ("border-radius" , 8 )
79- .css ("padding" , 12 )
97+ .css ("padding" , 12 ),
8098 )
8199 .attr ("id" , "reactive" )
82100 .attr ("name" , "Reactive" )
83101 )
84102
85- def order_hammers (event ):
86- product .name = "Hammer"
87- product .count = 10
88- product .price = 100.0
89- product .warranty = True
90- product .delivery = 2
91- product .service = False
92-
93103def row (label , * widgets ):
94104 return ltk .HBox (
95105 ltk .Text (label )
0 commit comments