From 5bbf568e736c6a2d987efb6741acbe323f923dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 28 Mar 2014 20:02:24 +0100 Subject: [PATCH] Enforce readonly on WinForm issue3778 review4511002 --- tryton/gui/window/view_form/view/form_gtk/interface.py | 10 ++++++---- tryton/gui/window/view_form/view/form_gtk/many2many.py | 3 ++- tryton/gui/window/view_form/view/form_gtk/one2many.py | 1 + tryton/gui/window/win_form.py | 8 ++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tryton/gui/window/view_form/view/form_gtk/interface.py b/tryton/gui/window/view_form/view/form_gtk/interface.py index 52d17cf383..22ef029413 100644 --- a/tryton/gui/window/view_form/view/form_gtk/interface.py +++ b/tryton/gui/window/view_form/view/form_gtk/interface.py @@ -150,10 +150,12 @@ class WidgetInterface(object): self._readonly_set(self.attrs.get('readonly', True)) self.invisible_set(self.attrs.get('invisible', False)) return - self._readonly_set(self.attrs.get('readonly', - field.get_state_attrs(record).get('readonly', False))) - if self.attrs.get('readonly', - field.get_state_attrs(record).get('readonly', False)): + readonly = self.attrs.get('readonly', + field.get_state_attrs(record).get('readonly', False)) + if self.view.screen.readonly: + readonly = True + self._readonly_set(readonly) + if readonly: self.color_set('readonly') elif not field.get_state_attrs(record).get('valid', True): self.color_set('invalid') 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 12bee20f09..fbc0dd6f5e 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -196,7 +196,8 @@ class Many2Many(WidgetInterface): domain = [domain, add_remove] screen = Screen(self.attrs['relation'], domain=domain, view_ids=self.attrs.get('view_ids', '').split(','), - mode=['form'], views_preload=self.attrs.get('views', {})) + mode=['form'], views_preload=self.attrs.get('views', {}), + readonly=self.attrs.get('readonly', False)) screen.load([self.screen.current_record.id]) def callback(result): 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 123b80d408..ca9f02cbce 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -178,6 +178,7 @@ class One2Many(WidgetInterface): view_ids=attrs.get('view_ids', '').split(','), views_preload=attrs.get('views', {}), row_activate=self._on_activate, + readonly=self.attrs.get('readonly', False), exclude_field=attrs.get('relation_field', None)) self.screen.pre_validate = bool(int(attrs.get('pre_validate', 0))) self.screen.signal_connect(self, 'record-message', self._sig_label) diff --git a/tryton/gui/window/win_form.py b/tryton/gui/window/win_form.py index 3f866d337a..5f672f6c4c 100644 --- a/tryton/gui/window/win_form.py +++ b/tryton/gui/window/win_form.py @@ -45,10 +45,12 @@ class WinForm(NoModal): self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) + readonly = self.screen.readonly or self.screen.group.readonly + self.but_ok = None self.but_new = None - if view_type == 'form': + if view_type == 'form' and not readonly: if not new and self.screen.current_record.id < 0: stock_id = gtk.STOCK_DELETE else: @@ -122,7 +124,6 @@ class WinForm(NoModal): hbox = gtk.HBox(homogeneous=False, spacing=0) tooltips = common.Tooltips() access = common.MODELACCESS[screen.model_name] - readonly = self.screen.group.readonly if domain is not None: self.wid_text = gtk.Entry() @@ -400,7 +401,9 @@ class WinForm(NoModal): validate = False cancel_responses = (gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT) self.screen.current_view.set_value() + readonly = self.screen.group.readonly if (response_id not in cancel_responses + and not readonly and self.screen.current_record is not None): validate = self.screen.current_record.validate( self.screen.current_view.get_fields()) @@ -426,6 +429,7 @@ class WinForm(NoModal): self.new() return if (self.screen.current_record + and not readonly and response_id in cancel_responses): if (self.screen.current_record.id < 0 or self.save_current):