コード例 #1
0
def initalize(request):
    versions = json.loads(request.responseText)

    if len(versions) < 1:
        raise Exception("No versions are available")

    main = document.query.getfirst("main", None)
    if main not in versions:
        main = versions[0]

    diff = document.query.getfirst("diff", None)
    if diff not in versions:
        diff = "None"

    for ver in versions:
        document.select("#version-main select")[0] <= html.OPTION(ver,
                                                                  value=ver)
        document.select("#version-diff select")[0] <= html.OPTION(ver,
                                                                  value=ver)

    document.select("#version-main select")[0].disabled = False
    document.select("#version-main select")[0].value = main
    document.select("#version-diff select")[0].disabled = False
    document.select("#version-diff select")[0].value = diff

    update_result()
コード例 #2
0
def setup_samples_to_search(res):
    sample_1 = document["selector_samples_1"]
    sample_2 = document["selector_samples_2"]
    sample_1.options.length = 0
    sample_2.options.length = 0
    for each in res:
        sample_1.add(html.OPTION(each["subset_name"]))
        sample_2.add(html.OPTION(each["subset_name"]))
コード例 #3
0
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)
コード例 #4
0
 def __init__(self,
              choices,
              onchange,
              size=None,
              initialchoice=None,
              id=None):
     html.SELECT.__init__(self, "", Class="listbox")
     self <= (html.OPTION(text) for text in choices)
     self.bind("change", onchange)
     self.size = size if size else len(choices)
     self.selectedIndex = initialchoice if initialchoice else -1
     if id: self.id = id
コード例 #5
0
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)
コード例 #6
0
ファイル: slideshow.py プロジェクト: zenUnicorn/brython
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)
コード例 #7
0
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()
コード例 #8
0
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()
コード例 #9
0
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
コード例 #10
0
ファイル: slideshow.py プロジェクト: dblanchet/cours_python
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
コード例 #11
0
 def __init__(self, choices, onchange, initialchoice=None, id=None):
     html.SELECT.__init__(self, "", Class="dropdown")
     self <= (html.OPTION(text) for text in choices)
     self.bind("change", onchange)
     if initialchoice: self.selectedIndex = initialchoice
     if id: self.id = id
コード例 #12
0
ファイル: brython_input1.py プロジェクト: 40223103/cpv1
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