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
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
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()
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()