• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.9.5/pyobjc-42/2.5/pyobjc/pyobjc-framework-Cocoa/Examples/AppKit/TinyTinyEdit/
1"""TinyTinyEdit -- A minimal Document-based Cocoa application."""
2from Cocoa import *
3from PyObjCTools import AppHelper
4
5class TinyTinyDocument(NSDocument):
6    textView = objc.IBOutlet()
7    path = None
8
9    def windowNibName(self):
10        return "TinyTinyDocument"
11
12    def readFromFile_ofType_(self, path, tp):
13        if self.textView is None:
14            # we're not yet fully loaded
15            self.path = path
16        else:
17            # "revert"
18            self.readFromUTF8(path)
19        return True
20
21    def writeToFile_ofType_(self, path, tp):
22        f = file(path, "w")
23        text = self.textView.string()
24        f.write(text.encode("utf8"))
25        f.close()
26        return True
27
28    def windowControllerDidLoadNib_(self, controller):
29        if self.path:
30            self.readFromUTF8(self.path)
31
32    def readFromUTF8(self, path):
33        f = file(path)
34        text = unicode(f.read(), "utf8")
35        f.close()
36        self.textView.setString_(text)
37
38
39if __name__ == "__main__":
40    AppHelper.runEventLoop()
41