def build(self): s = Tag.select(onchange=self.bind.select(b"this.value"), style="width:100%", disabled=bool(self.disabled)) for idx, i in enumerate(self.choices): s.add(Tag.option(i, value=idx, selected=(self.value == i))) return Tag.div(s, klass="select")
def build(self): # DYNAMIC RENDERING HERE ! nav = Nav( "gtag-demo", { "Page1": lambda: self.setPage(1), "Page2 (%s)" % int(self.nb): lambda: self.setPage(2), "Page3": lambda: self.setPage(3), "Login": lambda: self.doLogin(), }, { "exit": lambda: self.exit(-1), }) if self.page == 1: page = Page1(self.n, self.txt) elif self.page == 2: page = Page2(self.nb) elif self.page == 3: page = Page3(self.selectedTab, self.rb, self.so, self.sb, self.cb) else: page = "no" return Tag.div( nav, Section(Tag.div("<br>", page, klass="container")), Button("test mbox", onclick=self.bind.setMBox(42)), Button("test toast", onclick=self.bind.setToast(42)), MBox(self.msg), Toaster(self.toast), )
def build(self): o = Tag.div(klass="control") o.add( '<label class="checkbox">', Tag.input( checked=value(self.value), type="checkbox", klass="checkbox", # override onclick=self.bind.switch(), disabled=bool(self.disabled)), self.title, self.value, "</label>") return o
def build(self): return Tag.div( ShareState(), self.a, Button("++", onclick=self.bind.changeState()), Button("QUIT", onclick=self.bind.quit() + ";window.close()"), )
class Fake(GTag): headers = Tag.script(""" function m1() {alert(1)} function m2() {alert(2)} function m3() {alert(3)} function JJJJJJJJJ() {} """)
def build(self): return Tag.div( Box("A test page, with a binding value:", self.nb), MyInc(self.nb), Button("show", onclick=self.bind.kik()), Button("show T", onclick=self.bind.kik2()), )
class My(GTag): headers=Tag.script("//hello") def init(self): self.v=12 def build(self): return Tag.div("hello",self.v,onclick=self.bind.onclick()) def onclick(self): pass
class My(GTag): headers=Tag.script("// hi") def init(self,v): self.v=v def build(self): return Tag.div("hello",self.v,onclick=self.bind.onclick(42)) def onclick(self,anArg=None): pass
def test_TagWithStrangeContent(): assert str(Tag(False)) == '<div></div>' assert str(Tag(True)) == '<div></div>' assert str(Tag(None)) == '<div></div>' assert str(Tag("1")) == '<div>1</div>' assert str(Tag(1)) == '<div>1</div>' assert str(Tag(0)) == '<div>0</div>'
def test_Tag(): assert str(Tag()) == '<div></div>' assert str(Tag(checked=True)) == '<div checked></div>' assert str(Tag(checked=False)) == '<div></div>' assert str(Tag("hello")) == '<div>hello</div>' assert str(Tag("hello", klass="john doe", value=0)) == '<div value="0" class="john doe">hello</div>' assert str(Tag( "hello", data_mining="hell")) == '<div data-mining="hell">hello</div>' assert str(Tag("hello", 42, klass="john doe")) == '<div class="john doe">hello 42</div>' assert str( Tag("hello", onclick='alert("bill & john")') ) == '<div onclick="alert("bill & john")">hello</div>'
def test_Tag_change_props(): t = Tag() t.id = 1 assert str(t) == '<div id="1"></div>' t.id = None assert str(t) == '<div></div>' t.cid = 1 assert str(t) == '<div cid="1"></div>' t.cid = None assert str(t) == '<div></div>'
def build(self): tabs = Tabs(self.selected, ["tab1", "tab2", "tab3"]) return Tag.div( tabs, Box(self.renderContent()), Checkbox(self.cb, "disable all (vv)"), HBox( Text("You selected", self.rb), RadioButtons(self.rb, ["apple", "pear", "banana"], disabled=self.cb, onchange=self.realCallback), ), HBox( Text("You selected", self.so), Select(self.so, ["apple", "pear", "banana"], disabled=self.cb), ), HBox( Text("You selected", self.sb), SelectButtons(self.sb, ["apple", "pear", "banana"], disabled=self.cb), ))
def build(self): return Tag.div( self.c, self.v )
def build(self): return Tag.div( "hello", self.main.a, # <-- the shared state is the main instance ! )
def build(self): return Tag.div("hello")
def build(self): return Tag.pre("hello")
def build(self): ll = [Star(i) for i in range(int(self.n))] return Tag.text("-%s-" % self.n, *ll)
def build(self): return Tag.div(ShareState(), )
def build(self): return Tag.div(self.v, Tag.button("++", onclick=self.bind.add()), style="border:2px solid red")
def compute(self): return Tag.text("-%s-" % self.n)
def build(self): rows=[C(i) for i in self.ll] return Tag.div(*rows)
def build(self): return Tag.div( self.c, C())
def build(self): o=Tag.div( self.v, Tag.button("reload1",onclick=self.bind.evtReload()), Tag.button("reload2",onclick=self.bind.evtReload2()), ) return o
def build(self): return Tag.div("hello", self.main.a, self.parent.v)
def build(self): return Tag.div("hello",self.v,onclick=self.bind.onclick(42))
def build(self): return Tag.text(self.n, *self.stars())
def build(self): return Tag.div(self.cpt, Btn(self.cpt), XSelect(self.v, list("123")), Checkbox(self.cb, "yoo"), self.cb, Tag.button("EXIT", onclick=self.bind.exxx()))
def build(self): self.child=C() return Tag.div( self.child )
def build(self): self("m3()") return Tag.span(self.cpt, Tag.Button("++", onclick=self.bind.add()), style="background:yellow;padding:10px")
def build(self): return Tag.text(self.compute(), self.stars( )) # <---- DANGEROUS the binded is str'ised at build !!!!