def output_data(req): if document.select('#data_on_page'): document['xls_link'].clear() if document.select('#rt1'): document['output_txt'].clear() global _name _name = req.text link_xls = html.P( html.IMG(loading='lazy', src='/static/img/xlsx_logo.png', width='45px', height='49px', Class='mr-2') + html.A('Скачать данные в формате xlsx', href=f'/static/combs/{_name}.xlsx')) link_txt = html.P( html.IMG(loading='lazy', src='/static/img/txt_logo.png', width='45px', height='49px', Class='mr-2') + html.A('Скачать данные в формате txt', href=f'/static/combs/{_name}.txt')) document['xls_link'] <= link_xls document['xls_link'] <= link_txt document['xls_link'] <= html.P( html.IMG(loading='lazy', src='/static/img/arrow_b.png', width='45px', height='49px', Class='mr-2') + html.A('Вывести данные на странице ниже', id='data_on_page', href='#output-txt')) document["data_on_page"].bind('click', output_txt_data)
def update_result(*args, **kwargs): left = document.select("#version-main select")[0].value right = document.select("#version-diff select")[0].value document.select("#version-main span")[0].textContent = left document.select("#version-diff span")[0].textContent = right document.getElementById("vitrine").innerHTML = ''' <h2>Working...</h2><div class="entry"> <h3><label for="vitrine-progress" id="vitrine-progress-label">Loading burger JSONs...</label></h3> <progress id="vitrine-progress"></progress> </div> ''' if left == "None" and right == "None": #window.location = "about" return elif left == "None": data = {"main": right} call_worker("vitrine", left) elif right == "None": data = {"main": left} call_worker("vitrine", data) else: data = {"main": left, "diff": right} call_worker("hamburglar", data)
def unfold(self, ev): """Called when a label with a submenu is clicked.""" target = ev.target if target.nodeName == "SPAN": # click on a navbar item selected = document.select(".brython-menu-navbar-item-selected") if selected: self.hide_menus() for item in selected: item.classList.remove("brython-menu-navbar-item-selected") submenu = target.submenu target.classList.add("brython-menu-navbar-item-selected") submenu.style.left = f"{target.abs_left}px" submenu.style.top = f"{target.abs_top + target.offsetHeight}px" # Once an item has been selected, mouseenter on the other items # unfolds them if not selected: for item in document.select(".brython-menu-navbar-item"): item.bind("mouseenter", self.unfold) # Display menu submenu.style.display = "block" else: target = target.closest("TR") # Remove other submenus table = target.closest("TABLE") self.hide_submenus(table) # If another item in the table was selected, unselect it selected = table.select(".brython-menu-submenu-row-selected") for row in selected: row.classList.remove("brython-menu-submenu-row-selected") # Mark target as selected target.classList.add("brython-menu-submenu-row-selected") if hasattr(target, "submenu"): # Set top and left of submenu and display it target.submenu.style.top = f"{target.abs_top}px" target.submenu.style.left = \ f"{target.abs_left + target.offsetWidth}px" target.submenu.style.display = "block" if not selected: # Once an item has been selected, mouseenter on the other # items unfolds them for row in table.select("TR"): row.bind("mouseenter", self.unfold) # stop propagation, otherwise "click" is triggered on document, # which removes all menus... ev.stopPropagation()
def hide_menus(self, *args): """When user clicks outside of open submenus, close them all.""" for css in [ ".brython-menu-navbar-item-selected", ".brython-menu-submenu-row-selected" ]: for item in document.select(css): item.classList.remove(css[1:]) for div in document.select(".brython-menu-submenu"): if div.style.display != "none": div.style.display = "none"
def toggle_ie_desc(event): button = event.target text = button.text if text == 'show IE description': button.text = 'hide IE description' for s, div in zip(ie_desc_array, document.select('.iedescdiv')): if div.needsep == 'y': div <= BR() div <= sniff_24008_link(s) else: button.text = 'show IE description' for div in document.select('.iedescdiv'): div.clear()
def on_complete(req): if req.status == 200: # print(req.text) document["update-grid"].className = "ui right primary button" document.select("body")[0].toast({ "class": "success", "message": "You're using the good framework !" }) else: print("error ", req.text)
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()
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 change_view(self, event): b = event.target table = ready.get_table() if table.tview == 'tree': # change to table view table.tview = 'table' b.html = 'tree view' for span in document.select('.iepad'): span.html = span.tablepad document.select('.iepad')[0].html = '' else: # change to tree view table.tview = 'tree' b.html = 'table view' for span in document.select('.iepad'): span.html = span.treepad ready.set_width_for_asn1_table(table)
def show_source(text): shown = document.select(".show_source") print(shown) if not shown: top = btn.offsetTop + btn.offsetHeight else: top = max(elt.offsetTop + elt.offsetHeight for elt in shown) top += int(0.5 * btn.offsetHeight) div = html.DIV(style=div_style, Class="show_source") indent = None lines = text.split("\n") for line in lines: if line.strip(): _indent = len(line) - len(line.lstrip()) if indent is None: indent = _indent break if indent: text = "\n".join(line[indent:] for line in lines) div <= highlight.highlight(text) document <= div div.top = top div.left = max(int(width / 2), width - div.offsetWidth - int(0.02 * width))
def chan_edit_reset(evt): chanlist = chan_edit_data( document.select(".reset"), str(evt.currentTarget.children[0].id).replace("reset_", "")) postForm = chan_edit_postform(chanlist) postForm.submit() evt.preventDefault()
def save_grid(self, ev): def on_complete(req): if req.status == 200: # print(req.text) document["update-grid"].className = "ui right primary button" document.select("body")[0].toast({ "class": "success", "message": "You're using the good framework !" }) else: print("error ", req.text) ev.target.className = "ui loading button" displays = document.select(".displays") displays_data = {} for display in displays: displays_data[display.id] = display.innerHTML # print(displays_data) ajax.post( self.save_gird_url, data={ "displays": JSON.stringify(displays_data), "grid_id": self.grid_id, }, oncomplete=on_complete, headers={"Content-Type": "application/x-www-form-urlencoded"}, )
def _complete(request): game_names = json.loads(request.responseText) for game_name in game_names: if not document.select( f'#game-selector option[value="{game_name}"]'): option = html.OPTION(value=game_name) option.textContent = game_name favorites.game_selector <= option if select_newest: latest_game_name = get_latest_game_name() latest_game_name_option = document.select( f'#game-selector option[value="{get_latest_game_name()}"]')[0] latest_game_name_option.selected = True timeline.game_name = latest_game_name if loop: timer.set_timeout(lambda: update_game_names(loop=True), 20_000)
def connect(ws_url=None): global WS_URL if ws_url: WS_URL = ws_url project_id = document.select('.lp-viewer')[0].id ws = websocket.WebSocket(WS_URL + '/projects/' + project_id) ws_bind(ws)
def chan_edit_modify(evt): chanlist = chan_edit_data( document.select(".channels"), str(evt.currentTarget.children[0].id).replace("update_", "")) postForm = chan_edit_postform(chanlist) postForm.submit() evt.preventDefault()
def show_source(text): shown = document.select(".show_source") if not shown: top = btn.offsetTop + btn.offsetHeight else: top = max(elt.offsetTop + elt.offsetHeight for elt in shown) top += int(0.5 * btn.offsetHeight) div = html.DIV(style=div_style, Class="show_source") indent = None lines = text.split("\n") for line in lines: if line.strip(): _indent = len(line) - len(line.lstrip()) if indent is None: indent = _indent break if indent: text = "\n".join(line[indent:] for line in lines) div <= highlight.highlight(text) document <= div div.top = top div.left = max(int(width / 2), width - div.offsetWidth - int(0.02 * width))
def chan_edit_modify(evt): channel_id = chan_edit_id(evt) chanlist = chan_edit_data(document.select(".channels"), str(channel_id).replace("modify_", "")) postForm = chan_edit_postform(chanlist) postForm.submit() evt.preventDefault()
def error_message(): if not document.select('.terminal-alert-error'): error_div = html.DIV( 'Preencha corretamente', Class='terminal-alert terminal-alert-error', ) form_field = document.select_one('fieldset') form_field.insertBefore(error_div, form_field.firstChild)
def change_profile(ev): global selected_profile profile_selector = document.select("#profile") selected_profile = profile_selector[0].value if selected_profile != "": draw_fields() else: clean_fields()
def start(self): # print("start") for camera in document.select(".cameras"): camera.bind("mouseover", self.mouseover) camera.bind("dragstart", self.dragstart) for display in document.select(".displays"): display.bind("dragover", self.dragover) display.bind("dragleave", self.dragleave) display.bind("drop", self.drop) document["update-grid"].bind("click", self.save_grid) ajax.get( f"{self.get_grid_url}?grid_id={self.grid_id}", oncomplete=self.initial_grid, )
def inter_stimulus(self) -> None: """Remove the highlight over the focus character.""" for element in document.select('.p300-char'): element.style = { 'opacity': 0.3, 'color': '#ffffff', 'font-weight': 'normal', }
def f(ev): # Remove all submenus for div in document.select(".submenu"): div.style.display = "none" ev.stopPropagation() ev.preventDefault() if callback is not None: return callback(ev)
def show(ev): global state if state == "on": for div in document.select(".show_source"): div.remove() state = "off" btn.text = "Show source code" else: scripts = document.select("script") for script in scripts: if not script.src: show_source(script.text) else: if script.src.endswith(".py") and \ not script.src.endswith("show_source.py"): req = ajax.get(script.src, oncomplete=show_external) state = "on" btn.text = "Hide source code"
def show(ev): global state if state == "on": for div in document.select(".show_source"): div.remove() state = "off" btn.text = "Show source code" else: scripts = document.select("script") for script in scripts: if not script.src: show_source(script.text) else: if script.src.endswith(".py") and \ not script.src.endswith("show_source.py"): req = ajax.get(script.src, oncomplete=show_external) state = "on" btn.text = "Hide source code"
def click_hidden_prefix(self, e): table = document.select('.asn1tree')[0] b = e.target if b.html == 'Hidden Prefix': b.html = 'Show Prefix' table.hiddeniepad = 'y' else: b.html = 'Hidden Prefix' table.removeAttribute('hiddeniepad')
def setup(): import app_main real_app_elm = html.maketag("main-app")() document.body.removeChild(document.select("App")[0]) document.body <= real_app_elm app_main.setup() import views import components from App import App as main_app Mapsi.render(main_app) may_router_view = document.select("router-view") if len(may_router_view) > 0: may_router_view[0].render()
def connect(ws_url=None): global WS_URL if ws_url: WS_URL = ws_url print("WS_URL", WS_URL) camera_id = document.select(".get-id")[0].id # print(camera_id) ws = websocket.WebSocket(WS_URL + "/cameras/" + camera_id) ws_bind(ws)
def btn_creates(index): btn = document.select('#request') if btn: btn[0].remove() classes = ( f'btn btn-{choice(["default", "primary", "error"])} btn-ghost') if index == r_value: classes += ' selenium' print('selenium') create_btn('fieldset', 'Botão', classes)
def reset_20(): global allow_change_20 allow_change_20 = False for e in document.select('div.anim_letter'): e.style.transition = 'none' e.style.transform = 'translateY(0px)' if 'odd_letter' in e.attrs['class']: e.text = '2' if 'even_letter' in e.attrs['class']: e.text = '0'
def editor_changed(*args): """Called when the editor content changes.""" current = document.select(".current") if current: filename = current[0].text.rstrip("*") if open_files[filename]["content"] != editor.getValue(): if not current[0].text.endswith("*"): current[0].text += "*" elif current[0].text.endswith("*"): current[0].text = current[0].text.rstrip("*")
def restore(default_values): #restore form values from internal browser memory for i, e in enumerate(document.select('input, select')): k = '%s_%d' % (e.name, i) if 'result' in e.class_name: continue if k in storage: e.value = storage[k] elif k in default_values: e.value = default_values[k]
def autoinit(): """""" window.mdc.autoInit() try: [ window.mdc.slider.MDCSlider.attachTo(slider) for slider in document.select('.mdc-slider') ] except: pass