Pie Meets Py / PyCon JP 2019

6fa3836d10d691125749472297cf516a?s=47 7pairs
September 16, 2019

Pie Meets Py / PyCon JP 2019

6fa3836d10d691125749472297cf516a?s=128

7pairs

September 16, 2019
Tweet

Transcript

  1. 2.

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

    • ޷͖ͳେࡕۅӂ͸தଜ߶໵ " / ޷͖ͳ෋࢜େֶ͸֎࡚मଡ # • ͓࢓ࣄͰ͸Android (Java / Kotlin) / iOS (Objective-C / Swift) ͕த৺ • ͋·ΓҰൠతͱ͸ݴ͑ͳ͍Pythonͷ࢖͍ํΛ໛ࡧ͢Δͷ͕େ޷͖ • PyCon JP 2018Ͱ͸Transcryptʹ͍ͭͯൃද • https://speakerdeck.com/7pairs
  2. 9.

    Pieͱ͸ʁ • Android 9.0ͷίʔυωʔϜ • Android 1.5 (3൪໨ͷόʔδϣϯ) Ҏ߱ 


    ֤όʔδϣϯʹ͸ΞϧϑΝϕοτॱʹ 
 ͓՛ࢠͷίʔυωʔϜ͕͚ͭΒΕ͍ͯΔ
  3. 24.

    Android 10 • 2019೥9݄3೔ϦϦʔε • PixelγϦʔζ͔Βॱ࣍഑৴ • ͓՛ࢠͷίʔυωʔϜ͕ഇࢭ $ •

    ੈքதͷ͢΂ͯͷϢʔβʔ͕ 
 ಉ͡Α͏ʹೝࣝͰ͖Δ໊લͰ͸ͳ͍ͨΊ
  4. 37.
  5. 42.

    Transcrypt • PythonΛJavaScriptʹม׵͢ΔAltJS • ެࣜαΠτᐌ͘ “subset of Python” Ͱ͋Γ 


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

    React Native + Transcrypt • React Native͸ϓϩάϥϜΛ 
 JavaScriptͰ࣮૷͢Δ •

    Transcrypt͸PythonΛJavaScriptʹม׵͢Δ • ૊Έ߹ΘͤΕ͹PythonͰReact Nativeͷ 
 ϓϩάϥϜ͕ॻ͚ΔͷͰ͸ʁ
  7. 48.

    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)
  8. 50.
  9. 51.

    Kivy • Φʔϓϯιʔεͷ 
 ϚϧνλονΞϓϦέʔγϣϯϑϨʔϜϫʔΫ • OpenGL ES 2.0ͱޓ׵ੑͷ͋Δ 


    άϥϑΟοΫඳըϥΠϒϥϦ • தؒݴޠKVͰͷը໘ɾ΢ΟδΣοτͷఆٛ • Android / iOS / Linux / Mac / WindowsʹରԠ
  10. 53.

    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()
  11. 54.

    Buildozer • KivyΞϓϦͷAndroid / iOS޲͚ͷύοέʔδϟʔ • Android޲͚ͷύοέʔδϯάͷࡍʹ͸ 
 Buildozer಺෦Ͱpython-for-androidΛར༻ •

    Ұ෦ͷPythonύοέʔδͷΠϯετʔϧʹ΋ରԠ • ඇରԠͷύοέʔδΛΠϯετʔϧ͢Δʹ͸ 
 recipeΛࣗྗͰ࡞੒͢Δඞཁ͕͋Δ
  12. 55.

    Plyer • OS΍୺຤ݻ༗ͷػೳΛ 
 Python͔Βར༻͢ΔͨΊͷAPI܈ • ৼಈ / Χϝϥ /

    GPS ... • ରԠ͍ͯ͠ͳ͍ϓϥοτϑΥʔϜͰ͸ 
 NotImplementedErrorΛraise͢Δ
  13. 58.

    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)
  14. 61.
  15. 62.

    Chaquopy • ެࣜαΠτᐌ͘ “Python SDK for Android” • build.gradleʹهड़Λ௥Ճͯ͠ಋೖ •

    Java / Kotlinͷ୅ΘΓʹ 
 PythonͰ࣮૷͢ΔΠϝʔδ (ࠞࡏ΋Մೳ)
  16. 63.

    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)
  17. 68.

    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())
  18. 70.

    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()))
  19. 72.

    Positive ! • ಋೖ͕༰қ • Java / Pythonͷύοέʔδͱ࿈ܞ͕Մೳ • Java

    / KotlinʹΑΔΞϓϦ։ൃͷ஌ݟΛ 
 ΄΅ͦͷ··׆͔͢͜ͱ͕Ͱ͖Δ
  20. 74.
  21. 76.

    BeeWare • PythonʹΑΔΫϩεϓϥοτϑΥʔϜ։ൃ؀ڥ • Mac / Windows / Linux /

    iPhone / iPad / Android 
 AppleTV / tvOSʹରԠ • Android͸VOCͱͷ࿈ܞͰಈ࡞͢Δ • PythonόΠτίʔυΛJavaόΠτίʔυʹม׵
  22. 78.

    PySide for Android • PySide (QtͷPythonόΠϯσΟϯά) ʹΑΔ 
 AndroidΞϓϦ։ൃ؀ڥ •

    Qtͱ͍͏࣮੷ͷ͋ΔGUIϥΠϒϥϦΛ 
 AndroidͰར༻͢Δ͜ͱ͕Ͱ͖Δ
  23. 80.
  24. 81.

    React Native + Transcrypt • ࣮੷ͷ͋ΔReact Nativeʹ৐͔ͬΔ͜ͱ͕Ͱ͖Δ • React NativeΛૉͷJavaScriptͰ

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