Skip to content

Commit

Permalink
first part of cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Mar 8, 2012
1 parent edcdf98 commit cfa91a7
Show file tree
Hide file tree
Showing 19 changed files with 576 additions and 1 deletion.
Binary file added templates/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions templates/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// main.m
// iOS-python-test
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include <python2.7/Python.h>
#include "SDL/SDL_main.h"
#include <dlfcn.h>

int main(int argc, char *argv[]) {
int ret = 0;

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// Change the executing path to YourApp
chdir("YourApp");

// Special environment to prefer .pyo, and don't write bytecode if .py are found
// because the process will not have write attribute on the device.
putenv("PYTHONOPTIMIZE=2");
putenv("PYTHONDONTWRITEBYTECODE=1");
putenv("PYTHONNOUSERSITE=1");

// Kivy environment to prefer some implementation on ios platform
putenv("KIVY_BUILD=ios");
putenv("KIVY_NO_CONFIG=1");
putenv("KIVY_NO_FILELOG=1");
putenv("KIVY_NO_CONSOLELOG=1");
putenv("KIVY_WINDOW=sdl");
putenv("KIVY_IMAGE=imageio");
putenv("KIVY_AUDIO=sdl");

NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSLog(@"PythonHome is: %s", (char *)[resourcePath UTF8String]);
Py_SetPythonHome((char *)[resourcePath UTF8String]);

NSLog(@"Initializing python");
Py_Initialize();
PySys_SetArgv(argc, argv);

// If other modules are using thread, we need to initialize them before.
PyEval_InitThreads();

// Search and start main.py
const char * prog = [
[[NSBundle mainBundle] pathForResource:@"YourApp/main" ofType:@"pyo"] cStringUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"Running main.pyo: %s", prog);
FILE* fd = fopen(prog, "r");
if ( fd == NULL ) {
ret = 1;
NSLog(@"Unable to open main.pyo, abort.");
} else {
ret = PyRun_SimpleFileEx(fd, prog, 1);
if (ret != 0)
NSLog(@"Application quit abnormally!");
}

Py_Finalize();
NSLog(@"Leaving");

[pool release];

// Look like the app still runn even when we leaved here.
exit(ret);
return ret;
}
51 changes: 51 additions & 0 deletions templates/template-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//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>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIconFiles</key>
<array>
<string>icon.png</string>
</array>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon.png</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>org.kivy.##APPID##</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Loading

0 comments on commit cfa91a7

Please sign in to comment.