Пример #1
0
    def __init__(self,parent=None):
        QDialog.__init__(self,parent)
        layout = QVBoxLayout(self)
        tree = QTreeView(self)
        tree.setRootIsDecorated( False )
        layout.addWidget(tree)
        layout.setContentsMargins(0, 0, 0, 0)
        self.resize(600, 300)

        Rpc.session.login( 'http://*****:*****@127.0.0.1:8069', 'semantic' )

        # Example of asynchronous call:
        # The function 'called()' will be called twice in this example,
        # one for the signal and another one for the callback. Of course,
        # only one method is needed.
        self.thread = Rpc.session.executeAsync( self.called, '/object', 'execute', 'res.partner', 'search', [] )

        visible = ['create_date', 'name', 'act_from', 'act_to', 'body' ]
        self.fields = Rpc.session.execute('/object', 'execute', 'res.request', 'fields_get', visible)
        ids = Rpc.session.execute('/object', 'execute', 'res.request', 'search', [])
        self.group = RecordGroup( 'res.request', self.fields, ids )
        treeModel = KooModel( self )
        treeModel.setRecordGroup( self.group )
        treeModel.setFields( self.fields )
        treeModel.setShowBackgroundColor( False )

        tree.setModel( treeModel )
Пример #2
0
    def create(self, viewId, parent, model, rootNode, fields):
        # It's expected that parent will be a Screen
        screen = parent

        attrs = Common.nodeAttributes(rootNode)

        view = TreeView(parent, attrs.get('type', 'tree'))
        view.id = viewId
        if 'gridwidth' in attrs:
            view.setGridWidth(int(attrs['gridwidth']))
        if 'gridheight' in attrs:
            view.setGridWidth(int(attrs['gridheight']))

        view.setOnWriteFunction(attrs.get('on_write', ''))

        if not view.title:
            view.title = attrs.get('string', 'Unknown')

        colors = []
        for color_spec in attrs.get('colors', '').split(';'):
            if color_spec:
                colour, test = color_spec.split(':')
                colors.append((colour, str(test)))

        columns = []
        buttons = {}
        for node in rootNode.childNodes:
            node_attrs = Common.nodeAttributes(node)
            if node.localName == 'button':
                fname = node_attrs['name']
                columns.append({
                    'name': fname,
                    'width': 20,
                    'type': 'button',
                    'attributes': node_attrs,
                    'visible': True,
                })
                buttons[fname] = node_attrs
            if node.localName == 'field':
                fname = node_attrs['name']
                twidth = {
                    'integer': 60,
                    'float': 80,
                    'date': 70,
                    'datetime': 130,
                    'selection': 130,
                    'char': 140,
                    'one2many': 50,
                }

                if 'readonly' in node_attrs:
                    fields[fname]['readonly'] = Common.stringToBool(
                        node_attrs['readonly'])
                if 'required' in node_attrs:
                    fields[fname]['required'] = Common.stringToBool(
                        node_attrs['required'])

                if 'sum' in node_attrs and fields[fname]['type'] in ('integer', 'float', 'float_time'):
                    bold = bool(int(node_attrs.get('sum_bold', 0)))
                    label = node_attrs['sum']
                    digits = fields.get('digits', (16, 2))
                    view.addAggregate(fname, label, bold, digits)

                node_attrs.update(fields[fname])

                visible = not eval(fields[fname].get('invisible', 'False'), {
                                   'context': screen.context})

                if 'width' in fields[fname]:
                    width = int(fields[fname]['width'])
                else:
                    width = twidth.get(fields[fname]['type'], 200)
                columns.append({
                    'name': fname,
                    'width': width,
                    'type': fields[fname]['type'],
                    'attributes': node_attrs,
                    'visible': visible,
                })

        view.finishAggregates()

        model = KooModel.KooModel(view)
        model.setMode(KooModel.KooModel.ListMode)
        model.setRecordGroup(screen.group)
        model.setFields(fields)
        model.setButtons(buttons)
        model.setFieldsOrder([x['name'] for x in columns])
        model.setColors(colors)
        model.setReadOnly(not attrs.get('editable', False))
        view.setReadOnly(not attrs.get('editable', False))

        if attrs.get('editable', False) == 'top':
            view.setAddOnTop(True)

        if view.isReadOnly():
            model.setShowBackgroundColor(False)
        else:
            model.setShowBackgroundColor(True)

        # Here we use a trick to avoid double data loading.
        # If we don't disallow record loading, records would be loaded twice
        # once, in "view.setModel( model )" and another one when Screen loads
        # view.setViewSettings(). What we do here is disallow record loading,
        # run setModel(), load settings and finally allow record loading again.
        # This optimizes Tree View loading times.
        domain = screen.group.domain()
        screen.group.setDomainForEmptyGroup()

        view.setModel(model)

        for column in range(len(columns)):
            current = columns[column]
            if view._widgetType in ('tree', 'table'):
                view.widget.setColumnWidth(column, current['width'])
            if not current['visible']:
                view.widget.hideColumn(column)

            delegate = FieldDelegateFactory.create(
                current['type'], view.widget, current['attributes'])
            view.widget.setItemDelegateForColumn(column, delegate)

        view.setViewSettings(ViewSettings.load(view.id))

        screen.group.setDomain(domain)

        return view
Пример #3
0
    def create(self, viewId, parent, model, rootNode, fields):
        self.screen = parent
        view = CalendarView(parent)
        view.id = viewId

        attrs = Common.nodeAttributes(rootNode)
        view.setOnWriteFunction(attrs.get('on_write', ''))

        if not view.title:
            view.title = attrs.get('string', _('Unknown'))

        startDate = attrs.get('date_start')
        stopDate = attrs.get('date_stop')
        dateDelay = attrs.get('date_delay')
        color = attrs.get('color')

        header = []
        header.append(startDate)
        if dateDelay:
            header.append(dateDelay)
        if color:
            header.append(color)
        for node in rootNode.childNodes:
            node_attrs = Common.nodeAttributes(node)
            if node.localName == 'field':
                header.append(node_attrs['name'])

        #<calendar string="Tasks" date_start="date_start" date_delay="planned_hours" color="user_id">
        #	<field name="name"/>
        #	<field name="project_id"/>
        #</calendar>

        model = KooModel(view)
        model.setMode(KooModel.ListMode)
        model.setRecordGroup(self.screen.group)
        model.setFields(fields)
        model.setFieldsOrder(header)
        model.setReadOnly(not attrs.get('editable', False))
        model.setShowBackgroundColor(True)

        view.setReadOnly(not attrs.get('editable', False))
        view.setModel(model)
        view.setModelDateColumn(0)
        column = 1
        if dateDelay:
            view.setModelDurationColumn(column)
            column += 1
        if color:
            view.setModelColorColumn(column)
            column += 1
        view.setModelTitleColumn(column)

        return view
Пример #4
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        Rpc.session.login('http://*****:*****@127.0.0.1:8069', 'nan')

        #model = 'account.account'
        #visibleFields = ['name', 'code', 'debit', 'credit', 'balance', 'company_currency_id']
        #domain = [('code', '=', '0')]

        model = 'ir.ui.menu'
        visibleFields = ['name']
        extraFields = ['child_id', 'icon']
        domain = [('parent_id', '=', False)]

        #model = 'res.partner.address'
        #visibleFields = ['partner_id', 'name', 'zip', 'city', 'country_id']
        #visibleFields = ['street', 'name', 'zip', 'city', 'street2']
        extraFields = []
        domain = []

        self.fields = Rpc.session.execute('/object', 'execute', model,
                                          'fields_get',
                                          visibleFields + extraFields)
        ids = Rpc.session.execute('/object', 'execute', model, 'search',
                                  domain)
        import gc
        import sys
        #from muppy import tracker

        self.group = RecordGroup(model, self.fields, ids)
        #mt = tracker.ObjectTracker()
        iterations = 0
        for x in range(iterations):
            # print "NUM OBJECTS: ", len(gc.get_objects())
            self.group = RecordGroup(model, self.fields, ids)
            print("GC 0: ", len(gc.get_referrers(self.group)))
            # for x in gc.get_referrers(self.group):
            #	print "REF: ", x
            #	print "--------"
            self.group.ensureAllLoaded()
            # print "GC 0: ", len(gc.get_referrers(self.group))
            # print "GC 1: ", sys.getrefcount(self.group)
            # print "COUNT: ", len(self.group.records)
            # for r in self.group.records:
            #r.parent = None
            #r.group = None
            #r.setParent( None )
            # for key, value in r.values.iteritems():
            #import Koo.Model.Field
            # if isinstance(value, Koo.Model.Field.ToManyField):
            #value.parent = None
            #r.values = {}
            # print "COUNT 2: ", len(self.group.fieldObjects)
            #self.group.records = []
            # for f in self.group.fieldObjects:
            #self.group.fieldObjects[f].parent = None
            #self.group.fieldObjects = {}
            # print "NUM OBJECTS: ", len(gc.get_objects())
            # print "GC 1: ", len(gc.get_referrers(self.group))
            #del self.group
            #del f
            #del r
            #del self.group
            if x != iterations - 1:
                self.group.__del__()
            #self.group = None
            gc.collect()
            # mt.print_diff()
            print("NUM OBJECTS: ", len(gc.get_objects()))
            # print "----"
            # print "GC: ", gc.get_referrers(self.group)
            print("GC: ", len(gc.get_referrers(self.group)))
        print("AFD")

        # Setup Qt Model
        self.model = KooModel(self)
        self.model.setFields(self.fields)
        self.model.setFieldsOrder(visibleFields)
        self.model.setIconForField('icon', 'name')
        self.model.setChildrenForField('child_id', 'name')
        self.model.setShowBackgroundColor(False)
        self.model.setRecordGroup(self.group)

        # Create GUI
        layout = QVBoxLayout(self)
        #widget = QTreeView(self)
        widget = QColumnView(self)
        #widget = QListView(self)
        #widget.setViewMode( QListView.IconMode )
        #widget.setGridSize( QSize( 100, 100 ) )
        layout.addWidget(widget)
        layout.setMargin(0)
        widget.setModel(self.model)
Пример #5
0
    def create(self, viewId, parent, viewModel, rootNode, fields, filter=None):
        self.viewModel = viewModel
        self.filter = filter

        self.header = [{'name': 'name'}]
        # It's expected that parent will be a Screen
        screen = parent
        attrs = Common.nodeAttributes(rootNode)
        colors = []
        print "Model, Filter:", viewModel, ',', filter

        for color_spec in attrs.get('colors', '').split(';'):
            if color_spec:
                colour, test = color_spec.split(':')
                colors.append((colour, str(test)))

        if attrs.get('debug', True):
            model = KooModelDbg.KooModelDbg(parent)
        else:
            model = KooModel.KooModel(parent)

        model.setMode(KooModel.KooModel.ListMode)
        #model.setMode( KooModel.KooModel.TreeMode )
        model.setReadOnly(not attrs.get('editable', False))
        screen.group.setAllowRecordLoading(False)
        model.setRecordGroup(screen.group)

        view = ShowerView(model, parent)
        #if not view.title:
        #	view.title = attrs.get('string', 'Unknown' )
        # view.setReadOnly( not attrs.get('editable', False) )

        #if attrs.get('editable', False) == 'top':
        #	view.setAddOnTop( True )

        rootProj = self._parseDiagram(model, view, rootNode)
        assert rootProj, "No main projection found in <diagram>"

        print "Diagram fields:", fields.keys()
        print "Diagram header:", self.header
        model.setFields(fields)
        try:
            pfields = []
            for n in self.header:
                if not fields.has_key(n['name']):
                    pfields.append(n['name'])

            afields = {}
            if len(pfields):
                afields.update(
                    Rpc.session.execute('/object', 'execute', self.viewModel,
                                        'fields_get', pfields,
                                        screen.group.context))
                # print "Brought extra fields:", afields

            for h in self.header:
                for k in h.keys():
                    if k in ('type', 'string', 'width'):
                        afields[h['name']][k] = h[k]

            print "Fields to add:", afields
            screen.group.addFields(afields)
            del afields
        except Exception, e:
            print "Sth went wrong", e
            pass