# # REAppDelegate.py # ReSTedit # # Created by Dinu Gherman on Wed Jul 02 2003. # Copyright (c) 2003 Dinu Gherman. All rights reserved. # import os from PyObjCTools import NibClassBuilder import objc from objc import * from Foundation import * from AppKit import * # create ObjC classes as defined in MainMenu.nib NibClassBuilder.extractClasses("MainMenu") from REDocument import REDocument def path2dict(path): bundlePath = NSBundle.mainBundle().bundlePath() value = {} value['path'] = path value['shortName'] = NSString.lastPathComponent(path) if path.find(bundlePath) == 0: value['displayName'] = '%s (built in)' % NSString.lastPathComponent(path) else: value['displayName'] = '%s - %s' % (NSString.lastPathComponent(path), NSString.stringByDeletingLastPathComponent(path)) return value class REAppDelegate(NibClassBuilder.AutoBaseClass): infoPanel = ivar('infoPanel') styleSheets = ivar('styleSheets') pdfEnabled = ivar('pdfEnabled', objc._C_BOOL) def init(self): self = super(REAppDelegate, self).init() # add known LaTeX path to environment PATH, if needed texPath = ":/usr/local/teTeX/bin/powerpc-apple-darwin-current" os.environ["PATH"] += texPath # try disabling PDF export menu item, if needed... res = os.popen("which pdflatex").read() self.pdfEnabled = len(res) and res[0] == '/' return self def showInfoPanel_(self, sender): if self.infoPanel is None: from REInfoPanel import REInfoPanel self.infoPanel = REInfoPanel.alloc().init() self.infoPanel.showWindow_(sender) def applicationShouldOpenUntitledFile_(self, sender): # return NO if you don't want untitled document to be opened on app launch return YES def openReSTSourceURL_(self, u): d = REDocument.alloc().initWithContentsOfURL_ofType_(u, "ReSTDoc") if not d: print "failed to create document" return NSDocumentController.sharedDocumentController().addDocument_(d) d.makeWindowControllers() d.showWindows() def showReSTQuickStart_(self, sender): u = NSURL.URLWithString_("http://docutils.sourceforge.net/docs/rst/quickstart.txt") self.openReSTSourceURL_(u) def showReSTReference_(self, sender): u = NSURL.URLWithString_("http://docutils.sourceforge.net/spec/rst/reStructuredText.txt") self.openReSTSourceURL_(u) def availableStyleSheets(self): if not self.styleSheets: styleSheets = [] for p in NSBundle.mainBundle().pathsForResourcesOfType_inDirectory_("css", None): styleSheets.append(path2dict(p)) supportDirectory = NSWorkspace.sharedWorkspace().applicationSupportDirectory() supportContents = NSFileManager.defaultManager().directoryContentsAtPath_(supportDirectory) for aFile in supportContents: if aFile[-4:] == '.css': styleSheets.append(path2dict(os.path.join(supportDirectory, aFile))) self.styleSheets = styleSheets return self.styleSheets