def populatebox(self, request): folderlist, filelist = request.text.strip().split(chr(30)) self.folderlist = folderlist.split(chr(31)) self.filelist = filelist.split(chr(31)) if self.extlist: self.filelist = [ filename for filename in self.filelist if filename.split(".")[-1] in self.extlist ] self.filelistbox.text = "" if len(self.path) > 1: upalevel = html.LI("[Up a level]", Class="parentfolder") upalevel.bind("dblclick", self.onupdoubleclick) self.filelistbox <= upalevel self.filelistbox <= (html.LI(x, Class="foldername") for x in self.folderlist) self.filelistbox <= (html.LI(x, Class="filename") for x in self.filelist) for item in self.filelistbox.select("li"): item.bind("click", self.onitemclick) for item in self.filelistbox.select("li.foldername"): item.bind("dblclick", self.onfolderdoubleclick) for item in self.filelistbox.select("li.filename"): item.bind("dblclick", self.onfiledoubleclick)
def __init__(self, todos, filter): count = len([todo for todo in todos if not todo.completed]) item_text = 'item' if count == 1 else 'items' super().__init__( [ H.SPAN( [ H.STRONG(count), ' {} left'.format(item_text), ], Class='todo-count', ), H.UL( [ H.LI( FilterLink('All', filter=ALL_FILTER, current_filter=filter), ), H.LI( FilterLink('Active', filter=ACTIVE_FILTER, current_filter=filter), ), H.LI( FilterLink('Completed', filter=COMPLETED_FILTER, current_filter=filter), ), ], Class='filters', ), ClearCompletedButton(todos), ], Class='footer', style={'display': 'block' if len(todos) else 'none'}, )
def update_saves(): saves = json.loads(storage["saves"]) dropdown = doc["load-dropdown"] dropdown.innerHTML = "" for s in saves: link = html.A(s, href='#', onclick="load_buffer('{}')".format(s)) dropdown <= html.LI(link)
async def asker(a, b): # Present the choices as a list with buttons. global n_questions n_questions += 1 buttons = {} def button(the_id, text): buttons[the_id] = lambda _: signal('choice', the_id) return H.BUTTON(T(text), id = the_id) def display_item(item): # Display the item as a list with one criterion and value # per list item. Highlight the criteria value that differ # between the two options. return H.UL([ H.LI([T(name + ': '), (T(value) if a[i] == b[i] else H.STRONG(T(value)))]) for i, (name, value) in enumerate(zip(criterion_names, item))]) document['dm'] <= H.DIV( [H.P(T('Q{}: Which would you prefer?'.format(n_questions))), H.UL([ H.LI([button('option_a', 'Option A'), display_item(a)]), H.LI([button('option_b', 'Option B'), display_item(b)]), H.LI([button('equal', 'Equal'), T('The two options are equally preferable')])])], Class = 'query') for button, callback in buttons.items(): document[button].bind('click', callback) # Wait for the user to click a button. choice = await get_signal('choice') if choice == 'quit': raise Quit() # Replace the buttons with indicators of the user's decision. for button in buttons: document[button].replaceWith(H.SPAN( T('your choice' if button == choice else 'not chosen'), Class = 'chosen' if button == choice else 'not-chosen')) # Return the choice. return dict(option_a = GT, option_b = LT, equal = EQ)[choice]
def add_item(self, name, callback=None): if self.parent is None: # First level li = html.LI(name, style=li_style1, Class="top") else: # Next levels li = html.LI(name, style=li_style2, Class="sub") self.panel <= li if callback is not None: def f(ev): for div in document.select(".submenu"): div.style.display = "none" ev.stopPropagation() ev.preventDefault() return callback(ev) li.bind("click", f) return li
def display_item(item): # Display the item as a list with one criterion and value # per list item. Highlight the criteria value that differ # between the two options. return H.UL([ H.LI([T(name + ': '), (T(value) if a[i] == b[i] else H.STRONG(T(value)))]) for i, (name, value) in enumerate(zip(criterion_names, item))])
def add_exercises(self, source, id): """Attach exercises to this editor component.""" self.exercises = source self.exercise_items = [] triple_quoted = TRIPLE_QUOTES_RE.findall(source) for docstring in triple_quoted: lines = docstring.strip().splitlines() mk, scripts = markdown.mark('\n'.join(ln.strip() for ln in lines)) img = '<img alt="Unsolved" src="static/svg/unsolved.svg">' item = html.LI(**{'class': 'exercise'}) item.html = img + window.twemoji.parse(mk) document[id] <= item self.exercise_items.append(item)
def render(self): app = group(html.DIV(), [ html.H1("HI THERE!"), html.H2("GOOD TO SEE YOU!"), html.P("Some things about me:"), html.UL([html.LI("I am"), html.LI("Does this work")]), html.H2("here is a nice little ticker"), TickerWithDescription().render(), TextField("here is a prop being passed").render() ]) return app # app = html.DIV(id="hithere") # # app <= html.H1("hi there", id="what") # thing = group(app, [WithGroups().render()]) # # thing = app # document["root"] <= thing # thid = document["hithere"] # thid.innerHTML = "hedy" # print(document.getElementById("hithere").innerHTML) # document["what"] <= html.H1("buy")
def refresh_UI(new_app_info): global app_info, current_activity, data_hub, user_info user, session_code, app, app_secret = user_info window.set_user_name(user) window.user_info = '' if app in ('me', 'ui', 'elt') and user != '': window.user_info = JSON.stringify({ 'user': user, 'session_code': session_code, 'app': app, 'app_secret': app_secret }) document["login"].hidden = (user == '') document["logout"].hidden = (user != '') for activity in app_info['activities']: document['nav-' + activity['id']].unbind('click') document["main-nav"].clear() app_info.update(new_app_info) for activity in app_info['activities']: a = html.A(activity['name'], **{ 'id': 'nav-' + activity['id'], 'class': 'nav-link' }) li = html.LI(a, **{'class': 'nav-item'}) document["main-nav"] <= li a.bind('click', lambda ev: show_activity(ev.target.id)) document["main"].clear() client = user_info[0] data_hub = DataHub(client if app_info['app'] == 'db' else '', True) for i, activity in enumerate(app_info['activities']): page = html.DIV(**{'id': 'page-' + activity['id']}) document["main"] <= page if activity['ui_json'] == '': pass else: make_ui(JSON.parse(activity['ui_json']), page, data_hub) page.style.display = 'none' if len(app_info['activities']) > 0: current_activity = None show_activity('nav-' + app_info['activities'][0]['id']) data_hub.onevent('', '', '') else: window.hide_spinner_modal()
def gen_li(item, level=''): item_title = HTML.A(item['show'], href=item['url']) item_text1 = HTML.DIV('展馆:{}'.format(item['name']), Class='am-list-item-text') time_text = HTML.SPAN('时间:{}-{}'.format(item['start'], item['end']), Class=level) item_text2 = HTML.DIV('', Class='am-list-item-text') item_text2 <= time_text item_text3 = HTML.DIV('展厅:{}'.format(item['hall']), Class='am-list-item-text') item_text4 = HTML.DIV('地址:{}'.format(item['addr']), Class='am-list-item-text') list_item = HTML.LI('', Class='am-g am-list-item-desced') list_item <= item_title list_item <= item_text1 list_item <= item_text2 list_item <= item_text3 list_item <= item_text4 return list_item
def createMatchLi(self, result): def doClose(e): e.target.parent.parent.removeChild(e.target.parent) print("REMOVED", [ str(x.result) for x in [x for x in self.editorRow.children][:-1] ]) self.rebuildBatch() token = html.SPAN(result.token, Class="token") label = html.SPAN(str(result.obj), Class="label") close = html.SPAN("⨉", Class="close") close.bind("click", doClose) close.style.display = "none" li = html.LI([token, label, close]) li.result = result li.close = close return li
def employee_list(): global response try: response = urllib.request.urlopen("http://127.0.0.1:8001/employee/default/liste_employee.json") response = response.read() response = json.loads(response) li = html.UL(id="id01", Class="w3-ul w3-card-4") for x in response['employee']: ul = html.LI(Class="w3-bar",style={'display': "none"}) img = html.IMG(Class="w3-bar-item w3-circle", src="img/img_avatar2.png", style={"width":"85px"}) divbar = html.DIV(Class="w3-bar-item") a = html.A(x['full_name'],id=str(x['id']), href="#employee" + str(x['id'])) divbar <=a ul <= img + divbar li <= ul return li except: return html.DIV("We're sorry, server is busy", Class="w3-center w3-xxlarge w3-text-blue")
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
def anchor_in_list(name, href, attr=''): li = html.LI() anchor = html.A(name, attr=attr) anchor.href = href li <= anchor return li
# Toggle the class button = html.BUTTON("Toggle Largess") button.bind('click', lambda e: main.classList.toggle("huge")) main <= button # My favorite things favorites = [ "Programming", "Sweets", "Westworld", ] ul = html.UL([html.LI(fav) for fav in favorites]) main <= ul # Canvas import math canvas = html.CANVAS(width=200, height=200) canvas.style = dict(border="10px black", backgroundColor="white") ctx = canvas.getContext("2d") draw_button = html.BUTTON("Draw a circle") x = 50 @draw_button.bind("click")