def on_complete(self, req): # if req.status == 200: datas = js.JSON.parse(req.text) for data in datas: # print(data) # document[f"state-{data['camera_id']}"].text = data['state'] i = html.I() data_id = data["camera_id"] + "/" + data["project_id"] if data["state"] in ["running", "start"]: i.class_name = "ui green circle icon big" s = html.SPAN(style={"color": "green"}) self.disable_button(document.select(".startlpr"), data_id) self.enable_button(document.select(".stoplpr"), data_id) elif data["state"] in ["starting"]: i.class_name = "ui yellow circle icon big" s = html.SPAN(style={"color": "yellow"}) self.disable_button(document.select(".stoplpr"), data_id) self.enable_button(document.select(".startlpr"), data_id) elif data["state"] in ["stop"]: i.class_name = "ui grey circle icon big" s = html.SPAN(style={"color": "grey"}) self.disable_button(document.select(".stoplpr"), data_id) self.enable_button(document.select(".startlpr"), data_id) elif data["state"] in ["stopping"]: i.class_name = "ui red circle icon big" s = html.SPAN(style={"color": "red"}) self.disable_button(document.select(".stoplpr"), data_id) self.enable_button(document.select(".startlpr"), data_id) s <= data["state"].capitalize() document[f"state-{data['camera_id']}"].text = "" document[f"state-{data['camera_id']}"] <= i + s
def drop(self, ev): """Function attached to the destination zone. Describes what happens when the object is dropped, ie when the mouse is released while the object is over the zone. """ # retrieve data stored in drag_start (the draggable element's id) src = ev.dataTransfer.getData("text") camera = document[src] camera_id, url = src.split("-") display = document[ev.target.id] display.attrs["drop-active"] = False try: document[f"img-{src}"].unbind("dragstart") document[f"img-{src}"].parent.clear() except Exception as e: pass img = html.IMG( id=f"img-{src}", src=url, ) btn = html.A( Class="clear-btn icon rightbottom ui inverted red button circular", ) trash_icon = html.I(Class="trash icon") btn <= trash_icon display.clear() display <= img display <= btn img.draggable = True btn.bind("click", self.clear_display) img.bind("dragstart", self.dragstart_img) ev.preventDefault()
def __init__(self): # Create a shadow root shadow = self.attachShadow({'mode': 'open'}) # Insert the value of attribute "data-val" in bold italic # in the shadow root shadow <= html.B(html.I(self.attrs['data-val']))
def show_results(self): """ show table of results""" doc['container'].clear() doc['container'] <= html.DIV( 'Browser Version: %s' % window.navigator.userAgent) _v = sys.implementation.version doc['container'] <= html.DIV('Brython Version: %s.%s.%s' % (_v.major, _v.minor, _v.micro)) doc['container'] <= html.DIV( 'Brython debug mode: %s' % sys.brython_debug_mode) doc['container'] <= html.DIV( 'CPython Version: %s' % self.cpython_version) doc['container'] <= html.P(html.I('Results are in milliseconds (ms)')) _table = html.TABLE() _tr = html.TR() _tr <= html.TH('Benchmark') _tr <= html.TH('Code') _tr <= html.TH('Brython') _tr <= html.TH('CPython') _tr <= html.TH('Difference') _tr <= html.TH('X Faster') _table <= _tr for _filename in self._timings.keys(): _tr = html.TR() _tr <= html.TD(_filename) _tr <= html.TD( highlight.highlight(self._timings[_filename]['code'])) for _platform in ('brython', 'cpython'): _tr <= html.TD('%5.0f' % self._timings[_filename][_platform], style={'text-align': 'right'}) _diff = self._timings[_filename]['cpython'] - self._timings[ _filename]['brython'] _x = self._timings[_filename]['cpython'] / self._timings[ _filename]['brython'] if _x > 1: _color = "green" elif _x < 0.5: _color = "red" else: _color = "black" _tr <= html.TD('%5.0f' % _diff, style={'text-align': 'right'}) _tr <= html.TD('%4.2f' % _x, style={ 'color': _color, 'text-align': 'right' }) _table <= _tr doc['container'] <= _table
def create_error_message(): gui = document["main-display"] errorMessage = html.DIV(id="error-message", Class="alert alert-warning alert-dismissible") errorMessage.text = "Case vide ou votre coup affame l'adversaire, choisissez une autre case." closeBtn = html.BUTTON(Class="close", data_dismiss="alert", aria_label="close") span = html.SPAN(aria_hidden="true") x = html.I(Class="fa fa-times") span <= x closeBtn <= span errorMessage <= closeBtn gui <= errorMessage
def create_end_message(rslt): # div pour montrer qui a gagné gui = document["main-display"] endMessage = html.DIV(id="end-message", Class="alert alert-danger alert-dismissible") if isinstance(rslt, Human): endMessage.text = "Vous avez gagné ! " + "IA : " + str(t.game.player1.loft) + " Vous: " + str(t.game.player0.loft) elif isinstance(rslt, AI): endMessage.text = "L'ordinateur gagne ! " + "IA : " + str(t.game.player1.loft) + " Vous: " + str(t.game.player0.loft) closeBtn = html.BUTTON(Class="close", data_dismiss="alert", aria_label="close") span = html.SPAN(aria_hidden="true") x = html.I(Class="fa fa-times") newGameBtn = html.BUTTON(Class="btn ml-3 mr-auto", id="newgame", onclick="showSettings()", data_dismiss="alert") newGameBtn.text = "Nouvelle partie" span <= x closeBtn <= span endMessage <= closeBtn endMessage <= newGameBtn gui <= endMessage
def update_state(self, req_data): for data in req_data: print(data) # document[f"state-{data['camera_id']}"].text = data['state'] data_id = data["camera_id"] + "/" + data["project_id"] i = html.I() color = "grey" if data["state"] in ["running", "start"]: color = "green" s = html.SPAN(style={"color": "green"}) if "video-recorder" in data["type"]: self.disable_button(document.select(".start-recorder"), data_id) self.enable_button(document.select(".stop-recorder"), data_id) else: self.disable_button(document.select(".stop-recorder"), data_id) self.enable_button(document.select(".start-recorder"), data_id) elif data["state"] in ["starting"]: color = "yellow" s = html.SPAN(style={"color": "yellow"}) if "video-recorder" in data["type"]: self.disable_button(document.select(".stop-recorder"), data_id) self.enable_button(document.select(".start-recorder"), data_id) elif data["state"] in ["stop"]: color = "grey" s = html.SPAN(style={"color": "grey"}) # if "video-recorder" in data["type"]: # document.select(".stop-recorder")[ # 0 # ].className = "ui button stop-recorder" self.disable_button(document.select(".stop-recorder"), data_id) self.enable_button(document.select(".start-recorder"), data_id) elif data["state"] in ["stopping"]: color = "red" s = html.SPAN(style={"color": "red"}) # if "video-recorder" in data["type"]: self.disable_button(document.select(".stop-recorder"), data_id) self.enable_button(document.select(".start-recorder"), data_id) i.class_name = f"ui {color} circle icon {self.icon_size}" label = html.DIV(data["state"].capitalize(), Class=f"ui {color} large label", styles={}) label.style = {"width": "6rem", "text-align": "center"} try: document[f"state-{data['camera_id']}"].text = "" document[f"state-{data['camera_id']}"].clear() streamer_icon = html.I() streamer_icon.class_name = "inverted grey chromecast icon big" recorder_icon = html.I() recorder_icon.class_name = "inverted grey record vinyl icon big" acquisitor_icon = html.I() acquisitor_icon.class_name = "inverted grey video icon big" if self.type == "text": document[f"state-{data['camera_id']}"] <= label if "video-streamer" in data["type"]: streamer_icon.class_name = "inverted green chromecast icon big" if "video-recorder" in data["type"]: recorder_icon.class_name = ( "inverted green record vinyl icon big") if "acquisitor" in data["type"]: acquisitor_icon.class_name = "inverted green video icon big" # label_type = html.DIV( # processor_type.capitalize(), Class=f"ui {color} large label" # ) document[f"state-{data['camera_id']}"] <= recorder_icon document[f"state-{data['camera_id']}"] <= streamer_icon document[f"state-{data['camera_id']}"] <= acquisitor_icon elif self.type == "circle": document[f"state-{data['camera_id']}"] <= i + s except Exception: continue
def detail_employee(ev): global response if response is not None: test = eval(ev.target.id) if isinstance(test, int): div = html.DIV(Class="w3-animate-left") div1 = html.DIV(Class="w3-border-bottom w3-bar w3-animate-left") i = html.I(Class="fa fa-angle-left w3-xxxlarge w3-text-cyan", id="back1") a = html.A(Class="w3-bar-item",id="back", style={"width": "10%"}) a <= i h1 = html.H1("Employee Details", Class="w3-wide w3-myfont w3-xlarge w3-bar-item w3-center", style={"width": "90%"}) div1 <= a + h1 for x in response['employee']: ul = html.UL(Class="w3-ul w3-border w3-animate-left") if x['id'] == int(ev.target.id): li = html.LI(Class="w3-bar") img = html.IMG(Class="w3-bar-item w3-circle", src="img/img_avatar2.png", style={"width":"85px"}) #first li div2 = html.DIV(Class="w3-bar-item") span1 = html.SPAN(x['full_name']) + html.BR() span2 = html.SPAN(x['job']) div2 <= span1 + span2 li <= img + div2 #second li li2= html.LI(Class="w3-bar w3-button w3-hover-cyan",id="office") div3 = html.DIV(Class="w3-bar-item") span3 = html.SPAN("Call Office") + html.BR() span4 = html.SPAN("781-000-002") a1 = html.A(href="tel:781-000-002",id="number" ,style={"display":"none"}) span = html.SPAN(html.I(Class="fa fa-angle-right w3-xxlarge"), Class="w3-right w3-bar-item") div3 <= span3 + span4 + a1 li2 <= span + div3 #third li li3 = html.LI(Class="w3-bar w3-button w3-hover-cyan", id="call") div4 = html.DIV(Class="w3-bar-item") span5 = html.SPAN("Call Mobile") + html.BR() span6 = html.SPAN("615-000-002", href="tel:615-000-002") a2 = html.A(href="tel:615-000-002",id="mobile" ,style={"display":"none"} ) spanbis = html.SPAN(html.I(Class="fa fa-angle-right w3-xxlarge"), Class="w3-right w3-bar-item") div4 <= span5 + span6 + a2 li3 <= spanbis + div4 # fourth li li4 = html.LI(Class="w3-bar w3-button w3-hover-cyan", id="sms") div5 = html.DIV(Class="w3-bar-item") span7 = html.SPAN("Number Sms") + html.BR() span8 = html.SPAN("615-000-002", href="tel:615-000-002") a3 = html.A(href="sms:615-000-002", id="sendsms", style={"display": "none"}) spanbis1 = html.SPAN(html.I(Class="fa fa-angle-right w3-xxlarge"), Class="w3-right w3-bar-item") div5 <= span7 + span8 + a3 li4 <= spanbis1 + div5 #five li li5 = html.LI(Class="w3-bar w3-button w3-hover-cyan", id="email") div6 = html.DIV(Class="w3-bar-item") span9 = html.SPAN("Email Professional") + html.BR() span10 = html.SPAN("*****@*****.**",href="mailto:[email protected]") a4 = html.A(href="mailto:[email protected]", id="sendemail",style={"display": "none"}) spanbis1 = html.SPAN(html.I(Class="fa fa-angle-right w3-xxlarge"), Class="w3-right w3-bar-item") div6 <= span9 + span10 + a4 li5 <= spanbis1 + div6 #end ul <= li + li2 + li3 + li4 +li5 retail <= div1 + html.BR() + ul doc['detail'].bind("click", direction) return retail
# issue 1384 class A(html.DIV): def __init__(self, s): self.myattr = s x = A("Andy") assert x.myattr == "Andy" del x.myattr assert not hasattr(x, "myattr") try: del x.attrs raise Exception("should have raised AttributeError") except AttributeError: pass class B(svg.line): def __init__(self, s): self.myattr = s y = B("Didier") assert y.myattr == "Didier" del y.myattr assert not hasattr(y, "myattr") # chained insertions html.P() <= html.B() <= html.I("coucou")
def requComplete(request): global unitdict unitdict = JSON.parse(request.responseText) code = 'en' document['privatebrowsing'].style.display = 'none' toolbar = html.DIV(id='toolbar', Class='container-fluid mx-3 mb-1') document <= toolbar langbar = html.DIV(id="langbar", Class="btn-group btn-group-toggle px-3", data_toggle="buttons", role="group", aria_label="Select language") langlabel = html.BUTTON(Class='btn-secondary rounded-left', disabled=True) langtext = document.createTextNode('Select language: ') langlabel <= langtext langbar <= langlabel toolbar <= langbar filestatus = html.I(Class='icon ion-md-checkmark-circle ml-3') filestatus.style.display = 'none' docbar = html.DIV(id='docbar', Class='btn-group px-3') doclabel = html.BUTTON(Class='btn-secondary rounded-left', disabled=True) doctext = document.createTextNode('Select file: ') doclabel <= doctext docbar <= doclabel toolbar <= docbar choosefile = html.INPUT(type='file', Class='btn btn-outline-primary') docbar <= choosefile buttonrun = html.BUTTON(id='buttonrun', Class='btn btn-primary px-3') buttontext = document.createTextNode('Show moogles!') buttonrun <= buttontext toolbar <= buttonrun toolbar <= filestatus