Reviewers: ,


Please review this at http://codereview.tryton.org/594005/

Affected files:
  M tryton/gui/window/view_board/action.py
  M tryton/gui/window/view_board/view_board.py


Index: tryton/gui/window/view_board/action.py
===================================================================

--- a/tryton/gui/window/view_board/action.py
+++ b/tryton/gui/window/view_board/action.py
@@ -5,11 +5,12 @@
 from tryton.gui.window.view_form.screen import Screen
 import tryton.rpc as rpc
 import tryton.common as common
-from tryton.pyson import PYSONDecoder
+from tryton import pyson
+from tryton.pyson import PYSONDecoder, PYSONEncoder, CONTEXT
 import gettext
 from tryton.signal_event import SignalEvent
 from tryton.gui.window.win_form import WinForm
-from tryton.common import RPCExecute, RPCException
+from tryton.common import RPCExecute, RPCException, safe_eval
 _ = gettext.gettext


@@ -17,12 +18,49 @@

     def __init__(self, attrs=None, context=None):
         super(Action, self).__init__()
+        self.context = context or {}
         self.name = attrs['name']
-        self.context = context or {}
+        self.action_name = None
+        self.attrs = attrs.copy()
+        self.widget = gtk.Frame()
+        self.widget.set_border_width(0)
+        self.title = gtk.Label()
+        self.widget.set_label_widget(self.title)
+        self.widget.set_label_align(0.0, 0.5)
+        self.widget.show_all()
+        self.update_action()
+
+    def update_action(self, actions=None):
+        if actions is None:
+            actions = []
+
+        name_ctx = self.context.copy()
+        name_ctx['context'] = name_ctx
+        name_ctx['_user'] = rpc._USER
+        for action in actions:
+            if action.active:
+                name_ctx[action.name] = action.active
+
+        action_name = self.attrs.get('action', self.name)
+        action_name = PYSONEncoder(name_ctx).encode(safe_eval(action_name,
+                CONTEXT))
+        action_name = PYSONDecoder(name_ctx).decode(action_name)
+
+        if action_name == self.action_name:
+            self.update_domain(actions)
+            return
+        self.action_name = action_name
+
+        if hasattr(self, 'screen'):
+            self.screen.destroy()
+            del self.screen
+            self.vbox.destroy()
+        self.vbox = gtk.VBox(homogeneous=False, spacing=3)
+        self.widget.add(self.vbox)

         try:
self.action = RPCExecute('model', 'ir.action.act_window', 'get',
-                self.name)
+                self.action_name)
         except RPCException:
             raise

@@ -34,8 +72,8 @@
         elif self.action.get('view_id', False):
             view_ids = [self.action['view_id'][0]]

-        if 'view_mode' in attrs:
-            self.action['view_mode'] = attrs['view_mode']
+        if 'view_mode' in self.attrs:
+            self.action['view_mode'] = self.attrs['view_mode']

         self.action.setdefault('pyson_domain', '[]')
         self.context.update(rpc.CONTEXT)
@@ -48,7 +86,6 @@
             self.action.get('pyson_context', '{}')))

         self.domain = []
-        self.update_domain([])

         search_context = self.context.copy()
         search_context['context'] = self.context
@@ -56,37 +93,29 @@
         search_value = PYSONDecoder(search_context).decode(
             self.action['pyson_search_value'] or '{}')

-        self.widget = gtk.Frame()
-        self.widget.set_border_width(0)
-
-        vbox = gtk.VBox(homogeneous=False, spacing=3)
-        self.widget.add(vbox)
-
-        self.title = gtk.Label()
-        self.widget.set_label_widget(self.title)
-        self.widget.set_label_align(0.0, 0.5)
-        self.widget.show_all()

         self.screen = Screen(self.action['res_model'],
             mode=self.action['view_mode'], context=self.context,
             view_ids=view_ids, domain=self.domain,
             search_value=search_value, row_activate=self.row_activate)
-        vbox.pack_start(self.screen.widget, expand=True, fill=True)
+        self.update_domain(actions or [])
+        self.vbox.pack_start(self.screen.widget, expand=True, fill=True)
         name = self.screen.current_view.title
         self.screen.signal_connect(self, 'record-message',
             self._active_changed)

-        if attrs.get('string'):
-            self.title.set_text(attrs['string'])
+        if self.attrs.get('string'):
+            self.title.set_text(self.attrs['string'])
         elif self.action.get('window_name'):
             self.title.set_text(self.action['name'])
         else:
             self.title.set_text(name)

-        self.widget.set_size_request(int(attrs.get('width', -1)),
-                int(attrs.get('height', -1)))
+        self.widget.set_size_request(int(self.attrs.get('width', -1)),
+                int(self.attrs.get('height', -1)))

         self.screen.search_filter()
+        self.widget.show_all()

     def row_activate(self):
         if not self.screen.current_record:
@@ -104,7 +133,8 @@
         return True

     def display(self):
-        self.screen.search_filter(self.screen.screen_container.get_text())
+        if hasattr(self, 'screen'):
+ self.screen.search_filter(self.screen.screen_container.get_text())

     def _active_changed(self, *args):
         self.signal('active-changed')

Index: tryton/gui/window/view_board/view_board.py
===================================================================

--- a/tryton/gui/window/view_board/view_board.py
+++ b/tryton/gui/window/view_board/view_board.py
@@ -38,4 +38,4 @@
         for action in self.actions:
             if action == event_action:
                 continue
-            action.update_domain(self.actions)
+            action.update_action(self.actions)



--
--
[email protected] mailing list



Reply via email to