2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2012-03-15 18:28:40 +00:00
|
|
|
Copyright 2012 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2010-09-30 10:17:41 +00:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
2012-01-11 17:18:03 +00:00
|
|
|
#import <Python.h>
|
|
|
|
#import <wchar.h>
|
2012-01-16 19:20:51 +00:00
|
|
|
#import <locale.h>
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-01-16 19:20:51 +00:00
|
|
|
/* We have to set the locate to UTF8 for mbstowcs() to correctly convert non-ascii chars in paths */
|
|
|
|
setlocale(LC_ALL, "en_US.UTF-8");
|
2012-01-11 17:18:03 +00:00
|
|
|
NSString *respath = [[NSBundle mainBundle] resourcePath];
|
|
|
|
NSString *mainpy = [respath stringByAppendingPathComponent:@"dg_cocoa.py"];
|
|
|
|
wchar_t wPythonPath[PATH_MAX+1];
|
|
|
|
NSString *pypath = [respath stringByAppendingPathComponent:@"py"];
|
|
|
|
mbstowcs(wPythonPath, [pypath fileSystemRepresentation], PATH_MAX+1);
|
|
|
|
Py_SetPath(wPythonPath);
|
|
|
|
Py_SetPythonHome(wPythonPath);
|
|
|
|
Py_Initialize();
|
|
|
|
PyEval_InitThreads();
|
|
|
|
PyGILState_STATE gilState = PyGILState_Ensure();
|
|
|
|
FILE* fp = fopen([mainpy UTF8String], "r");
|
|
|
|
PyRun_SimpleFile(fp, [mainpy UTF8String]);
|
|
|
|
fclose(fp);
|
|
|
|
PyGILState_Release(gilState);
|
|
|
|
if (gilState == PyGILState_LOCKED) {
|
|
|
|
PyThreadState_Swap(NULL);
|
|
|
|
PyEval_ReleaseLock();
|
|
|
|
}
|
|
|
|
int result = NSApplicationMain(argc, (const char **) argv);
|
|
|
|
Py_Finalize();
|
2009-06-01 09:55:11 +00:00
|
|
|
[pool release];
|
2012-01-11 17:18:03 +00:00
|
|
|
return result;
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|