mirror of https://github.com/kivy/kivy.git
vkeyboard: enhance textinput tests + release_all_keyboards() method in window.
This commit is contained in:
parent
daa8f33f48
commit
09e36f8ee4
|
@ -1,9 +1,59 @@
|
||||||
|
'''
|
||||||
|
Textinput tests
|
||||||
|
===============
|
||||||
|
|
||||||
|
This test is used to demonstrate virtual keyboard according to current
|
||||||
|
configuration.
|
||||||
|
Run this test as::
|
||||||
|
|
||||||
|
# use dock virtual keyboard (one instance)
|
||||||
|
python textinput.py -c kivy:keyboard_mode:dock
|
||||||
|
# use multi users virtual keyboard (multiples instance)
|
||||||
|
python textinput.py -c kivy:keyboard_mode:multi
|
||||||
|
# use system keyboard (one instance)
|
||||||
|
python textinput.py -c kivy:keyboard_mode:system
|
||||||
|
# use automatic detection from current platform
|
||||||
|
python textinput.py -c kivy:keyboard_mode:
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import kivy
|
||||||
|
kivy.require('1.0.8')
|
||||||
|
|
||||||
|
from kivy.core.window import Window
|
||||||
from kivy.uix.textinput import TextInput
|
from kivy.uix.textinput import TextInput
|
||||||
from kivy.uix.anchorlayout import AnchorLayout
|
from kivy.uix.floatlayout import FloatLayout
|
||||||
from kivy.uix.scatter import Scatter
|
from kivy.uix.scatter import Scatter
|
||||||
|
from kivy.uix.button import Button
|
||||||
|
from kivy.uix.label import Label
|
||||||
|
from kivy.config import Config
|
||||||
from kivy.base import runTouchApp
|
from kivy.base import runTouchApp
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
root = Scatter(size_hint=(None, None))
|
|
||||||
root.add_widget(TextInput(size_hint=(None, None), size=(100, 50)))
|
root = FloatLayout()
|
||||||
|
|
||||||
|
# create a button to release everything
|
||||||
|
def release_all_keyboard(*l):
|
||||||
|
Window.release_all_keyboards()
|
||||||
|
btn = Button(text='Release\nall\nkeyboards', size_hint=(None, None),
|
||||||
|
halign='center')
|
||||||
|
btn.bind(on_release=release_all_keyboard)
|
||||||
|
root.add_widget(btn)
|
||||||
|
|
||||||
|
# show current configuration
|
||||||
|
lbl = 'Configuration keyboard_mode is %r, keyboard_layout is %r' % (
|
||||||
|
Config.get('kivy', 'keyboard_mode'),
|
||||||
|
Config.get('kivy', 'keyboard_layout'))
|
||||||
|
label = Label(text=lbl, size_hint_y=None, height=50, pos_hint={'top': 1})
|
||||||
|
root.add_widget(label)
|
||||||
|
|
||||||
|
s = Scatter(size_hint=(None, None), pos=(300, 300))
|
||||||
|
s.add_widget(TextInput(size_hint=(None, None), size=(100, 50)))
|
||||||
|
root.add_widget(s)
|
||||||
|
|
||||||
|
s = Scatter(size_hint=(None, None), pos=(400, 300), rotation=45)
|
||||||
|
s.add_widget(TextInput(size_hint=(None, None), size=(100, 50)))
|
||||||
|
root.add_widget(s)
|
||||||
|
|
||||||
runTouchApp(root)
|
runTouchApp(root)
|
||||||
|
|
|
@ -223,6 +223,7 @@ class WindowBase(EventDispatcher):
|
||||||
self._size = (0, 0)
|
self._size = (0, 0)
|
||||||
self._rotation = 0
|
self._rotation = 0
|
||||||
self._clearcolor = [0, 0, 0, 0]
|
self._clearcolor = [0, 0, 0, 0]
|
||||||
|
self._vkeyboard_cls = None
|
||||||
|
|
||||||
# event subsystem
|
# event subsystem
|
||||||
self.register_event_type('on_draw')
|
self.register_event_type('on_draw')
|
||||||
|
@ -730,7 +731,18 @@ class WindowBase(EventDispatcher):
|
||||||
Set the VKeyboard class to use. If None set, it will use the
|
Set the VKeyboard class to use. If None set, it will use the
|
||||||
:class:`kivy.uix.vkeyboard.VKeyboard`.
|
:class:`kivy.uix.vkeyboard.VKeyboard`.
|
||||||
'''
|
'''
|
||||||
self.vkeyboard_cls = cls
|
self._vkeyboard_cls = cls
|
||||||
|
|
||||||
|
def release_all_keyboards(self):
|
||||||
|
'''.. versionadded:: 1.0.8
|
||||||
|
|
||||||
|
This will ensure that no virtual keyboard / system keyboard are actually
|
||||||
|
requested. All will be closed.
|
||||||
|
'''
|
||||||
|
for key in self._keyboards.keys()[:]:
|
||||||
|
keyboard = self._keyboards[key]
|
||||||
|
if keyboard:
|
||||||
|
keyboard.release()
|
||||||
|
|
||||||
def request_keyboard(self, callback, target):
|
def request_keyboard(self, callback, target):
|
||||||
'''.. versionadded:: 1.0.4
|
'''.. versionadded:: 1.0.4
|
||||||
|
@ -774,14 +786,14 @@ class WindowBase(EventDispatcher):
|
||||||
|
|
||||||
# late import
|
# late import
|
||||||
global VKeyboard
|
global VKeyboard
|
||||||
if VKeyboard is None and self.vkeyboard_cls is None:
|
if VKeyboard is None and self._vkeyboard_cls is None:
|
||||||
from kivy.uix.vkeyboard import VKeyboard
|
from kivy.uix.vkeyboard import VKeyboard
|
||||||
self.vkeyboard_cls = VKeyboard
|
self._vkeyboard_cls = VKeyboard
|
||||||
|
|
||||||
# if the keyboard doesn't exist, create it.
|
# if the keyboard doesn't exist, create it.
|
||||||
key = 'single' if self.single_vkeyboard else target
|
key = 'single' if self.single_vkeyboard else target
|
||||||
if key not in self._keyboards:
|
if key not in self._keyboards:
|
||||||
vkeyboard = self.vkeyboard_cls()
|
vkeyboard = self._vkeyboard_cls()
|
||||||
keyboard = Keyboard(widget=vkeyboard, window=self)
|
keyboard = Keyboard(widget=vkeyboard, window=self)
|
||||||
vkeyboard.bind(
|
vkeyboard.bind(
|
||||||
on_key_down=keyboard._on_vkeyboard_key_down,
|
on_key_down=keyboard._on_vkeyboard_key_down,
|
||||||
|
@ -791,8 +803,8 @@ class WindowBase(EventDispatcher):
|
||||||
keyboard = self._keyboards[key]
|
keyboard = self._keyboards[key]
|
||||||
|
|
||||||
# configure vkeyboard
|
# configure vkeyboard
|
||||||
keyboard.target = target
|
keyboard.target = keyboard.widget.target = target
|
||||||
keyboard.callback = callback
|
keyboard.callback = keyboard.widget.callback = callback
|
||||||
|
|
||||||
# add to the window
|
# add to the window
|
||||||
self.add_widget(keyboard.widget)
|
self.add_widget(keyboard.widget)
|
||||||
|
@ -827,8 +839,8 @@ class WindowBase(EventDispatcher):
|
||||||
callback()
|
callback()
|
||||||
keyboard.target = None
|
keyboard.target = None
|
||||||
self.remove_widget(keyboard.widget)
|
self.remove_widget(keyboard.widget)
|
||||||
if key != 'single':
|
if key != 'single' and key in self._keyboards:
|
||||||
self._keyboards.remove(key)
|
del self._keyboards[key]
|
||||||
elif self._system_keyboard.callback:
|
elif self._system_keyboard.callback:
|
||||||
# this way will prevent possible recursion.
|
# this way will prevent possible recursion.
|
||||||
callback = self._system_keyboard.callback
|
callback = self._system_keyboard.callback
|
||||||
|
|
Loading…
Reference in New Issue