Commits

Anonymous committed a5f1df6

new doc-based example

Comments (0)

Files changed (9)

pyobjc/Examples/00ReadMe.txt

 
   Basic demo that shows how to use a NSTableView.
 
+- TinyTinyEdit
+
+  A minimal Document-based text editor application.
+
 - Todo
 
   A more complex NIB based applications. This is a document-based application.

pyobjc/Examples/TinyTinyEdit/MainMenu.nib/classes.nib

+{
+    IBClasses = ({CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }); 
+    IBVersion = 1; 
+}

pyobjc/Examples/TinyTinyEdit/MainMenu.nib/info.nib

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBEditorPositions</key>
+	<dict>
+		<key>29</key>
+		<string>87 457 318 44 0 0 1152 746 </string>
+	</dict>
+	<key>IBFramework Version</key>
+	<string>291.0</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>29</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>6L60</string>
+</dict>
+</plist>

pyobjc/Examples/TinyTinyEdit/MainMenu.nib/objects.nib

Binary file added.

pyobjc/Examples/TinyTinyEdit/TinyTinyDocument.nib/classes.nib

+{
+    IBClasses = (
+        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
+        {
+            CLASS = TinyTinyDocument; 
+            LANGUAGE = ObjC; 
+            OUTLETS = {textView = id; }; 
+            SUPERCLASS = NSDocument; 
+        }
+    ); 
+    IBVersion = 1; 
+}

pyobjc/Examples/TinyTinyEdit/TinyTinyDocument.nib/info.nib

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBDocumentLocation</key>
+	<string>44 306 356 240 0 0 1152 746 </string>
+	<key>IBFramework Version</key>
+	<string>291.0</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>5</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>6L60</string>
+</dict>
+</plist>

pyobjc/Examples/TinyTinyEdit/TinyTinyDocument.nib/objects.nib

Binary file added.

pyobjc/Examples/TinyTinyEdit/TinyTinyEdit.py

+"""TinyTinyEdit -- A minimal Document-based Cocoa application."""
+
+
+from PyObjCTools import NibClassBuilder, AppHelper
+
+
+NibClassBuilder.extractClasses("TinyTinyDocument")
+
+
+# class defined in TinyTinyDocument.nib
+class TinyTinyDocument(NibClassBuilder.AutoBaseClass):
+    # the actual base class is NSDocument
+    # The following outlets are added to the class:
+    # textView
+
+    path = None
+
+    def windowNibName(self):
+        return "TinyTinyDocument"
+
+    def readFromFile_ofType_(self, path, tp):
+        if self.textView is None:
+            # we're not yet fully loaded
+            self.path = path
+        else:
+            # "revert"
+            self.readFromUTF8(path)
+        return True
+
+    def writeToFile_ofType_(self, path, tp):
+        f = file(path, "w")
+        text = self.textView.string()
+        f.write(text.encode("utf8"))
+        f.close()
+        return True
+
+    def windowControllerDidLoadNib_(self, controller):
+        if self.path:
+            self.readFromUTF8(self.path)
+
+    def readFromUTF8(self, path):
+        f = file(path)
+        text = unicode(f.read(), "utf8")
+        f.close()
+        self.textView.setString_(text)
+
+
+if __name__ == "__main__":
+    AppHelper.runEventLoop()

pyobjc/Examples/TinyTinyEdit/buildapp.py

+from bundlebuilder import buildapp
+from plistlib import Plist, Dict
+
+
+plist = Plist(
+    CFBundleDocumentTypes = [
+        Dict(
+            CFBundleTypeExtensions = ["txt", "text", "*"],
+            CFBundleTypeName = "Text File",
+            CFBundleTypeRole = "Editor",
+            NSDocumentClass = "TinyTinyDocument",
+        ),
+    ]
+)
+
+
+buildapp(
+	mainprogram = "TinyTinyEdit.py",
+	resources = ["MainMenu.nib", "TinyTinyDocument.nib"],
+	nibname = "MainMenu",
+    plist = plist,
+)