| Issue 229: | Enhance the virtual keyboard (example code provided) | |
| 2 people starred this issue and may be notified of changes. | Back to list |
I've been using multiple virtual keyboards with MTInnerWindow objects and
needed to do three things:
- add the virtual keyboard to the root window so they are attached to
something inside the inner window but are not obscured by the inner window.
- place the virtual keyboard near the control it's attached to when it's shown.
- initialise the virtual keyboard's rotation to that of the control it's
attached to.
I have attached a screen shot. The diff against git HEAD is below:
diff --git a/pymt/ui/widgets/composed/textinput.py
b/pymt/ui/widgets/composed/textinput.py
index 6957bea..05ed185 100644
--- a/pymt/ui/widgets/composed/textinput.py
+++ b/pymt/ui/widgets/composed/textinput.py
@@ -41,17 +41,25 @@ class MTTextInput(MTButton):
kwargs.setdefault('keyboard', None)
kwargs.setdefault('password', False)
kwargs.setdefault('group', None)
+ kwargs.setdefault('add_keyboard_to_root_window', False)
+ kwargs.setdefault('place_keyboard_by_control', False)
+ kwargs.setdefault('get_initial_keyboard_rotation_from', None)
super(MTTextInput, self).__init__(**kwargs)
self._keyboard = kwargs.get('keyboard')
self.original_width = None
self.is_active_input = False
self.password = kwargs.get('password')
-
+ self.add_keyboard_to_root_window =
kwargs.get('add_keyboard_to_root_window')
+ self.place_keyboard_by_control =
kwargs.get('place_keyboard_by_control')
+ self.get_initial_keyboard_rotation_from =
kwargs.get('get_initial_keyboard_rotation_from')
+
@@ -70,7 +78,7 @@ class MTTextInput(MTButton):
if not self._keyboard:
self._keyboard = self.group['keyboard']
if self._keyboard is None:
- self._keyboard = MTVKeyboard()
+ self._keyboard = MTVKeyboard() # default position
self.group['keyboard'] = self._keyboard
return self._keyboard
def _set_keyboard(self, value):
@@ -145,8 +153,22 @@ class MTTextInput(MTButton):
if self.is_active_input:
return
self.deactivate_group()
- w = self.get_parent_window()
+ if(self.add_keyboard_to_root_window == False):
+ w = self.get_parent_window()
+ else:
+ w = self.get_root_window()
+
+ if(self.place_keyboard_by_control == True): # should we place the
keyboard near to the text input control
+ self.keyboard.pos = self.to_window(self.pos[0] + (self.width /
2), self.pos[1] - (self.height / 2) - (self.keyboard.height / 2)) #
position of the text input field
+ if(self.get_initial_keyboard_rotation_from != None):
+ self.keyboard.rotation =
self.get_initial_keyboard_rotation_from.rotation
w.add_widget(self.keyboard)
+
w = self.get_root_window()
w.push_handlers(on_keyboard=self._window_on_keyboard)
self.is_active_input = True
@@ -161,7 +183,12 @@ class MTTextInput(MTButton):
'''Hide the associed keyboard of this widget.'''
if not self.is_active_input:
return
- w = self.get_parent_window()
+
+ if(self.add_keyboard_to_root_window == False):
+ w = self.get_parent_window()
+ else:
+ w = self.get_root_window()
+
w.remove_widget(self.keyboard)
w = self.get_root_window()
w.remove_handlers(on_keyboard=self._window_on_keyboard)
Apr 7, 2010
Project Member
#1
txprog
Apr 7, 2010
(No comment was entered for this change.)
Status:
Accepted
Labels: Component-Core Milestone-0.4.1
Apr 7, 2010
I think the way I've done it with really long names is a bit clunky. I think renaming them is good. These changes were quite specific to me but I'm sure someone else might use them. I'm not sure of the tidiest way to do this as I'm quite new to PyMT and to python too.
Jun 1, 2010
(No comment was entered for this change.)
Labels:
Milestone-0.5
Jun 8, 2010
(No comment was entered for this change.)
Owner:
dennda85
Jun 15, 2010
Jay, I've included the "add to root window" patch, thanks for that. About the pos/rot: I'm not sure. a) Both are kwargs for the keyboard, so if we want that adjustable we might just as well provide a keyboard_kwargs param for textinput. b) You can create your own MTVKeyBoard with your own params and pass it to textinput. c) You can, after creating the textinput object, access the keyboard via my_textinput_object.keyboard and if you want adjust the parameters yourself. Since the calculations in the patch are pretty specific for your case, I'd rather not include it since other's might want other behaviour. I'd just make setting these params the caller's responsibility. What do you think?
Jun 15, 2010
I think you're correct. The best thing to do would be to access the keyboard after creating the text input and adjust it then using my_textinput_object.keyboard. Thanks for adding the "add to root window" bit in though. I'd consider this issue done now.
Jun 15, 2010
OK, you can find it in the latest master. Here is the link to the commit: http://github.com/tito/pymt/commit/9c5e8791caf7e23bc8caf6b5d070dae88a41cff2 Thanks. (We're missing you on IRC! :-)
Status:
Done
|