Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pie Meets Py / PyCon JP 2019

7pairs
September 16, 2019

Pie Meets Py / PyCon JP 2019

7pairs

September 16, 2019
Tweet

More Decks by 7pairs

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ௕୩৔ ५໵ (͸ͤ͹ ͡ΎΜ΍) • ֤छSNSͰ͸ 7pairs Ͱ׆ಈத

    • ޷͖ͳେࡕۅӂ͸தଜ߶໵ " / ޷͖ͳ෋࢜େֶ͸֎࡚मଡ # • ͓࢓ࣄͰ͸Android (Java / Kotlin) / iOS (Objective-C / Swift) ͕த৺ • ͋·ΓҰൠతͱ͸ݴ͑ͳ͍Pythonͷ࢖͍ํΛ໛ࡧ͢Δͷ͕େ޷͖ • PyCon JP 2018Ͱ͸Transcryptʹ͍ͭͯൃද • https://speakerdeck.com/7pairs
  2. Pieͱ͸ʁ • Android 9.0ͷίʔυωʔϜ • Android 1.5 (3൪໨ͷόʔδϣϯ) Ҏ߱ 


    ֤όʔδϣϯʹ͸ΞϧϑΝϕοτॱʹ 
 ͓՛ࢠͷίʔυωʔϜ͕͚ͭΒΕ͍ͯΔ
  3. Android 10 • 2019೥9݄3೔ϦϦʔε • PixelγϦʔζ͔Βॱ࣍഑৴ • ͓՛ࢠͷίʔυωʔϜ͕ഇࢭ $ •

    ੈքதͷ͢΂ͯͷϢʔβʔ͕ 
 ಉ͡Α͏ʹೝࣝͰ͖Δ໊લͰ͸ͳ͍ͨΊ
  4. Transcrypt • PythonΛJavaScriptʹม׵͢ΔAltJS • ެࣜαΠτᐌ͘ “subset of Python” Ͱ͋Γ 


    ͢΂ͯͷػೳΛαϙʔτ͍ͯ͠ΔΘ͚Ͱ͸ͳ͍ • Ұ෦ͷඪ४ϥΠϒϥϦ͕ར༻Ͱ͖ͳ͍ͳͲ • JavaScriptͷॲཧΛγʔϜϨεʹݺͼग़ͤΔ • JavaScriptͷ֎෦ύοέʔδ΋ར༻Մೳ
  5. React Native + Transcrypt • React Native͸ϓϩάϥϜΛ 
 JavaScriptͰ࣮૷͢Δ •

    Transcrypt͸PythonΛJavaScriptʹม׵͢Δ • ૊Έ߹ΘͤΕ͹PythonͰReact Nativeͷ 
 ϓϩάϥϜ͕ॻ͚ΔͷͰ͸ʁ
  6. TranscryptͷܕνΣοΫ def concat(a: str, b: str) -> str: return f"{a}-{b}"

    # 33-4 concat("33", "4") # error: Argument 2 to "concat" has # incompatible type "int"; expected "str" concat("33", 4)
  7. Kivy • Φʔϓϯιʔεͷ 
 ϚϧνλονΞϓϦέʔγϣϯϑϨʔϜϫʔΫ • OpenGL ES 2.0ͱޓ׵ੑͷ͋Δ 


    άϥϑΟοΫඳըϥΠϒϥϦ • தؒݴޠKVͰͷը໘ɾ΢ΟδΣοτͷఆٛ • Android / iOS / Linux / Mac / WindowsʹରԠ
  8. KivyʹΑΔHello world from kivy.app import App from kivy.uix.button import Button

    class TestApp(App): def build(self): return Button(text='Hello World') TestApp().run()
  9. Buildozer • KivyΞϓϦͷAndroid / iOS޲͚ͷύοέʔδϟʔ • Android޲͚ͷύοέʔδϯάͷࡍʹ͸ 
 Buildozer಺෦Ͱpython-for-androidΛར༻ •

    Ұ෦ͷPythonύοέʔδͷΠϯετʔϧʹ΋ରԠ • ඇରԠͷύοέʔδΛΠϯετʔϧ͢Δʹ͸ 
 recipeΛࣗྗͰ࡞੒͢Δඞཁ͕͋Δ
  10. Plyer • OS΍୺຤ݻ༗ͷػೳΛ 
 Python͔Βར༻͢ΔͨΊͷAPI܈ • ৼಈ / Χϝϥ /

    GPS ... • ରԠ͍ͯ͠ͳ͍ϓϥοτϑΥʔϜͰ͸ 
 NotImplementedErrorΛraise͢Δ
  11. Pyjniusͷαϯϓϧ from jnius import autoclass Context = autoclass('android.content.Context') PythonActivity =

    autoclass('org.kivy.android.PythonActivity') activity = PythonActivity.mActivity vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE) vibrator.vibrate(10000)
  12. Chaquopy • ެࣜαΠτᐌ͘ “Python SDK for Android” • build.gradleʹهड़Λ௥Ճͯ͠ಋೖ •

    Java / Kotlinͷ୅ΘΓʹ 
 PythonͰ࣮૷͢ΔΠϝʔδ (ࠞࡏ΋Մೳ)
  13. ChaquopyͰͷHello world from android.os import Bundle from android.support.v7.app import AppCompatActivity

    from java import jvoid, Override, static_proxy class MainActivity(static_proxy(AppCompatActivity)): @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state) self.setContentView(R.layout.activity_main)
  14. dynamic_proxyͷαϯϓϧ # <略> @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state)

    self.setContentView(R.layout.activity_main) class Listener(dynamic_proxy(View.OnClickListener)): def onClick(self, view): # クリック時の処理 self.findViewById(R.id.button).setOnClickListener(Listener())
  15. Android্Ͱಈ͘pandas from android.os import Bundle from android.support.v7.app import AppCompatActivity from

    java import jvoid, Override, static_proxy import pandas as pd class MainActivity(static_proxy(AppCompatActivity)): @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state) self.setContentView(R.layout.activity_main) url = "http://npb.jp/bis/players/81085115.html" df = pd.read_html(url)[1].query('年度 == 年度') Log.d("PyConJP", str(df['本塁打'].sum()))
  16. Positive ! • ಋೖ͕༰қ • Java / Pythonͷύοέʔδͱ࿈ܞ͕Մೳ • Java

    / KotlinʹΑΔΞϓϦ։ൃͷ஌ݟΛ 
 ΄΅ͦͷ··׆͔͢͜ͱ͕Ͱ͖Δ
  17. BeeWare • PythonʹΑΔΫϩεϓϥοτϑΥʔϜ։ൃ؀ڥ • Mac / Windows / Linux /

    iPhone / iPad / Android 
 AppleTV / tvOSʹରԠ • Android͸VOCͱͷ࿈ܞͰಈ࡞͢Δ • PythonόΠτίʔυΛJavaόΠτίʔυʹม׵
  18. PySide for Android • PySide (QtͷPythonόΠϯσΟϯά) ʹΑΔ 
 AndroidΞϓϦ։ൃ؀ڥ •

    Qtͱ͍͏࣮੷ͷ͋ΔGUIϥΠϒϥϦΛ 
 AndroidͰར༻͢Δ͜ͱ͕Ͱ͖Δ
  19. React Native + Transcrypt • ࣮੷ͷ͋ΔReact Nativeʹ৐͔ͬΔ͜ͱ͕Ͱ͖Δ • React NativeΛૉͷJavaScriptͰ

    
 ॻ͍͍ͯΔͷͰ͋Ε͹࠾༻ͯ͠΋ྑ͍͔΋ • ࢒೦ͳ͕ΒTypeScript౳ͷ༗ྗͳAltJSΛ 
 ஔ͖׵͑Δ΄ͲͷΠϯύΫτ͸……