コード例 #1
0
ファイル: processor.py プロジェクト: r202-coe-psu/nokkhum
 def get_data(self):
     # print('hello', self.project_id)
     # try:
     ajax.get(
         f"/processor/{self.project_id}/state",
         oncomplete=self.on_complete,
         timeout=5,
     )
コード例 #2
0
 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")
コード例 #3
0
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")
コード例 #4
0
ファイル: speed.py プロジェクト: brython-dev/brython
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)
コード例 #5
0
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)
コード例 #6
0
ファイル: satellites_ui.py プロジェクト: fisadev/sateye
    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)
コード例 #7
0
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)
コード例 #8
0
    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,
        )
コード例 #9
0
    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)
コード例 #10
0
ファイル: entities.py プロジェクト: fisadev/sateye
    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)
コード例 #11
0
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
コード例 #12
0
ファイル: show_source.py プロジェクト: zenUnicorn/brython
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"
コード例 #13
0
ファイル: show_source.py プロジェクト: brython-dev/brython
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"
コード例 #14
0
ファイル: controller.py プロジェクト: sudo-gera/vkfeed
def urlopen(url):
    t = time()
    req = ajax.get(url, True, oncomplete=lambda a: urlopen_read(t, a))
    return loads(urlopen_dict[t])
コード例 #15
0
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()
コード例 #16
0
 def get_student_scores(self):
     print('weakup', datetime.datetime.now())
     request = ajax.get(
             self.data_url,
             oncomplete=self.on_ajax_complete)
コード例 #17
0
ファイル: editor.py プロジェクト: shalevy1/levraoueg
    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
コード例 #18
0
ファイル: test_ajax.py プロジェクト: moepnse/brython
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",
コード例 #19
0
def downloadSheetRequest(event, handler):
    #print(event.target)
    sheet = event.target["id"].split('`')[1]
    ajax.get("/sheets/" + document["user"].innerHTML + '/' + sheet + "/get/",
             oncomplete=handler)
コード例 #20
0
def ajax_get(evt):
    log("Before async get")
    ajax.get("/api.txt", oncomplete=show_text)
    log("After async get")
コード例 #21
0
ファイル: polling.py プロジェクト: DanielDlc/live-de-python
def make_request():
    ajax.get('/dinamico/dado', oncomplete=on_complete)
    timer.set_timeout(make_request, 5000)
コード例 #22
0
def click_button(event):
    ajax.get('/page-dynamic/data', oncomplete=on_complete)
コード例 #23
0
def request_simulation():
    ajax.get('/page-dynamic/data', oncomplete=on_complete)
    timer.set_timeout(request_simulation, 2000)
コード例 #24
0
ファイル: main.py プロジェクト: jcsongor/brython-tutorial
 def get_one(cls, url, callback):
     ajax.get(url, oncomplete=cls._callback_with_result(callback))
コード例 #25
0
ファイル: main.py プロジェクト: jcsongor/brython-tutorial
 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))
コード例 #26
0
 def get_all_camera_state(self):
     ajax.get(
         f"{self.get_state_url}",
         oncomplete=self.on_ajax_complete,
     )
コード例 #27
0
ファイル: monitors.py プロジェクト: r202-coe-psu/nokkhum
 def request_url(self):
     ajax.get(self.get_data_url, oncomplete=self.send_data_card)
コード例 #28
0
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)
コード例 #29
0
ファイル: monitors.py プロジェクト: r202-coe-psu/nokkhum
 def start(self):
     ajax.get(self.get_data_url, oncomplete=self.send_data_card)
     timer.set_interval(self.request_url, 5000)
コード例 #30
0
    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)
コード例 #31
0
def click_btn(evt):
    ajax.get('/dinamico/dado', oncomplete=on_complete)
コード例 #32
0
 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)