~openerp-dev/openobject-client/trunk-bug-756343-nch

« back to all changes in this revision

Viewing changes to bin/widget_search/form.py

[MERGE] Improvement Custom dynamic filter

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import tools
29
29
from lxml import etree
30
30
import uuid
 
31
import copy
31
32
 
32
33
class _container(object):
33
34
    def __init__(self, max_width):
316
317
        self.show()
317
318
        for x in self.widgets.values():
318
319
            x[0].sig_activate(self.sig_activate)
 
320
        self.invisible_widgets = []
319
321
 
320
322
    def xml_process(self,xml_arch):
321
323
        root = etree.fromstring(xml_arch)
364
366
    def remove_custom(self, button, panel):
365
367
        button.parent.destroy()
366
368
        # Removing the Destroyed widget from Domain calculation
367
 
        for element in self.custom_widgets.keys():
368
 
            if self.custom_widgets[element][0] == panel:
369
 
                del self.custom_widgets[element]
370
 
                break
 
369
        ## also removing the field from the list of invisible fields
 
370
        ## so that they dont reappear and as the childs are deleted for the panel
 
371
        ## that has to be deleted we need to do a reverse process for removing the
 
372
        ## the invisible fields from the list of invisible fields.
 
373
        def process(widget):
 
374
            if isinstance(widget, gtk.HBox):
 
375
                for child in widget.get_children():
 
376
                    process(child)
 
377
            inv_childs = self.invisible_widgets
 
378
            for inv_child in inv_childs:
 
379
                if inv_child != widget:
 
380
                    self.invisible_widgets.remove(inv_child)
 
381
            return True
 
382
 
 
383
        custom_panel = copy.copy(self.custom_widgets)
 
384
        for key, wid in custom_panel.iteritems():
 
385
            for child in wid[0].widget.get_children():
 
386
                if not isinstance(child, (gtk.ComboBox, gtk.Button)):
 
387
                    process(child)
 
388
            if wid[0] == panel:
 
389
               del self.custom_widgets[key]
371
390
        return True
372
391
 
373
392
    def add_custom(self, widget, table, fields):
374
393
        new_table = gtk.Table(1,1,False)
375
 
        panel = widgets_type['custom_filter'][0]('', self.parent,{'fields':fields},call=self.remove_custom)
 
394
        panel = widgets_type['custom_filter'][0]('', self.parent, fields, callback=self.remove_custom, search_callback=self.call[1])
376
395
        x =  self.rows
377
396
        new_table.attach(panel.widget,0, 1, x, x+1, xoptions=gtk.FILL, yoptions=gtk.FILL , ypadding=2, xpadding=0)
378
397
        panelx = 'panel' + str(x)
380
399
        self.custom_widgets[panelx] = (panel, new_table, 1)
381
400
        table.attach(new_table, 1, 9, x, x+1)
382
401
        self.rows += 1
 
402
        ## Store the  widgets original visible attribute because as they are
 
403
        ## attached to the table as a child widgets and the table.show_all() will
 
404
        ## set all child widgets to visible inspite of their visibility is set to FALSE
 
405
        ## so make them invisible again after the table.show_all()
 
406
        def process(widget):
 
407
            if isinstance(widget, gtk.HBox):
 
408
                for sub_child in widget.get_children():
 
409
                    process(sub_child)
 
410
            if widget.get_visible():
 
411
                if widget in self.invisible_widgets:
 
412
                    self.invisible_widgets.remove(widget)
 
413
            else:
 
414
                if not widget in self.invisible_widgets:
 
415
                    self.invisible_widgets.append(widget)
 
416
            return True
 
417
 
 
418
        for key, wid in self.custom_widgets.iteritems():
 
419
            for child in wid[0].widget.get_children():
 
420
                if not isinstance(child, (gtk.ComboBox, gtk.Button)):
 
421
                    process(child)
383
422
        table.show_all()
 
423
        for wid in self.invisible_widgets:
 
424
            wid.set_visible(False)
384
425
        return panel
385
426
 
386
427
    def toggle(self, widget, event=None):
413
454
        if self.groupby:
414
455
            context.update({'group_by':self.groupby})
415
456
        if domain:
416
 
            if len(domain)>1 and domain[-2] in ['&','|']:
417
 
                if len(domain) == 2:
418
 
                    domain = [domain[1]]
 
457
            if '&' in domain or '|' in domain:
 
458
                if domain[-2] in ['&','|']:
 
459
                    pos = 2
 
460
                elif len(domain) >= 4 and domain[-4] in ['&','|']:
 
461
                    pos = 4
 
462
                if len(domain) == 4 and domain[1] in ['&','|']:
 
463
                    domain = domain[1:]
419
464
                else:
420
 
                    res1 = domain[:-2]
421
 
                    res2 = domain[-1:]
 
465
                    res1 = domain[:-pos]
 
466
                    res2 = domain[-(pos-1):]
422
467
                    domain = res1 + res2
423
468
        return {'domain':domain, 'context':context}
424
469