Exemplo n.º 1
0
 def init(self):
     self = super(DrawBotAppDelegate, self).init()
     code = stringToInt(b"GURL")
     AppKit.NSAppleEventManager.sharedAppleEventManager(
     ).setEventHandler_andSelector_forEventClass_andEventID_(
         self, "getUrl:withReplyEvent:", code, code)
     return self
Exemplo n.º 2
0
 def init(self):
     
     self = objc.super(DrawBotAppDelegate, self).init()
     code = stringToInt("GURL")
     ae = AppKit.NSAppleEventManager.sharedAppleEventManager()
     ae.setEventHandler_andSelector_forEventClass_andEventID_(
                                 self, "getUrl:withReplyEvent:", code, code)
     return self
Exemplo n.º 3
0
    def getUrl_withReplyEvent_(self, event, reply):
        if PY3:
            from urllib.parse import urlparse
            from urllib.request import urlopen
        else:
            from urlparse import urlparse
            from urllib2 import urlopen
        code = stringToInt(b"----")
        url = event.paramDescriptorForKeyword_(code)
        urlString = url.stringValue()
        documentController = AppKit.NSDocumentController.sharedDocumentController(
        )

        data = urlparse(urlString)
        if data.netloc:
            # in the cloudzzz
            pythonPath = "http://%s%s" % (data.netloc, data.path)
            response = urlopen(pythonPath)
            code = response.read()
            response.close()
        else:
            # local
            pythonPath = data.path
            f = open(pythonPath, "rb")
            code = f.read()
            f.close()
        document, error = documentController.openUntitledDocumentAndDisplay_error_(
            True, None)
        try:
            code = code.decode("utf-8")
        except Exception:
            pass
        document.vanillaWindowController.setCode(code)

        def result(shouldOpen):
            if not shouldOpen:
                document.close()

        fileName = os.path.basename(data.path)
        domain = data.netloc
        if not domain:
            domain = "Local"
        document.vanillaWindowController.showAskYesNo(
            "Download External Script", "You opened '%s' from '%s'.\n\n"
            "Read the code before running it so you know what it will do. If you don't understand it, don't run it.\n\n"
            "Do you want to open this Script?" % (fileName, domain), result)
Exemplo n.º 4
0
    def getUrl_withReplyEvent_(self, event, reply):
        if PY3:
            from urllib.parse import urlparse
            from urllib.request import urlopen
        else:
            from urlparse import urlparse
            from urllib2 import urlopen
        code = stringToInt(b"----")
        url = event.paramDescriptorForKeyword_(code)
        urlString = url.stringValue()
        documentController = AppKit.NSDocumentController.sharedDocumentController()

        data = urlparse(urlString)
        if data.netloc:
            # in the cloudzzz
            pythonPath = "http://%s%s" % (data.netloc, data.path)
            response = urlopen(pythonPath)
            code = response.read()
            response.close()
        else:
            # local
            pythonPath = data.path
            f = open(pythonPath, "rb")
            code = f.read()
            f.close()
        document, error = documentController.openUntitledDocumentAndDisplay_error_(True, None)
        try:
            code = code.decode("utf-8")
        except Exception:
            pass
        document.vanillaWindowController.setCode(code)

        def result(shouldOpen):
            if not shouldOpen:
                document.close()

        fileName = os.path.basename(data.path)
        domain = data.netloc
        if not domain:
            domain = "Local"
        document.vanillaWindowController.showAskYesNo("Download External Script",
            "You opened '%s' from '%s'.\n\n"
            "Read the code before running it so you know what it will do. If you don't understand it, don't run it.\n\n"
            "Do you want to open this Script?" % (fileName, domain),
            result
        )
Exemplo n.º 5
0
    def getUrl_withReplyEvent_(self, event, reply):
        import urlparse, urllib2
        code = stringToInt("----")
        url = event.paramDescriptorForKeyword_(code)
        urlString = url.stringValue()
        documentController = NSDocumentController.sharedDocumentController()

        data = urlparse.urlparse(urlString)
        if data.netloc:
            # in the cloudzzz
            pythonPath = "http://%s%s" % (data.netloc, data.path)
            response = urllib2.urlopen(pythonPath)
            code = response.read()
            response.close()
            document, error = documentController.openUntitledDocumentAndDisplay_error_(True, None)
            document.windowController.setCode(code)
        else:
            # local
            pythonPath = data.path
            f = open(pythonPath, "rb")
            code = f.read()
            f.close()
            document, error = documentController.openUntitledDocumentAndDisplay_error_(True, None)
            document.windowController.setCode(code)