This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
import urllib.request 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="#ff314859" | |
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="10"> | |
<Button | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:text="Load" | |
android:id="@+id/but_load" | |
android:textSize="8dp" | |
android:background="#ff25567b" | |
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="#ff25567b" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hellow