Skip to content

Commit 6331007

Browse files
committed
Add utils.py to pythonnative
1 parent 41cf420 commit 6331007

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

apps/android_pythonnative_3/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ android {
2121
}
2222
python {
2323
pip {
24-
install "matplotlib"
24+
// install "matplotlib"
25+
install "pythonnative"
2526
}
2627
}
2728
}

apps/android_pythonnative_3/app/src/main/java/com/pythonnative/pythonnative/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class MainActivity : AppCompatActivity() {
4040
val pyLayout = createWidgetsModule.callAttr("create_widgets", this).toJava(LinearLayout::class.java)
4141
layoutMain.addView(pyLayout)
4242

43+
// val createLayoutModule = py.getModule("create_pn_layout")
44+
// val pyLayout = createLayoutModule.callAttr("create_pn_layout").toJava(LinearLayout::class.java)
45+
// layoutMain.addView(pyLayout)
46+
4347
// val createConstraintLayoutModule = py.getModule("create_constraint_layout")
4448
// val pyLayout = createConstraintLayoutModule.callAttr("create_constraint_layout", this).toJava(ConstraintLayout::class.java)
4549
// layoutMain.addView(pyLayout)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# pythonnative.py
2+
3+
import pythonnative as pn
4+
5+
6+
def create_pn_layout():
7+
layout = pn.LinearLayout()
8+
9+
label = pn.Label("This is a PythonNative label")
10+
layout.add_view(label)
11+
12+
button = pn.Button("Click me")
13+
layout.add_view(button)
14+
15+
return layout.native_instance

libs/pythonnative/pythonnative/button.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import platform
1+
from .utils import IS_ANDROID
22
from .view import View
33

4-
if platform.system() == "Android":
4+
if IS_ANDROID:
55
from java import jclass
66

77
class Button(View):
@@ -18,7 +18,7 @@ def set_title(self, title: str) -> None:
1818
def get_title(self) -> str:
1919
return self.native_instance.getText().toString()
2020

21-
elif platform.system() == "iOS":
21+
else:
2222
from rubicon.objc import ObjCClass
2323

2424
class Button(View):

libs/pythonnative/pythonnative/label.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import platform
1+
from .utils import IS_ANDROID
22
from .view import View
33

4-
if platform.system() == "Android":
4+
if IS_ANDROID:
55
from java import jclass
66

77
class Label(View):
@@ -18,7 +18,7 @@ def set_text(self, text: str) -> None:
1818
def get_text(self) -> str:
1919
return self.native_instance.getText().toString()
2020

21-
elif platform.system() == "iOS":
21+
else:
2222
from rubicon.objc import ObjCClass
2323

2424
class Label(View):

libs/pythonnative/pythonnative/linear_layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import platform
1+
from .utils import IS_ANDROID
22
from .view import View
33

4-
if platform.system() == "Android":
4+
if IS_ANDROID:
55
from java import jclass
66

77
class LinearLayout(View):
@@ -17,7 +17,7 @@ def add_view(self, view):
1717
self.views.append(view)
1818
self.native_instance.addView(view.native_instance)
1919

20-
elif platform.system() == "iOS":
20+
else:
2121
from rubicon.objc import ObjCClass
2222

2323
class LinearLayout(View):

libs/pythonnative/pythonnative/screen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import platform
1+
from .utils import IS_ANDROID
22
from .view import View
33

4-
if platform.system() == "Android":
4+
if IS_ANDROID:
55
from java import jclass
66

77
class Screen(View):
@@ -25,7 +25,7 @@ def show(self):
2525
# This method should contain code to start the Activity
2626
pass
2727

28-
elif platform.system() == "iOS":
28+
else:
2929
from rubicon.objc import ObjCClass
3030

3131
class Screen(View):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
3+
IS_ANDROID = "ANDROID_BOOTLOGO" in os.environ

0 commit comments

Comments
 (0)