def __init__(self, container=document.body, parent=None): self.container = container self.parent = parent if parent is None: self._table = html.TABLE(Class="menu-table") self.panel = html.TR(Class="menu-row") self._table <= self.panel self.container <= self._table self.panel.bind("mouseover", self.hide_submenus) document.bind("click", self.reset) else: self.panel = html.TABLE(Class="menu-table") self.container <= self.panel @bind(self.panel, "click") def click(evt): evt.stopPropagation() cstyle = window.getComputedStyle(self.container) self.fontSize = cstyle.getPropertyValue('font-size') self.selecting = False container.open_child = None
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 __init__(self, title="", *, top=None, left=None, ok_cancel=False, default_css=True): if default_css: for stylesheet in document.styleSheets: if stylesheet.ownerNode.id == "brython-dialog": break else: document <= html.STYLE(style_sheet, id="brython-dialog") html.DIV.__init__(self, style=dict(position="absolute"), Class="brython-dialog-main") #set_style(self, "dialog-main") self.title_bar = html.DIV(html.SPAN(title), Class="brython-dialog-title") self <= self.title_bar self.close_button = html.SPAN("×", Class="brython-dialog-close") self.title_bar <= self.close_button self.close_button.bind("click", self.close) self.panel = html.DIV(Class="brython-dialog-panel") self <= self.panel if ok_cancel: ok_cancel_zone = html.DIV(style={"text-align": "center"}) ok, cancel = "Ok", "Cancel" if isinstance(ok_cancel, (list, tuple)): if not len(ok_cancel) == 2: raise ValueError( f"ok_cancel expects 2 elements, got {len(ok_cancel)}") ok, cancel = ok_cancel self.ok_button = html.BUTTON(ok, Class="brython-dialog-button") self.cancel_button = html.BUTTON(cancel, Class="brython-dialog-button") self.cancel_button.bind("click", self.close) ok_cancel_zone <= self.ok_button + self.cancel_button self <= ok_cancel_zone document <= self cstyle = window.getComputedStyle(self) # Center horizontally and vertically if left is None: width = round(float(cstyle.width[:-2]) + 0.5) left = int((window.innerWidth - width) / 2) self.left = left self.style.left = f'{left}px' if top is None: height = round(float(cstyle.height[:-2]) + 0.5) top = int((window.innerHeight - height) / 2) # top is relative to document scrollTop top += document.scrollingElement.scrollTop self.top = top self.style.top = f'{top}px' self.title_bar.bind("mousedown", self.mousedown) self.title_bar.bind("touchstart", self.mousedown) self.title_bar.bind("mouseup", self.mouseup) self.title_bar.bind("touchend", self.mouseup) self.bind("leave", self.mouseup) self.is_moving = False
def __init__(self, title="", style={}, top=None, left=None, ok_cancel=False): for key in style: for item in styles: styles[item][key] = style[key] html.DIV.__init__(self, style=styles["dialog"]) self._title = html.DIV(html.SPAN(title), style=styles["title"]) self <= self._title btn = html.SPAN("×", style=styles["close"]) self._title <= btn btn.bind("click", self.close) self.panel = html.DIV(style=styles["panel"]) self <= self.panel if ok_cancel: ok_cancel_zone = html.DIV(style={"text-align": "center"}) self.ok_button = html.BUTTON("Ok") self.cancel_button = html.BUTTON("Cancel") self.cancel_button.bind("click", self.close) ok_cancel_zone <= self.ok_button + self.cancel_button self <= ok_cancel_zone document <= self cstyle = window.getComputedStyle(self) # Center horizontally and vertically if left is None: width = round(float(cstyle.width[:-2]) + 0.5) left = int((window.innerWidth - width) / 2) self.left = left self.style.left = f'{left}px' if top is None: height = round(float(cstyle.height[:-2]) + 0.5) top = int((window.innerHeight - height) / 2) self.top = top self.style.top = f'{top}px' self._title.bind("mousedown", self.mousedown) document.bind("mousemove", self.mousemove) self._title.bind("mouseup", self.mouseup) self.bind("leave", self.mouseup) self.is_moving = False
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 _fsize(): body_style = window.getComputedStyle(document.body, None) fontSize = body_style.getPropertyValue("font-size") fsize = float(fontSize.rstrip("px")) return fsize