diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 08dbfe5aba..52c74df0a4 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -373,7 +373,8 @@ class Screen(SignalEvent): break self.screen_container.set(self.current_view.widget) self.display() - self.set_cursor() + # Postpone set of the cursor to ensure widgets are allocated + gobject.idle_add(self.set_cursor) def load_view_to_load(self): if len(self.view_to_load): @@ -444,7 +445,8 @@ class Screen(SignalEvent): previous_view.set_default_date(record, selected_date) self.current_record = record self.display() - self.set_cursor(new=True) + # Postpone set of the cursor to ensure widgets are allocated + gobject.idle_add(self.set_cursor, True) return self.current_record def new_model_position(self): diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index c3c3773e2a..61e90df02f 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -8,7 +8,7 @@ from collections import defaultdict from . import View from tryton.common.focus import (get_invisible_ancestor, find_focused_child, - next_focus_widget) + next_focus_widget, find_focusable_child) from tryton.common import Tooltips, node_attributes, ICONFACTORY from tryton.common.button import Button from tryton.config import CONFIG @@ -122,6 +122,7 @@ class ViewForm(View): vbox.pack_start(viewport, expand=True, fill=True) self.widget = vbox + self._viewport = vp def parse(self, node, container=None): if not container: @@ -483,6 +484,10 @@ class ViewForm(View): notebook.set_current_page(0) if self.attributes.get('cursor') in self.widgets: focus_widget = self.widgets[self.attributes['cursor']][0] + else: + child = find_focusable_child(self._viewport) + if child: + child.grab_focus() record = self.screen.current_record position = reduce(lambda x, y: x + len(y), self.widgets, 0) if record: