-
Notifications
You must be signed in to change notification settings - Fork 4
/
manual_tests_htbulma.py
65 lines (44 loc) · 1.84 KB
/
manual_tests_htbulma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!./venv/bin/python3
from htag import Tag
import htbulma as b
class Star1(Tag.div): # it's a component ;-)
""" rendering lately (using render (called before __str__))
it's simpler ... but event/action shouldn't try to draw something, coz render will rebuild all at each time
"""
def init(self,value=0):
self.value=value
def inc(self,v):
self.value+=v
def render(self): # <- ensure dynamic rendering
self.clear()
self <= b.Button( "-", _onclick = lambda o: self.inc(-1), _class="is-small" )
self <= b.Button( "+", _onclick = lambda o: self.inc(+1), _class="is-small" )
self <= "⭐"*self.value
class Star2(Tag.div): # it's a component ;-)
""" rendering immediatly (each event does the rendering)
it's less simple ... but event/action should redraw something !
"""
def init(self,value=0):
self.value=value
self <= b.Button( "-", _onclick = lambda o: self.inc(-1), _class="is-small" )
self <= b.Button( "+", _onclick = lambda o: self.inc(+1), _class="is-small" )
self.content = Tag.span( "⭐"*self.value )
self <= self.content
def inc(self,v):
self.value+=v
self.content.clear( "⭐"*self.value )
class App(Tag.body):
def init(self):
self._s = b.Service(self)
nav = b.Nav("My App")
nav.addEntry("entry 1", lambda: self._s.alert( "You choose 1" ) )
nav.addEntry("entry 2", lambda: self._s.alert( "You choose 2" ) )
tab = b.Tabs()
tab.addTab("Tab 1", Tag.b("Set star1s") + Star1(12) )
tab.addTab("Tab 2", Tag.b("Set star2s") + Star2(12) )
self <= nav + b.Section( tab )
if __name__=="__main__":
# import logging
# logging.basicConfig(format='[%(levelname)-5s] %(name)s: %(message)s',level=logging.DEBUG)
from htag.runners import *
BrowserStarletteWS( App ).run()