Commits

Anonymous committed 986dbb9

removed redundant TableModel2 demo

Comments (0)

Files changed (8)

pyobjc/Examples/TableModel2/English.lproj/InfoPlist.strings

Binary file removed.

pyobjc/Examples/TableModel2/English.lproj/MainMenu.nib/classes.nib

-{
-    IBClasses = (
-        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
-        {CLASS = PyModel; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
-    ); 
-    IBVersion = 1; 
-}

pyobjc/Examples/TableModel2/English.lproj/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>IBDocumentLocation</key>
-	<string>58 119 356 240 0 0 1152 746 </string>
-	<key>IBEditorPositions</key>
-	<dict>
-		<key>29</key>
-		<string>69 252 318 44 0 0 1152 746 </string>
-	</dict>
-	<key>IBFramework Version</key>
-	<string>291.0</string>
-	<key>IBOpenObjects</key>
-	<array>
-		<integer>21</integer>
-		<integer>29</integer>
-	</array>
-	<key>IBSystem Version</key>
-	<string>6I32</string>
-</dict>
-</plist>

pyobjc/Examples/TableModel2/English.lproj/MainMenu.nib/objects.nib

Binary file removed.

pyobjc/Examples/TableModel2/README.txt

-TableModel2
-bbum@codefab.com
-
-This is a conversion of Ronald's TableModel example into a standalone Cocoa project.   This project also provides a basic recipe for creating any standalone Cocoa applications (or multiple document applications) that are implemented in Python using the Obj-C bridge.
-
-Projects of this style allow for freely mixing python and objective-c source.  Simply add the python source to the project as you would any other source file.  Project Builder will automatically copy all python source files into the Resources/ directory of the resulting application product.
-
-Because the PyObjC module-- the Cocoa support piece, specifically-- automatically adds the 'Contents/Resources/' directory of the application wrapper to Python's sys.path attribute, any python scripts added to the project will both be automatically copied into the Resources/ directory and automatically found by Python.
-
-Of course, if you localize the python scripts, they won't be automatically found.   However, this would be easy to fix by calling NSBundle's -preferredLocalizations method and adding the associated localization directories to sys.path.
-
-To create a new PyCocoa project in Project Builder, do the following.  Of course, this assumes that pyobjc is correctly installed.  This has been tested both with the Fink build of Python and with the Apple supplied version of Python.
-
-1. Create a new Cocoa Application or Cocoa Document-based Application
-
-2. Replace the main.m in the project with the main.m from this example.
-
-3. Add the key 'PrincipalPythonFile' to the Info.plist.  The value is the name of the Python file that you want to be loaded first as the application starts up.  Whatever Python file is chosen, it should take care of loading any other Python files necessary to define the various classes necessary for application startup.   If this key is not defined, the main() function will try to load the file 'Main.py'.   If that file is not found, the application will raise an exception and exit.
-
-If you want to create a project that will create a standalone Cocoa application that contains all the resources necessary to run the application, perform the following additional steps:
-
-4. [optionally] Create a new group called 'pyobjc'.   This is merely cosmetic.
-
-5. Add a Copy Files phase to the project.
-
-6. Drag in the AppKit, Foundation, and objc directories from /sw/lib/python2.2/site-packages/ and create absolute path references (you can copy the folders into the project, but it isn't a requirement unless there will be developers contributing to the project that do not have pyobjc installed). 
-
-7. Add the AppKit, Foundation, and objc to the Copy Files phase. 
-
-8. Set Copy Files phase to copy the three directories into the Resources area of the wrapper.
-
-9. Set the Copy Files phase to copy the three files into a subdirectory named 'pyobjc' [optional, but keeps the Resources directory more organized].
-
-If you want to mix in compiled Objective-C classes, add a bundle or framework target to your project.   Then, in the Main.py (or equivalent), load the framework or bundle using the NSBundle API as normal.  Because the main class passes control entirely to the python command-line executable, classes linked into the binary in the traditional fashion (by simply adding the source files to the project) will not be available at runtime.
-

pyobjc/Examples/TableModel2/TableModel.py

-import sys
-import os.path
-import AppKit
-from PyObjCTools import NibClassBuilder, AppHelper
-
-sys.path.insert(0, os.path.join(sys.path[0], "pyobjc"))
-
-import objc
-import AppKit
-
-NibClassBuilder.extractClasses("MainMenu")
-class PyModel (NibClassBuilder.AutoBaseClass, AppKit.NSTableDataSource, AppKit.NSTableViewDelegate):
-    __slots__  = ('rowcount')
-
-    def init(self):
-        print "PyModel instance initialized"
-        self.rowcount = 10
-        return self
-
-    def numberOfRowsInTableView_(self, aTableView):
-        print "numerOfRowsInTableView: called"
-        return self.rowcount
-
-
-    def tableView_objectValueForTableColumn_row_(
-        self, aTableView, aTableColumn, rowIndex):
-
-        print "tableView:objectValueForTableColumn:row: called"
-        return "{%s, %d}"%(aTableColumn.identifier(), rowIndex)
-    
-    def tableView_shouldSelectRow_(self, aTableView, aRow):
-        print "tableView:shouldSelectRow:", aRow
-        return 1
-
-AppHelper.runEventLoop()

pyobjc/Examples/TableModel2/TableModel2.pbproj/project.pbxproj

-// !$*UTF8*$!
-{
-	archiveVersion = 1;
-	classes = {
-	};
-	objectVersion = 38;
-	objects = {
-		080E96DDFE201D6D7F000001 = {
-			children = (
-				F67591E9034123C701336B42,
-			);
-			isa = PBXGroup;
-			name = Classes;
-			refType = 4;
-		};
-		089C165CFE840E0CC02AAC07 = {
-			children = (
-				089C165DFE840E0CC02AAC07,
-			);
-			isa = PBXVariantGroup;
-			name = InfoPlist.strings;
-			refType = 4;
-		};
-		089C165DFE840E0CC02AAC07 = {
-			fileEncoding = 10;
-			isa = PBXFileReference;
-			name = English;
-			path = English.lproj/InfoPlist.strings;
-			refType = 4;
-		};
-		089C165EFE840E0CC02AAC07 = {
-			fileRef = 089C165CFE840E0CC02AAC07;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-//080
-//081
-//082
-//083
-//084
-//100
-//101
-//102
-//103
-//104
-		1058C7A1FEA54F0111CA2CBB = {
-			isa = PBXFrameworkReference;
-			name = Cocoa.framework;
-			path = /System/Library/Frameworks/Cocoa.framework;
-			refType = 0;
-		};
-//100
-//101
-//102
-//103
-//104
-//170
-//171
-//172
-//173
-//174
-		17587328FF379C6511CA2CBB = {
-			isa = PBXApplicationReference;
-			path = TableModel2.app;
-			refType = 3;
-		};
-//170
-//171
-//172
-//173
-//174
-//190
-//191
-//192
-//193
-//194
-		19C28FACFE9D520D11CA2CBB = {
-			children = (
-				17587328FF379C6511CA2CBB,
-			);
-			isa = PBXGroup;
-			name = Products;
-			refType = 4;
-		};
-//190
-//191
-//192
-//193
-//194
-//290
-//291
-//292
-//293
-//294
-		29B97313FDCFA39411CA2CEA = {
-			buildStyles = (
-				4A9504CCFFE6A4B311CA0CBA,
-				4A9504CDFFE6A4B311CA0CBA,
-			);
-			hasScannedForEncodings = 1;
-			isa = PBXProject;
-			mainGroup = 29B97314FDCFA39411CA2CEA;
-			projectDirPath = "";
-			targets = (
-				29B97326FDCFA39411CA2CEA,
-			);
-		};
-		29B97314FDCFA39411CA2CEA = {
-			children = (
-				080E96DDFE201D6D7F000001,
-				29B97315FDCFA39411CA2CEA,
-				29B97317FDCFA39411CA2CEA,
-				29B97323FDCFA39411CA2CEA,
-				19C28FACFE9D520D11CA2CBB,
-				F67591ED0341252E01336B42,
-			);
-			isa = PBXGroup;
-			name = TableModel2;
-			path = "";
-			refType = 4;
-		};
-		29B97315FDCFA39411CA2CEA = {
-			children = (
-				29B97316FDCFA39411CA2CEA,
-			);
-			isa = PBXGroup;
-			name = "Other Sources";
-			path = "";
-			refType = 4;
-		};
-		29B97316FDCFA39411CA2CEA = {
-			fileEncoding = 30;
-			isa = PBXFileReference;
-			path = main.m;
-			refType = 4;
-		};
-		29B97317FDCFA39411CA2CEA = {
-			children = (
-				F61BA2AC0357996801C36587,
-				089C165CFE840E0CC02AAC07,
-				F67591E6034123A101336B42,
-			);
-			isa = PBXGroup;
-			name = Resources;
-			path = "";
-			refType = 4;
-		};
-		29B97323FDCFA39411CA2CEA = {
-			children = (
-				29B97325FDCFA39411CA2CEA,
-				1058C7A1FEA54F0111CA2CBB,
-				29B97324FDCFA39411CA2CEA,
-			);
-			isa = PBXGroup;
-			name = Frameworks;
-			path = "";
-			refType = 4;
-		};
-		29B97324FDCFA39411CA2CEA = {
-			isa = PBXFrameworkReference;
-			name = AppKit.framework;
-			path = /System/Library/Frameworks/AppKit.framework;
-			refType = 0;
-		};
-		29B97325FDCFA39411CA2CEA = {
-			isa = PBXFrameworkReference;
-			name = Foundation.framework;
-			path = /System/Library/Frameworks/Foundation.framework;
-			refType = 0;
-		};
-		29B97326FDCFA39411CA2CEA = {
-			buildPhases = (
-				F61BA2B4035799BC01C36587,
-				29B97327FDCFA39411CA2CEA,
-				29B97328FDCFA39411CA2CEA,
-				29B9732BFDCFA39411CA2CEA,
-				29B9732DFDCFA39411CA2CEA,
-			);
-			buildSettings = {
-				FRAMEWORK_SEARCH_PATHS = "";
-				HEADER_SEARCH_PATHS = /sw/include/python2.2;
-				INSTALL_PATH = "$(HOME)/Applications";
-				LIBRARY_SEARCH_PATHS = "";
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = "-force_flat_namespace -undefined suppress";
-				PREBINDING = NO;
-				PRODUCT_NAME = TableModel2;
-				SECTORDER_FLAGS = "";
-				WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
-				WRAPPER_EXTENSION = app;
-			};
-			dependencies = (
-			);
-			isa = PBXApplicationTarget;
-			name = TableModel2;
-			productInstallPath = "$(HOME)/Applications";
-			productName = TableModel2;
-			productReference = 17587328FF379C6511CA2CBB;
-			productSettingsXML = "<?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>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>TableModel2</string>
-	<key>CFBundleIconFile</key>
-	<string></string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>0.1</string>
-	<key>NSMainNibFile</key>
-	<string>MainMenu</string>
-	<key>NSPrincipalClass</key>
-	<string>NSApplication</string>
-	<key>PrincipalPythonFile</key>
-	<string>TableModel.py</string>
-</dict>
-</plist>
-";
-		};
-		29B97327FDCFA39411CA2CEA = {
-			buildActionMask = 2147483647;
-			files = (
-			);
-			isa = PBXHeadersBuildPhase;
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		29B97328FDCFA39411CA2CEA = {
-			buildActionMask = 2147483647;
-			files = (
-				089C165EFE840E0CC02AAC07,
-				F67591E8034123A101336B42,
-				F67591EA034123C701336B42,
-				F67591EE0341252E01336B42,
-			);
-			isa = PBXResourcesBuildPhase;
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		29B9732BFDCFA39411CA2CEA = {
-			buildActionMask = 2147483647;
-			files = (
-				29B9732CFDCFA39411CA2CEA,
-			);
-			isa = PBXSourcesBuildPhase;
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		29B9732CFDCFA39411CA2CEA = {
-			fileRef = 29B97316FDCFA39411CA2CEA;
-			isa = PBXBuildFile;
-			settings = {
-				ATTRIBUTES = (
-				);
-			};
-		};
-		29B9732DFDCFA39411CA2CEA = {
-			buildActionMask = 2147483647;
-			files = (
-				F67591FA0341FC6601336B42,
-			);
-			isa = PBXFrameworksBuildPhase;
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-//290
-//291
-//292
-//293
-//294
-//4A0
-//4A1
-//4A2
-//4A3
-//4A4
-		4A9504CCFFE6A4B311CA0CBA = {
-			buildRules = (
-			);
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-				OPTIMIZATION_CFLAGS = "-O0";
-			};
-			isa = PBXBuildStyle;
-			name = Development;
-		};
-		4A9504CDFFE6A4B311CA0CBA = {
-			buildRules = (
-			);
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			isa = PBXBuildStyle;
-			name = Deployment;
-		};
-//4A0
-//4A1
-//4A2
-//4A3
-//4A4
-//F60
-//F61
-//F62
-//F63
-//F64
-		F61BA2AC0357996801C36587 = {
-			children = (
-				F61BA2AD035799A001C36587,
-				F61BA2AE035799A001C36587,
-				F61BA2AF035799A001C36587,
-			);
-			isa = PBXGroup;
-			name = pyobjc;
-			path = "";
-			refType = 4;
-		};
-		F61BA2AD035799A001C36587 = {
-			includeInIndex = 1;
-			isa = PBXFolderReference;
-			name = AppKit;
-			path = "/usr/lib/python2.2/site-packages/AppKit";
-			refType = 0;
-		};
-		F61BA2AE035799A001C36587 = {
-			includeInIndex = 1;
-			isa = PBXFolderReference;
-			name = Foundation;
-			path = "/usr/lib/python2.2/site-packages/Foundation";
-			refType = 0;
-		};
-		F61BA2AF035799A001C36587 = {
-			includeInIndex = 1;
-			isa = PBXFolderReference;
-			name = objc;
-			path = "/usr/lib/python2.2/site-packages/objc";
-			refType = 0;
-		};
-		F61BA2B4035799BC01C36587 = {
-			buildActionMask = 8;
-			dstPath = pyobjc;
-			dstSubfolderSpec = 7;
-			files = (
-				F61BA2B7035799D301C36587,
-				F61BA2B9035799DD01C36587,
-				F61BA2BA035799E001C36587,
-			);
-			isa = PBXCopyFilesBuildPhase;
-			runOnlyForDeploymentPostprocessing = 1;
-		};
-		F61BA2B7035799D301C36587 = {
-			fileRef = F61BA2AF035799A001C36587;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F61BA2B9035799DD01C36587 = {
-			fileRef = F61BA2AD035799A001C36587;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F61BA2BA035799E001C36587 = {
-			fileRef = F61BA2AE035799A001C36587;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F67591E6034123A101336B42 = {
-			children = (
-				F67591E7034123A101336B42,
-			);
-			isa = PBXVariantGroup;
-			name = MainMenu.nib;
-			path = "";
-			refType = 4;
-		};
-		F67591E7034123A101336B42 = {
-			isa = PBXFileReference;
-			name = English;
-			path = English.lproj/MainMenu.nib;
-			refType = 4;
-		};
-		F67591E8034123A101336B42 = {
-			fileRef = F67591E6034123A101336B42;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F67591E9034123C701336B42 = {
-			fileEncoding = 30;
-			isa = PBXFileReference;
-			path = TableModel.py;
-			refType = 4;
-		};
-		F67591EA034123C701336B42 = {
-			fileRef = F67591E9034123C701336B42;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F67591ED0341252E01336B42 = {
-			fileEncoding = 30;
-			isa = PBXFileReference;
-			path = README.txt;
-			refType = 4;
-		};
-		F67591EE0341252E01336B42 = {
-			fileRef = F67591ED0341252E01336B42;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		F67591FA0341FC6601336B42 = {
-			fileRef = 29B97325FDCFA39411CA2CEA;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-	};
-	rootObject = 29B97313FDCFA39411CA2CEA;
-}

pyobjc/Examples/TableModel2/main.m

-/*
- This main file uses execve() to transfer control of execution to the standard command line python interpreter.   As such, compiled classes in the project will not actually be linked into the runtime as execve() effectively overlays the existing process with the process being called -- in this case the python command line tool.
-
- To use compiled classes with this main, create a separate bundle target and load the bundle in the Main.py file.
-
- This style of execution works with the Apple provided version of Python.
- */
-
-#import <Foundation/Foundation.h>
-#import <sys/param.h>
-#import <unistd.h>
-
-int pyobjc_main(int argc, char * const *argv, char *envp[])
-{
-  [[NSAutoreleasePool alloc] init];
-
-  const char **childArgv = alloca(sizeof(char *) * (argc + 5));
-  const char *pythonBinPathPtr;
-  const char *mainPyPathPtr;
-  NSEnumerator *bundleEnumerator = [[NSBundle allFrameworks] reverseObjectEnumerator];
-  NSBundle *aBundle;
-  NSMutableArray *bundlePaths = [[NSMutableArray array] retain];
-  int i;
-  int envc;
-  char** childEnvp;
-  char*  PYTHONPATH = NULL;
-
-  for (envc = 0; envp[envc] != NULL; envc++) {
-  	if (strncmp(envp[envc], "PYTHONPATH=", sizeof("PYTHONPATH=")-1) == 0) {
-		PYTHONPATH=envp[envc] + sizeof("PYTHONPATH=") - 1;
-		/* No break, we also want to know how large envp is */
-	}
-  } 
-
-  childEnvp = alloca(sizeof(char*) * (envc + 2));
-  for (envc = 0; envp[envc] != NULL; envc ++) {
-  	if (strncmp(envp[envc], "PYTHONPATH=", sizeof("PYTHONPATH=")-1) == 0) {
-		const char* s = [[[NSBundle mainBundle] resourcePath] UTF8String];
-		childEnvp[envc] = alloca(strlen(envp[envc]) + strlen(s) + 2);
-		sprintf(childEnvp[envc], "%s:%s", s, envp[envc]);
-
-	} else {
-		childEnvp[envc] = envp[i];
-	}
-  }
-  if (PYTHONPATH) {
-	envp[envc] = NULL;
-  } else {
-	const char* s = [[[NSBundle mainBundle] resourcePath] UTF8String];
-	childEnvp[envc] = alloca(sizeof("PYTHONPATH=") + strlen(s));
-	sprintf(childEnvp[envc], "PYTHONPATH=%s", s);
-	childEnvp[envc+1] = NULL;
-  }
-
-
-  while ( aBundle = [bundleEnumerator nextObject] ) {
-    if ( [[[aBundle bundlePath] pathExtension] isEqualToString: @"framework"] )
-      [bundlePaths addObject: [aBundle bundlePath]];
-  }
-
-  NSString *pythonBinPath = [[NSUserDefaults standardUserDefaults] stringForKey: @"PythonBinPath"];
-  pythonBinPath = pythonBinPath ? pythonBinPath : @"/usr/bin/python";
-  [pythonBinPath retain];
-  pythonBinPathPtr = [pythonBinPath UTF8String];
-
-  NSString *mainPyFile = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"PrincipalPythonFile"];
-  NSString *mainPyPath = nil;
-
-  if (mainPyFile)
-    mainPyPath = [[NSBundle mainBundle] pathForResource: mainPyFile ofType: nil];
-
-  if ( !mainPyPath )
-    mainPyPath = [[NSBundle mainBundle] pathForResource: @"Main.py" ofType: nil];
-
-  if ( !mainPyPath )
-    [NSException raise: NSInternalInconsistencyException
-                format: @"%s:%d pyobjc_main() Failed to find main python entry point for application.  Exiting.", __FILE__, __LINE__];
-  [mainPyPath retain];
-  mainPyPathPtr = [mainPyPath UTF8String];
-
-  childArgv[0] = argv[0];
-  childArgv[1] = mainPyPathPtr;
-  for (i = 1; i<argc; i++)
-    childArgv[i+1] = argv[i];
-  childArgv[i+1] = "-PyFrameworkPaths";
-  childArgv[i+2] = [[bundlePaths componentsJoinedByString: @":"] UTF8String];
-  childArgv[i+3] = NULL;
-
-  i = execve(pythonBinPathPtr, (char **)childArgv, (char**) childEnvp);
-  if (i == -1) perror("execv");
-  return 1;
-}
-
-int main(int argc, char * const *argv, char *envp[])
-{
-  return pyobjc_main(argc, argv, envp);
-}