Please review this at http://codereview.appspot.com/3950041/

The communication (refresh) is simply activated by using "_active_%s" in the
domain of the act_window (where %s is the id of the other act_window).
When the selection of one board is changed, every other board domain are
evaluated and if they change the corresponding board is reloaded.

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


Index: CHANGELOG
===================================================================
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add communication between boards
 * Handle loading attribute on fields
 * Use default format for value in wizard form
 * Add One2One field
Index: tryton/gui/window/view_board/action.py
===================================================================
--- a/tryton/gui/window/view_board/action.py
+++ b/tryton/gui/window/view_board/action.py
@@ -13,12 +13,15 @@
 from tryton.pyson import PYSONDecoder
 import gettext
 from tryton.config import CONFIG
+from tryton.signal_event import SignalEvent
+from tryton.gui.window.view_form.model.record import EvalEnvironment
 _ = gettext.gettext


-class Action(object):
+class Action(SignalEvent):

     def __init__(self, window, attrs=None):
+        super(Action, self).__init__()
         self.act_id = int(attrs['name'])
         self._window = window
         self.screen = None
@@ -51,10 +54,8 @@
         self.context.update(PYSONDecoder(eval_ctx).decode(
             self.action.get('pyson_context', '{}')))

-        domain_ctx = self.context.copy()
-        self.domain = PYSONDecoder(domain_ctx).decode(
-                self.action['pyson_domain'])
-
+        self.domain = []
+        self.update_domain([])

         self.widget = gtk.Frame()
         self.widget.set_border_width(0)
@@ -151,6 +152,8 @@
             alignment.add(self.screen.screen_container.alternate_viewport)
             name = self.screen.current_view.title
             self.screen.signal_connect(self, 'record-message',
self._sig_label)
+            self.screen.signal_connect(self, 'record-message',
+                    self._active_changed)
         elif self.action['view_type'] == 'tree':
             ctx = {}
             ctx.update(rpc.CONTEXT)
@@ -172,6 +175,8 @@
             alignment.add(self.tree.widget_get())
             name = self.tree.name
             self.tree.view.connect('key_press_event', self.sig_key_press)
+            self.tree.signal_connect(self, 'select-changed',
+                    self._active_changed)

         if attrs.get('string'):
             self.title.set_text(attrs['string'])
@@ -251,3 +256,28 @@
                     .get_selected_rows()
             for path in paths:
                 self.tree.view.expand_row(path, False)
+
+    def _active_changed(self, *args):
+        self.signal('active-changed')
+
+    def _get_active(self):
+        if self.screen:
+            return EvalEnvironment(self.screen.current_record, False)
+        elif self.tree:
+            return {'id': self.tree.sel_id_get()}
+
+    active = property(_get_active)
+
+    def update_domain(self, actions):
+        domain_ctx = self.context.copy()
+        for action in actions:
+            if action.active:
+                domain_ctx['_active_%s' % action.act_id] = action.active
+        new_domain = PYSONDecoder(domain_ctx).decode(
+                self.action['pyson_domain'])
+        if self.domain == new_domain:
+            return
+        del self.domain[:]
+        self.domain.extend(new_domain)
+        if self.screen:
+            self.screen.search_filter()
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
@@ -2,8 +2,9 @@
 #this repository contains the full copyright notices and license terms.
 'View board'

+import xml.dom.minidom
 from parser import ParserBoard
-import xml.dom.minidom
+from tryton.gui.window.view_board.action import Action

 class ViewBoard(object):
     'View board'
@@ -18,7 +19,12 @@
                 continue
             self.widget, self.widgets = parser.parse(node)
             break
+        self.actions = [x for x in self.widgets if isinstance(x, Action)]
+        for action in self.actions:
+            action.signal_connect(self, 'active-changed',
+                    self._active_changed)
         self.widget.show_all()
+        self._active_changed(None)

     def widget_get(self):
         return self.widget
@@ -26,3 +32,9 @@
     def reload(self):
         for widget in self.widgets:
             widget.display()
+
+    def _active_changed(self, event_action, *args):
+        for action in self.actions:
+            if action == event_action:
+                continue
+            action.update_domain(self.actions)
Index: tryton/gui/window/view_tree/view_tree.py
===================================================================
--- a/tryton/gui/window/view_tree/view_tree.py
+++ b/tryton/gui/window/view_tree/view_tree.py
@@ -13,6 +13,7 @@
 import tryton.common as common
 from tryton.translate import date_format
 from tryton.pyson import PYSONDecoder
+from tryton.signal_event import SignalEvent

 FIELDS_LIST_TYPE = {
     'boolean': gobject.TYPE_BOOLEAN,
@@ -323,11 +324,12 @@
         except Exception:
             return None

-class ViewTree(object):
+class ViewTree(SignalEvent):
     "View tree"

     def __init__(self, view_info, ids, window, sel_multi=False,
             context=None):
+        super(ViewTree, self).__init__()
         self.window = window
         self.view = gtk.TreeView()
         self.view.set_headers_visible(not CONFIG['client.modepda'])
@@ -342,10 +344,12 @@
         self.name = parse.title
         self.sel_multi = sel_multi

+        selection = self.view.get_selection()
         if sel_multi:
-            self.view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
+            selection.set_mode(gtk.SELECTION_MULTIPLE)
         else:
-            self.view.get_selection().set_mode(gtk.SELECTION_SINGLE)
+
selection.self.view.get_selection().set_mode(gtk.SELECTION_SINGLE)
+        selection.connect('changed', self.__select_changed)
         self.view.set_expander_column(self.view.get_column(1))
         self.view.set_enable_search(False)
         self.view.get_column(0).set_visible(False)
@@ -413,3 +417,6 @@
         if not i:
             return None
         return model.get_value(i, col)
+
+    def __select_changed(self, tree_sel):
+        self.signal('select-changed')



-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpAj2sMRPAxb.pgp
Description: PGP signature

Reply via email to