You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.3 KiB

  1. /*
  2. Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
  3. This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
  4. which should be included with this package. The terms are also available at
  5. http://www.gnu.org/licenses/gpl-3.0.html
  6. */
  7. #import <Cocoa/Cocoa.h>
  8. #import <Python.h>
  9. #import <wchar.h>
  10. #import <locale.h>
  11. int main(int argc, char *argv[])
  12. {
  13. /* We have to set the locate to UTF8 for mbstowcs() to correctly convert non-ascii chars in paths */
  14. setlocale(LC_ALL, "en_US.UTF-8");
  15. NSString *respath = [[NSBundle mainBundle] resourcePath];
  16. NSString *mainpy = [respath stringByAppendingPathComponent:@"dg_cocoa.py"];
  17. wchar_t wPythonPath[PATH_MAX+1];
  18. NSString *pypath = [respath stringByAppendingPathComponent:@"py"];
  19. mbstowcs(wPythonPath, [pypath fileSystemRepresentation], PATH_MAX+1);
  20. Py_SetPath(wPythonPath);
  21. Py_SetPythonHome(wPythonPath);
  22. Py_Initialize();
  23. PyGILState_STATE gilState = PyGILState_Ensure();
  24. FILE* fp = fopen([mainpy UTF8String], "r");
  25. PyRun_SimpleFile(fp, [mainpy UTF8String]);
  26. fclose(fp);
  27. PyGILState_Release(gilState);
  28. if (gilState == PyGILState_LOCKED) {
  29. PyThreadState_Swap(NULL);
  30. PyEval_ReleaseLock();
  31. }
  32. int result = NSApplicationMain(argc, (const char **) argv);
  33. Py_Finalize();
  34. return result;
  35. }