-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathQPy_SL4AApp
More file actions
109 lines (97 loc) · 2.99 KB
/
Copy pathQPy_SL4AApp
File metadata and controls
109 lines (97 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#qpy:quiet
#-*-coding:utf8;-*-
"""
This is a sample project which use SL4A UI Framework,
There is another Sample project: https://github.com/qpython-android/qpy-calcount
"""
import qpy
import androidhelper
try:
import urllib.request as ur
except:
import urllib as ur
from qsl4ahelper.fullscreenwrapper2 import *
droid = androidhelper.Android()
class MainScreen(Layout):
def __init__(self):
super(MainScreen,self).__init__(str("""<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0E4200"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/logo"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="10"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="20">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="8dp"
android:text="Hello, QPython"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"
/>
</LinearLayout>
<ListView
android:id="@+id/data_list"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="55"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="8">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Load"
android:id="@+id/but_load"
android:textSize="8dp"
android:background="#ffEFC802"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Exit"
android:id="@+id/but_exit"
android:textSize="8dp"
android:background="#ff06AF00"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
"""),"SL4AApp")
def on_show(self):
self.views.but_exit.add_event(click_EventHandler(self.views.but_exit, self.exit))
self.views.but_load.add_event(click_EventHandler(self.views.but_load, self.load))
pass
def on_close(self):
pass
def load(self, view, dummy):
droid = FullScreenWrapper2App.get_android_instance()
droid.makeToast("Load")
saved_logo = qpy.tmp+"/qpy.logo"
ur.urlretrieve("https://www.qpython.org/static/img_logo.png", saved_logo)
self.views.logo.src = "file://"+saved_logo
def exit(self, view, dummy):
droid = FullScreenWrapper2App.get_android_instance()
droid.makeToast("Exit")
FullScreenWrapper2App.close_layout()
if __name__ == '__main__':
FullScreenWrapper2App.initialize(droid)
FullScreenWrapper2App.show_layout(MainScreen())
FullScreenWrapper2App.eventloop()