mansrz / pymt

Automatically exported from code.google.com/p/pymt
0 stars 0 forks source link

Enhance the virtual keyboard (example code provided) #229

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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)

Original issue reported on code.google.com by jaybradl...@gmail.com on 7 Apr 2010 at 2:19

Attachments:

GoogleCodeExporter commented 9 years ago
That's a nice patch. I'm just a little worried about the option name :)

Do you agree for this renaming : 
* add_keyboard_to_root_window -> keyboard_use_root
* place_keyboard_by_control -> keyboard_place_near_control

For initial rotation, it's really specific for you, i will search how to 
generalize
it (because get_initial_keyboard_rotation_from wait for an object... maybe it 
would
be better to have a keyboard_arguments or something like that...)

Original comment by txprog on 7 Apr 2010 at 3:43

GoogleCodeExporter commented 9 years ago

Original comment by txprog on 7 Apr 2010 at 3:43

GoogleCodeExporter commented 9 years ago
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.

Original comment by jaybradl...@gmail.com on 7 Apr 2010 at 3:47

GoogleCodeExporter commented 9 years ago

Original comment by txprog on 1 Jun 2010 at 8:43

GoogleCodeExporter commented 9 years ago

Original comment by txprog on 8 Jun 2010 at 12:15

GoogleCodeExporter commented 9 years ago
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?

Original comment by dennd...@gmail.com on 15 Jun 2010 at 9:33

GoogleCodeExporter commented 9 years ago
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.

Original comment by jaybradl...@gmail.com on 15 Jun 2010 at 9:50

GoogleCodeExporter commented 9 years ago
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! :-)

Original comment by dennd...@gmail.com on 15 Jun 2010 at 9:57