예제 #1
0
    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()
예제 #2
0
 def makeWindowControllers(self):
     self.windowController = DrawBotController()
     self.windowController.assignToDocument(self)
     url = self.fileURL()
     if url:
         self.windowController.setPath(url.path())
     self.windowController.open()
예제 #3
0
파일: DrawBot.py 프로젝트: bitforks/drawbot
    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()
예제 #4
0
class DrawBotDocument(AppKit.NSDocument):
    def readFromFile_ofType_(self, path, tp):
        return True, None

    def writeSafelyToURL_ofType_forSaveOperation_error_(
            self, url, fileType, saveOperation, error):
        path = url.path()
        code = self.vanillaWindowController.code()
        f = open(path, "wb")
        f.write(code.encode("utf8"))
        f.close()
        self._modDate = self.getModificationDate(path)
        return True, None

    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()
        self._modDate = self.getModificationDate()

    # main menu callbacks

    def runCode_(self, sender):
        liveCoding = False
        if hasattr(sender, "isLiveCoding"):
            liveCoding = sender.isLiveCoding()
        self.vanillaWindowController.runCode(liveCoding)
        return True

    def checkSyntax_(self, sender):
        self.vanillaWindowController.checkSyntax()
        return True

    def saveDocumentAsPDF_(self, sender):
        self.vanillaWindowController.savePDF()
        return True

    def validateMenuItem_(self, menuItem):
        if menuItem.action() in ("saveDocumentAsPDF:"):
            return self.vanillaWindowController.pdfData() is not None
        return True

    def testForExternalChanges(self):
        if self._modDate is None:
            return
        url = self.fileURL()
        if url is None:
            return
        path = url.path()

        modDate = self.getModificationDate()
        if modDate > self._modDate:

            def _update(value):
                if value:
                    self.vanillaWindowController.setPath(path)

            if self.isDocumentEdited():
                self.vanillaWindowController.showAskYesNo(
                    "External Change", "Update this un-saved document.",
                    _update)
            else:
                _update(True)
            self._modDate = modDate

    def getModificationDate(self, path=None):
        if path is None:
            url = self.fileURL()
            if url is None:
                return None
            path = url.path()
        fm = AppKit.NSFileManager.defaultManager()
        attr, error = fm.attributesOfItemAtPath_error_(path, None)
        if attr is None:
            return None
        return attr.fileModificationDate()
예제 #5
0
class DrawBotDocument(NSDocument):
    def readFromFile_ofType_(self, path, tp):
        return True, None

    def writeSafelyToURL_ofType_forSaveOperation_error_(
            self, url, fileType, saveOperation, error):
        path = url.path()
        code = self.vanillaWindowController.code()
        f = file(path, "w")
        f.write(code.encode("utf8"))
        f.close()
        return True, None

    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()

    # main menu callbacks

    def runCode_(self, sender):
        liveCoding = False
        if hasattr(sender, "isLiveCoding"):
            liveCoding = sender.isLiveCoding()
        self.vanillaWindowController.runCode(liveCoding)
        return True

    def checkSyntax_(self, sender):
        self.vanillaWindowController.checkSyntax()
        return True

    def saveDocumentAsPDF_(self, sender):
        self.vanillaWindowController.savePDF()
        return True

    def validateMenuItem_(self, menuItem):
        if menuItem.action() in ("saveDocumentAsPDF:"):
            return self.vanillaWindowController.pdfData() is not None
        return True
예제 #6
0
파일: DrawBot.py 프로젝트: bitforks/drawbot
class DrawBotDocument(AppKit.NSDocument):

    def readFromFile_ofType_(self, path, tp):
        return True, None

    def writeSafelyToURL_ofType_forSaveOperation_error_(self, url, fileType, saveOperation, error):
        path = url.path()
        code = self.vanillaWindowController.code()
        f = file(path, "w")
        f.write(code.encode("utf8"))
        f.close()
        return True, None

    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()

    # main menu callbacks

    def runCode_(self, sender):
        liveCoding = False
        if hasattr(sender, "isLiveCoding"):
            liveCoding = sender.isLiveCoding()
        self.vanillaWindowController.runCode(liveCoding)
        return True

    def checkSyntax_(self, sender):
        self.vanillaWindowController.checkSyntax()
        return True

    def saveDocumentAsPDF_(self, sender):
        self.vanillaWindowController.savePDF()
        return True

    def validateMenuItem_(self, menuItem):
        if menuItem.action() in ("saveDocumentAsPDF:"):
            return self.vanillaWindowController.pdfData() is not None
        return True
예제 #7
0
파일: DrawBot.py 프로젝트: thomgb/drawbot
class DrawBotDocument(AppKit.NSDocument):

    def readFromFile_ofType_(self, path, tp):
        return True, None

    def writeSafelyToURL_ofType_forSaveOperation_error_(self, url, fileType, saveOperation, error):
        path = url.path()
        code = self.vanillaWindowController.code()
        f = file(path, "w")
        f.write(code.encode("utf8"))
        f.close()
        self._modDate = self.getModificationDate(path)
        return True, None

    def makeWindowControllers(self):
        self.vanillaWindowController = DrawBotController()
        wc = self.vanillaWindowController.w.getNSWindowController()
        self.addWindowController_(wc)
        wc.setShouldCloseDocument_(True)

        url = self.fileURL()
        if url:
            self.vanillaWindowController.setPath(url.path())
        self.vanillaWindowController.open()
        self._modDate = self.getModificationDate()

    # main menu callbacks

    def runCode_(self, sender):
        liveCoding = False
        if hasattr(sender, "isLiveCoding"):
            liveCoding = sender.isLiveCoding()
        self.vanillaWindowController.runCode(liveCoding)
        return True

    def checkSyntax_(self, sender):
        self.vanillaWindowController.checkSyntax()
        return True

    def saveDocumentAsPDF_(self, sender):
        self.vanillaWindowController.savePDF()
        return True

    def validateMenuItem_(self, menuItem):
        if menuItem.action() in ("saveDocumentAsPDF:"):
            return self.vanillaWindowController.pdfData() is not None
        return True

    def testForExternalChanges(self):
        if self._modDate is None:
            return
        url = self.fileURL()
        if url is None:
            return
        path = url.path()

        modDate = self.getModificationDate()
        if modDate > self._modDate:
            def _update(value):
                if value:
                    self.vanillaWindowController.setPath(path)

            if self.isDocumentEdited():
                self.vanillaWindowController.showAskYesNo("External Change", "Update this un-saved document.", _update)
            else:
                _update(True)
            self._modDate = modDate

    def getModificationDate(self, path=None):
        if path is None:
            url = self.fileURL()
            if url is None:
                return None
            path = url.path()
        fm = AppKit.NSFileManager.defaultManager()
        attr, error = fm.attributesOfItemAtPath_error_(path, None)
        if attr is None:
            return None
        return attr.fileModificationDate()