Skip to content

Commit bf529c5

Browse files
committed
More testapp rearranging
1 parent 34ac4fb commit bf529c5

File tree

3 files changed

+201
-49
lines changed

3 files changed

+201
-49
lines changed

testapps/testapp/main.py

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
import os
44
print('imported os')
55

6-
from kivy import platform
6+
print('contents of ./lib/python2.7/site-packages/ etc.')
7+
print(os.listdir('./lib'))
8+
print(os.listdir('./lib/python2.7'))
9+
print(os.listdir('./lib/python2.7/site-packages'))
710

8-
if platform == 'android':
9-
print('contents of ./lib/python2.7/site-packages/ etc.')
10-
print(os.listdir('./lib'))
11-
print(os.listdir('./lib/python2.7'))
12-
print(os.listdir('./lib/python2.7/site-packages'))
11+
print('this dir is', os.path.abspath(os.curdir))
1312

14-
print('this dir is', os.path.abspath(os.curdir))
13+
print('contents of this dir', os.listdir('./'))
1514

16-
print('contents of this dir', os.listdir('./'))
17-
18-
with open('./lib/python2.7/site-packages/kivy/app.pyo', 'rb') as fileh:
19-
print('app.pyo size is', len(fileh.read()))
15+
with open('./lib/python2.7/site-packages/kivy/app.pyo', 'rb') as fileh:
16+
print('app.pyo size is', len(fileh.read()))
2017

2118
import sys
2219
print('pythonpath is', sys.path)
@@ -40,51 +37,61 @@
4037

4138
kv = '''
4239
#:import Metrics kivy.metrics.Metrics
43-
#:import Window kivy.core.window.Window
4440
4541
<FixedSizeButton@Button>:
4642
size_hint_y: None
4743
height: dp(60)
4844
4945
50-
BoxLayout:
51-
orientation: 'vertical'
52-
BoxLayout:
46+
ScrollView:
47+
GridLayout:
48+
cols: 1
5349
size_hint_y: None
54-
height: dp(50)
55-
orientation: 'horizontal'
56-
Button:
57-
text: 'None'
58-
on_press: Window.softinput_mode = ''
59-
Button:
60-
text: 'pan'
61-
on_press: Window.softinput_mode = 'pan'
62-
Button:
63-
text: 'below_target'
64-
on_press: Window.softinput_mode = 'below_target'
65-
Button:
66-
text: 'resize'
67-
on_press: Window.softinput_mode = 'resize'
68-
Widget:
69-
Scatter:
70-
id: scatter
71-
size_hint: None, None
72-
size: dp(300), dp(80)
73-
on_parent: self.pos = (300, 100)
74-
BoxLayout:
75-
size: scatter.size
76-
orientation: 'horizontal'
77-
canvas:
78-
Color:
79-
rgba: 1, 0, 0, 1
80-
Rectangle:
81-
pos: 0, 0
82-
size: self.size
83-
Widget:
84-
size_hint_x: None
85-
width: dp(30)
86-
TextInput:
87-
text: 'type in me'
50+
height: self.minimum_height
51+
FixedSizeButton:
52+
text: 'test pyjnius'
53+
on_press: app.test_pyjnius()
54+
Image:
55+
keep_ratio: False
56+
allow_stretch: True
57+
source: 'colours.png'
58+
size_hint_y: None
59+
height: dp(100)
60+
Label:
61+
height: self.texture_size[1]
62+
size_hint_y: None
63+
font_size: 100
64+
text_size: self.size[0], None
65+
markup: True
66+
text: '[b]Kivy[/b] on [b]SDL2[/b] on [b]Android[/b]!'
67+
halign: 'center'
68+
Widget:
69+
size_hint_y: None
70+
height: 20
71+
Label:
72+
height: self.texture_size[1]
73+
size_hint_y: None
74+
font_size: 50
75+
text_size: self.size[0], None
76+
markup: True
77+
text: 'dpi: {}\\ndensity: {}\\nfontscale: {}'.format(Metrics.dpi, Metrics.density, Metrics.fontscale)
78+
halign: 'center'
79+
FixedSizeButton:
80+
text: 'test ctypes'
81+
on_press: app.test_ctypes()
82+
FixedSizeButton:
83+
text: 'test numpy'
84+
on_press: app.test_numpy()
85+
Widget:
86+
size_hint_y: None
87+
height: 1000
88+
on_touch_down: print 'touched at', args[-1].pos
89+
90+
<ErrorPopup>:
91+
title: 'Error'
92+
size_hint: 0.75, 0.75
93+
Label:
94+
text: root.error_text
8895
'''
8996

9097

@@ -140,5 +147,6 @@ def test_numpy(self, *args):
140147
print(numpy.zeros(5))
141148
print(numpy.arange(5))
142149
print(numpy.random.random((3, 3)))
150+
143151

144152
TestApp().run()

testapps/testapp_keyboard/colours.png

187 KB
Loading

testapps/testapp_keyboard/main.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
print('main.py was successfully called')
2+
3+
import os
4+
print('imported os')
5+
6+
from kivy import platform
7+
8+
if platform == 'android':
9+
print('contents of ./lib/python2.7/site-packages/ etc.')
10+
print(os.listdir('./lib'))
11+
print(os.listdir('./lib/python2.7'))
12+
print(os.listdir('./lib/python2.7/site-packages'))
13+
14+
print('this dir is', os.path.abspath(os.curdir))
15+
16+
print('contents of this dir', os.listdir('./'))
17+
18+
with open('./lib/python2.7/site-packages/kivy/app.pyo', 'rb') as fileh:
19+
print('app.pyo size is', len(fileh.read()))
20+
21+
import sys
22+
print('pythonpath is', sys.path)
23+
24+
import kivy
25+
print('imported kivy')
26+
print('file is', kivy.__file__)
27+
28+
from kivy.app import App
29+
30+
from kivy.lang import Builder
31+
from kivy.properties import StringProperty
32+
33+
from kivy.uix.popup import Popup
34+
from kivy.clock import Clock
35+
36+
print('Imported kivy')
37+
from kivy.utils import platform
38+
print('platform is', platform)
39+
40+
41+
kv = '''
42+
#:import Metrics kivy.metrics.Metrics
43+
#:import Window kivy.core.window.Window
44+
45+
<FixedSizeButton@Button>:
46+
size_hint_y: None
47+
height: dp(60)
48+
49+
50+
BoxLayout:
51+
orientation: 'vertical'
52+
BoxLayout:
53+
size_hint_y: None
54+
height: dp(50)
55+
orientation: 'horizontal'
56+
Button:
57+
text: 'None'
58+
on_press: Window.softinput_mode = ''
59+
Button:
60+
text: 'pan'
61+
on_press: Window.softinput_mode = 'pan'
62+
Button:
63+
text: 'below_target'
64+
on_press: Window.softinput_mode = 'below_target'
65+
Button:
66+
text: 'resize'
67+
on_press: Window.softinput_mode = 'resize'
68+
Widget:
69+
Scatter:
70+
id: scatter
71+
size_hint: None, None
72+
size: dp(300), dp(80)
73+
on_parent: self.pos = (300, 100)
74+
BoxLayout:
75+
size: scatter.size
76+
orientation: 'horizontal'
77+
canvas:
78+
Color:
79+
rgba: 1, 0, 0, 1
80+
Rectangle:
81+
pos: 0, 0
82+
size: self.size
83+
Widget:
84+
size_hint_x: None
85+
width: dp(30)
86+
TextInput:
87+
text: 'type in me'
88+
'''
89+
90+
91+
class ErrorPopup(Popup):
92+
error_text = StringProperty('')
93+
94+
def raise_error(error):
95+
print('ERROR:', error)
96+
ErrorPopup(error_text=error).open()
97+
98+
class TestApp(App):
99+
def build(self):
100+
root = Builder.load_string(kv)
101+
Clock.schedule_interval(self.print_something, 2)
102+
# Clock.schedule_interval(self.test_pyjnius, 5)
103+
print('testing metrics')
104+
from kivy.metrics import Metrics
105+
print('dpi is', Metrics.dpi)
106+
print('density is', Metrics.density)
107+
print('fontscale is', Metrics.fontscale)
108+
return root
109+
110+
def print_something(self, *args):
111+
print('App print tick', Clock.get_boottime())
112+
113+
def on_pause(self):
114+
return True
115+
116+
def test_pyjnius(self, *args):
117+
try:
118+
from jnius import autoclass
119+
except ImportError:
120+
raise_error('Could not import pyjnius')
121+
return
122+
123+
print('Attempting to vibrate with pyjnius')
124+
# PythonActivity = autoclass('org.renpy.android.PythonActivity')
125+
# activity = PythonActivity.mActivity
126+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
127+
activity = PythonActivity.mActivity
128+
Intent = autoclass('android.content.Intent')
129+
Context = autoclass('android.content.Context')
130+
vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE)
131+
132+
vibrator.vibrate(1000)
133+
134+
def test_ctypes(self, *args):
135+
import ctypes
136+
137+
def test_numpy(self, *args):
138+
import numpy
139+
140+
print(numpy.zeros(5))
141+
print(numpy.arange(5))
142+
print(numpy.random.random((3, 3)))
143+
144+
TestApp().run()

0 commit comments

Comments
 (0)