def __init__(self, id=None, style=None, content=None, on_select=None, factory=None): super().__init__(id=id, style=style, factory=factory) self._div_bar_nav = document.createElement('DIV') self._div_bar_nav.className = "nav nav-tabs" self._div_bar_nav.setAttribute('role', 'tablist') self._bar_nav = document.createElement('NAV') self._bar_nav.appendChild(self._div_bar_nav) self._div_windows = document.createElement('DIV') self._div_windows.className = "tab-content" self.elm.appendChild(self._bar_nav) self.elm.appendChild(self._div_windows) self.on_select = on_select self._content = [] self.initial = True if content: for label, widget in content: self.add(label, widget)
def board_as_html(dom_board, ttt_board, board_size, callback, args): # first row for coordinates span = document.createElement('span') span.textContent = ' ' + ' '.join([str(i) for i in range(board_size)]) dom_board.appendChild(span) line_break = document.createElement('br') dom_board.appendChild(line_break) for y, row in enumerate(ttt_board): d = new_div() s = new_span(str(y)) d.appendChild(s) s = new_span(' ') d.appendChild(s) for x, cell_value in enumerate(row): if cell_value < 0: a = new_empty_cell(x,y) d.appendChild(a) else: d.appendChild(new_clicked_cell(cell_value)) s = new_span(' ') d.appendChild(s) # for cell in row # span = document.createElement('span') # span.textContent = str(i) + ' ' + ' '.join(map(cell_code_to_presentation, row)) dom_board.appendChild(d) # line_break = document.createElement('br') # dom_board.appendChild(line_break) if callback != None: callback(*args)
def switch_to(self, switch_to, form_prefix): """ Switches to new rows - removes current ones and adds new. """ to_remove = self.get_rows(form_prefix, self.current) to_add = self.get_rows(form_prefix, switch_to) self.remove(form_prefix, to_remove) self.add(form_prefix, to_add) self.current = switch_to if self.switch_to_select_data_target: target_select = doc['id_{}{}'.format(form_prefix, self.switch_to_select_data_target)] target_select.clear() items = self.switch_to_select_data_target_items[self.switch_to_select_data_target] items = items[self.current] # Initially, nothing is selected option = doc.createElement('option'); option.value = '' option.text = '------' target_select.appendChild(option) for item in items: option = doc.createElement('option'); option.value = item.id option.text = item.name target_select.appendChild(option)
def register_new_os(osname): def os_hash_generated(response): if response.status != 200: console.log("Request failed: " + str(response.status)) return result_hash = None parser = window.DOMParser.new() tree = parser.parseFromString(response.text, 'application/xml') opsys_root = tree.getElementsByTagName('operating_systems')[0] for os in opsys_root.getElementsByTagName('operating_system'): if str(os.textContent).strip() == osname: result_hash = os.getAttribute('hash') break if result_hash: opsys_list_loaded(response, put_details=True) ajax_request = ajax.ajax() ajax_request.bind('complete', os_hash_generated) ajax_request.open('POST', '/opsys/', True) ajax_request.set_header('Content-Type', 'text/xml;charset=utf-8') os_root = document.createElement('operating_systems') os_entry = os_root.appendChild(document.createElement('operating_system')) os_entry.appendChild(document.createTextNode(osname)) ajax_request.send(remove_xmlns(os_root.outerHTML))
def create_input_field(name, n): div = document.createElement("div") div.classList.add("mdl-textfield", "mdl-js-textfield") input_field = document.createElement("input") input_field.classList.add("mdl-textfield__input", "field-input", str(n)) input_field.attrs["placeholder"] = "Field name..." input_field.value = name input_field.bind("change", change_field_name) div.appendChild(input_field) return div
def create_opsys_details(oshash, name, details={}): ajax_request = ajax.ajax() ajax_request.bind('complete', opsys_details_loaded) ajax_request.open('PUT', '/opsys/' + oshash, True) os_root = document.createElement('operating_system') os_root.setAttribute('hash', oshash) os_root.appendChild(document.createTextNode(name)) for key, value in details.items(): os_entry = os_root.appendChild(document.createElement(key)) os_entry.appendChild(document.createTextNode(value)) ajax_request.send(remove_xmlns(os_root.outerHTML))
def main(): global configuration, selected_profile load_configuration("config.json") # Profile selector profile_selector = document.select("#profile") profile_selector[0].appendChild(document.createElement("option")) for profile in list(configuration["profiles"].keys())[1:]: option = document.createElement("option") option.value = profile option.innerHTML = profile profile_selector[0].appendChild(option) profile_selector[0].bind("change", change_profile)
def exibirPilhas(evt): global lista resultado = diff.sortMerge(lista) pilhas = diff.stacks tabela.innerHTML = "" for i in pilhas: novo = document.createElement("tr") tabela.appendChild(novo) for j in i: coluna = document.createElement("td") coluna.innerText = str(j) novo.appendChild(coluna) ordenado.innerText = " - ".join([str(x) for x in resultado])
def add(self, label, widget): if self._children == None: raise ValueError('Cannot add children') widget.app = self.app # --- revisar --- widget.parent = self widget.root = self.root widget.window = self.window self.children.append(widget) # --- New --- self._content.append(widget) new_window = document.createElement('DIV') new_window.id = identifier() new_href = document.createElement('A') new_href.id = identifier() if self.initial: new_href.className = "nav-item nav-link active" new_href.setAttribute('aria-selected', True) new_window.className = "tab-pane fade show active" else: new_href.className = "nav-item nav-link" new_href.setAttribute('aria-selected', False) new_window.className = "tab-pane fade" new_href.innerHTML = label new_href.href = "#" + new_window.id new_href.setAttribute('data-toggle', 'tab') new_href.setAttribute('role', 'tab') new_href.setAttribute('aria-controls', new_window.id) new_window.setAttribute('role', 'tabpanel') new_window.setAttribute('aria-labelledby', new_href.id) new_window.appendChild(widget.elm) self._div_windows.appendChild(new_window) self._div_bar_nav.appendChild(new_href) self.initial = False widget.refresh()
def epg_chan_map_postform(chanlist): source = document["source"].value postForm = document.createElement('form') postForm.method = "POST" postForm.action = "/api/epg?method=map&redirect=/guide?source=%s" % source postForm.setRequestHeader = "('Content-Type', 'application/json')" postData = document.createElement('input') postData.type = 'hidden' postData.name = "channels" postData.value = json.dumps(chanlist) postForm.appendChild(postData) document.body.appendChild(postForm) return postForm
def chan_edit_postform(chanlist): origin = document["origin"].value postForm = document.createElement('form') postForm.method = "POST" postForm.action = "/api/channels?method=modify&origin=%s&redirect=/channels_editor&origin=%s" % (origin, origin) postForm.setRequestHeader = "('Content-Type', 'application/json')" postData = document.createElement('input') postData.type = 'hidden' postData.name = "channels" postData.value = json.dumps(chanlist) postForm.appendChild(postData) document.body.appendChild(postForm) return postForm
def write(self, string): """Write a new string to the output.""" element = document.createElement("pre") for cls in self.cls: element.classList.add(cls) element.innerText = string outputElement.appendChild(element)
def makeList(self, element, items): for i in items: opt = document.createElement("option") opt["value"] = i.key opt.obj = i opt.appendChild(document.createTextNode(str(i))) element.appendChild(opt)
def set_icon(self, Surface=None): link = document.createElement("link") link.type = "image/x-icon" link.rel = "shortcut icon" link.href = Surface document.get(selector='head')[0] <= link return None
def __init__(self, add_to_scene_entities=True, **kwargs): self.b = document.createElement("button") self.b.entity = self # print('-------------', self.b.entity) self.b.style.cssText = '''width:100%; height:100%; position:absolute; top:50%; left:50%; will-change: transform; transform:translate(-50%, -50%); font-size:50; color:black; background-size: 100% 100%; padding:0; border-radius: 128px; border-style:solid; border-width:0px; border-color: white;''' self.enabled = True self.ignore = False self.add_to_scene_entities = add_to_scene_entities # set to False to be ignored by the engine, but still get rendered. if add_to_scene_entities: try: from ursina.main import scene self.parent = scene scene.entities.append(self) except: print('no scene entity yet') self.x = 0 self.y = 0 self.scale_x = 1 self.scale_y = 1 # self.origin = (0,0) # self.origin_x = 0 # self.origin_y = 0 self.model = None self.color = color.white self.hovered = False self.collision = False self.name = 'entity' for key, value in kwargs.items(): setattr(self, key ,value)
def __init__(self): #Initiate canvas self.canvas = doc.createElement("canvas") self.ctx = self.canvas.getContext("2d") self.canvas.width = 800 self.canvas.height = 550 doc["pokemon_game"].appendChild(self.canvas) #Initiatie User Interaction self.input_text = "" self.problem = None #initiate the timer self.count_down_timer = CountDownTimer((PokemonGame.count_down_timer_dim[0],PokemonGame.count_down_timer_dim[1]), PokemonGame.count_down_timer_dim[2], self, PokemonGame.timer_text_loc, 10) #initiate the game stats self.game_stats = {"Pokemon Defeated" : 0,"Total Experience Gained" : 0,"Total Damage Inflicted" : 0,"Total Damage Taken" : 0} self.popup_queue = [] self.runner = None #Initiate pokemon self.pokemon = PlayerPokemon(PokemonGame.pokemon_locs[0][0],PokemonGame.pokemon_locs[0][1]) self.enemy_pokemon = None
def patch_opsys(name, value): oshash = name.split('_')[-1] field_name = name[:-len(oshash) - 1] ajax_request = ajax.ajax() ajax_request.bind('complete', lambda response: opsys_details_loaded(response, True)) ajax_request.open('PATCH', '/opsys/' + oshash, True) ajax_request.set_header('Content-Type', 'text/xml;charset=utf-8') device = document.createElement('operating_system') device.setAttribute('hash', oshash) field = device.appendChild(document.createElement(field_name)) field.appendChild(document.createTextNode(value)) ajax_request.send(remove_xmlns(device.outerHTML))
def create_script_tag(src): _fp, _, _ = urllib.request.urlopen(src) _data = _fp.read() _tag = document.createElement('script') _tag.type = "text/javascript" _tag.text = _data document.get(tag='head')[0].appendChild(_tag)
def loadSound(self, file): sound = document.createElement("audio") sound.src = file sound.setAttribute("preload", "auto") sound.setAttribute("controls", "none") sound.style.display = "none" self._doc <= sound return sound
def new_empty_cell(x, y): a = document.createElement('a') s = new_span('█') s.attrs['data-x'] = x s.attrs['data-y'] = y a.appendChild(s) a.bind('click', take_move) return a
def create_script_tag(src): _fp, _, _=urllib.request.urlopen(src) _data=_fp.read() _tag=document.createElement('script') _tag.type="text/javascript" _tag.text=_data document.get(tag='head')[0].appendChild(_tag)
def patch_device(name, value): mac = name.split('_')[-1] field_name = name[:-len(mac) - 1] s_mac = ':'.join(mac[2 * _i:2 * _i + 2] for _i in range(6)) ajax_request = ajax.ajax() ajax_request.bind( 'complete', lambda response: device_details_loaded(response, s_mac, True)) ajax_request.open('PATCH', '/device/' + mac, True) ajax_request.set_header('Content-Type', 'text/xml;charset=utf-8') device = document.createElement('device') device.setAttribute('mac', s_mac) field = device.appendChild(document.createElement(field_name)) field.appendChild(document.createTextNode(value)) ajax_request.send(remove_xmlns(device.outerHTML))
def dom(self): element = document.createElement(self.tagname) element.className = self.className self.element = element for key, value in self.props.items(): element.attrs[key] = value return element
def create_script_tag(self, src): import urllib.request from browser import document _fp = urllib.request.urlopen(src) _data = _fp.read() _tag = document.createElement('div') #_tag.type = "image/svg+xml" _tag.html = _data return _tag
def makeList(self, element, items, select=None): for i in items: opt = document.createElement("option") opt["value"] = i.key opt.obj = i if select and select is i: opt["selected"] = True opt.appendChild(document.createTextNode(str(i))) element.appendChild(opt)
def elm(elm_type: object, attr=None) -> any: """ Create an HTML element with given type and attribute :param elm_type: type of the element :param attr: attributes that will given to the element :return: jQuery HTML element """ jquery_elm = window.jQuery(document.createElement(elm_type)) if attr is not None: jquery_elm.attr(attr) return jquery_elm
def extend_options_list(name, value): if not value: return console.log("extend_options_list " + name + " '" + value + "'") options_list = document[name] value_set = set() for option in options_list.getElementsByTagName('option'): value_set.add(option.getAttribute('value')) if value not in value_set: option = options_list.appendChild(document.createElement('option')) option.setAttribute('value', value)
def __init__(self, id=None, title=None, position=(100, 100), size=(640, 480), toolbar=None, resizeable=True, closeable=True, minimizable=True, factory=None): self._elm = document.createElement('DIV') self._title = document.createElement('H1') self._id = id if id else identifier() self._app = None self._content = None self._position = position self._size = size self._is_full_screen = False self.resizeable = resizeable self.closeable = closeable self.minimizable = minimizable #self._toolbar = CommandSet(self, self._impl.create_toolbar) self.position = position self.size = size self.title = title
def sheet(x, dom_type, type_animation): if type_animation in animation: shee = doc.createElement('style') if dom_type == 'id': shee.innerHTML = "#" + x + animation[type_animation] doc[x].appendChild(shee) elif dom_type == 'class': shee.innerHTML = "." + x + animation[type_animation] doc.body.appendChild(shee) else: print('module object has no attribute ' + type_animation)
def draw_fields(): fields_list = document.createElement('ul') fields_list.classList.add("mdl-list") fields_list.classList.add("flist") page = document.select(".fields-container") page[0].appendChild(fields_list) n = 0 for field in list(configuration["profiles"][selected_profile]["fields_list"]): element = document.createElement("li") element.classList.add("mdl-list__item") text_field = create_input_field(field, n) element.appendChild(text_field) fields_list.appendChild(element) n += 1 add_field = document.createElement('button') add_field.classList.add("mdl-button", "mdl-js-button", "mdl-button--fab", "add-button") content = document.createElement("i") content <= "+" add_field.appendChild(content) page[0].appendChild(add_field)
def downloadSheet(response): if response.status == 200: downloadLink = document.createElement('A') downloadLink.attrs["href"] = window.URL.createObjectURL( window.Blob.new([response.text], {"type": "application/json"})) downloadLink.attrs["target"] = "_blank" downloadLink.attrs["download"] = "characterSheet.json" document.body.appendChild(downloadLink) downloadLink.click() document.body.removeChild(downloadLink) else: dialogShowHTTPError(response)
def __init__(self, **kwargs): self.b = document.createElement("button") self.b.style.cssText = '''width:100%; height:100%; position:absolute; top:50%; left:50%; will-change: transform; transform:translate(-50%, -50%); font-size:50; color:black; background-size: 100% 100%; padding:0; border-radius: 128px; border-style:solid; border-width:0px; border-color: white;''' self.enabled = True self.parent = scene self.x = 0 self.y = 0 self.scale_x = 0 self.scale_y = 0 self.color = color.white for key, value in kwargs.items(): setattr(self, key, value) scene.entities.append(self)
def select_folder_dialog(self, title, initial_directory=None, multiselect=False): inputfile = document.createElement('INPUT') inputfile.setAttribute('type', 'file') inputfile.setAttribute('webkitdirectory', True) inputfile.setAttribute('directory', True) inputfile.setAttribute('multiple', multiselect) inputfile.setAttribute('name', title) #inputfile.setAttribute('hidden', True) inputfile.style="display:none" if initial_directory: print('Not recomended used initial directory') inputfile.value = initial_directory self._root.appendChild(inputfile) inputfile.click() self._root.removeChild(inputfile) return inputfile.value
def init(): global canvas,overlay,map,mpos #ele = doc["map"] #if not ele.getContext: # alert('An error occured creating a Canvas 2D context. ' # 'This may be because you are using an old browser') # return #map=ele.getContext("2d") _css=doc.createElement('link') _css.type="text/css" _css.rel="stylesheet" _css.href="gallery/brython/css/3Dwalker.css" doc['pydiv'] <= _css _app = html.DIV(id="app") _app <= html.CANVAS(id="underMap", width="80px", height="80px") _app <= html.CANVAS(id="map", width="80px", height="80px") doc['pydiv'] <= html.DIV(id="content") doc['content'] <= _app _app <= html.DIV(id='holder') doc['holder']<=html.DIV(id='sky') doc['holder']<=html.DIV(id='floor') doc['holder']<=html.CANVAS(id='canvas', width="400px", height="300px") doc['holder']<=html.DIV(id='overlay') canvas=doc["canvas"].getContext("2d") overlay=doc["overlay"] map=doc["map"].getContext('2d') doc["sky"].style.backgroundPosition="%spx 0" %floor(-playerDir/(2*pi)*2400) drawCanvas() initUnderMap() timer.set_interval(update, 35)
gear.spur(cx+pr1+pr2, cy, m, n2, pa, 180-180/n2) # 第2齒與第3齒的囓合, 首先假定第2齒的定位線在 theta 角為 0 的原始位置 # 如此, 第3齒只要逆時鐘旋轉 180 度後, 再逆時鐘或順時鐘轉動半齒的角度, 即可與第2齒囓合 # 但是第2齒為了與第一齒囓合時, 已經從原始定位線轉了 180-180/n2 度 # 而當第2齒從與第3齒囓合的定位線, 逆時鐘旋轉 180-180/n2 角度後, 原先囓合的第3齒必須要再配合旋轉 (180-180/n2 )*n2/n3 spur(cx+pr1+pr2+pr2+pr3, cy, m, n3, pa, 180-180/n3+(180-180/n2)*n2/n3) spur(cx+pr1+pr2+pr2+pr3+pr3+pr4, cy, m, n4, pa, 180-180/n3*n3/n4+(180-180/n2)*n2/n3*n3/n4+(180-180/n3)*n3/n4) </script> <script type='text/javascript'> var onWebChat={ar:[], set: function(a,b){if (typeof onWebChat_==='undefined'){this.ar. push([a,b]);}else{onWebChat_.set(a,b);}},get:function(a){return(onWebChat_.get(a));},w :(function(){ var ga=document.createElement('script'); ga.type = 'text/javascript';ga. async=1;ga.src='//www.onwebchat.com/clientchat/795d781612868f02aa4bb0552c0655a5/1/1'; var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})()} </script> </body> </html> gear.spur(cx+pr1+pr2+pr2+pr3, cy, m, n3, pa, 180-180/n3+(180-180/n2)*n2/n3) </script> ''' return outstring @bg11.route('/gear') def gear(): outstring = ''' <!DOCTYPE html> <html>