Пример #1
0
class ActionFieldWidget(AbstractFieldWidget, ActionFieldWidgetUi):
    def __init__(self, parent, view, attrs={}):
        AbstractFieldWidget.__init__(self, parent, view, attrs)
        ActionFieldWidgetUi.__init__(self)
        self.setupUi(self)

        self.colors['normal'] = self.palette().color(self.backgroundRole())
        self.act_id = attrs['name']
        res = Rpc.session.execute('/object', 'execute', 'ir.actions.actions',
                                  'read', [self.act_id], ['type'],
                                  Rpc.session.context)
        if not res:
            raise Exception('ActionNotFound')
        type = res[0]['type']

        self.action = Rpc.session.execute('/object', 'execute', type, 'read',
                                          [self.act_id], False,
                                          Rpc.session.context)[0]
        if 'view_mode' in attrs:
            self.action['view_mode'] = attrs['view_mode']

        if self.action['type'] == 'ir.actions.act_window':
            if not self.action.get('domain', False):
                self.action['domain'] = '[]'
            self.context = {'active_id': False, 'active_ids': []}
            self.context.update(
                eval(self.action.get('context', '{}'), self.context.copy()))
            a = self.context.copy()
            a['time'] = time
            self.domain = Rpc.session.evaluateExpression(
                self.action['domain'], a)

            if self.action['view_type'] == 'form':
                self.view_id = []
                if self.action['view_id']:
                    self.view_id = [self.action['view_id'][0]]

                self.recordGroup = RecordGroup(self.action['res_model'],
                                               context=self.context)
                self.recordGroup.setDomain(self.domain)

                # Try to make the impression that it loads faster...
                QTimer.singleShot(0, self.createScreen)
            elif self.action['view_type'] == 'tree':
                pass  # TODO
        self.screen = None

    def createScreen(self):
        QApplication.setOverrideCursor(Qt.WaitCursor)
        try:
            self.screen = Screen(self)
            self.screen.setRecordGroup(self.recordGroup)
            #self.screen.setDomain( self.domain )
            self.screen.setEmbedded(True)
            if int(self.attrs.get('koo.show_toolbar', '0')):
                self.screen.setToolbarVisible(True)
            else:
                self.screen.setToolbarVisible(False)
            self.connect(self.screen, SIGNAL('activated()'), self.switch)
            mode = (self.action['view_mode'] or 'form,tree').split(',')
            # if self.view_id:
            #self.screen.setViewIds( self.view_id )
            # else:
            #self.screen.setViewTypes( mode )
            self.screen.setupViews(mode, self.view_id)
            self.uiTitle.setText(QString(self.attrs['string'] or ""))
            layout = QVBoxLayout(self.uiGroup)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.addWidget(self.screen)

            self.connect(self.pushSearch, SIGNAL('clicked()'), self.slotSearch)
            self.connect(self.pushSwitchView, SIGNAL('clicked()'), self.switch)
            self.connect(self.pushOpen, SIGNAL('clicked()'), self.slotOpen)

            self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        except Rpc.RpcException as e:
            pass
        QApplication.restoreOverrideCursor()

    def sizeHint(self):
        return QSize(200, 400)

    def switch(self):
        self.screen.switchView()

    def slotSearch(self):
        win = SearchDialog(self.action['res_model'],
                           domain=self.domain,
                           context=self.context)
        win.exec_()
        if win.result:
            self.screen.clear()
            self.screen.load(win.result)

    def slotOpen(self):
        Api.instance.execute(self.act_id)

    def storeValue(self):
        self.screen.currentView().store()

    def showValue(self):
        if self.screen:
            self.screen.reload()
Пример #2
0
class WizardPage(QDialog):
    """
    The WizardPage class shows a QDialog with the information givenin one
    wizard step.
    """
    def __init__(self, arch, fields, state, name, datas, parent=None):
        QDialog.__init__(self, parent)
        self.setModal(True)
        buttons = []
        self.datas = datas
        self.buttonsLayout = QHBoxLayout()
        self.buttonsLayout.addStretch()
        for x in state:
            but = QPushButton(Common.normalizeLabel(x[1]))
            # We store the value to return into objectName property
            but.setObjectName(x[0])
            # The third element is the gtk-icon
            if len(x) >= 3:
                but.setIcon(Icons.kdeIcon(x[2]))
            # The forth element is True if the button is the default one
            if len(x) >= 4 and x[3]:
                but.setDefault(True)
            self.buttonsLayout.addWidget(but)
            but.clicked.connect(self.slotPush)

        val = {}
        for f in fields:
            if 'value' in fields[f]:
                val[f] = fields[f]['value']

        self.group = RecordGroup('wizard.' + name)
        # Do not allow record loading as most probably 'wizard.'+name model
        # won't exist in the server
        self.group.setDomainForEmptyGroup()
        self.screen = Screen(self)
        self.screen.setRecordGroup(self.group)
        self.screen.new(default=False)
        # We don't want the toolbar to be shown at the wizard
        self.screen.setToolbarVisible(False)
        self.screen.addView(arch, fields, display=True)
        # Set default values
        self.screen.currentRecord().set(val)
        # Set already stored values
        self.screen.currentRecord().set(self.datas)
        self.screen.display()

        # Set minimum and maximum dialog size
        size = self.screen.sizeHint()
        self.setMinimumSize(size.width() + 100, min(600, size.height() + 25))
        size = QApplication.desktop().availableGeometry(self).size()
        size -= QSize(50, 50)
        self.setMaximumSize(size)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.screen)
        self.layout.addLayout(self.buttonsLayout)
        self.setWindowTitle(self.screen.currentView().title)

    def slotPush(self):
        o = self.sender()
        self.screen.currentView().store()
        # Get the value we want to return
        button = str(o.objectName())
        if button != 'end' and not self.screen.currentRecord().validate():
            self.screen.display()
            return
        self.datas.update(self.screen.get())
        self.result = (button, self.datas)
        self.accept()

    def save(self):
        pass

    def cancel(self):
        pass