Exemple #1
0
 def applicationDidFinishLaunching_(self, notification):
     self._debugger = DebugWindowController()
     Updater()
     if sys.argv[1:]:
         import re
         pat = re.compile("--testScript=(.*)")
         for arg in sys.argv[1:]:
             m = pat.match(arg)
             if m is None:
                 continue
             testScript = m.group(1)
             self._runTestScript_(testScript)
             AppKit.NSApp().terminate_(None)
Exemple #2
0
 def applicationDidFinishLaunching_(self, notification):
     retrieveCheckEventQueueForUserCancelFromCarbon()
     self._debugger = DebugWindowController()
     Updater()
     if sys.argv[1:]:
         import re
         pat = re.compile("--testScript=(.*)")
         for arg in sys.argv[1:]:
             m = pat.match(arg)
             if m is None:
                 continue
             AppKit.NSApp().activateIgnoringOtherApps_(True)
             testScript = m.group(1)
             self.performSelector_withObject_afterDelay_("_runTestScript:", testScript, 0.25)
Exemple #3
0
 def applicationDidFinishLaunching_(self, notification):
     retrieveCheckEventQueueForUserCancelFromCarbon()
     self._debugger = DebugWindowController()
     Updater()
     if sys.argv[1:]:
         import re
         pat = re.compile("--testScript=(.*)")
         for arg in sys.argv[1:]:
             m = pat.match(arg)
             if m is None:
                 continue
             AppKit.NSApp().activateIgnoringOtherApps_(True)
             testScript = m.group(1)
             self.performSelector_withObject_afterDelay_("_runTestScript:", testScript, 0.25)
Exemple #4
0
class DrawBotAppDelegate(AppKit.NSObject):
    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

    def applicationDidFinishLaunching_(self, notification):
        retrieveCheckEventQueueForUserCancelFromCarbon()
        self._debugger = DebugWindowController()
        Updater()
        if sys.argv[1:]:
            import re
            pat = re.compile("--testScript=(.*)")
            for arg in sys.argv[1:]:
                m = pat.match(arg)
                if m is None:
                    continue
                AppKit.NSApp().activateIgnoringOtherApps_(True)
                testScript = m.group(1)
                self.performSelector_withObject_afterDelay_(
                    "_runTestScript:", testScript, 0.25)

    def _runTestScript_(self, testScript):
        import traceback
        assert os.path.exists(testScript), "%r cannot be found" % testScript
        with open(testScript) as f:
            source = f.read()
        try:
            exec(source, {"__name__": "__main__", "__file__": testScript})
        except Exception:
            traceback.print_exc()
        AppKit.NSApp().terminate_(None)

    def applicationDidBecomeActive_(self, notification):
        for document in AppKit.NSApp().orderedDocuments():
            document.testForExternalChanges()
        self.sheduleIconTimer()

    def applicationShouldOpenUntitledFile_(self, sender):
        return getDefault("shouldOpenUntitledFile", True)

    def sheduleIconTimer(self):
        if getDefault("DrawBotAnimateIcon", True):
            self._iconTimer = AppKit.NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                0.1, self, "animateApplicationIcon:", None, False)

    _iconCounter = 0
    _iconHand = random.choice(["left", "right"])

    def animateApplicationIcon_(self, timer):
        if AppKit.NSApp().isActive():
            image = AppKit.NSImage.imageNamed_(
                "icon_%s_%s" % (self._iconHand, self._iconCounter))
            AppKit.NSApp().setApplicationIconImage_(image)
            self._iconCounter += 1
            if self._iconCounter > 20:
                self._iconCounter = 0
            self.sheduleIconTimer()

    def showDocumentation_(self, sender):
        url = "http://www.drawbot.com"
        ws = AppKit.NSWorkspace.sharedWorkspace()
        ws.openURL_(AppKit.NSURL.URLWithString_(url))

    def showPreferences_(self, sender):
        try:
            self.preferencesController.show()
        except Exception:
            self.preferencesController = PreferencesController()

    def showDebug_(self, sender):
        self._debugger.showHide()

    def showForum_(self, sender):
        url = "http://forum.drawbot.com"
        ws = AppKit.NSWorkspace.sharedWorkspace()
        ws.openURL_(AppKit.NSURL.URLWithString_(url))

    def buildPackage_(self, sender):
        DrawBotPackageController()

    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)

    def performFindPanelAction_(self, action):
        try:
            # a bug somewhere in OSX
            # the short cuts (fe cmd+g) arent redirected properly to the text views
            view = AppKit.NSApp().keyWindow().firstResponder()
            dest = view.superview().superview().superview()._contentView(
            ).documentView()
            dest.performFindPanelAction_(action)
        except Exception:
            pass

    def application_openFile_(self, app, path):
        ext = os.path.splitext(path)[-1]
        if ext.lower() == ".drawbot":
            succes, report = DrawBotPackage(path).run()
            if not succes:
                fileName = os.path.basename(path)
                message("The DrawBot package '%s' failed." % fileName, report)
            return True
        return False
Exemple #5
0
 def applicationDidFinishLaunching_(self, notification):
     self._debugger = DebugWindowController()
     Updater()
Exemple #6
0
class DrawBotAppDelegate(NSObject):
    def init(self):
        self = super(DrawBotAppDelegate, self).init()
        code = stringToInt("GURL")
        NSAppleEventManager.sharedAppleEventManager(
        ).setEventHandler_andSelector_forEventClass_andEventID_(
            self, "getUrl:withReplyEvent:", code, code)
        return self

    def applicationDidFinishLaunching_(self, notification):
        self._debugger = DebugWindowController()
        Updater()

    def applicationDidBecomeActive_(self, notification):
        self.sheduleIconTimer()

    def applicationShouldOpenUntitledFile_(self, sender):
        return True

    def sheduleIconTimer(self):
        if getDefault("DrawBotAnimateIcon", True):
            self._iconTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                0.1, self, "animateApplicationIcon:", None, False)

    def animateApplicationIcon_(self, timer):
        if NSApp().isActive():
            image = NSImage.imageNamed_("icon_%s" % randint(0, 20))
            NSApp().setApplicationIconImage_(image)
            self.sheduleIconTimer()

    def showDocumentation_(self, sender):
        url = "http://www.drawbot.com"
        ws = NSWorkspace.sharedWorkspace()
        ws.openURL_(NSURL.URLWithString_(url))

    def showPreferences_(self, sender):
        try:
            self.preferencesController.show()
        except:
            self.preferencesController = PreferencesController()

    def showDebug_(self, sender):
        self._debugger.showHide()

    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.vanillaWindowController.setCode(code)
        else:
            # local
            pythonPath = data.path
            f = open(pythonPath, "rb")
            code = f.read()
            f.close()
            document, error = documentController.openUntitledDocumentAndDisplay_error_(
                True, None)
            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, data.netloc),
            result)
Exemple #7
0
 def applicationDidFinishLaunching_(self, notification):
     self._debugger = DebugWindowController()
     Updater()
Exemple #8
0
class DrawBotAppDelegate(AppKit.NSObject):

    def init(self):
        self = super(DrawBotAppDelegate, self).init()
        code = stringToInt("GURL")
        AppKit.NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(self, "getUrl:withReplyEvent:", code, code)
        return self

    def applicationDidFinishLaunching_(self, notification):
        self._debugger = DebugWindowController()
        Updater()

    def applicationDidBecomeActive_(self, notification):
        self.sheduleIconTimer()

    def applicationShouldOpenUntitledFile_(self, sender):
        return True

    def sheduleIconTimer(self):
        if getDefault("DrawBotAnimateIcon", True):
            self._iconTimer = AppKit.NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.1, self, "animateApplicationIcon:", None, False)

    def animateApplicationIcon_(self, timer):
        if AppKit.NSApp().isActive():
            image = AppKit.NSImage.imageNamed_("icon_%s" % randint(0, 20))
            AppKit.NSApp().setApplicationIconImage_(image)
            self.sheduleIconTimer()

    def showDocumentation_(self, sender):
        url = "http://www.drawbot.com"
        ws = AppKit.NSWorkspace.sharedWorkspace()
        ws.openURL_(AppKit.NSURL.URLWithString_(url))

    def showPreferences_(self, sender):
        try:
            self.preferencesController.show()
        except:
            self.preferencesController = PreferencesController()

    def showDebug_(self, sender):
        self._debugger.showHide()

    def getUrl_withReplyEvent_(self, event, reply):
        import urlparse
        import urllib2
        code = stringToInt("----")
        url = event.paramDescriptorForKeyword_(code)
        urlString = url.stringValue()
        documentController = AppKit.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.vanillaWindowController.setCode(code)
        else:
            # local
            pythonPath = data.path
            f = open(pythonPath, "rb")
            code = f.read()
            f.close()
            document, error = documentController.openUntitledDocumentAndDisplay_error_(True, None)
            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, data.netloc),
            result
            )
Exemple #9
0
class DrawBotAppDelegate(NSObject):
    
    def init(self):
        self = super(DrawBotAppDelegate, self).init()
        code = stringToInt("GURL")
        NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(self, "getUrl:withReplyEvent:", code, code)
        return self

    def applicationDidFinishLaunching_(self, notification):
        self._debugger = DebugWindowController()

    def applicationDidBecomeActive_(self, notification):
        self.sheduleIconTimer()

    def applicationShouldOpenUntitledFile_(self, sender):
        return True

    def sheduleIconTimer(self):
        if getDefault("DrawBotAnimateIcon", True):
            self._iconTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.1, self, "animateApplicationIcon:", None, False)

    def animateApplicationIcon_(self, timer):
        if NSApp().isActive():
            image = NSImage.imageNamed_("icon_%s" % randint(0, 20))
            NSApp().setApplicationIconImage_(image)
            self.sheduleIconTimer()

    def showDocumentation_(self, sender):
        url = "http://www.drawbot.com"
        ws = NSWorkspace.sharedWorkspace()
        ws.openURL_(NSURL.URLWithString_(url))

    def showPreferences_(self, sender):
        try:
            self.preferencesController.show()
        except:
            self.preferencesController = PreferencesController()

    def showDebug_(self, sender):
        self._debugger.showHide()

    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)
Exemple #10
0
class DrawBotAppDelegate(AppKit.NSObject):

    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

    def applicationDidFinishLaunching_(self, notification):
        retrieveCheckEventQueueForUserCancelFromCarbon()
        self._debugger = DebugWindowController()
        Updater()
        if sys.argv[1:]:
            import re
            pat = re.compile("--testScript=(.*)")
            for arg in sys.argv[1:]:
                m = pat.match(arg)
                if m is None:
                    continue
                AppKit.NSApp().activateIgnoringOtherApps_(True)
                testScript = m.group(1)
                self.performSelector_withObject_afterDelay_("_runTestScript:", testScript, 0.25)

    def _runTestScript_(self, testScript):
        import traceback
        assert os.path.exists(testScript), "%r cannot be found" % testScript
        with open(testScript) as f:
            source = f.read()
        try:
            exec(source, {"__name__": "__main__", "__file__": testScript})
        except Exception:
            traceback.print_exc()
        AppKit.NSApp().terminate_(None)

    def applicationDidBecomeActive_(self, notification):
        for document in AppKit.NSApp().orderedDocuments():
            document.testForExternalChanges()
        self.sheduleIconTimer()

    def applicationShouldOpenUntitledFile_(self, sender):
        return getDefault("shouldOpenUntitledFile", True)

    def sheduleIconTimer(self):
        if getDefault("DrawBotAnimateIcon", True):
            self._iconTimer = AppKit.NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.1, self, "animateApplicationIcon:", None, False)

    _iconCounter = 0
    _iconHand = random.choice(["left", "right"])

    def animateApplicationIcon_(self, timer):
        if AppKit.NSApp().isActive():
            image = AppKit.NSImage.imageNamed_("icon_%s_%s" % (self._iconHand, self._iconCounter))
            AppKit.NSApp().setApplicationIconImage_(image)
            self._iconCounter += 1
            if self._iconCounter > 20:
                self._iconCounter = 0
            self.sheduleIconTimer()

    def showDocumentation_(self, sender):
        url = "http://www.drawbot.com"
        ws = AppKit.NSWorkspace.sharedWorkspace()
        ws.openURL_(AppKit.NSURL.URLWithString_(url))

    def showPreferences_(self, sender):
        try:
            self.preferencesController.show()
        except Exception:
            self.preferencesController = PreferencesController()

    def showDebug_(self, sender):
        self._debugger.showHide()

    def showForum_(self, sender):
        url = "http://forum.drawbot.com"
        ws = AppKit.NSWorkspace.sharedWorkspace()
        ws.openURL_(AppKit.NSURL.URLWithString_(url))

    def buildPackage_(self, sender):
        DrawBotPackageController()

    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
        )

    def performFindPanelAction_(self, action):
        try:
            # a bug somewhere in OSX
            # the short cuts (fe cmd+g) arent redirected properly to the text views
            view = AppKit.NSApp().keyWindow().firstResponder()
            dest = view.superview().superview().superview()._contentView().documentView()
            dest.performFindPanelAction_(action)
        except Exception:
            pass

    def application_openFile_(self, app, path):
        ext = os.path.splitext(path)[-1]
        if ext.lower() == ".drawbot":
            succes, report = DrawBotPackage(path).run()
            if not succes:
                fileName = os.path.basename(path)
                message("The DrawBot package '%s' failed." % fileName, report)
            return True
        return False