← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-client/trunk-radio_group-nch into lp:openobject-client

 

Naresh(OpenERP) has proposed merging lp:~openerp-dev/openobject-client/trunk-radio_group-nch into lp:openobject-client.

Requested reviews:
  OpenERP sa GTK client R&D (openerp-dev-gtk)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client/trunk-radio_group-nch/+merge/51261

Hello,

This branch contains the change that adds attribute 'group' to filters for providing mutex behaviour i.e simulation of a radio button.

eg:
<filter string="Paid Invoices" domain="[('state','=','paid')]" group='test'/>
<filter string="Unpaid Invoices" domain="[('state','=',unpaid]" group='test'/>
So this to filter buttons will simulate like a radio button only 1 of them will be active at a time.

Note:Needed to merge the server part to see the changes in effect.

Thanks,
-- 
https://code.launchpad.net/~openerp-dev/openobject-client/trunk-radio_group-nch/+merge/51261
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client/trunk-radio_group-nch.
=== modified file 'bin/widget_search/filter.py'
--- bin/widget_search/filter.py	2010-12-13 15:45:20 +0000
+++ bin/widget_search/filter.py	2011-02-25 06:52:24 +0000
@@ -48,7 +48,6 @@
         if self.default_search:
             self.butt.set_active(True)
         self.butt.set_alignment(0.5, 0.5)
-        self.butt.connect('toggled', call[1])
         self.screen_context = call[0].context
         self.widget = self.butt
 

=== modified file 'bin/widget_search/form.py'
--- bin/widget_search/form.py	2011-02-01 09:45:54 +0000
+++ bin/widget_search/form.py	2011-02-25 06:52:24 +0000
@@ -132,6 +132,7 @@
         self.col = col
         self.focusable = None
         self.add_widget_end = []
+        self.filter_group = {}
 
     def destroy(self):
         self.container.destroy()
@@ -167,6 +168,20 @@
             else:
                 self.name_lst.append((name,attrs))
 
+    def filter_group_control(self, filter_button=False, group=False):
+        ## This function is used to simulate a Toggle button to behave
+        ## like a radiobutton.
+        filter_group = self.filter_group.get(group, [])
+        for child in filter_group:
+            if child[0] == filter_button:
+                continue
+            child[0].disconnect(child[1])
+            child[0].set_active(False)
+            handler_id = child[0].connect('toggled', child[2])
+            self.filter_group[group].remove(child)
+            self.filter_group[group].append((child[0], handler_id, child[2]))
+        return True
+
     def parse_filter(self, xml_data, max_width, root_node, call=None):
         psr = expat.ParserCreate()
         psr.StartElementHandler = self.dummy_start
@@ -236,6 +251,14 @@
                 name = str(attrs.get('string','filter'))
                 widget_act = filter.filter(name, self.parent, attrs, call)
                 help = attrs.get('help', False) or name
+                filter_group = attrs.get('group', False)
+                handler_id = widget_act.butt.connect('toggled', call[1])
+                if filter_group:
+                    if not self.filter_group.has_key(filter_group):
+                        self.filter_group[filter_group] = []
+                    self.filter_group[filter_group].append((widget_act.butt, handler_id, call[1]))
+                    widget_act.butt.connect('pressed',self.filter_group_control, filter_group)
+
                 wid = container.wid_add(widget_act.butt, xoptions=gtk.SHRINK, help=help)
                 dict_widget[name + str(uuid.uuid1())] = (widget_act, widget_act, 1)
 


Follow ups