예제 #1
0
def share_code(ev):
    src = editor.getValue()
    if len(src) > 2048:
        d = dialog.InfoDialog("Copy url",
                              f"code length is {len(src)}, must be < 2048",
                              style={"zIndex": 10},
                              ok=True)
    else:
        href = window.location.href.rsplit("?", 1)[0]
        query = doc.query
        query["code"] = src
        url = f"{href}{query}"
        url = url.replace("(", "%28").replace(")", "%29")
        d = dialog.Dialog("Copy url")
        area = html.TEXTAREA(rows=0, cols=0)
        d.panel <= area
        area.value = url
        # copy to clipboard
        area.focus()
        area.select()
        doc.execCommand("copy")
        d.remove()
        d = dialog.Dialog("Copy url")
        d.panel <= html.DIV("url copied in the clipboard<br>Send it to share the code")
        buttons = html.DIV()
        ok = html.BUTTON("Ok")
        buttons <= html.DIV(ok, style={"text-align": "center"})
        d.panel <= html.BR() + buttons

        @bind(ok, "click")
        def click(evt):
            d.remove()
예제 #2
0
def sheetReplyGeneric(response, dialogStrings, replyKeys):
    if response.status == 200:
        reply = ajaxParseJSON(response)
        if reply["error"] == "None.":
            dialog.InfoDialog(
             dialogStrings["noErrorTitle"],
             dialogStrings["noErrorBody"].format([
              reply[key] for key in replyKeys
             ]),
             default_css = (
              dialogStrings["defaultCSS"] \
               if "defaultCSS" in dialogStrings.keys()
               else True
             )
            )
        else:
            dialog.InfoDialog(dialogStrings["errorTitle"], reply["error"])
    else:
        dialogShowHTTPError(response)
예제 #3
0
def open_success(evt):
    db = evt.target.result
    if not db.objectStoreNames.contains("modules"):
        dialog.InfoDialog('indexedDB cache', 'db has no store "modules"')
        return

    table = TABLE(border=1)
    table <= TR(
        TH(col) for col in
        ['Name', 'Package', 'Size', 'Brython timestamp', 'Stdlib timestamp'])
    tx = db.transaction("modules", "readwrite")
    store = tx.objectStore("modules")
    outdated = []

    openCursor = store.openCursor()

    @bind(openCursor, "error")
    def cursor_error(evt):
        print("open cursor error", evt)

    @bind(openCursor, "success")
    def cursor_success(evt):
        infos['nb_modules'] += 1
        cursor = evt.target.result
        if cursor:
            record = cursor.value
            timestamp = datetime.fromtimestamp(record.timestamp / 1000)
            source_ts = datetime.fromtimestamp(record.source_ts / 1000)
            table <= TR(
                TD(record.name) + TD(bool(record.is_package)) +
                TD(len(record.content), align="right") +
                TD(timestamp.strftime('%Y-%m-%d %H:%M')) +
                TD(source_ts.strftime('%Y-%m-%d %H:%M')))
            infos['size'] += len(record.content)
            getattr(cursor, "continue")()
        else:
            panel = dialog.Dialog('indexedDB cache', top=0, left=0).panel
            panel <= H1("Brython indexedDB cache")
            size = '{:,d}'.format(infos['size'])
            panel <= H3(f"{infos['nb_modules']} modules, size {size} bytes")
            panel <= table
예제 #4
0
def dialogShowHTTPError(response):
    dialog.InfoDialog("HTTP Error",
                      str(response.status) + ": " + str(response.text))
예제 #5
0
 def evaluate(entryEvent):
     value = box.value
     box.close()
     print(value)
     dialog.InfoDialog("Foobar", value + "?")