Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Pythonista
iOS
@jbking
PyCon JP 2017
Who?
@jbking
Yarch( )
ex-OpenStacker
IoT Platform
Pythonista
?
Pythonista
• Pythonista: A full-featured Python environment for iOS devices
• europython 2014 https://ep2014.europython.eu...
(1)
•
•
• Pythonista iOS
• iOS Pythonista
•
• NumPy SymPy, SimPy, Matplotlib
• StaSh
• , Git
(2)
•
• iOS Python
•
• Python
• Objective-C
• iOS
Pythonista
iOS
•
• Xcode
•
• AppStore ?
•
• Xcode https://github.com/omz/
PythonistaAppTemplate
• Python
Pythonista iOS
• Pythonista Python
• iOS Framework Python
•
•
Python
Yes
No
Pythonista
No
Yes
C
iOS objc_util
No
Yes
Yes
No
• Pythonista
•
• (BLE)
• iOS
• ( , C/S)
• GPIO
•
• Python
• NG
• iOS Pythonista
• objc_util
• ( Framework … )
•
•
objc_util ???
objc_util
• Pythonista
• Objective-C
•
• iOS
• objc_msgSend
Framework
from objc_util import *
NSBundle.bundleWithPath_('/System/Library/
Frameworks/Photos.framework').load()
AVFounda...
from objc_util import *
UIScreen = ObjCClass('UIScreen')
screen = UIScreen.mainScreen()
if screen.brightness() < 0.3:
scre...
from objc_util import *
def DemoClass_foo_(_self, _cmd, _s):
print('result: %s' % ObjCInstance(_s))
# NSObject
DemoClass =...
def DemoClass_foo_(_self, _cmd, _s): ...
def bar_baz_(_self, _cmd, _x1, _x2): ...
DemoClass = create_objc_class(
...
metho...
from objc_util import ObjCClass
def is_word_valid(word):
reflib =
ObjCClass('UIReferenceLibraryViewController')
return ref...
from objc_util import *
UIApplication = ObjCClass('UIApplication')
vc =
UIApplication.sharedApplication().keyWindow
().roo...
• objc_util
• iOS Framework
• ObjCClass ObjCInstance
Python
•
•
•
IoT
• cb
• BLE
• CoreBluetooth
• Sony MESH
https://youtu.be/uJ6VVklLUQc
https://github.com/jbking/pythonista-misc/blob/mas...
• objc_util
• SpriteKit
(SKPhysicsBody)
https://youtu.be/rS6FHvKrU6Y
https://github.com/jbking/pythonista-misc/blob/master...
•
• ui, Requests
•
• appex, webbrowser,
(pythonista://ScriptName)
tips
•
• view.present(hide_title_bar=True)
•
• CPU
• GPU
•
• Omz gist
• https://gist.github.com/omz/
• Pythonista Tools
• https://github.com/Pythonista-Tools/Pythonista-
Tools
Questions?
Pythonistaで始めるiOSプロトタイプ開発
Pythonistaで始めるiOSプロトタイプ開発
Pythonistaで始めるiOSプロトタイプ開発
Pythonistaで始めるiOSプロトタイプ開発
Upcoming SlideShare
Loading in …5
×

Pythonistaで始めるiOSプロトタイプ開発

3,781 views

Published on

Slide talked at PyCon JP 2017

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Pythonistaで始めるiOSプロトタイプ開発

  1. 1. Pythonista iOS @jbking PyCon JP 2017
  2. 2. Who? @jbking Yarch( ) ex-OpenStacker IoT Platform
  3. 3. Pythonista ?
  4. 4. Pythonista • Pythonista: A full-featured Python environment for iOS devices • europython 2014 https://ep2014.europython.eu/en/ schedule/sessions/109/ • Pythonista Pythonista 
 iOS Pythonista • https://pycon.jp/2016/ja/schedule/presentation/47/ PyCon JP 2016 • Pythonista • PyCon mini Kumamoto
  5. 5. (1) • • • Pythonista iOS • iOS Pythonista • • NumPy SymPy, SimPy, Matplotlib • StaSh • , Git
  6. 6. (2) • • iOS Python • • Python • Objective-C • iOS
  7. 7. Pythonista iOS • • Xcode • • AppStore ? • • Xcode https://github.com/omz/ PythonistaAppTemplate • Python
  8. 8. Pythonista iOS • Pythonista Python • iOS Framework Python • •
  9. 9. Python Yes No Pythonista No Yes C iOS objc_util No Yes Yes No
  10. 10. • Pythonista • • (BLE) • iOS • ( , C/S) • GPIO •
  11. 11. • Python • NG • iOS Pythonista • objc_util • ( Framework … ) • •
  12. 12. objc_util ???
  13. 13. objc_util • Pythonista • Objective-C • • iOS • objc_msgSend
  14. 14. Framework from objc_util import * NSBundle.bundleWithPath_('/System/Library/ Frameworks/Photos.framework').load() AVFoundation.framework AVKit.framework Accelerate.framework Accounts.framework AdSupport.framework AddressBook.framework AddressBookUI.framework AssetsLibrary.framework AudioToolbox.framework AudioUnit.framework CFNetwork.framework CallKit.framework CloudKit.framework Contacts.framework ContactsUI.framework CoreAudio.framework CoreAudioKit.framework CoreBluetooth.framework CoreData.framework CoreFoundation.framework CoreGraphics.framework CoreImage.framework CoreLocation.framework CoreMIDI.framework CoreMedia.framework CoreMotion.framework CoreSpotlight.framework CoreTelephony.framework CoreText.framework CoreVideo.framework EventKit.framework EventKitUI.framework ExternalAccessory.framework Foundation.framework GLKit.framework GSS.framework GameController.framework GameKit.framework GameplayKit.framework HealthKit.framework HealthKitUI.framework HomeKit.framework IOKit.framework ImageIO.framework Intents.framework IntentsUI.framework JavaScriptCore.framework LocalAuthentication.framework MapKit.framework MediaAccessibility.framework MediaPlayer.framework MediaToolbox.framework MessageUI.framework Messages.framework Metal.framework MetalKit.framework MetalPerformanceShaders.framework MobileCoreServices.framework ModelIO.framework MultipeerConnectivity.framework NetworkExtension.framework NewsstandKit.framework NotificationCenter.framework OpenAL.framework OpenGLES.framework PassKit.framework Photos.framework PhotosUI.framework PushKit.framework QuartzCore.framework QuickLook.framework ReplayKit.framework SafariServices.framework SceneKit.framework Security.framework Social.framework Speech.framework SpriteKit.framework StoreKit.framework System.framework SystemConfiguration.framework Twitter.framework UIKit.framework UserNotifications.framework UserNotificationsUI.framework VideoSubscriberAccount.framework VideoToolbox.framework WatchConnectivity.framework WebKit.framework iAd.framework
  15. 15. from objc_util import * UIScreen = ObjCClass('UIScreen') screen = UIScreen.mainScreen() if screen.brightness() < 0.3: screen.setBrightness_(0.6) else: screen.setBrightness_(0.1)
  16. 16. from objc_util import * def DemoClass_foo_(_self, _cmd, _s): print('result: %s' % ObjCInstance(_s)) # NSObject DemoClass = create_objc_class( 'DemoClass', ObjCClass('NSObject'), methods=[DemoClass_foo_], protocols=[]) demo_obj = DemoClass.alloc().init() demo_obj.foo_("hello") result: hello
  17. 17. def DemoClass_foo_(_self, _cmd, _s): ... def bar_baz_(_self, _cmd, _x1, _x2): ... DemoClass = create_objc_class( ... methods=[DemoClass_foo_, bar_baz_], ... demo_obj = DemoClass.alloc().init() demo_obj.foo_("hello") demo_obj.bar_baz_(2, 3) demo_obj.bar_(2, baz=5) # UIColor.colorWithRed:green:blue:alpha UIColor.colorWithRed(1.0, green=0.0, blue=0.0, alpha=1.0) UIColor.color(red=1.0, green=0.0, blue=0.0, alpha=1.0)
  18. 18. from objc_util import ObjCClass def is_word_valid(word): reflib = ObjCClass('UIReferenceLibraryViewController') return reflib.dictionaryHasDefinitionForTerm_(word) test_words = ['foo', 'bar', 'quuz', 'cat', 'dog'] for word in test_words: print('%s: %s' % (word, is_word_valid(word))) foo: False bar: True quuz: False cat: True dog: True https://gist.github.com/omz/599ef8aeae22620261c6
  19. 19. from objc_util import * UIApplication = ObjCClass('UIApplication') vc = UIApplication.sharedApplication().keyWindow ().rootViewController() print(vc.childViewControllers()) <b'__NSArrayI': ( "<UINavigationController: 0x1038db200>", "<PA2TabViewController: 0x104003000>", "<PA2AccessoryTabViewController: 0x1038dac00>" )> Pythonista
  20. 20. • objc_util • iOS Framework • ObjCClass ObjCInstance Python • • •
  21. 21. IoT • cb • BLE • CoreBluetooth • Sony MESH https://youtu.be/uJ6VVklLUQc https://github.com/jbking/pythonista-misc/blob/master/mesh/button_demo.py
  22. 22. • objc_util • SpriteKit (SKPhysicsBody) https://youtu.be/rS6FHvKrU6Y https://github.com/jbking/pythonista-misc/blob/master/spritekit/skview-demo.py
  23. 23. • • ui, Requests • • appex, webbrowser, (pythonista://ScriptName)
  24. 24. tips • • view.present(hide_title_bar=True) • • CPU • GPU •
  25. 25. • Omz gist • https://gist.github.com/omz/ • Pythonista Tools • https://github.com/Pythonista-Tools/Pythonista- Tools
  26. 26. Questions?

×