Remove widget position and use tab_compare instead

issue4092
review13451002
This commit is contained in:
Cédric Krier committed 2014-08-29 13:36:19 +02:00
1 parent 4c73900104
commit 944834994a
14 files changed
+11 -55

No files matched your search

+11 -12
View File
@@ -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()
@@ -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:
@@ -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())
@@ -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:
@@ -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:
@@ -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:
@@ -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]
@@ -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']
@@ -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:
@@ -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'):
@@ -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:
@@ -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)
@@ -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)
@@ -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