Reviewers: ,

Description:
Enable Ctrl + Space on selection-like Dict entries

Safer get_values and lambdas.

issue3163

Please review this at http://codereview.tryton.org/809002/

Affected files:
  M tryton/gui/window/view_form/view/form_gtk/dictionary.py


Index: tryton/gui/window/view_form/view/form_gtk/dictionary.py
===================================================================
--- a/tryton/gui/window/view_form/view/form_gtk/dictionary.py
+++ b/tryton/gui/window/view_form/view/form_gtk/dictionary.py
@@ -81,11 +81,12 @@
         widget.child.props.activates_default = True
         widget.child.connect('changed', self.parent_widget.send_modified)
         widget.child.connect('focus-out-event',
-            lambda w, e: self.parent_widget._focus_out())
+            lambda *a: self.parent_widget._focus_out())
         widget.child.connect('activate',
-            lambda w, e: self.parent_widget._focus_out())
+            lambda *a: self.parent_widget._focus_out())
         widget.connect('notify::active',
-            lambda w, e: self.parent_widget._focus_out())
+            lambda *a: self.parent_widget._focus_out())
+        widget.child.connect('key_press_event', self.sig_key_press)

         # setting completion and selection
         model = gtk.ListStore(gobject.TYPE_STRING)
@@ -111,7 +112,16 @@

     def get_value(self):
         text = self.widget.child.get_text()
-        return self._selection[text]
+        value = None
+        if text:
+            for txt, val in self._selection.items():
+                if not val:
+                    continue
+                if txt[:len(text)].lower() == text.lower():
+                    value = val
+                    if len(txt) == len(text):
+                        break
+        return value

     def set_value(self, value):
         values = dict(self.definition['selection'])
@@ -120,6 +130,12 @@
     def set_readonly(self, readonly):
         self.widget.set_sensitive(not readonly)

+    def sig_key_press(self, widget, event):
+        if event.type == gtk.gdk.KEY_PRESS \
+                and event.state & gtk.gdk.CONTROL_MASK \
+                and event.keyval == gtk.keysyms.space:
+            self.widget.popup()
+

 class DictIntegerEntry(DictEntry):
     expand = False


Reply via email to