ひとりぶろぐ

価値ある情報をユーザー視点で発信するブログ

iOS上で動作する革命的ものづくり環境「Pythonista 3」の魅力をとくと語る

      2016/12/29


Pythonista 3 for ios 00001Pythonista 3 for ios 00001
iOSMac使

iOS

iOS

iOSPythonista 3

Pythonista 3 for ios 00019Pythonista 3 for ios 00019
2016921PyCon JP 2016 @equal_001 Pythonista

PythonPythonista

Python


[] Kazuhiro AbeTwitter使: 2010/9http://t.co/x3BhbtyRbu (2.2.7)https://t.co/4fgsucIHq5 AirDrop


iOSSandbox使

Pythonista 3iOS App StoreApp StoreObj-CSwiftiOS


iOSPythonPythonistaPythonista 3

 Pythonista 3AppApp : Productivity
 : Ole Zorn: 244.4 MB
 : 0 
 

Pythonista 3

Python使

Python logoPython logo
PythonPythonista 3iOS

python if使使

PythonistaPython使

iOS史上最も発想力を刺激するアプリ


Pythonista 31,200

iOSPythonista 3

 Pythonista 3AppApp : Productivity
 : Ole Zorn: 244.4 MB
 : 0 
 

PythonistaPythonista 3Pythonista

Pythonista 3


[] Overview  Pythonista Documentation


Pythonista 3

Pythonista 3 for ios 00020Pythonista 3 for ios 00020
Pythonista 3使iPad
Anker® TC930 ウルトラスリムBluetoothキーボードカバー iPad Air用
「Origin」 iPhone6 スライドキーボード  4.7インチ対応 iPhone6 Bluetooth キーボード iPhone6ジャストフィット ワイヤレスキーボード + ケース 一体型 IP6SKB ホワイト

iPad Air 2

w00t! Pythonista 3 supports split-screen mode on iPad and has extended keyboard. pic.twitter.com/XJMklAQipe

 Keith Bradnam (@kbradnam) June 14, 2016

PC1使

Pythonista 32008App Store

Pythonista 3


Pythonista 3iOSPython

PythonPythoniOS

Python 2Python 3


Python23使Pythonista 3Python 3.5.1Python 2.7.5

Pythonista 3 for ios 00022Pythonista 3 for ios 00022

  • 初期設定からデフォルトのインタプリタを指定
  • 実行ボタン(▶︎)を長押しして、使用するインタプリタを実行直前に指定
  • スクリプト冒頭のシェバング行「#!python2」「#!python3」で指定
  • 対話型コンソールでは、[2.7]もしくは[3.5]ボタンを押して指定

Pythonista 3 for ios 00021Pythonista 3 for ios 00021
Python 2 to 3Python 2Python 3


PythonPythonPythonista 3

DropboxEvernote

xmlrpclib使WordPressPythonistaWordPressWordPress
  • bs4 — BeautifulSoup 4
  • Bottle — Python Web Framework
  • Dropbox for Python
  • evernote
  • faker
  • feedparser — Universal Feed Parser
  • Markdown
  • markdown2 — A fast and complete implementation of Markdown in Python
  • paramiko
  • pil — Python Imaging Library
  • qrcode — Pure python QR Code generator
  • Requests – HTTP for Humans
  • xmltodict

使WebmechanizePython 2.7


[] mechanize 0.2.5 : Python Package Index


CookieWeb使

Pythonmatplotlib


[] matplotlib: python plotting  Matplotlib 1.5.1 documentation


Pythonista 3 for ios 00023Pythonista 3 for ios 00023

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import matplotlib

X = [1,2,3]
Y = [3,1,4]

plt.bar(X,Y, align="center")
plt.xticks(X, [u'Tokyo',u'Osaka','Fukuoka'])
plt.show()


使使

site-packagesPython 23site-packages2site-packages3

Pythonistastashpip


[] StaSh  Shell Like an Expert in Pythonista | omz:forum


@stroughtonsmith Seriously, check out StaSh for Pythonista. https://t.co/Rqo9kUFRla. It's awesome. pic.twitter.com/XGHo8nfgrD

 Luke Taylor (@lukedeentaylor) March 25, 2016



iOSUIGUI


UIUI

Pythonista 3 for ios 00017Pythonista 3 for ios 00017
UIiOS

GUIPythonScript with UI*.py*.pyui

Pythonista 3 for ios 00026Pythonista 3 for ios 00026
*.pyuii

Pythonista 3 for ios 00028Pythonista 3 for ios 00028
Action

Pythonista 3 for ios 00029Pythonista 3 for ios 00029
Python

使
import ui
import console

def button_tapped(sender):
  sender.title = "Baka"
  console.alert("Pushed")

v = ui.load_view()
v.present('sheet')

Pythonista 3 for ios 00031Pythonista 3 for ios 00031
Baka

Pythonista 3 for ios 00033Pythonista 3 for ios 00033
UI


[] jsbain/uicomponents: Various ui components for pythonista


Pythonista20124




This is the community forum for my apps Pythonista and Editorial.





http://pythonista-tools.github.io/Pythonista-Tools/index.html

ywangd/pythonista-tools-installer

Pythonista 3


Pythonista 3

Python




Empty ScriptDocuments

Pythonista 3 for ios 00001Pythonista 3 for ios 00001

Python




Pythonista 3 for ios 00003Pythonista 3 for ios 00003

import console
 
console.alert("Hello, Pythonista!")

imimportPythonista 3

Pythonista 3 for ios 00004Pythonista 3 for ios 00004
TabTab|

Python




Pythonista 3 for ios 00016Pythonista 3 for ios 00016
Pythonista 3consolealert()


console


pyflakes

Pythonista 3 for ios 00034Pythonista 3 for ios 00034
pep8import1

Pythonista 3 for ios 00035Pythonista 3 for ios 00035


Python

Pythonista 3 for ios 00005Pythonista 3 for ios 00005




Pythonista 3 for ios 00006Pythonista 3 for ios 00006


Command使
  • Command + R – 実行
  • Command + L – アウトラインを表示(カーソルキーの上下とリターンでアウトラインを選択して移動が可能)
  • Command + D – スニペットの挿入
  • Command + J – インタラクティブコンソールの表示/隠す
  • Command + return – エディターにフォーカス
  • Command + F – 検索のトグル
  • Command + G – 次の検索結果の表示
  • Command + Shift + G – 前方の検索結果の表示
  • Command + K – インタラクティブコンソールの出力をクリア

TabShiftTab




[] Custom keyboard shortcuts | omz:forum

Python


Pythonista

Python

Python

Pythonista 3 for ios 00007Pythonista 3 for ios 00007
Pythonreturn便

print

Imageshow
import photos
p = photos.pic_image()
p.show()

Pythonista 3 for ios 00008Pythonista 3 for ios 00008
PythonistaPILPython Imaging Library使ImageMagickphotosImagePIL
import photos
from PIL import ImageFilter
p = photos.pick_image()
p2 = p.filter(ImageFilter.FIND_EDGES())
p2.show()

Pythonista 3 for ios 00025Pythonista 3 for ios 00025


editor使Pythonista


editor


Pythonista

Pythonista

使

Pythonista 3 for ios 00009Pythonista 3 for ios 00009

import sys
import editor
 
# 日本語処理のためデフォルトエンコーディング設定
sys.setdefaultencoding('utf-8')
 
# Pythonistaのコードエディタ上で選択されたテキストを取得する
def selected_text():
 text = unicode(editor.get_text(), 'utf-8')
 selection = editor.get_selection()
 selected_text = text[selection[0]:selection[1]]
 return selected_text



PythonistaPythonHTMLJavaScript使


Pythonista 3Pythonista

便

URL Scheme


PythonistaPythonURL Scheme


The Pythonista URL Scheme


URLSafariTest.py

pythonista3://Test?action=run

URL Scheme

pythonista3://Test?action=run&args=foo%20bar

pythonista3://Test?action=run&argv=foo&argv=bar

WebPythonista 3

x-callback-urlPythonista 3


[] [Share Code] Implemented x-callback-url | omz:forum

Home


HomeHome

Pythonista 3 for ios 00010Pythonista 3 for ios 00010
Touch Icon GeneratorPythonista 3

Pythonista 3 for ios 00015Pythonista 3 for ios 00015


Pythonista 3

Beta使

Launcher  Pythonista使URLpythonista3://ScriptName?action=runURL

 Launcher  AppApp : Productivity
 : Cromulent Labs, Inc: 17.7 MB
 : 535 
 

notification1使

Open In


iOSOpen In

TwitterWebURLGoodReaderPython

Pythonista 3URL SchemeOpen IniOS

Open InExtension

TwitterRun Pythonista Script

Pythonista 2 0 update 00005Pythonista 2 0 update 00005
Copy Photo LocationImage HistogramPythonistaExtensionPythonScratchpadConsole11iOSPythonistaiOS

TwitterURLURL to QR Code

Pythonista 2 0 update 00006Pythonista 2 0 update 00006
PythonQR

Pythonista 2 0 update 00007Pythonista 2 0 update 00007


qrcodeappeximport

appex.get_url() URL qrcode.make(url) URLQR img.show() Console
# coding: utf-8

import qrcode
import appex

def main():
 if not appex.is_running_extension():
  print 'This script is intended to be run from the sharing extension.'
  return
 url = appex.get_url()
 if not url:
  print 'No input URL found.'
  return
 print url
 img = qrcode.make(url)
 img.show()
 
if __name__ == '__main__':
 main()

Extension

appex


appex  Using the Pythonista Sharing Extension


Open In appex.get_attachments()  appex.get_file_path() 

Open InPythonista 3
# coding: utf-8

import appex, os, console

def save():
    if appex.is_running_extension():
        sFp = appex.get_file_path()
        if sFp:
            console.hud_alert('Saving...')
            with open(sFp, 'rb') as f1:
                with open(os.path.basename(sFp), 'wb') as f2:
                    f2.write(f1.read())
            console.hud_alert('Saved')

if __name__ == '__main__':
    save()

: [Share Code] Extension to save attachment

Python


Pythonista 3iOS使iOS

objc_util

Pythonista 3iOSPython




appex

iOS



canvas-1

2D



cbBluetooth LE

Bluetooth LEBluetooth Smart Core Bluetooth使



clipboard





console

alertconfirmpromptUI/HUDQuickLookOpen In



dialogs

consoleUIUIUIUI



contacts

iOS



editor

Pythonista



keychain

iOSKeychain



linguistictagger

iOSNSLinguisticTagger



location





motion





notification

iOS



objc_utilObjective-C

PythonObjective-CiOSObjective-CObjective-CPythonObjective-CPythonista 3sandboxPrivate FrameworkAPI



photos

iOSPythonista 3photosAssetAssetCollection



reminders

iOSCalendarReminderAlarm



scene-2

2D60fpsCoreAnimationMFi



webbrowser

PythonistaWebfilehtmlSafari



sound

MIDI



speech

AVSpeechSynthesizer



twitterTwitter

iOSTwitter稿



uiUI

Pythonista 3UI使UIPythonUI




iOSPython


PythonistaURL Scheme使

iOSPythonista 3

webbrowseropen使
# -*- coding: utf-8 -*-

import webbrowser
import urllib2
import sys

sys.setdefaultencoding('utf-8')

mes = urllib2.quote("ほげ")

webbrowser.open("tweetbot:///post?text="+mes)


webbrowser


objc_util使 1: 


objc_util使

Pythonista 3UIDeviceobjc_utilObjCClass(UIDevice) UIDevicePython使

iOS
# coding: utf-8

'''Simple demo of using UIDevice to query the current battery state'''

from objc_util import *

UIDevice = ObjCClass('UIDevice')
device = UIDevice.currentDevice()
battery_states = {1: 'unplugged', 2: 'charging', 3: 'full'}

device.setBatteryMonitoringEnabled_(True)
battery_percent = device.batteryLevel() * 100
state = device.batteryState()
state_str = battery_states.get(state, 'unknown')
print 'Battery level: %0.1f%% (%s)' % (battery_percent, state_str)
device.setBatteryMonitoringEnabled_(False)

objc_util使 2:Pythonista


Objective-C使Pythonista
# coding: utf-8

from objc_util import *

UIApplication = ObjCClass('UIApplication')

# Pythonista自身のインスタンスを取得
app = UIApplication.sharedApplication()

# Pythonistaのウインドウを取得
win = app.windows()[0]

# ビュー構造を再帰的にダンプ
win.recursiveDescription()

# ウインドウの透明度を設定
win.alpha = 0.5

# Pythonista内のクラスの取得
PythonistaWindow = ObjCClass('PythonistaWindow')

# インスタンス生成
pywin = PythonistaWindow.alloc()

site-packages/pythonista_startup.pysite-packages2site-packages3pythonista_startup.pyPythonista 3

Objective-CMethod Swizzling


[] jsbain/objc_hacks: experiments with pythonista objc module

SiriKit


iOS 10 beta

Pythonnista 3iOS 10 beta使Pythonista 3SiriKit
# coding: utf-8

from objc_util import *

ObjCClass('NSBundle').bundleWithPath_('/System/Library/Frameworks/Speech.ramework').load()
SFSpeechRecognizer = ObjCClass('SFSpeechRecognizer')


[] Siri SDK! | omz:forum


Objective-C

iOSApple

App StorePythonista 3

Pythonista 3


Pythonista 3




[] Whats New in Pythonista  Pythonista Documentation



Python 3.5.1Python 2.7.5



iPad Air 2

UI/

使Python

PEP-8



photos


PythonpdbPythonista 3使

I've started working on an actual debugger for Pythonista. It's not quite done yet, but here's a sneak peek: pic.twitter.com/tC18oS4e4r

 omz (@olemoritz) March 12, 2016

main26img.show()linkunicode



@olemoritz ...it also supports debugging UIs. pic.twitter.com/FvJKgiMtG4

 omz (@olemoritz) March 12, 2016

1: UIColorUIQuick Look姿VariablesCode

2: UIUISliders2Quick Look


iOSiOSObjective-CPythonista 3



iOS

 Pythonista 3AppApp : Productivity
 : Ole Zorn: 244.4 MB
 : 0 
 

Dash便PythonistaDash使PythonistaDocsets


https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/Pythonista


 Dash API DocsAppApp : Productivity
 : Bogdan Popescu: 4.2 MB
 : 0 
 

 - iOS