window: add method to request/release keyboard. Just a way to ensure that only one widget at time will have the real keyboard

This commit is contained in:
Mathieu Virbel 2011-03-10 16:43:50 +01:00
parent 532d400b6d
commit 30098917ba
1 changed files with 25 additions and 0 deletions

View File

@ -88,6 +88,7 @@ class WindowBase(EventDispatcher):
super(WindowBase, self).__init__()
# init privates
self._keyboard_callback = None
self._modifiers = []
self._size = (0, 0)
self._rotation = 0
@ -509,6 +510,30 @@ class WindowBase(EventDispatcher):
'''Event called when a key is up (same arguments as on_keyboard)'''
pass
def request_keyboard(self, callback):
'''Internal method for widget, to request the keyboard. This method is
not intented to be used by end-user, however, if you want to use the
real-keyboard (not virtual keyboard), you don't want to share it with
another widget.
A widget can request the keyboard, indicating a callback to call
when the keyboard will be released (or taken by another widget).
'''
self.release_keyboard()
self._keyboard_callback = callback
return True
def release_keyboard(self):
'''Internal method for widget, to release the real-keyboard. Check
:func:`request_keyboard` to understand how it works.
'''
if self._keyboard_callback:
# this way will prevent possible recursion.
callback = self._keyboard_callback
self._keyboard_callback = None
callback()
return True
#: Instance of a :class:`WindowBase` implementation
Window = core_select_lib('window', (