def get_data(self): # print('hello', self.project_id) # try: ajax.get( f"/processor/{self.project_id}/state", oncomplete=self.on_complete, timeout=5, )
def send_word(self): word = self.guess.textContent.lower() if len(word) > 2 and word not in self.guesses: self.guesses.append(word) storage.set_guesses(self.guesses) ajax.get(f"https://app-pkmnt5mjza-rj.a.run.app/{word}", oncomplete=check) self.clear_guess("inactive")
def ajax_get_blocking(evt): log("Before blocking get") try: ajax.get("/api.txt", blocking=True, oncomplete=show_text) except Exception as exc: log(f"Error: {exc.__name__}") log("Did you start a web server (ex: 'python3 -m http.server')?") else: log("After blocking get")
def load_script(evt): """Load a Python test script.""" doc["run"].attrs["disabled"] = True script_name = evt.target.value + '?foo=%s' % time.time() def loaded(req): editor.setValue(req.text) doc["console"].value = "" # Enable "run" button. del doc["run"].attrs["disabled"] ajax.get(script_name, oncomplete=loaded, timeout=4)
def on_existing_satellites_form_shown(self, e): """ When the existing satellites form is shown, populate the satellites list. """ # hide the creation form self.create_satellite_form.collapse("hide") # the user must know the list is loading self.existing_satellites_list.html("") self.existing_satellites_list.append("<p>Loading...</p>") # request the list of satellites ajax.get("/api/satellites/", oncomplete=self.on_server_satellites_received)
def output_txt_data(e): if not document.select('#rt1'): link_txt = f'static/combs/{_name}.txt' def read(f): document['rt1'].value = f.read() div = html.DIV(html.P(), Class='form-group') div <= html.TEXTAREA(id="rt1", rows="20", cols="30", autocomplete="off", Class='form-control') document['output_txt'] <= div ajax.get(link_txt, oncomplete=read)
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 get(url, mode="json", then=None): """Request a GET method to the url provided after the request, the [then] method will be fired. Parameters ---------- url : str The URL where to request the GET mode : str Mode of the request then : method After the request, the [then] method provided will be fired passing the request object as the argument. """ ajax.get(url, mode=mode, oncomplete=then)
def get_from_server(cls, dashboard_id, callback): """ Load a user dashboard config from the server. """ print("Requesting dashboard", dashboard_id, "...") def on_dashboard_received(req): """ Before calling the specified callback, parse the response and build a dashboard instance. """ if req.status in (0, 200): print("Dashboard received from the server") dashboard = cls.from_jsobj(jsjson.parse(req.text)) callback(dashboard) else: print("Error reading the dashboard from the server") ajax.get("/api/dashboards/{}/".format(dashboard_id), oncomplete=on_dashboard_received)
def test_browser_ajax(): from browser import document, ajax def on_complete(req): if req.status == 200 or req.status == 0: document["result"].html = req.text else: document["result"].html = "error " + req.text url = "" req = ajax.Ajax() req.bind('complete', on_complete) # send a POST request to the url req.open('POST', url, True) req.set_header('content-type', 'application/x-www-form-urlencoded') # send data as a dictionary req.send({'x': 0, 'y': 1}) from browser import document, ajax def on_complete(req): if req.status == 200: document["result"].html = req.text else: document["result"].html = "error " + req.text ajax.post(url, data={'x': 0, 'y': 1}, oncomplete=on_complete) from browser import ajax def read(f): data = f.read() assert isinstance(data, bytes) req = ajax.get("tests.zip", mode="binary", oncomplete=read) from browser import ajax, bind, document def upload_ok(req): print("all right") @bind("#upload", "click") def uploadfiles(event): for f in document["choosefiles"].files: ajax.file_upload("/cgi-bin/savefile.py", f, oncomplete=upload_ok) assert True uploadfiles(evt) ## added
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 urlopen(url): t = time() req = ajax.get(url, True, oncomplete=lambda a: urlopen_read(t, a)) return loads(urlopen_dict[t])
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 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) @bind('[name="name"]', 'keydown') def check_error_message(evt): if (error := document.select_one('#error')): error.remove() ajax.get('/tasks', oncomplete=get_todos) document.select_one('#wait').remove()
def get_student_scores(self): print('weakup', datetime.datetime.now()) request = ajax.get( self.data_url, oncomplete=self.on_ajax_complete)
language = window.navigator.language # browser setting if language is not None: language = language[:2] # Translate if language in translations: for elt_id, translation in translations[language].items(): if elt_id in document: document[elt_id].attrs["title"] = translation # If there is an argument "file" in the query string, try to load a file # of the same name in this HTML page's directory load_file = document.query.getfirst("file") if load_file: # try to load the file req = ajax.get(load_file, oncomplete=lambda evt: load3(evt.text, load_file)) # Set height of container to 80% of screen height = document.documentElement.clientHeight document['container'].style.height = f'{int(height * 0.8)}px' # Set position of legend text document['legend'].style.top = f'{int(height * 0.9)}px' filezone = document["filezone"] filebrowser = document["file-browser"] open_files = {} # Maps file name to their content editor = None
from browser import ajax def show(req, expect): text = req.text if expect not in text: print(req.responseURL, expect, 'not in', text) print(text.encode('latin-1')) # ajax.get to read text files ajax.get("files/text-utf8.txt", encoding='utf-8', oncomplete=lambda req: show(req, 'bébé')) ajax.get("files/text-utf8.txt", encoding='utf-8', oncomplete=lambda req: show(req, 'bébé'), blocking=True) ajax.get("../static_doc/en/cookbook/file.txt", encoding='utf-8', oncomplete=lambda req: show(req, 'Шея')) ajax.get("../static_doc/en/cookbook/file.txt", encoding='utf-8', oncomplete=lambda req: show(req, 'Шея'), blocking=True) # other encodings ajax.get("files/text-latin1.txt",
def downloadSheetRequest(event, handler): #print(event.target) sheet = event.target["id"].split('`')[1] ajax.get("/sheets/" + document["user"].innerHTML + '/' + sheet + "/get/", oncomplete=handler)
def ajax_get(evt): log("Before async get") ajax.get("/api.txt", oncomplete=show_text) log("After async get")
def make_request(): ajax.get('/dinamico/dado', oncomplete=on_complete) timer.set_timeout(make_request, 5000)
def click_button(event): ajax.get('/page-dynamic/data', oncomplete=on_complete)
def request_simulation(): ajax.get('/page-dynamic/data', oncomplete=on_complete) timer.set_timeout(request_simulation, 2000)
def get_one(cls, url, callback): ajax.get(url, oncomplete=cls._callback_with_result(callback))
def get_all(cls, callback): ajax.get("https://rickandmortyapi.com/api/character/1,2,3,4,5,6,7,8", oncomplete=cls._callback_with_result(callback))
def get_all_camera_state(self): ajax.get( f"{self.get_state_url}", oncomplete=self.on_ajax_complete, )
def request_url(self): ajax.get(self.get_data_url, oncomplete=self.send_data_card)
def load_lesson(name, loader=True): """Initiate an AJAX request to load lesson source.""" if loader: document['lesson'].html = '<div class="loader"></div>' url = f'lessons/{name}.md' ajax.get(url, oncomplete=render_lesson)
def start(self): ajax.get(self.get_data_url, oncomplete=self.send_data_card) timer.set_interval(self.request_url, 5000)
def get_choices(self, ev): url = self.get_camera_model_choices_url.replace( "brand_id", document["brand"].value) ajax.get(url, oncomplete=self.render_model_choices)
def click_btn(evt): ajax.get('/dinamico/dado', oncomplete=on_complete)
def initial_camera(self): url = self.get_initial_form_url.replace("camera_id", self.camera_id) ajax.get(url, oncomplete=self.render_form_for_edit)