diff --git a/CHANGELOG b/CHANGELOG index 27e8986772..3fb7600eb5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Deactivate switch view button when there is only 1 view * Manage create/delete field access * Add dynamic size limit on the One2Many, Many2Many and Char * Search only on fields in XML view diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 1adfc6418e..086c3916c6 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -468,11 +468,13 @@ class Form(SignalEvent, TabContent): if signal_data[0]: name = str(signal_data[0]) for button_id in ('print', 'action', 'relate', 'email', 'open', 'save', - 'switch', 'attach'): + 'attach'): button = self.buttons[button_id] can_be_sensitive = getattr(button, '_can_be_sensitive', True) button.props.sensitive = (bool(signal_data[0]) and can_be_sensitive) + button_switch = self.buttons['switch'] + button_switch.props.sensitive = self.screen.number_of_views > 1 msg = name + ' / ' + str(signal_data[1]) if signal_data[1] < signal_data[2]: diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 94f1ab3c0c..09694d2882 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -306,6 +306,10 @@ class Screen(SignalEvent): self.switch_view(view_type='form') return True + @property + def number_of_views(self): + return len(self.views) + len(self.view_to_load) + def switch_view(self, view_type=None, default=True, context=None): if not self.parent and self.modified(): return @@ -320,7 +324,7 @@ class Screen(SignalEvent): self.current_view.display() return if not view_type or self.current_view.view_type != view_type: - for i in xrange(len(self.views) + len(self.view_to_load)): + for i in xrange(self.number_of_views): if len(self.view_to_load): self.load_view_to_load() self.__current_view = len(self.views) - 1 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 cd79352b4a..4347188455 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -170,6 +170,8 @@ class One2Many(WidgetInterface): if self.attrs.get('add_remove'): self.wid_text.connect('key_press_event', self.on_keypress) + but_switch.props.sensitive = self.screen.number_of_views > 1 + def _color_widget(self): if hasattr(self.screen.current_view, 'widget_tree'): return self.screen.current_view.widget_tree diff --git a/tryton/gui/window/win_form.py b/tryton/gui/window/win_form.py index 6f12ea91d9..674e11d5ae 100644 --- a/tryton/gui/window/win_form.py +++ b/tryton/gui/window/win_form.py @@ -233,6 +233,8 @@ class WinForm(NoModal): but_switch.set_relief(gtk.RELIEF_NONE) hbox.pack_start(but_switch, expand=False, fill=False) + but_switch.props.sensitive = screen.number_of_views > 1 + tooltips.enable() alignment = gtk.Alignment(1.0)