Skip to content

Instantly share code, notes, and snippets.

@riverfor
Created February 1, 2020 13:56
Show Gist options
  • Save riverfor/427c4c8762d5c57468e24ec026bbb0e9 to your computer and use it in GitHub Desktop.
Save riverfor/427c4c8762d5c57468e24ec026bbb0e9 to your computer and use it in GitHub Desktop.
#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()
@Rickardo82
Copy link

Hellow

@Rickardo82
Copy link

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment