Esempio n. 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()
Esempio n. 2
0
def CopyTextToClipborad(string):
    #將文字先禁行解碼
    string = JavascriptSymbolDecoder(string)
    #製作暫時元素複製文字
    textarea_elt_forCopyText = TEXTAREA()
    textarea_elt_forCopyText.text = string
    doc <= textarea_elt_forCopyText
    textarea_elt_forCopyText.select()
    doc.execCommand("copy")
    textarea_elt_forCopyText.remove()
    def handlePaste(self, e):
        e.preventDefault()
        try:
            text = e.clipboardData.getData("text/plain")
            doc.execCommand("insertHTML", False, text)
        except:
            pass

        try:
            text = window.clipboardData.getData("Text")
            self.insertTextAtCursor(text)
        except:
            pass
Esempio n. 4
0
 def keypress(self, event):
     if event.key == "Tab":  # tab key
         event.preventDefault()
         self.zone.value += "    "
     elif event.key == "Enter":  # return
         sel_start = self.zone.selectionStart
         sel_end = self.zone.selectionEnd
         if sel_end > sel_start:
             # If text was selected by the mouse, copy to clipboard
             document.execCommand("copy")
             self.cursor_to_end()
             event.preventDefault()  # don't insert line feed
             return
         src = self.zone.value
         self.handle_line(self, event)
Esempio n. 5
0
def CopyTextToClipborad(string):
    #定義函式:JS特殊符號解碼器
    def JavascriptSymbolDecoder(encodedStr):
        parser =window.DOMParser.new()
        dom=parser.parseFromString('<!doctype html><body>'+ encodedStr,'text/html')
        decodedString =dom.body.textContent
        return decodedString
    #將文字先禁行解碼
    string=JavascriptSymbolDecoder(string)
    #製作暫時元素複製文字
    textarea_elt_forCopyText=TEXTAREA()
    textarea_elt_forCopyText.text=string
    doc<=textarea_elt_forCopyText
    textarea_elt_forCopyText.select()
    doc.execCommand("copy")
    textarea_elt_forCopyText.remove()
Esempio n. 6
0
    def keypress(self, event):
        if event.keyCode == 9:  # tab key
            event.preventDefault()
            self.zone.value += "    "
        elif event.keyCode == 13:  # return
            sel_start = self.zone.selectionStart
            sel_end = self.zone.selectionEnd
            if sel_end > sel_start:
                # If text was selected by the mouse, copy to clipboard
                document.execCommand("copy")
                self.cursor_to_end()
                event.preventDefault() # don't insert line feed
                return
            src = self.zone.value
            if self._status == "main":
                currentLine = src[src.rfind('\n>>>') + 5:]
            elif self._status == "3string":
                currentLine = src[src.rfind('\n>>>') + 5:]
                currentLine = currentLine.replace('\n... ', '\n')
            else:
                currentLine = src[src.rfind('\n...') + 5:]
            if self._status == 'main' and not currentLine.strip():
                self.zone.value += '\n>>> '
                event.preventDefault()
                return
            self.zone.value += '\n'
            self.history.append(currentLine)
            self.current = len(self.history)
            if self._status in ["main", "3string"]:
                try:
                    _ = self.globals['_'] = eval(currentLine,
                                              self.globals,
                                              self.locals)
                    if _ is not None:
                        self.write(repr(_) + '\n')
                    self.flush()
                    self.zone.value += '>>> '
                    self._status = "main"
                except IndentationError:
                    self.zone.value += '... '
                    self._status = "block"
                except SyntaxError as msg:
                    if str(msg) == 'invalid syntax : triple string end not found' or \
                            str(msg).startswith('Unbalanced bracket'):
                        self.zone.value += '... '
                        self._status = "3string"
                    elif str(msg) == 'eval() argument must be an expression':
                        try:
                            exec(currentLine,
                                self.globals,
                                self.locals)
                        except:
                            self.print_tb()
                        self.flush()
                        self.zone.value += '>>> '
                        self._status = "main"
                    elif str(msg) == 'decorator expects function':
                        self.zone.value += '... '
                        self._status = "block"
                    else:
                        self.syntax_error(msg.args)
                        self.zone.value += '>>> '
                        self._status = "main"
                except:
                    # the full traceback includes the call to eval(); to
                    # remove it, it is stored in a buffer and the 2nd and 3rd
                    # lines are removed
                    self.print_tb()
                    self.zone.value += '>>> '
                    self._status = "main"
            elif currentLine == "":  # end of block
                block = src[src.rfind('\n>>>') + 5:].splitlines()
                block = [block[0]] + [b[4:] for b in block[1:]]
                block_src = '\n'.join(block)
                # status must be set before executing code in globals()
                self._status = "main"
                try:
                    _ = exec(block_src,
                             self.globals,
                             self.locals)
                    if _ is not None:
                        print(repr(_))
                except:
                    self.print_tb()
                self.flush()
                self.zone.value += '>>> '
            else:
                self.zone.value += '... '

            self.cursor_to_end()
            event.preventDefault()
Esempio n. 7
0
def copy(event):
    textElement = document['downloadLink']
    textElement.select()
    document.execCommand('copy')
Esempio n. 8
0
 def clip_copy(self):
     self.elm.focus()
     self.elm.select()
     document.execCommand('copy')
Esempio n. 9
0
 def copy(self):
     self.elm.select()
     document.execCommand('copy')