Skip to content

Commit d1c44c7

Browse files
committed
Added sqlite and openssl testapp
1 parent 11382b7 commit d1c44c7

File tree

3 files changed

+251
-0
lines changed

3 files changed

+251
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
from distutils.core import setup
3+
from setuptools import find_packages
4+
5+
options = {'apk': {#'debug': None,
6+
'requirements': 'sdl2,pyjnius,kivy,python2,openssl,requests,peewee,sqlite3',
7+
'android-api': 19,
8+
'ndk-dir': '/home/sandy/android/crystax-ndk-10.3.2',
9+
'dist-name': 'bdisttest_python2_sqlite_openssl',
10+
'ndk-version': '10.3.2',
11+
'permission': 'VIBRATE',
12+
'permission': 'INTERNET',
13+
'arch': 'armeabi-v7a',
14+
'window': None,
15+
}}
16+
17+
packages = find_packages()
18+
print('packages are', packages)
19+
20+
setup(
21+
name='testapp_python2_sqlite_openssl',
22+
version='1.1',
23+
description='p4a setup.py test',
24+
author='Alexander Taylor',
25+
author_email='[email protected]',
26+
packages=find_packages(),
27+
options=options,
28+
package_data={'testapp_sqlite_openssl': ['*.py', '*.png']}
29+
)
187 KB
Loading
+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
print('main.py was successfully called')
2+
3+
import os
4+
print('imported os')
5+
6+
7+
print('this dir is', os.path.abspath(os.curdir))
8+
9+
print('contents of this dir', os.listdir('./'))
10+
11+
import sys
12+
print('pythonpath is', sys.path)
13+
14+
import kivy
15+
print('imported kivy')
16+
print('file is', kivy.__file__)
17+
18+
from kivy.app import App
19+
20+
from kivy.lang import Builder
21+
from kivy.properties import StringProperty
22+
23+
from kivy.uix.popup import Popup
24+
from kivy.clock import Clock
25+
26+
print('Imported kivy')
27+
from kivy.utils import platform
28+
print('platform is', platform)
29+
30+
import peewee
31+
import requests
32+
import sqlite3
33+
34+
35+
try:
36+
inclemnet = requests.get('http://inclem.net/')
37+
print('got inclem.net request')
38+
except:
39+
inclemnet = 'failed inclemnet'
40+
41+
try:
42+
kivy = requests.get('https://kivy.org/')
43+
print('got kivy request (https)')
44+
except:
45+
kivy = 'failed kivy'
46+
47+
from peewee import *
48+
db = SqliteDatabase('test.db')
49+
50+
class Person(Model):
51+
name = CharField()
52+
birthday = DateField()
53+
is_relative = BooleanField()
54+
55+
class Meta:
56+
database = db
57+
58+
def __repr__(self):
59+
return '<Person: {}, {}>'.format(self.name, self.birthday)
60+
61+
def __str__(self):
62+
return repr(self)
63+
64+
db.connect()
65+
try:
66+
db.create_tables([Person])
67+
except:
68+
import traceback
69+
traceback.print_exc()
70+
71+
import random
72+
from datetime import date
73+
test_person = Person(name='person{}'.format(random.randint(0, 1000)),
74+
birthday=date(random.randint(1900, 2000), random.randint(1, 9), random.randint(1, 20)),
75+
is_relative=False)
76+
test_person.save()
77+
78+
79+
kv = '''
80+
#:import Metrics kivy.metrics.Metrics
81+
#:import sys sys
82+
83+
<FixedSizeButton@Button>:
84+
size_hint_y: None
85+
height: dp(60)
86+
87+
88+
ScrollView:
89+
GridLayout:
90+
cols: 1
91+
size_hint_y: None
92+
height: self.minimum_height
93+
FixedSizeButton:
94+
text: 'test pyjnius'
95+
on_press: app.test_pyjnius()
96+
Label:
97+
height: self.texture_size[1]
98+
size_hint_y: None
99+
text_size: self.size[0], None
100+
markup: True
101+
text: 'kivy request: {}\\ninclemnet request: {}'.format(app.kivy_request, app.inclemnet_request)
102+
halign: 'center'
103+
Label:
104+
height: self.texture_size[1]
105+
size_hint_y: None
106+
text_size: self.size[0], None
107+
markup: True
108+
text: 'people: {}'.format(app.people)
109+
halign: 'center'
110+
Image:
111+
keep_ratio: False
112+
allow_stretch: True
113+
source: 'colours.png'
114+
size_hint_y: None
115+
height: dp(100)
116+
Label:
117+
height: self.texture_size[1]
118+
size_hint_y: None
119+
font_size: 100
120+
text_size: self.size[0], None
121+
markup: True
122+
text: '[b]Kivy[/b] on [b]SDL2[/b] on [b]Android[/b]!'
123+
halign: 'center'
124+
Label:
125+
height: self.texture_size[1]
126+
size_hint_y: None
127+
text_size: self.size[0], None
128+
markup: True
129+
text: sys.version
130+
halign: 'center'
131+
padding_y: dp(10)
132+
Widget:
133+
size_hint_y: None
134+
height: 20
135+
Label:
136+
height: self.texture_size[1]
137+
size_hint_y: None
138+
font_size: 50
139+
text_size: self.size[0], None
140+
markup: True
141+
text: 'dpi: {}\\ndensity: {}\\nfontscale: {}'.format(Metrics.dpi, Metrics.density, Metrics.fontscale)
142+
halign: 'center'
143+
FixedSizeButton:
144+
text: 'test ctypes'
145+
on_press: app.test_ctypes()
146+
FixedSizeButton:
147+
text: 'test numpy'
148+
on_press: app.test_numpy()
149+
Widget:
150+
size_hint_y: None
151+
height: 1000
152+
on_touch_down: print('touched at', args[-1].pos)
153+
154+
<ErrorPopup>:
155+
title: 'Error'
156+
size_hint: 0.75, 0.75
157+
Label:
158+
text: root.error_text
159+
'''
160+
161+
162+
class ErrorPopup(Popup):
163+
error_text = StringProperty('')
164+
165+
def raise_error(error):
166+
print('ERROR:', error)
167+
ErrorPopup(error_text=error).open()
168+
169+
class TestApp(App):
170+
171+
kivy_request = kivy
172+
inclemnet_request = inclemnet
173+
174+
people = ', '.join(map(str, list(Person.select())))
175+
176+
def build(self):
177+
root = Builder.load_string(kv)
178+
Clock.schedule_interval(self.print_something, 2)
179+
# Clock.schedule_interval(self.test_pyjnius, 5)
180+
print('testing metrics')
181+
from kivy.metrics import Metrics
182+
print('dpi is', Metrics.dpi)
183+
print('density is', Metrics.density)
184+
print('fontscale is', Metrics.fontscale)
185+
return root
186+
187+
def print_something(self, *args):
188+
print('App print tick', Clock.get_boottime())
189+
190+
def on_pause(self):
191+
return True
192+
193+
def test_pyjnius(self, *args):
194+
try:
195+
from jnius import autoclass
196+
except ImportError:
197+
raise_error('Could not import pyjnius')
198+
return
199+
200+
print('Attempting to vibrate with pyjnius')
201+
# PythonActivity = autoclass('org.renpy.android.PythonActivity')
202+
# activity = PythonActivity.mActivity
203+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
204+
activity = PythonActivity.mActivity
205+
Intent = autoclass('android.content.Intent')
206+
Context = autoclass('android.content.Context')
207+
vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE)
208+
209+
vibrator.vibrate(1000)
210+
211+
def test_ctypes(self, *args):
212+
import ctypes
213+
214+
def test_numpy(self, *args):
215+
import numpy
216+
217+
print(numpy.zeros(5))
218+
print(numpy.arange(5))
219+
print(numpy.random.random((3, 3)))
220+
221+
222+
TestApp().run()

0 commit comments

Comments
 (0)