From 944834994a44367d35337036bf2456a21cdeadf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 29 Aug 2014 13:36:19 +0200 Subject: [PATCH] Remove widget position and use tab_compare instead issue4092 review13451002 --- tryton/gui/window/view_form/view/form.py | 23 +++++++++---------- .../window/view_form/view/form_gtk/binary.py | 6 ----- .../view_form/view/form_gtk/calendar.py | 3 --- .../window/view_form/view/form_gtk/char.py | 3 --- .../view_form/view/form_gtk/float_time.py | 3 --- .../window/view_form/view/form_gtk/image.py | 3 --- .../view_form/view/form_gtk/many2many.py | 3 --- .../view_form/view/form_gtk/many2one.py | 3 --- .../view_form/view/form_gtk/multiselection.py | 3 --- .../view_form/view/form_gtk/one2many.py | 3 --- .../view_form/view/form_gtk/reference.py | 3 --- .../view_form/view/form_gtk/selection.py | 3 --- .../window/view_form/view/form_gtk/textbox.py | 3 --- .../window/view_form/view/form_gtk/widget.py | 4 ---- 14 files changed, 11 insertions(+), 55 deletions(-) diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index 61e90df02f..1bfbc04495 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -1,14 +1,14 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. import operator -from functools import reduce +from functools import cmp_to_key import gtk import gettext from collections import defaultdict from . import View from tryton.common.focus import (get_invisible_ancestor, find_focused_child, - next_focus_widget, find_focusable_child) + next_focus_widget, find_focusable_child, tab_compare) from tryton.common import Tooltips, node_attributes, ICONFACTORY from tryton.common.button import Button from tryton.config import CONFIG @@ -101,7 +101,6 @@ class ViewForm(View): def __init__(self, screen, xml): super(ViewForm, self).__init__(screen, xml) self.view_type = 'form' - self.widget_id = 0 self.widgets = defaultdict(list) self.state_widgets = [] self.notebooks = [] @@ -309,8 +308,6 @@ class ViewForm(View): Widget = self.get_widget(attributes['widget']) widget = Widget(self, attributes) - self.widget_id += 1 - widget.position = self.widget_id self.widgets[name].append(widget) if Widget.expand: @@ -483,29 +480,31 @@ class ViewForm(View): for notebook in self.notebooks: notebook.set_current_page(0) if self.attributes.get('cursor') in self.widgets: - focus_widget = self.widgets[self.attributes['cursor']][0] + focus_widget = find_focused_child(self.widgets[ + self.attributes['cursor']][0].widget) 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: + invalid_widgets = [] for name, widgets in self.widgets.iteritems(): for widget in widgets: field = record.group.fields.get(name) if not field: continue if not field.get_state_attrs(record).get('valid', True): - if widget.position > position: - continue - position = widget.position - focus_widget = widget + invalid_widgets.append( + find_focusable_child(widget.widget)) + invalid_widgets.sort(key=cmp_to_key(tab_compare)) + if invalid_widgets: + focus_widget = invalid_widgets[0] if focus_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 focus_widget.is_ancestor(child): notebook.set_current_page(i) focus_widget.grab_focus() diff --git a/tryton/gui/window/view_form/view/form_gtk/binary.py b/tryton/gui/window/view_form/view/form_gtk/binary.py index c7ecca48bf..50bc773317 100644 --- a/tryton/gui/window/view_form/view/form_gtk/binary.py +++ b/tryton/gui/window/view_form/view/form_gtk/binary.py @@ -103,12 +103,6 @@ class Binary(Widget): focus_chain = [self.but_new, self.but_save_as, self.but_remove] self.widget.set_focus_chain(focus_chain) - def grab_focus(self): - if self.wid_text: - return self.wid_text.grab_focus() - else: - return self.wid_size.grab_focus() - def sig_new(self, widget=None): filename = '' if self.last_open_file: diff --git a/tryton/gui/window/view_form/view/form_gtk/calendar.py b/tryton/gui/window/view_form/view/form_gtk/calendar.py index 64682c3ce6..628e182b3d 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -44,9 +44,6 @@ class Calendar(Widget): def sig_key_press(self, widget, event): self.send_modified() - def grab_focus(self): - return self.entry.grab_focus() - def set_value(self, record, field): field.set_client(record, self.get_value()) diff --git a/tryton/gui/window/view_form/view/form_gtk/char.py b/tryton/gui/window/view_form/view/form_gtk/char.py index 664832d608..d917883196 100644 --- a/tryton/gui/window/view_form/view/form_gtk/char.py +++ b/tryton/gui/window/view_form/view/form_gtk/char.py @@ -81,9 +81,6 @@ class Char(Widget, TranslateMixin, PopdownMixin): return self.entry.get_child() return self.entry - def grab_focus(self): - return self.entry.grab_focus() - @property def modified(self): if self.record and self.field: diff --git a/tryton/gui/window/view_form/view/form_gtk/float_time.py b/tryton/gui/window/view_form/view/form_gtk/float_time.py index 573530740b..c35cfdeb5d 100644 --- a/tryton/gui/window/view_form/view/form_gtk/float_time.py +++ b/tryton/gui/window/view_form/view/form_gtk/float_time.py @@ -28,9 +28,6 @@ class FloatTime(Widget): def _color_widget(self): return self.entry - def grab_focus(self): - return self.entry.grab_focus() - @property def modified(self): if self.record and self.field: diff --git a/tryton/gui/window/view_form/view/form_gtk/image.py b/tryton/gui/window/view_form/view/form_gtk/image.py index 4139e45709..8508d33298 100644 --- a/tryton/gui/window/view_form/view/form_gtk/image.py +++ b/tryton/gui/window/view_form/view/form_gtk/image.py @@ -102,9 +102,6 @@ class Image(Widget): def filename_field(self): return self.record.group.fields.get(self.filename) - def grab_focus(self): - return self.image.grab_focus() - def _readonly_set(self, value): self._readonly = value if self.but_add: diff --git a/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/gui/window/view_form/view/form_gtk/many2many.py index d2229a9b0d..b3774fc578 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -102,9 +102,6 @@ class Many2Many(Widget): return self.screen.current_view.treeview return super(Many2Many, self)._color_widget() - def grab_focus(self): - return self.wid_text.grab_focus() - def on_keypress(self, widget, event): editable = self.wid_text.get_editable() activate_keys = [gtk.keysyms.Tab, gtk.keysyms.ISO_Left_Tab] diff --git a/tryton/gui/window/view_form/view/form_gtk/many2one.py b/tryton/gui/window/view_form/view/form_gtk/many2one.py index db41b1d9bd..eabf917435 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -79,9 +79,6 @@ class Many2One(Widget): self._readonly = False - def grab_focus(self): - return self.wid_text.grab_focus() - def get_model(self): return self.attrs['relation'] diff --git a/tryton/gui/window/view_form/view/form_gtk/multiselection.py b/tryton/gui/window/view_form/view/form_gtk/multiselection.py index 9581b3763c..c14682cae9 100644 --- a/tryton/gui/window/view_form/view/form_gtk/multiselection.py +++ b/tryton/gui/window/view_form/view/form_gtk/multiselection.py @@ -41,9 +41,6 @@ class MultiSelection(Widget, SelectionMixin): def _color_widget(self): return self.tree - def grab_focus(self): - self.tree.grab_focus() - @property def modified(self): if self.record and self.field: diff --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py index 604a03a886..930af5a554 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -197,9 +197,6 @@ class One2Many(Widget): return self.screen.current_view.treeview return super(One2Many, self)._color_widget() - def grab_focus(self): - return self.screen.widget.grab_focus() - def on_keypress(self, widget, event): if (event.keyval == gtk.keysyms.F3) \ and self.but_new.get_property('sensitive'): diff --git a/tryton/gui/window/view_form/view/form_gtk/reference.py b/tryton/gui/window/view_form/view/form_gtk/reference.py index 4faa4be4cc..089c9f2a60 100644 --- a/tryton/gui/window/view_form/view/form_gtk/reference.py +++ b/tryton/gui/window/view_form/view/form_gtk/reference.py @@ -27,9 +27,6 @@ class Reference(Many2One, SelectionMixin, PopdownMixin): self.widget.set_focus_chain([self.widget_combo, self.wid_text]) - def grab_focus(self): - return self.widget_combo.grab_focus() - def get_model(self): active = self.widget_combo.get_active() if active < 0: diff --git a/tryton/gui/window/view_form/view/form_gtk/selection.py b/tryton/gui/window/view_form/view/form_gtk/selection.py index addb331723..fe49d9d606 100644 --- a/tryton/gui/window/view_form/view/form_gtk/selection.py +++ b/tryton/gui/window/view_form/view/form_gtk/selection.py @@ -39,9 +39,6 @@ class Selection(Widget, SelectionMixin, PopdownMixin): # Must be deferred because it triggers a display of the form gobject.idle_add(focus_out) - def grab_focus(self): - return self.entry.grab_focus() - def _readonly_set(self, value): super(Selection, self)._readonly_set(value) self.entry.set_sensitive(not value) diff --git a/tryton/gui/window/view_form/view/form_gtk/textbox.py b/tryton/gui/window/view_form/view/form_gtk/textbox.py index 19306da54b..d09754e0ff 100644 --- a/tryton/gui/window/view_form/view/form_gtk/textbox.py +++ b/tryton/gui/window/view_form/view/form_gtk/textbox.py @@ -77,9 +77,6 @@ class TextBox(Widget, TranslateMixin): textview.set_editable(not value) textview.props.sensitive = not value - def grab_focus(self): - return self.textview.grab_focus() - def _readonly_set(self, value): super(TextBox, self)._readonly_set(value) self.textview.set_editable(not value) diff --git a/tryton/gui/window/view_form/view/form_gtk/widget.py b/tryton/gui/window/view_form/view/form_gtk/widget.py index 98f720f2eb..dcb0191c63 100644 --- a/tryton/gui/window/view_form/view/form_gtk/widget.py +++ b/tryton/gui/window/view_form/view/form_gtk/widget.py @@ -21,7 +21,6 @@ class Widget(object): self.view = view self.attrs = attrs self.widget = None - self.position = 0 self.colors = {} self.visible = True self.color_name = None @@ -59,9 +58,6 @@ class Widget(object): def _invisible_widget(self): return self.widget - def grab_focus(self): - return self.widget.grab_focus() - @property def modified(self): return False