def register_task(req): json_response = JSON.parse(req.text) div = document.select_one('div.todo div.terminal-timeline') if json_response['urgent']: div.insertBefore(html_todo(json_response), div.firstChild) else: div <= html_todo(json_response)
def on_update(data, ack): data = JSON.parse(data) Game().updates = data['updates'] Game().new_bots = data['bots'] Game().time = data['time'] Game().started = data['started'] window.requestAnimationFrame(Game().draw) ack()
def get_todos(req): todo_states = {'todo': html_todo, 'doing': html_doing, 'done': html_done} json = JSON.parse(req.text) for todo in json: div = document.select_one(f'div.{todo["state"]} div.terminal-timeline') if todo['urgent']: div.insertBefore(todo_states[todo['state']](todo), div.firstChild) else: div <= todo_states[todo['state']](todo)
def _set_text_data(self, text): from javascript import JSON if text is None: self.data = None self.text_data = None else: text_data_col = int(self.config['attr']['text_data_col']) self.text_data = text text = text['rows'][0][text_data_col].strip() if text == '': if 'text_data_init' not in self.config['attr']: window.error_toast('控件配置中缺少 text_data_init') else: text_data_init = self.config['attr']['text_data_init'] self.data = JSON.parse(text_data_init) self._set_data(self.data) else: self.data = JSON.parse(text) self._set_data(self.data)
def onload_callback(ev): if xhr.status == 200: reply = JSON.parse(xhr.responseText) if 'url' in reply: if self.event_listener is not None: self.event_listener('add', reply['url']) window.info_toast('已上传' + str(files.length) + '个文件') return if 'error' in reply: window.error_toast('上传失败: ' + reply['error']) else: window.error_toast('上传失败')
def initial_grid(self, req): displays_data = JSON.parse(req.text) for id, img_html in displays_data.items(): if not img_html: continue # print(img_html) # document[id].clear() document[id].innerHTML = img_html for child in document[id].children: child.bind("dragstart", self.dragstart_img) for clear_btn in document.select(".clear-btn"): clear_btn.bind("click", self.clear_display)
def render_model_choices(self, res): choices = JSON.parse(res.text) model_selector = document["model_selector"] model_selector.clear() is_fist = True for choice in choices: if is_fist: option = html.OPTION(choice[1], value=choice[0], selected=True) is_fist = False else: option = html.OPTION(choice[1], value=choice[0]) model_selector <= option
def get_data(self, data_name): if self.obj is None: if not hasattr(self.elt, data_name): return getattr(self.elt, data_name) else: window.error_toast('Component "%s" has no attribute "%s"' % (self.config['tag'], data_name)) else: if hasattr(self.obj, 'get_data'): return self.obj.get_data(data_name) if hasattr(self.obj, 'get_data_json_text'): data_json = self.obj.get_data_json_text(data_name) if data_json is None: return None return JSON.parse(data_json) window.error_toast('Component "%s" has no function "get_data" or "get_data_json_text"' % self.config['init']) return None
def on_initial(data): data = JSON.parse(data) Game().width = data['width'] Game().height = data['height'] Game().bots = data['bots'] Game().current_field = data['field'] Game().canvas.attrs['height'] = Game().width * PIXEL_WIDTH Game().canvas.attrs['width'] = Game().height * PIXEL_WIDTH Game().started = data['started'] for y in range(Game().width): for x in range(Game().height): Game().ctx.fillStyle = COLORS[Game().current_field[y][x]] Game().ctx.fillRect(x * PIXEL_WIDTH, y * PIXEL_WIDTH, PIXEL_WIDTH, PIXEL_WIDTH) # Game().ctx.beginPath() # Game().ctx.rect(i * PIXEL_WIDTH, j * PIXEL_WIDTH, PIXEL_WIDTH, PIXEL_WIDTH) # Game().ctx.stroke() Game().draw_bots()
def refresh_UI(new_app_info): global app_info, current_activity, data_hub, user_info user, session_code, app, app_secret = user_info window.set_user_name(user) window.user_info = '' if app in ('me', 'ui', 'elt') and user != '': window.user_info = JSON.stringify({ 'user': user, 'session_code': session_code, 'app': app, 'app_secret': app_secret }) document["login"].hidden = (user == '') document["logout"].hidden = (user != '') for activity in app_info['activities']: document['nav-' + activity['id']].unbind('click') document["main-nav"].clear() app_info.update(new_app_info) for activity in app_info['activities']: a = html.A(activity['name'], **{ 'id': 'nav-' + activity['id'], 'class': 'nav-link' }) li = html.LI(a, **{'class': 'nav-item'}) document["main-nav"] <= li a.bind('click', lambda ev: show_activity(ev.target.id)) document["main"].clear() client = user_info[0] data_hub = DataHub(client if app_info['app'] == 'db' else '', True) for i, activity in enumerate(app_info['activities']): page = html.DIV(**{'id': 'page-' + activity['id']}) document["main"] <= page if activity['ui_json'] == '': pass else: make_ui(JSON.parse(activity['ui_json']), page, data_hub) page.style.display = 'none' if len(app_info['activities']) > 0: current_activity = None show_activity('nav-' + app_info['activities'][0]['id']) data_hub.onevent('', '', '') else: window.hide_spinner_modal()
def render_form_for_edit(self, res): data = JSON.parse(res.text) # print(data) if data["type"] == "uri": document["byURIInput"].checked = True document["byModelInput"].checked = False self.cameraFromModel.style = {"display": "none"} self.cameraFormURI.style = {"display": ""} else: model_selector = document["model_selector"] model_selector.clear() for choice in data.get("choices", []): if choice[0] == data["model_id"]: option = html.OPTION(choice[1], value=choice[0], selected=True) else: option = html.OPTION(choice[1], value=choice[0]) model_selector <= option
def process_inventory(event): global inventory try: inventory = JSON.parse(event.target.result) fusedict = {} mooglelist = [u['tmrId'] for u in inventory if u['id'] == moogleid] containerlist = [u['tmrId'] for u in inventory if u['id'] == containerid if u['tmr'] <1000] ownedunits = [u['id'][:-1] for u in inventory if u['id'][0] != '9' if u['tmr'] <1000 ] for tmrId in mooglelist: tmrName = weapondict[tmrId]['name'] tmrUnit = weapondict[tmrId]['tmrUnit'] unitName = unitdict[tmrUnit]['name'] if tmrUnit[:-1] in ownedunits: if tmrId in fusedict.keys(): fusedict[tmrId]['count'] += 1 else: fusedict.update({tmrId:{'tmr':tmrName, 'unit':unitName, 'count':1, 'unitid':tmrUnit}}) if tmrId in containerlist: if tmrId in fusedict.keys(): fusedict[tmrId]['count'] += 1 else: fusedict.update({tmrId:{'tmr':tmrName, 'unit':containername[code], 'count':1, 'unitid':containerid}}) fusesort = sorted(fusedict.items(), key = lambda item: item[1]['tmr']) document['results'].clear() table = html.TABLE(Class='table table-hover') tbody = html.TBODY() table <= tbody for l in fusesort: tbody <= html.TR([html.TD(l[1]['tmr']), html.TD('\tx' + str(l[1]['count']) + '\t'), html.TD(l[1]['unit']), html.TD(html.IMG(src='https://ffbeequip.com/img/units/unit_icon_' + l[1]['unitid'] + '.png' ) )] ) document['results'] <= table except: alert('Error: Invalid file!') if 'ion-md-checkmark-circle' in filestatus.classList: filestatus.classList.remove('ion-md-checkmark-circle') filestatus.classList.add('ion-md-close-circle') elif 'ion-md-hourglass' in filestatus.classList: filestatus.classList.remove('ion-md-hourglass') filestatus.classList.add('ion-md-close-circle')
def pop(self, key, default=_UnProvided()): if type(default) is _UnProvided or JSON.stringify(key) in self.storage: return JSON.parse(self.storage.pop(JSON.stringify(key))) return default
def keys(self): return [JSON.parse(key) for key in self.storage.keys()]
def register_task(req): json_response = JSON.parse(req.text) document.select_one('div.todo div.terminal-timeline') <= html_todo( json_response)
def oncomplete(req): callback( JSON.parse(req.text) if req.status == 200 else {'error': req.text if req.text != '' else '未能从服务器获取信息'})
def __getitem__(self, key): return JSON.parse(self.storage[JSON.stringify(key)])
def requComplete(request): global unitdict unitdict = JSON.parse(request.responseText)
def reqwComplete(request): global weapondict weapondata = JSON.parse(request.responseText) weapondict = {w['id']:{'name':w['name'], 'tmrUnit':w['tmrUnit']} for w in weapondata if 'tmrUnit' in w.keys()}
def values(self): return [JSON.parse(val) for val in self.storage.values()]