@@ -27,40 +27,45 @@ class MainActivity : AppCompatActivity() {
2727 if (! Python .isStarted()) {
2828 Python .start(AndroidPlatform (this ))
2929 }
30-
3130 val py = Python .getInstance()
31+ val createButtonModule = py.getModule(" create_button" )
32+ val pyButton = createButtonModule.callAttr(" create_button" , this ).toJava(Button ::class .java)
33+ val layoutMain = findViewById<ConstraintLayout >(R .id.layout_main)
34+ layoutMain.addView(pyButton)
3235
33- // Generate UI from Python
34- val uiLayoutModule = py.getModule(" ui_layout" )
35- val layoutJson = uiLayoutModule.callAttr(" generate_layout" ).toString()
36- val layout = JSONObject (layoutJson)
37- val widgets = layout.getJSONArray(" widgets" )
38-
39- for (i in 0 until widgets.length()) {
40- val widget = widgets.getJSONObject(i)
41- when (widget.getString(" type" )) {
42- " Button" -> {
43- val button = Button (this )
44- button.text = widget.getJSONObject(" properties" ).getString(" text" )
45- button.setTextColor(Color .parseColor(widget.getJSONObject(" properties" ).getString(" textColor" )))
46- button.setBackgroundColor(Color .parseColor(widget.getJSONObject(" properties" ).getString(" backgroundColor" )))
36+ // TODO: Run python module and get button
4737
48- if (widget.has(" eventHandlers" ) && widget.getJSONObject(" eventHandlers" ).has(" onClick" )) {
49- val onClickFunctionName = widget.getJSONObject(" eventHandlers" ).getString(" onClick" )
50- val onClickFunction = py.getModule(" ui_layout" ).get(onClickFunctionName)
51-
52- button.setOnClickListener {
53- onClickFunction?.call()
54- }
55- }
56-
57- // Add button to your layout here
58- val layoutMain = findViewById<ConstraintLayout >(R .id.layout_main)
59- layoutMain.addView(button)
60- }
61- // Handle other widget types...
62- }
63- }
38+ // Generate UI from Python
39+ // val uiLayoutModule = py.getModule("ui_layout")
40+ // val layoutJson = uiLayoutModule.callAttr("generate_layout").toString()
41+ // val layout = JSONObject(layoutJson)
42+ // val widgets = layout.getJSONArray("widgets")
43+ //
44+ // for (i in 0 until widgets.length()) {
45+ // val widget = widgets.getJSONObject(i)
46+ // when (widget.getString("type")) {
47+ // "Button" -> {
48+ // val button = Button(this)
49+ // button.text = widget.getJSONObject("properties").getString("text")
50+ // button.setTextColor(Color.parseColor(widget.getJSONObject("properties").getString("textColor")))
51+ // button.setBackgroundColor(Color.parseColor(widget.getJSONObject("properties").getString("backgroundColor")))
52+ //
53+ // if (widget.has("eventHandlers") && widget.getJSONObject("eventHandlers").has("onClick")) {
54+ // val onClickFunctionName = widget.getJSONObject("eventHandlers").getString("onClick")
55+ // val onClickFunction = py.getModule("ui_layout").get(onClickFunctionName)
56+ //
57+ // button.setOnClickListener {
58+ // onClickFunction?.call()
59+ // }
60+ // }
61+ //
62+ // // Add button to your layout here
63+ // val layoutMain = findViewById<ConstraintLayout>(R.id.layout_main)
64+ // layoutMain.addView(button)
65+ // }
66+ // // Handle other widget types...
67+ // }
68+ // }
6469
6570 // Existing code for displaying plot
6671// val imageView = findViewById<ImageView>(R.id.image_home)
0 commit comments