def __init__(self, title="Frames inspector", rows=30, cols=84, default_css=True): frame = sys._getframe().f_back super().__init__(None, title, globals=frame.f_globals.copy(), locals=frame.f_locals.copy(), rows=rows, cols=cols, default_css=default_css) frames_sel = html.SELECT() self.frames = [] while frame: self.frames.append([frame.f_globals.copy(), frame.f_locals.copy()]) name = frame.f_code.co_name name = name.replace("<", "<").replace(">", ">") frames_sel <= html.OPTION(name) frame = frame.f_back frames_sel.bind("change", self.change_frame) frame_div = html.DIV("Frame " + frames_sel) panel_style = window.getComputedStyle(self.dialog.panel) frame_div.style.paddingLeft = panel_style.paddingLeft frame_div.style.paddingTop = panel_style.paddingTop self.dialog.insertBefore(frame_div, self.dialog.panel)
def test_browser_widgets_dialog(): from browser.widgets.dialog import InfoDialog # Info box with customized "Ok" button d1 = InfoDialog("Test", "Information message", ok="Got it") from browser.widgets.dialog import InfoDialog # Info box that disappears after 3 seconds d1 = InfoDialog("Test", "Closing in 3 seconds", remove_after=3) from browser import bind from browser.widgets.dialog import InfoDialog, EntryDialog d = EntryDialog("Test", "Name") @bind(d, "entry") def entry(ev): value = d.value d.close() InfoDialog("Test", f"Hello, {value} !") ## added entry(evt) from browser import bind, html from browser.widgets.dialog import Dialog, EntryDialog, InfoDialog translations = {'Français': 'Salut', 'Español': 'Hola', 'Italiano': 'Ciao'} d = Dialog("Test", ok_cancel=True) style = dict(textAlign="center", paddingBottom="1em") d.panel <= html.DIV("Name " + html.INPUT(), style=style) d.panel <= html.DIV( "Language " + html.SELECT(html.OPTION(k) for k in translations), style=style) # Event handler for "Ok" button @bind(d.ok_button, "click") def ok(ev): """InfoDialog with text depending on user entry, at the same position as the original box.""" language = d.select_one("SELECT").value prompt = translations[language] name = d.select_one("INPUT").value left, top = d.scrolled_left, d.scrolled_top d.close() d3 = InfoDialog("Test", f"{prompt}, {name} !", left=left, top=top) ## added translations[0] = "test" # mockbrython hashes to 0, avoid KeyError ok(evt)
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind( 'change', lambda ev: show_page( slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION( content[0], value=content[1], selected=page_num >= content[1]) slideshow.page_num = int(page_num) # store page num in a cookie document.cookie = "page={}".format(page_num) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if slideshow.title: footer <= html.DIV(slideshow.title, style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev: move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline wh = window.innerHeight footer.style.top = "{}px".format(int(wh * 0.9)) timeline.style.top = "{}px".format(int(wh * 0.85)) tl_pos.style.left = '%spx' % (timeline.width * page_num / len(slideshow.pages)) document["cours"].style.minHeight = "{}px".format(int(wh * 0.8)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' % int(0.7 * width) elt.bind('click', run_code)
def select_sheet(ev): names = sheet_names() names.sort() if names: d = ui.Dialog("Open sheet...") d.add_ok_cancel(ok=open_sheet) d.body <= html.SPAN('File', style=dict(marginRight='10px')) d.body <= html.SELECT(html.OPTION(name) for name in names) else: d = ui.Dialog("Error") d.body <= "No sheet found" document <= d
def __init__(self, title, prompt, options, action, _id=None): Dialog.__init__(self, _id) self.set_title(title) self.options = options self.action = action d_prompt = html.DIV(prompt, Class="ui-widget", style=dict(float="left", paddingRight="10px")) self.select = html.SELECT() for option in options: self.select <= html.OPTION(option) body = html.DIV(d_prompt + self.select, style={'padding': '15px'}) b_ok = html.BUTTON("Ok") b_ok.bind('click', self.ok) b_cancel = html.BUTTON("Cancel") b_cancel.bind('click', self.cancel) body += html.DIV(b_ok + b_cancel, style={'padding': '15px'}) self._div_dialog <= body
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind( 'change', lambda ev: show_page( slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION( content[0], value=content[1], selected=page_num >= content[1]) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if slideshow.title: footer <= html.DIV(slideshow.title, style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev: move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline tw = window.getComputedStyle(timeline).width tw = round(float(tw[:-2])) tl_pos.style.left = '%spx' % (tw * page_num / len(slideshow.pages)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' % int(0.7 * width)
def __init__(self): frame = sys._getframe().f_back Repl.__init__(self, title="Debugger", globals=frame.f_globals, locals=frame.f_locals) frames_sel = html.SELECT() self.frames = [] while frame: self.frames.append(frame) name = frame.f_code.co_name name = name.replace("<", "<").replace(">", ">") frames_sel <= html.OPTION(name) frame = frame.f_back frames_sel.bind("change", self.change_frame) frame_div = html.DIV("Frame " + frames_sel) panel_style = window.getComputedStyle(self.dialog.panel) frame_div.style.paddingLeft = panel_style.paddingLeft frame_div.style.paddingTop = panel_style.paddingTop self.dialog.insertBefore(frame_div, self.dialog.panel)
def draw_home2(): panel = document["main_panel"] table21 = html.TABLE() table21.style.fontSize = "large" table21.style.font = "16px verdana" tableBody21 = html.TBODY() #table22 = html.TABLE() #tableBody22 = html.TBODY() row21_1 = html.TR() #row21_2 = html.TR() table21.style.background = "#F7F7F7" table21.style.padding = "10px 25px 10px 10px" #table22.style.background = "#F7F7F7" #table22.style.padding = "10px 15px 10px 10px" label21 = html.LABEL("Search gene expressions by:") label21.style.verticalAlign = "center" label21.style.marginRight = "10px" td_1 = html.TD() td_1 <= label21 row21_1 <= td_1 op1 = html.OPTION("probe name") op2 = html.OPTION("gene name") sel2 = html.SELECT([op2, op1], id="select_probe_or_gene", font_size=16) sel2.style.fontSize = "large" sel2.style.verticalAlign = "center" sel2.style.marginRight = "20px" td_2 = html.TD() td_2 <= sel2 row21_1 <= td_2 inp21 = html.INPUT(id="input_probe_or_gene") inp21.style.verticalAlign = "center" inp21.style.marginRight = "0px" td_3 = html.TD() td_3 <= inp21 row21_1 <= td_3 global bSearch2 bSearch2 = html.BUTTON('Search') button_style_default(bSearch2) bSearch2.bind('click', click_search2) bSearch2.bind('mouseout', mouse_out_search2) bSearch2.bind('mouseover', mouse_over_search2) bSearch2.style.verticalAlign = "center" td_4 = html.TD() td_4 <= bSearch2 row21_1 <= td_4 #label22 = html.LABEL("Search gene expressions by gene name:") #label22.style.verticalAlign = "bottom" #label22.style.marginRight = "10px" #row21_2 <= label22 #inp22 = html.INPUT() #inp22.style.verticalAlign = "bottom" #inp22.style.marginRight = "0px" #row21_2 <= inp22 #global bSearch3 #bSearch3 = html.BUTTON('Search') #button_style_default(bSearch3) #bSearch3.bind('click', click_search3) #bSearch3.bind('mouseout', mouse_out_search3) #bSearch3.bind('mouseover', mouse_over_search3) #bSearch3.style.verticalAlign = "top" #row21_2 <= bSearch3 tableBody21 <= row21_1 #tableBody22 <= row21_2 table21 <= tableBody21 #table22 <= tableBody22 panel <= table21 panel <= html.BR() #panel <= table22 ############################################# table23 = html.TABLE() table23.style.font = "16px verdana" table23.style.background = "#F7F7F7" table23.style.padding = "20px 25px 20px 10px" tableBody23 = html.TBODY() row23_1 = html.TR() row23_2 = html.TR() row23_3 = html.TR() label23_1 = html.LABEL("Min sample size:") #label23_1.style.verticalAlign = "bottom" label23_1.style.marginRight = "10px" row23_1 <= label23_1 op21 = html.OPTION("5") op22 = html.OPTION("10") op23 = html.OPTION("15") op24 = html.OPTION("20") op25 = html.OPTION("25") sel23_1 = html.SELECT([op21, op22, op23, op24, op25], id="selector_min_sample_size", font_size=16) sel23_1.style.fontSize = "large" #sel23_1.style.verticalAlign = "bottom" sel23_1.style.marginRight = "50px" row23_1 <= sel23_1 #inp23_1 = html.INPUT() #inp23_1.style.verticalAlign = "bottom" #inp23_1.style.marginRight = "0px" #row23_1 <= inp23_1 label23_2 = html.LABEL("Max p-value:") label23_2.style.verticalAlign = "bottom" label23_2.style.marginRight = "10px" row23_1 <= label23_2 op31 = html.OPTION("1E-6") op32 = html.OPTION("1E-5") op33 = html.OPTION("1E-4") op34 = html.OPTION("1E-3") op35 = html.OPTION("0.005") op36 = html.OPTION("0.01") op37 = html.OPTION("0.02") op38 = html.OPTION("0.05") sel23_2 = html.SELECT([op38, op37, op36, op35, op34, op33, op32, op31], id="selector_max_pvalue", font_size=16) sel23_2.style.fontSize = "large" #sel23_1.style.verticalAlign = "bottom" sel23_2.style.marginRight = "50px" row23_1 <= sel23_2 #inp23_2 = html.INPUT() #inp23_2.style.verticalAlign = "bottom" #inp23_2.style.marginRight = "0px" #row23_1 <= inp23_2 label23_3 = html.LABEL("Max # results:") label23_3.style.verticalAlign = "bottom" label23_3.style.marginRight = "10px" row23_1 <= label23_3 op44 = html.OPTION("1000") op45 = html.OPTION("500") op46 = html.OPTION("300") op47 = html.OPTION("200") op48 = html.OPTION("100") sel23_3 = html.SELECT([op48, op47, op46, op45, op44], id="selector_max_num_results", font_size=16) sel23_3.style.fontSize = "large" #sel23_3.style.verticalAlign = "bottom" sel23_3.style.marginRight = "0px" row23_1 <= sel23_3 #inp23_3 = html.INPUT() #inp23_3.style.verticalAlign = "bottom" #inp23_3.style.marginRight = "0px" #row23_1 <= inp23_3 tableBody23 <= row23_1 #tableBody23 <= row23_2 #tableBody23 <= row23_3 table23 <= tableBody23 panel <= table23 panel <= html.BR()
def show_page(slideshow, zone, page_num): # if table of contents is not empty, add it if slideshow.contents: toc = html.SELECT(name="toc") toc.bind('change', lambda ev: show_page(slideshow, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in slideshow.contents: toc <= html.OPTION(content[0], value=content[1], selected=page_num>=content[1]) slideshow.page_num = int(page_num) # store page num in a cookie document.cookie = "page={}".format(page_num) zone.clear() body = html.DIV() body.html = markdown.mark(slideshow.pages[page_num])[0] if slideshow.contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if slideshow.title: footer <= html.DIV(slideshow.title,style=dict(display='inline')) if slideshow.show_page_num: footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev:move_to(ev, slideshow, zone)) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer +timeline wh = window.innerHeight footer.style.top = "{}px".format(int(wh * 0.9)) timeline.style.top = "{}px".format(int(wh * 0.85)) tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages)) document["cours"].style.minHeight = "{}px".format(int(wh * 0.8)) for elt in zone.get(selector='.python'): src = elt.text.strip() width = max(len(line) for line in src.split('\n')) width = max(width, 30) # replace element content by highlighted code elt.html = highlight.highlight(src).html elt.style.width = '%sem' %int(0.7*width) elt.bind('click', run_code) for elt in zone.get(selector='.python-console'): src = elt.text.strip() lines = src.split('\n') result = '' py = '' py_starts = [] for line in lines: if line.startswith('>>>') or line.startswith('...'): py += line[4:]+'\n' py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3])) else: if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] result += '\n' + line if py: colored = highlight.highlight(py).html colored_lines = colored.split('\n') if result: result += '\n' result += '\n'.join(start+' '+line for (start, line) in zip(py_starts, colored_lines)) py = '' py_starts = [] elt.html = result
table <= html.TR( html.TD(line[0]) + html.TD(line[1]) + html.TD(line[2]) + html.TD(line[3])) container <= table # 寶貝圖鑑輸入表 container <= html.DIV(html.H2('寶貝圖鑑輸入表'), Class="w3-container w3-blue w3-margin-top") form = html.FORM(Class="w3-container w3-border") form <= html.DIV( html.LABEL('中文名') + html.INPUT(type="text", name="firstname", value="", Class="w3-input")) form <= html.DIV( html.LABEL('最大CP') + html.INPUT(type="number", name="最大CP", value="", Class="w3-input")) label3 = html.LABEL('屬性') input3 = html.SELECT(Class="w3-select") for option in ['...', '草、毒', '火', '水']: input3 <= html.OPTION(option) form <= html.DIV(label3 + input3) form <= html.P(html.BUTTON("上傳", Class="w3-button w3-red")) container <= form # 畫布 Html Canvas container <= html.DIV(html.H2('Html Canvas'), Class="w3-container w3-blue w3-margin-top") canvas = html.CANVAS(width=300, height=100) canvas.style = {"width": "100%"} ctx = canvas.getContext("2d") x = 20
def spellEdit(spell : str) -> dialog.Dialog: def toggleDamage(event): for i in d.select(".damage"): if event.target.checked: del i.attrs["readonly"] else: i.attrs["readonly"] = '' d = dialog.Dialog(spell, ok_cancel = True, default_css = False) d.panel <= html.LABEL("Spell Name:", For = "name") d.panel <= html.INPUT(id = "name", Class = "dialogName") d.panel <= html.BR() d.panel <= html.LABEL("Spell Description:", For = "description") d.panel <= html.INPUT(id = "description") d.panel <= html.BR() d.panel <= html.LABEL("Spell Level:", For = "level") d.panel <= html.INPUT(id = "level", type = "number", min = 0, max = 9, value = 0) d.panel <= html.LABEL("Spell School:", For = "school") spellSchool = html.SELECT(id = "school", name = "school") for school in ( "abjuration", "conjuration", "divination", "enchantment", "evocation", "illusion", "necromancy", "transmutation" ): spellSchool <= html.OPTION(school.capitalize(), value = school) d.panel <= spellSchool d.panel <= html.BR() d.panel <= html.LABEL("Spell Range (Measure, Unit):", For = "rangeMeasure") d.panel <= html.INPUT(id = "rangeMeasure", type = "number", min = 0, value = 0) rangeUnit = html.SELECT(id = "rangeUnit", name = "rangeUnit") for unit in ("feet", "touch", "self"): rangeUnit <= html.OPTION(unit.capitalize(), value = unit) d.panel <= rangeUnit d.panel <= html.BR() d.panel <= html.P( "For touch and non-AoE self ranges, leave the Measure field at 0." ) d.panel <= html.BR() d.panel <= html.LABEL("Spell Casting Time (Measure, Unit):", For = "castingMeasure") d.panel <= html.INPUT(id = "castingMeasure", type = "number", min = 1, value = 1) castingUnit = html.SELECT(id = "castingUnit", name = "castingUnit") for unit in ("bonus Action", "action", "minutes", "hours"): castingUnit <= html.OPTION(unit.capitalize(), value = unit) d.panel <= castingUnit d.panel <= html.BR() d.panel <= html.LABEL("Spell Duration (Measure, Unit):", For = "durationMeasure") d.panel <= html.INPUT(id = "durationMeasure", type = "number", min = 0, value = 0) durationUnit = html.SELECT(id = "durationUnit", name = "durationUnit") for unit in ( "days", "hours", "minutes", "rounds", "days, Concentration", "hours, Concentration", "minutes, Concentration", "rounds, Concentration", "instantaneous", "until Dispelled", "special" ): durationUnit <= html.OPTION(unit.capitalize(), value = unit) d.panel <= durationUnit d.panel <= html.BR() d.panel <= html.P( "For instantaneous, until dispelled, or special durations, leave the Measure field at 0." ) d.panel <= html.BR() d.panel <= html.LABEL("Does Damage?", For = "damageCheckbox") damageCheckbox = html.INPUT(id = "damageCheckbox", type = "checkbox") damageCheckbox.bind("change", toggleDamage) d.panel <= damageCheckbox d.panel <= html.BR() d.panel <= html.LABEL("Damage Dice Count:", For = "damageCount") d.panel <= html.INPUT( id = "damageCount", Class = "damage", type = "number", min = 1, value = 1, readonly = '' ) d.panel <= html.LABEL("Damage Dice Value:", For = "damageDie") d.panel <= html.INPUT( id = "damageDie", Class = "damage", type = "number", min = 4, value = 4, readonly = '' ) d.panel <= html.BR() d.panel <= html.LABEL("Damage Type:", For = "damageType") d.panel <= html.INPUT(id = "damageType", Class = "damage", readonly = '') return d
def show(language=None): """Detect language, either from the key "lang" in the query string or from the browser settings.""" has_req = False qs_lang = None tuto_language = None prefix = "/" if language is None: qs_lang = document.query.getfirst("lang") # query string if qs_lang and qs_lang in ["en", "fr", "es"]: has_req = True language = qs_lang elif addr.startswith("gallery"): elts = addr.split("/") if len(elts) > 1: elt1 = elts[1].split(".")[0].split("_") if len(elt1) == 2: language = elt1[1] else: lang = __BRYTHON__.language # browser setting lang = lang.split('-')[0] if lang in ["en", "fr", "es"]: language = lang if addr.startswith("static_tutorial"): elts = addr.split("/") if len(elts) > 1: tuto_language = elts[1] if tuto_language in ["en", "fr", "es"]: language = tuto_language language = language or "en" _banner = document["banner_row"] loc = window.location.href current = None for key in ["home", "console", "demo", "editor", "groups"]: if links[key] in loc: current = key break if current is None: if "gallery" in loc: current = "gallery" elif "static_doc" in loc: current = "doc" def load_page(key): def f(e): href = links[key].format(language=language) window.location.href = href + f"?lang={language}" return f menu = Menu(_banner, default_css=False) menu.add_link(trans_menu["menu_tutorial"][language], href=links["tutorial"].format(language=language)) menu.add_link(trans_menu["menu_demo"][language], href=links["demo"] + f"?lang={language}") menu.add_link(trans_menu["menu_doc"][language], href=links["doc"].format(language=language)) menu.add_link(trans_menu["menu_console"][language], href=links["console"] + f"?lang={language}") menu.add_link(trans_menu["menu_editor"][language], href=links["editor"] + f"?lang={language}") menu.add_link(trans_menu["menu_gallery"][language], href=links["gallery"].format(language=language)) ex_resources = menu.add_menu(trans_menu["menu_resources"][language]) ex_resources.add_link(trans_menu["menu_download"][language], href=links["download"]) ex_resources.add_link(trans_menu["menu_dev"][language], href=links["dev"]) ex_resources.add_link(trans_menu["menu_groups"][language], href=links["groups"]) # insert language selection menu sel_lang = html.DIV(Class="sel_lang") document.body.insertBefore(sel_lang, _banner.nextElementSibling) select = html.SELECT(Class="language") sel_lang <= select selected_lang = tuto_language or language for lang1, lang2 in languages: select <= html.OPTION( lang2, value=lang1, selected=lang1 == selected_lang) @bind(select, "change") # If user changes the language in the select box, reload the page. def change_language(ev): sel = ev.target new_lang = sel.options[sel.selectedIndex].value head = f"{protocol}://{host}" new_href = href if addr.startswith("index.html") or addr == "": new_href = f"{head}/index.html?lang={new_lang}" elif addr.startswith(("static_tutorial", "static_doc")): elts = addr.split("/") elts[1] = new_lang new_href = f"{head}/{'/'.join(elts)}" elif addr.startswith("gallery"): new_href = links["gallery"].format(language=new_lang) elif addr.startswith( ("demo.html", "tests/console.html", "tests/editor.html")): elts = addr.split("?") new_href = f"{head}/{elts[0]}?lang={new_lang}" document.location.href = new_href return qs_lang, language
def show(path, zone, page_num=0): src = open(path).read() title = '' show_page_num = False # table of contents : matches matter with page number contents = [] # directives for the document while src.startswith('@'): line_end = src.find('\n') key, value = src[:line_end].split(' ', 1) if key == '@title': title = value elif key == '@pagenum': show_page_num = True elif key == "@index": contents.append([value, 0]) src = src[line_end + 1:] zone.html = '' pages = src.split('../..\n') # table of contents for num, _page in enumerate(pages): if num == 0: continue if _page.startswith('@index'): line_end = _page.find('\n') key, value = _page[:line_end].split(' ', 1) contents.append([value, num]) pages[num] = _page[line_end + 1:] if page_num < 0: page_num = 0 elif page_num >= len(pages): page_num = len(pages) - 1 doc.unbind('keydown') doc.bind('keydown', lambda ev: keydown(ev, path, zone, page_num)) # if table of contents is not empty, add it if contents: toc = html.SELECT(name="toc") toc.bind( 'change', lambda ev: show( path, zone, int(ev.target.options[ev.target.selectedIndex].value))) for content in contents: toc <= html.OPTION( content[0], value=content[1], selected=page_num >= content[1]) body = html.DIV() body.html = markdown.mark(pages[page_num])[0] if contents: body = html.DIV(toc + body) footer = html.DIV(Id="footer") if title: footer <= html.DIV(title, style=dict(display='inline')) if show_page_num: footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(pages)), style=dict(display='inline')) timeline = html.DIV(Id='timeline') tl_pos = html.DIV(Id='tl_pos') timeline <= tl_pos timeline.bind('click', lambda ev: move_to(ev, path, zone, len(pages))) tl_pos.bind('click', click_on_tl_pos) zone <= body + footer + timeline tl_pos.style.left = '%spx' % (timeline.width * page_num / len(pages))
def show(language=None): """Detect language, either from the key "lang" in the query string or from the browser settings.""" has_req = False qs_lang = None prefix = "/" if language is None: qs_lang = document.query.getfirst("lang") # query string if qs_lang and qs_lang in ["en", "fr", "es"]: has_req = True language = qs_lang else: lang = __BRYTHON__.language # browser setting if lang in ["en", "fr", "es"]: language = lang language = language or "en" _banner = document["banner_row"] loc = window.location.href current = None for key in ["home", "console", "demo", "editor", "groups"]: if links[key] in loc: current = key break if current is None: if "gallery" in loc: current = "gallery" elif "static_doc" in loc: current = "doc" def load_page(key): def f(e): href = links[key].format(language=language) window.location.href = href + f"?lang={language}" return f menu = Menu(_banner) home = menu.add_item("brython", callback=load_page("home")) home.attrs["class"] = "logo" menu.add_item(trans_menu["menu_console"][language], callback=load_page("console")) menu.add_item(trans_menu["menu_editor"][language], callback=load_page("editor")) docs_menu = menu.add_menu(trans_menu["menu_doc"][language]) docs_menu.add_item(trans_menu["menu_tutorial"][language], callback=load_page("tutorial")) docs_menu.add_item(trans_menu["menu_ref"][language], callback=load_page("ref")) ex_menu = menu.add_menu(trans_menu["menu_ex"][language]) ex_menu.add_item(trans_menu["menu_demo"][language], callback=load_page("demo")) ex_menu.add_item(trans_menu["menu_gallery"][language], callback=load_page("gallery")) ex_resources = menu.add_menu(trans_menu["menu_resources"][language]) ex_resources.add_item(trans_menu["menu_download"][language], callback=load_page("download")) ex_resources.add_item(trans_menu["menu_dev"][language], callback=load_page("dev")) ex_resources.add_item(trans_menu["menu_groups"][language], callback=load_page("groups")) # insert language selection menu sel_lang = html.DIV(Class="sel_lang") document.body.insertBefore(sel_lang, _banner.nextElementSibling) select = html.SELECT(Class="language") sel_lang <= select for lang1, lang2 in [["en", "English"], ["fr", "Français"], ["es", "Español"]]: select <= html.OPTION(lang2, value=lang1, selected=lang1==language) @bind(select, "change") # If user changes the language in the select box, reload the page. def change_language(ev): sel = ev.target new_lang = sel.options[sel.selectedIndex].value head = f"{protocol}://{host}" new_href = href if addr.startswith("index.html"): new_href = f"{head}/index.html?lang={new_lang}" elif addr.startswith(("static_tutorial", "static_doc")): elts = addr.split("/") page = elts[-1].split("?")[0] elts[1] = new_lang new_href = f"{head}/{elts[0]}/{new_lang}/{page}" elif addr.startswith(("demo.html", "tests/console.html", "tests/editor.html")): elts = addr.split("?") new_href = f"{head}/{elts[0]}?lang={new_lang}" document.location.href = new_href return qs_lang, language
from browser import doc, alert, html def echo(ev): alert(doc["input_zone"].value) # 在設定物件連結之前, 要先有物件設定, 因此將 button 放在這裡 doc <= html.BUTTON("顯示 alert 的按鈕", id="alert_button") # 連結 alert_button 與 echo 函式, 按下按鈕會執行 echo 函式 doc['alert_button'].bind('click', echo) # 顯示輸入欄位 doc <= html.BR() + '輸入:' + html.INPUT(id='input_zone') # 多重選項 items = ['one', 'two', 'three'] sel = html.SELECT() for i, elt in enumerate(items): sel <= html.OPTION(elt, value=i) doc <= sel
def draw_home1(): panel = document["main_panel"] table0 = html.TABLE() tableBody0 = html.TBODY() row0 = html.TR() b21 = html.P(id="status_indicator") #b21.text = "READY" #b21.style.verticalAlign = "bottom" #b21.style.marginRight = "40px" #g21.style.background = "#3366FF" #g21.style.color = "#FFEE00" #b21.style.background = "#55FF55" #b21.style.width = "120px" #b21.style.textAlign = "center" #b21.style.padding = "10px 0px 10px 0px" #b21.style.font = "16px verdana" #b21.style.border = "thin solid green" td01 = html.TD() td01 <= b21 row0 <= td01 head = html.LABEL("GeneXpresso - analyze DNA microarray datasets") head.style.font = "30px verdana" head.style.textAlign = "center" td02 = html.TD() td02 <= head row0 <= td02 tableBody0 <= row0 table0 <= tableBody0 panel <= table0 panel <= html.BR() status_indicator_ready(0) table1 = html.TABLE() table1.style.border = "none" table1.style.fontSize = "large" table1.style.background = "#F7F7F7" #table1.style.marginLeft = "50px" #b.style.marginTop = "30px" # table1.style.padding = "10px 20px 10px 10px" table1.style.font = "16px verdana" tableBody1 = html.TBODY() g1 = html.TR() g11 = html.LABEL("Search datasets by keyword:") g11.style.verticalAlign = "bottom" g11.style.marginRight = "10px" td_1 = html.TD() td_1 <= g11 g1 <= td_1 g12 = html.INPUT(id="g12") g12.style.verticalAlign = "bottom" g12.style.marginRight = "20px" td_2 = html.TD() td_2 <= g12 g1 <= td_2 g13 = html.LABEL("Search in:") g13.style.verticalAlign = "bottom" g13.style.marginRight = "10px" td_3 = html.TD() td_3 <= g13 g1 <= td_3 op1 = html.OPTION("title") op2 = html.OPTION("description") op3 = html.OPTION("dataset ID") op4 = html.OPTION("pubmed ID") op5 = html.OPTION("gene") op6 = html.OPTION("probe") sel1 = html.SELECT([op1, op2, op3, op4, op5, op6], id="selector1", font_size=12) sel1.style.fontSize = "large" sel1.style.verticalAlign = "bottom" td_4 = html.TD() td_4 <= sel1 g1 <= td_4 global bSearch1 bSearch1 = html.BUTTON('Search') button_style_default(bSearch1) #bSearch1.bind('click', click_search1) bSearch1.bind('mouseout', mouse_out_search1) bSearch1.bind('mouseover', mouse_over_search1) bSearch1.style.verticalAlign = "top" bSearch1.bind('click', datasets_by_keyword_search) td_5 = html.TD() td_5 <= bSearch1 g1 <= td_5 tableBody1 <= g1 table1 <= tableBody1 panel <= table1 panel <= html.BR()
def draw_home_samples(sample1, sample2): panel = document["main_panel"] table = html.TABLE() table.style.fontSize = "large" table.style.font = "16px verdana" tableBody = html.TBODY() row = html.TR() tableBody.style.verticalAlign = "center" row.style.verticalAlign = "center" table.style.background = "#F7F7F7" table.style.padding = "10px 25px 10px 10px" label = html.LABEL("Select samples to search:") label.style.verticalAlign = "center" label.style.marginRight = "10px" td1 = html.TD() td1 <= label row <= td1 #op11 = html.OPTION(sample1) #op12 = html.OPTION(sample2) #op21 = html.OPTION(sample1) #op22 = html.OPTION(sample2) sel1 = html.SELECT([], id="selector_samples_1", font_size=16) sel1.style.fontSize = "large" sel1.style.verticalAlign = "center" sel1.style.marginRight = "20px" sel1.style.width = "300px" td2 = html.TD() td2 <= sel1 row <= td2 sel2 = html.SELECT([], id="selector_samples_2", font_size=16) sel2.style.fontSize = "large" sel2.style.verticalAlign = "center" sel2.style.marginRight = "0px" sel2.style.width = "300px" td3 = html.TD() td3 <= sel2 row <= td3 b = html.BUTTON('Search', id="search_subsets") button_style_default(b) b.bind('click', click_search_subsets) b.bind('mouseout', mouse_out_search_subsets) b.bind('mouseover', mouse_over_search_subsets) b.style.verticalAlign = "center" b.style.marginTop = "0px" b.style.marginBottom = "0px" td4 = html.TD() td4.style.verticalAlign = "center" td4 <= b row <= td4 tableBody <= row table <= tableBody panel <= table panel <= html.BR()