Skip to content

Commit 4a7947e

Browse files
committed
Fixed textinput scatter testapp
1 parent 3060aad commit 4a7947e

File tree

1 file changed

+47
-120
lines changed

1 file changed

+47
-120
lines changed

testapps/testapp_setup/testapp/textinput_scatter.py

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

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'))
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'))
1013

11-
print('this dir is', os.path.abspath(os.curdir))
14+
print('this dir is', os.path.abspath(os.curdir))
1215

13-
print('contents of this dir', os.listdir('./'))
16+
print('contents of this dir', os.listdir('./'))
1417

15-
with open('./lib/python2.7/site-packages/kivy/app.pyo', 'rb') as fileh:
16-
print('app.pyo size is', len(fileh.read()))
18+
with open('./lib/python2.7/site-packages/kivy/app.pyo', 'rb') as fileh:
19+
print('app.pyo size is', len(fileh.read()))
1720

1821
import sys
1922
print('pythonpath is', sys.path)
@@ -35,58 +38,9 @@
3538
print('platform is', platform)
3639

3740

38-
###########
39-
from kivy import platform
40-
if platform == 'android':
41-
from jnius import PythonJavaClass, java_method, autoclass
42-
43-
_PythonActivity = autoclass('org.kivy.android.PythonActivity')
44-
45-
46-
class Runnable(PythonJavaClass):
47-
'''Wrapper around Java Runnable class. This class can be used to schedule a
48-
call of a Python function into the PythonActivity thread.
49-
'''
50-
51-
__javainterfaces__ = ['java/lang/Runnable']
52-
__runnables__ = []
53-
54-
def __init__(self, func):
55-
super(Runnable, self).__init__()
56-
self.func = func
57-
58-
def __call__(self, *args, **kwargs):
59-
self.args = args
60-
self.kwargs = kwargs
61-
Runnable.__runnables__.append(self)
62-
_PythonActivity.mActivity.runOnUiThread(self)
63-
64-
@java_method('()V')
65-
def run(self):
66-
try:
67-
self.func(*self.args, **self.kwargs)
68-
except:
69-
import traceback
70-
traceback.print_exc()
71-
72-
Runnable.__runnables__.remove(self)
73-
74-
def run_on_ui_thread(f):
75-
'''Decorator to create automatically a :class:`Runnable` object with the
76-
function. The function will be delayed and call into the Activity thread.
77-
'''
78-
def f2(*args, **kwargs):
79-
Runnable(f)(*args, **kwargs)
80-
return f2
81-
82-
else:
83-
def run_on_ui_thread(f):
84-
return f
85-
#############
86-
87-
8841
kv = '''
8942
#:import Metrics kivy.metrics.Metrics
43+
#:import Window kivy.core.window.Window
9044
9145
<FixedSizeButton@Button>:
9246
size_hint_y: None
@@ -95,53 +49,42 @@ def run_on_ui_thread(f):
9549
9650
BoxLayout:
9751
orientation: 'vertical'
98-
ScrollView:
99-
GridLayout:
100-
cols: 1
101-
size_hint_y: None
102-
height: self.minimum_height
103-
FixedSizeButton:
104-
text: 'test pyjnius'
105-
on_press: app.test_pyjnius()
106-
Image:
107-
keep_ratio: False
108-
allow_stretch: True
109-
source: 'colours.png'
110-
size_hint_y: None
111-
height: dp(100)
112-
Label:
113-
height: self.texture_size[1]
114-
size_hint_y: None
115-
font_size: 100
116-
text_size: self.size[0], None
117-
markup: True
118-
text: '[b]Kivy[/b] on [b]SDL2[/b] on [b]Android[/b]!'
119-
halign: 'center'
120-
Widget:
121-
size_hint_y: None
122-
height: 20
123-
Label:
124-
height: self.texture_size[1]
125-
size_hint_y: None
126-
font_size: 50
127-
text_size: self.size[0], None
128-
markup: True
129-
text: 'dpi: {}\\ndensity: {}\\nfontscale: {}'.format(Metrics.dpi, Metrics.density, Metrics.fontscale)
130-
halign: 'center'
131-
Widget:
132-
size_hint_y: None
133-
height: 1000
134-
on_touch_down: print 'touched at', args[-1].pos
135-
TextInput:
52+
BoxLayout:
13653
size_hint_y: None
137-
height: dp(100)
138-
text: 'textinput!'
139-
140-
<ErrorPopup>:
141-
title: 'Error'
142-
size_hint: 0.75, 0.75
143-
Label:
144-
text: root.error_text
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'
14588
'''
14689

14790

@@ -162,12 +105,8 @@ def build(self):
162105
print('dpi is', Metrics.dpi)
163106
print('density is', Metrics.density)
164107
print('fontscale is', Metrics.fontscale)
165-
Clock.schedule_once(self.android_init, 0)
166108
return root
167109

168-
def android_init(self, *args):
169-
self.set_softinput_mode()
170-
171110
def print_something(self, *args):
172111
print('App print tick', Clock.get_boottime())
173112

@@ -202,16 +141,4 @@ def test_numpy(self, *args):
202141
print(numpy.arange(5))
203142
print(numpy.random.random((3, 3)))
204143

205-
@run_on_ui_thread
206-
def set_softinput_mode(self):
207-
return
208-
from jnius import autoclass
209-
PythonActivity = autoclass('org.kivy.android.PythonActivity')
210-
WindowManager = autoclass('android.view.WindowManager')
211-
LayoutParams = autoclass('android.view.WindowManager$LayoutParams')
212-
activity = PythonActivity.mActivity
213-
214-
activity.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_PAN)
215-
216-
217144
TestApp().run()

0 commit comments

Comments
 (0)