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 __init__(self, returnaction=None): DialogBox.__init__(self, "Colour Picker", returnaction, id="colourpickerdialog") self.basecolourbox = html.DIV("", id="basecolourbox") self.basecolourbox <= html.IMG(src="brywidgets/whitemask.png", id="whitemask") self.basecolourbox <= html.IMG(src="brywidgets/blackmask.png", id="blackmask") self.colourpointer = html.IMG(src="brywidgets/circle.png", id="colourpointer") self.basecolourbox <= self.colourpointer self.basecolourbox.bind("click", self.selectcolour) self <= self.basecolourbox hueswatch = html.DIV(html.IMG(src="brywidgets/hues.png", id="hues"), id="hueswatch") self.huepointer = html.IMG(src="brywidgets/circle.png", id="huepointer") hueswatch <= self.huepointer hueswatch.bind("click", self.selecthue) self <= hueswatch self.colourdemo = html.DIV("", id="colourdemo") self <= self.colourdemo self <= Button("Select", self.onSelect, id="colourpickerselect") self.setupfromcolour("rgb(0, 255, 255)")
def profile_pics_selector(): """ choose appropriate profile pics based on screen size """ # use project element to detect if device is mobile mobile_view = document["project_small_display"].style.display pp_wrapper = document["profile_pics_cont"] small_img = "./img/about_pics_small.JPG" normal_img = "./img/about_pics.JPG" if mobile_view != "none": pp_wrapper <= html.IMG(src=small_img, alt="picture of emmanuel") else: pp_wrapper <= html.IMG(src=normal_img, alt="picture of emmanuel")
def __init__(self, resource): self.resource = resource self.path = {} self.html_image = {} for dir, path in constants.vehicles[resource].items(): self.path[dir] = self.URLPATH + path self.html_image[dir] = html.IMG(src=self.path[dir])
def start(self, top, right): self.img = html.IMG(src=self.src, id=self.name, width=self.interval * 12, height=self.interval * 8) document["canvas_parent"] <= self.img style = self.img.style self.is_upper_half = (True if top == 0 else False) clip_top = str(top) + "px" clip_right = str(right) + "px" clip_down = str(int(clip_top[:-2]) + self.interval) + "px" clip_left = str(int(clip_right[:-2]) - self.interval) + "px" style.clip = f'rect({clip_top},{clip_right},{clip_down},{clip_left})' style.position = "absolute" style.left = str(self.top_x) + "px" style.top = str(self.left_y) + "px" style.pointerEvents = "none" """連結按鈕到可以動""" document['btn-turn-left'].bind('click', self.turn_left1) document['btn-turn-right'].bind('click', self.turn_right1) document['btn-turn-over'].bind('click', self.turn_over1) document['btn-walk'].bind('click', self.walk1) """紀錄該spirit的clip_right、clip_top位置以供後續使用""" self.clip_top = clip_top self.clip_right = clip_right
def loadImage(self, file, sprite=None): if "referrer" in document["output_run"].attrs and not file.startswith( "http"): file = document["output_run"].attrs["referrer"] + file if file in self.resources: return self.resources[file] self.loadingResources += 1 window.console.log("Attempting to load file:" + file) img = html.IMG() img.crossOrigin = "Anonymous" img.src = file img.bind('load', self.resourceLoaded) img.bind('error', self.resourceError) img.bind('abort', self.resourceAbort) jmssImg = PyAngeloImage(img, sprite) img.jmssImg = jmssImg self.resources[file] = jmssImg return jmssImg
def __init__(self, name, ju, npc): self.name = name self.ju = ju self.npc = npc ctx_img.clearRect(0, 0, 680, 480) ctx_img.drawImage(html.IMG(src=room), 0, 0, 50, 50) ctx_txt.clearRect(0, 0, 680, 90)
def drop(self, ev): """Function attached to the destination zone. Describes what happens when the object is dropped, ie when the mouse is released while the object is over the zone. """ # retrieve data stored in drag_start (the draggable element's id) src = ev.dataTransfer.getData("text") camera = document[src] camera_id, url = src.split("-") display = document[ev.target.id] display.attrs["drop-active"] = False try: document[f"img-{src}"].unbind("dragstart") document[f"img-{src}"].parent.clear() except Exception as e: pass img = html.IMG( id=f"img-{src}", src=url, ) btn = html.A( Class="clear-btn icon rightbottom ui inverted red button circular", ) trash_icon = html.I(Class="trash icon") btn <= trash_icon display.clear() display <= img display <= btn img.draggable = True btn.bind("click", self.clear_display) img.bind("dragstart", self.dragstart_img) ev.preventDefault()
def __init__(self, img="", vai=None, style=NS, tit="", alt="", cena=INVENTARIO, score=NOSC, **kwargs): self._auto_score = self.score if score else self._auto_score self.img = img self.vai = vai if vai else lambda _=0: None self.cena = cena self.opacity = 0 self.style = dict(**PSTYLE) # self.style["min-width"], self.style["min-height"] = w, h self.style.update(**style) self.elt = html.DIV(Id=tit, style=self.style) self.xy = (-111, -111) self.scorer = dict(ponto=1, valor=cena.nome, carta=tit or img, casa=self.xy, move=None) self.scorer.update(score) if img: self.img = html.IMG(src=img, title=tit, alt=alt, style=EIMGSTY) # width=self.style["width"]) self.elt <= self.img self.elt.onclick = self._click self.c(**kwargs)
def bota(self, nome_item, item="", acao=None): """ Os objetos que estão de posse do jogador. .. doctest:: >>> inv.bota("uma_coisa") >>> "uma_coisa" in inv.inventario True :param nome_item: uma string com o nome do item, ele será criado e colocado no inventário :param item: URL da imagem do item nomeado por nome_item :param acao: ação associada com o item nomeado quando ele é clicado """ if isinstance(nome_item, str): item_img = html.IMG(Id=nome_item, src=item, width=30, style=EIMGSTY) self.elt <= item_img else: nome_item.entra(self) item_img = nome_item.elt item_img.style = ESTYLE Dropper(item_img) if acao: item_img.onclick = lambda *_: acao() else: acao = lambda *_: None self.inventario[nome_item] = acao
def drawimage(self, event): ctx = self.canvas.getContext("2d") ctx.drawImage(self.svgimage, 0, 0) png = self.canvas.toDataURL("image/png") self.pngimage = html.IMG(src=png, id="pngcopy") self <= self.pngimage window.URL.revokeObjectURL(png)
def __init__(self, img=IMAGEM, esquerda=NADA, direita=NADA, meio=NADA, vai=None, nome='', xy=(0, 0), score=NOSC, **kwargs): width = STYLE["width"] self.scorer = dict(ponto=1, valor="__JOGO__", carta=nome, casa=xy, move=None) self.scorer.update(score) self._auto_score = self.score if score else self._auto_score self.ev = NoEv() self.xy = xy self.img = img self.nome = nome self.dentro = [] self.esquerda, self.direita, self.meio = esquerda or NADA, direita or NADA, meio or NADA self.N, self.O, self.L = [NADA] * 3 self.vai = vai or self.vai self.elt = html.DIV(style=STYLE) self.elt <= html.IMG( src=self.img, width=width, style=STYLE, title=nome) Cena.c(**kwargs) self._cria_divs(width)
def setup(self, container): first = True for key, value in sorted(self.game.worlds.items(), key=lambda e: e[1].sortorder): world_container = html.DIV(Class="world-container" + (" world-container-enabled" if first else " world-container-hidden"), id="world-container_" + key) first = False resources = html.DIV(id="resources") resources <= html.B("Resources availible on " + value.name) resources <= html.HR() resources <= html.DIV(Class="currency-holder-holder") world_container <= resources buildings = html.DIV(id="buildings") buildings <= html.B("Buildings on " + value.name) buildings <= html.HR() buildings <= html.DIV(Class="building-holder-holder") world_container <= buildings world_container <= html.DIV(id="upgrades") vis = html.DIV(id="visualize") vis <= html.H1(key) vis <= html.IMG(src=value.image) world_container <= vis container["world-container-container"] <= world_container
def setup(self, container): def _make_handler(worldname): def _handler(e): print("Handling %s for %s" % (e, worldname)) for ele in container.get(selector=".world-container"): ele.class_name = "world-container world-container-hidden" container[ "world-container_" + worldname].class_name = "world-container world-container-enabled" for ele in container.get(selector=".world-bar-item"): ele.class_name = "world-bar-item" container["world_" + worldname].class_name += " world-button-enabled" return _handler for key, value in sorted(self.game.worlds.items(), key=lambda e: e[1].sortorder): baritem = html.DIV( id="world_" + key, Class="world-bar-item" + (" world-button-enabled" if value.sortorder == 0 else "")) baritem <= html.IMG(src=value.image, title=value.name) baritem <= html.P(value.name, Class="world-text") baritem.bind("click", _make_handler(key)) container["colonies"] <= baritem
def __init__(self, svgimage, id=None): html.BUTTON.__init__(self, html.IMG(src="brywidgets/Copy.png"), type="button", title="Copy or Save...", Class="imagebutton") self.bind("click", self.onClick) self.svgimage = svgimage
def show_no_data(): card = html.DIV(Class='ac_card') card <= html.IMG( src=f'/static/img/fall/random_thumbnails/{random.randint(1,50)}.png', Class='ac_card_thumbnail') card <= html.DIV('尚未有任何資料', Class='ac_card_content') document['ac_cards'] <= card document['ac_cards'] <= card
def SVGtoPNG(self, SVG): xmls = window.XMLSerializer.new() svgString = xmls.serializeToString(SVG) self.canvas.attrs["width"] = SVG.attrs["width"] self.canvas.attrs["height"] = SVG.attrs["height"] self.svgimage = html.IMG() self.svgimage.bind("load", self.drawimage) self.svgimage.src = 'data:image/svg+xml; charset=utf8, ' + window.encodeURIComponent( svgString)
def __init__(self, icon, returnaction, id=None): html.BUTTON.__init__(self, html.IMG(src=icon), type="button", title="Open Colour Picker...", Class="imagebutton") self.bind("click", self.onClick) self.returnaction = returnaction if id: self.id = id
def bota(self, nome_item): if isinstance(nome_item, str): item_img = html.IMG(Id=nome_item, src=nome_item, width=30, style=EIMGSTY) self.elt <= item_img else: nome_item.entra(self) self.dentro.append(nome_item)
def init(): global SCREEN, CTX document.body.append(html.H1("Browser Invaders - a Python adventure")) SCREEN = html.CANVAS(width=WIDTH, height=HEIGHT) SCREEN.style = {"background": "black"} document.body.append(SCREEN) CTX = SCREEN.getContext("2d") for image_name in "ship", "enemy_01", "enemy_02": images[image_name] = html.IMG(src="images/{}.png".format(image_name)) print("loaded {}.png".format(image_name))
def preloadimg(): #preloadimg imgs = [ "favicon.png", "pb_block.jpg", "pb_off.jpg", "pb_on.jpg", "ped_black.jpg", "ped_green.jpg", "ped.jpg", "ped_red.jpg", "rag_amber.jpg", "rag_green.jpg", "rag_red-amber.jpg", "rag_red.jpg" ] for i in imgs: document["preloadimg"] <= html.IMG( src="images/" + i, width="1", height="1", boarder="0")
def __init__(self, title, id=None): html.DIV.__init__(self, "", Class="overlaypanel") if id: self.id = id self.overlay = Overlay(self) closebutton = html.IMG(src="brywidgets/closebutton.png", Class="closebutton") closebutton.bind("click", self.close) titlebar = html.DIV([title, closebutton], Class="titlebar") self <= titlebar document <= self.overlay
async def main(): # Text file req = await aio.ajax("GET", "test.html") assert len(req.data) == 0 # Binary file req = await aio.get("memo.pdf", format="binary") assert len(req.data) == 0 # Read binary file as dataURL req = await aio.get("eraser.png", format="dataURL") # display the image in an IMG tag document <= html.IMG(src=req.data)
def main(): global posicao_carina universo = html.IMG(src=UNIVERSO) document["pydev"] <= universo carina = html.IMG(src=CARINA, style=CARINA_STYLE) document["pydev"] <= carina def anda_carina(evento): x, y = evento.x, evento.y global posicao_carina left, top = posicao_carina["left"], posicao_carina["top"] left = x top = y posicao_carina = dict(left=left, top=top) novo_estilo = dict(position="absolute", left=100, top=100) novo_estilo.update(posicao_carina) carina.style = novo_estilo universo.onclick = anda_carina
def init_cards(): for i in range(7): card = html.DIV(Class='ac_card') card <= html.IMG( src=f'/static/img/fall/random_thumbnails/{thumbnail[i]}.png', Class='ac_card_thumbnail') cc = html.DIV(Class='ac_card_content') cc <= html.P(peoples[i]) cc <= html.P(f'在 {towns[i]} 上傳') card <= cc card <= html.DIV(upload_time[i], Class='ac_card_time') document['ac_cards'] <= card
def __init__(self, returnaction=None, id=None): global logindialog html.BUTTON.__init__(self, html.IMG(src="brywidgets/login.png"), type="button", title="Log In...", Class="imagebutton") self.bind("click", self.onClick) if not logindialog: logindialog = LoginDialog("Please type your username below:", returnaction) if id: self.id = id
def __init__(self, title, returnaction=None, content=None, id=None): html.DIV.__init__(self, "", Class="dialogbox") self.returnaction = returnaction if id: self.id = id self.overlay = Overlay(self) closebutton = html.IMG(src="brywidgets/closebutton.png", Class="closebutton") closebutton.bind("click", self.close) titlebar = html.DIV([title, closebutton], Class="titlebar") self <= titlebar if content: self <= content document <= self.overlay
def reset(self): self.position = Vector(250 * visual_scale, 200 * visual_scale) self.speed = 0 self.heading = Vector(0, 1) self.orientation = 0 self.current_rotation = 0 self.target_rotation = 0 self.rotation_speed = 0 self.current_distance = 0 self.target_distance = 0 self.leftLED = False self.rightLED = False self.img = html.IMG(src="ed.png") self.led_img = html.IMG(src="led.png") self.height = 64 * visual_scale self.width = 62 * visual_scale
def __init__(self, returnaction, extlist=[], initialfolder=".", id=None): global fileopendialog html.BUTTON.__init__(self, html.IMG(src="brywidgets/Open.png"), type="button", title="Open File...", id=id, Class="imagebutton") self.bind("click", self.onClick) if not fileopendialog: fileopendialog = FileOpenDialog(returnaction, extlist) self.initialfolder = initialfolder if id: self.id = id
def loadImage(self, file): if file in self.resources: return self.resources[file] self.loadingResources += 1 img = html.IMG(src=file) #alert("Attempting to draw image"); img.bind('load', self.resourceLoaded) jmssImg = PyAngeloImage(img) img.jmssImg = jmssImg self.resources[file] = jmssImg return jmssImg