File tree Expand file tree Collapse file tree 6 files changed +28
-18
lines changed
apps/android_pythonnative_3/app
java/com/pythonnative/pythonnative
libs/pythonnative/pythonnative Expand file tree Collapse file tree 6 files changed +28
-18
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,13 @@ android {
2121 }
2222 python {
2323 pip {
24+ // https://chaquo.com/chaquopy/doc/current/android.html#android-requirements
2425// install "matplotlib"
25- install " pythonnative"
26+ // install "pythonnative"
27+
28+ // A directory containing a setup.py, relative to the project
29+ // directory (must contain at least one slash):
30+ install " /Users/owenthcarey/Documents/pythonnative-workspace/libs/pythonnative"
2631 }
2732 }
2833 }
Original file line number Diff line number Diff line change @@ -36,14 +36,14 @@ class MainActivity : AppCompatActivity() {
3636// val pyButton = createButtonModule.callAttr("create_button", this).toJava(Button::class.java)
3737// layoutMain.addView(pyButton)
3838
39- val createWidgetsModule = py.getModule(" create_widgets" )
40- val pyLayout = createWidgetsModule.callAttr(" create_widgets" , this ).toJava(LinearLayout ::class .java)
41- layoutMain.addView(pyLayout)
42-
43- // val createLayoutModule = py.getModule("create_pn_layout")
44- // val pyLayout = createLayoutModule.callAttr("create_pn_layout").toJava(LinearLayout::class.java)
39+ // val createWidgetsModule = py.getModule("create_widgets")
40+ // val pyLayout = createWidgetsModule.callAttr("create_widgets", this).toJava(LinearLayout::class.java)
4541// layoutMain.addView(pyLayout)
4642
43+ val createLayoutModule = py.getModule(" create_pn_layout" )
44+ val pyLayout = createLayoutModule.callAttr(" create_pn_layout" , this ).toJava(LinearLayout ::class .java)
45+ layoutMain.addView(pyLayout)
46+
4747// val createConstraintLayoutModule = py.getModule("create_constraint_layout")
4848// val pyLayout = createConstraintLayoutModule.callAttr("create_constraint_layout", this).toJava(ConstraintLayout::class.java)
4949// layoutMain.addView(pyLayout)
Original file line number Diff line number Diff line change 33import pythonnative as pn
44
55
6- def create_pn_layout ():
7- layout = pn .LinearLayout ()
6+ def create_pn_layout (context ):
7+ layout = pn .LinearLayout (context )
88
9- label = pn .Label ("This is a PythonNative label" )
9+ label = pn .Label (context , "This is a PythonNative label" )
1010 layout .add_view (label )
1111
12- button = pn .Button ("Click me" )
12+ button = pn .Button (context , "Click me" )
1313 layout .add_view (button )
1414
1515 return layout .native_instance
16+
17+ # from java import jclass
18+ # LinearLayout = jclass("android.widget.LinearLayout")
19+ # layout = LinearLayout(context)
20+ # return layout
Original file line number Diff line number Diff line change 77 class Button (View ):
88 native_class = jclass ("android.widget.Button" )
99
10- def __init__ (self , title : str = "" ) -> None :
10+ def __init__ (self , context , title : str = "" ) -> None :
1111 super ().__init__ ()
12- self .native_instance = self .native_class ()
12+ self .native_instance = self .native_class (context )
1313 self .set_title (title )
1414
1515 def set_title (self , title : str ) -> None :
Original file line number Diff line number Diff line change 77 class Label (View ):
88 native_class = jclass ("android.widget.TextView" )
99
10- def __init__ (self , text : str = "" ) -> None :
10+ def __init__ (self , context , text : str = "" ) -> None :
1111 super ().__init__ ()
12- self .native_instance = self .native_class ()
12+ self .native_instance = self .native_class (context )
1313 self .set_text (text )
1414
1515 def set_text (self , text : str ) -> None :
Original file line number Diff line number Diff line change 77 class LinearLayout (View ):
88 native_class = jclass ("android.widget.LinearLayout" )
99
10- def __init__ (self ) -> None :
10+ def __init__ (self , context ) -> None :
1111 super ().__init__ ()
12- self .native_instance = self .native_class ()
13- self .native_instance .setOrientation (1 ) # Set orientation to vertical
12+ self .native_instance = self .native_class (context )
13+ self .native_instance .setOrientation (self . native_class . VERTICAL ) # Set orientation to vertical
1414 self .views = []
1515
1616 def add_view (self , view ):
You can’t perform that action at this time.
0 commit comments