Skip to content

Commit 634f982

Browse files
committed
Initial Commit
1 parent d41903b commit 634f982

File tree

746 files changed

+456413
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

746 files changed

+456413
-0
lines changed

Python-iOS/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
.DS_Store
3+
4+
*.xcuserstate
5+
6+
python-ios.xcworkspace/xcuserdata/fancyzero.xcuserdatad/UserInterfaceState.xcuserstate
7+
8+
*.xcbkptlist
9+
10+
python-ios.xcworkspace/xcuserdata/fancyzero.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

Python-iOS/HowItsDone

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Goto Python-2.7.5, and "./configure" this will config for mac OSX plaform, but still can make next of your steps easier.
2+
3+
Create a static library project, then add all python file into project with directory structure.
4+
5+
while( build_not_successed )
6+
{
7+
Try to build it, and you will found some source file are not for iOS platform, remove these files, and some other files
8+
failed to compile because missing other 3rd party libs, remove it from the project , or provide the libs.
9+
}
10+
11+
you will get a python interpet with some useful builtin modules.
12+
13+
manually edit the Modules/config.c to register built-in modules, you see how, when you open the config.c it's easy to understand
14+
module "zlib" must be registered in order to import for a zip file.
15+
16+
and in python/libs/site.py there comment line "known_paths = addusersitepackages(known_paths)" , that depends a module called "_sysconfigdata", this module is generated when you make python in commandline, so this funciton call should be disabled
17+
18+
that's all I remember...
19+

Python-iOS/Python-iOS-app.xcodeproj/project.pbxproj

Lines changed: 385 additions & 0 deletions
Large diffs are not rendered by default.

Python-iOS/Python-iOS-app.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AppDelegate.h
3+
// Python-iOS-app
4+
//
5+
// Created by Fancyzero on 13-8-21.
6+
// Copyright (c) 2013年 Fancyzero. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class ViewController;
12+
13+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
14+
15+
@property (strong, nonatomic) UIWindow *window;
16+
17+
@property (strong, nonatomic) ViewController *viewController;
18+
19+
@end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// AppDelegate.m
3+
// Python-iOS-app
4+
//
5+
// Created by Fancyzero on 13-8-21.
6+
// Copyright (c) 2013年 Fancyzero. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
11+
#import "ViewController.h"
12+
#include "Python.h"
13+
14+
@implementation AppDelegate
15+
16+
- (void)dealloc
17+
{
18+
[_window release];
19+
[_viewController release];
20+
[super dealloc];
21+
}
22+
23+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
24+
{
25+
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
26+
// Override point for customization after application launch.
27+
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
28+
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
29+
} else {
30+
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
31+
}
32+
self.window.rootViewController = self.viewController;
33+
[self.window makeKeyAndVisible];
34+
35+
//init python
36+
//get python lib path and set this path as python home directory
37+
NSString* fullpath = [[NSBundle mainBundle] pathForResource:@"python" ofType:nil inDirectory:nil];
38+
char home[1024];
39+
strcpy(home, [fullpath UTF8String]);
40+
41+
Py_SetPythonHome(home);
42+
Py_Initialize();
43+
//执行python语句
44+
PyRun_SimpleString("print 'hello'");//say hello see debug output :)
45+
46+
dispatch_queue_t queue = dispatch_queue_create(0, DISPATCH_QUEUE_CONCURRENT);
47+
dispatch_async(queue, ^{
48+
//执行python脚本
49+
NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"server" ofType:@"py"];
50+
51+
FILE *mainFile = fopen([scriptPath UTF8String], "r");
52+
53+
PyRun_SimpleFile(mainFile, (char *)[[scriptPath lastPathComponent] UTF8String]) ;
54+
55+
});
56+
57+
return YES;
58+
}
59+
60+
- (void)applicationWillResignActive:(UIApplication *)application
61+
{
62+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
63+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
64+
}
65+
66+
- (void)applicationDidEnterBackground:(UIApplication *)application
67+
{
68+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
69+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
70+
}
71+
72+
- (void)applicationWillEnterForeground:(UIApplication *)application
73+
{
74+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
75+
}
76+
77+
- (void)applicationDidBecomeActive:(UIApplication *)application
78+
{
79+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
80+
}
81+
82+
- (void)applicationWillTerminate:(UIApplication *)application
83+
{
84+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
85+
}
86+
87+
@end

0 commit comments

Comments
 (0)