pythonistaで始めるiosプロトタイプ開発
TRANSCRIPT
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
Pythonista iOS
• • Xcode •
• AppStore ? • • Xcode https://github.com/omz/
PythonistaAppTemplate • Python
Frameworkfrom 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
from objc_util import *
UIScreen = ObjCClass('UIScreen')
screen = UIScreen.mainScreen() if screen.brightness() < 0.3: screen.setBrightness_(0.6) else: screen.setBrightness_(0.1)
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
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)
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
from objc_util import *
UIApplication = ObjCClass('UIApplication') vc = UIApplication.sharedApplication().keyWindow().rootViewController()
print(vc.childViewControllers())
<b'__NSArrayI': ( "<UINavigationController: 0x1038db200>", "<PA2TabViewController: 0x104003000>", "<PA2AccessoryTabViewController: 0x1038dac00>" )>
Pythonista
IoT• cb
• BLE • CoreBluetooth
• Sony MESH
https://youtu.be/uJ6VVklLUQc
https://github.com/jbking/pythonista-misc/blob/master/mesh/button_demo.py
• objc_util • SpriteKit
(SKPhysicsBody)
https://youtu.be/rS6FHvKrU6Y
https://github.com/jbking/pythonista-misc/blob/master/spritekit/skview-demo.py
• Omz gist • https://gist.github.com/omz/
• Pythonista Tools • https://github.com/Pythonista-Tools/Pythonista-
Tools