Reviewers: ,


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

Affected files:
  M tryton/gui/window/form.py
  M tryton/gui/window/view_form/screen/screen.py
  M tryton/gui/window/view_form/view/form.py
  M tryton/gui/window/window.py


Index: tryton/gui/window/form.py
===================================================================

--- a/tryton/gui/window/form.py
+++ b/tryton/gui/window/form.py
@@ -592,6 +592,10 @@

         return menu

+    def grab_focus(self):
+        if self.screen.focusable_widget:
+            self.screen.focusable_widget.grab_focus()
+
def _popup_menu_selected(self, menuitem, togglebutton, action, keyword):
         event = gtk.get_current_event()
         allow_similar = False

Index: tryton/gui/window/view_form/screen/screen.py
===================================================================

--- a/tryton/gui/window/view_form/screen/screen.py
+++ b/tryton/gui/window/view_form/screen/screen.py
@@ -505,6 +505,18 @@

     current_view = property(__get_current_view)

+    @property
+    def focusable_widget(self):
+        current_view = self.current_view
+        focusable_widget = None
+        if current_view.view_type == 'tree':
+            focusable_widget = current_view.widget_tree
+            if self.screen_container.filter_vbox:
+                focusable_widget = self.screen_container.search_entry
+        elif current_view.view_type == 'form':
+            focusable_widget = current_view.focusable_widget
+        return focusable_widget
+
     def get(self, get_readonly=True, includeid=False, check_load=True,
             get_modifiedonly=False):
         if not self.current_record:

Index: tryton/gui/window/view_form/view/form.py
===================================================================

--- a/tryton/gui/window/view_form/view/form.py
+++ b/tryton/gui/window/view_form/view/form.py
@@ -121,14 +121,9 @@
             button.state_set(record)
         return True

-    def set_cursor(self, new=False, reset_view=True):
-        if reset_view:
-            for notebook in self.notebooks:
-                notebook.set_current_page(0)
-            if self.cursor_widget in self.widgets:
-                self.widgets[self.cursor_widget][0].grab_focus()
+    @property
+    def focusable_widget(self):
         record = self.screen.current_record
-        position = reduce(lambda x, y: x + len(y), self.widgets, 0)
         focus_widget = None
         if record:
             for name, widgets in self.widgets.iteritems():
@@ -141,10 +136,20 @@
                             continue
                         position = widget.position
                         focus_widget = widget
-        if focus_widget:
+        return focus_widget
+
+    def set_cursor(self, new=False, reset_view=True):
+        if reset_view:
+            for notebook in self.notebooks:
+                notebook.set_current_page(0)
+            if self.cursor_widget in self.widgets:
+                self.widgets[self.cursor_widget][0].grab_focus()
+        record = self.screen.current_record
+        position = reduce(lambda x, y: x + len(y), self.widgets, 0)
+        if self.focusable_widget:
             for notebook in self.notebooks:
                 for i in range(notebook.get_n_pages()):
                     child = notebook.get_nth_page(i)
-                    if focus_widget.widget.is_ancestor(child):
+                    if self.focusable_widget.widget.is_ancestor(child):
                         notebook.set_current_page(i)
-            focus_widget.grab_focus()
+            self.focusable_widget.grab_focus()

Index: tryton/gui/window/window.py
===================================================================

--- a/tryton/gui/window/window.py
+++ b/tryton/gui/window/window.py
@@ -41,6 +41,7 @@
         win.icon = icon
         Main.get_main().win_add(win, hide_current=Window.hide_current,
             allow_similar=Window.allow_similar)
+        win.grab_focus()

     @staticmethod
     def create_wizard(action, data, state='init', direct_print=False,



--
[email protected] mailing list

Reply via email to