Exemple #1
0
class WizardPage(QDialog):
    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)
            self.connect(but, SIGNAL('clicked()'), 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)
        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()
Exemple #2
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()
Exemple #3
0
class ScreenDialog( QDialog, ScreenDialogUi ):
	def __init__(self, parent):
		QWidget.__init__( self, parent )
		ScreenDialogUi.__init__( self )
		self.setupUi( self )

		self.setMinimumWidth( 800 )
		self.setMinimumHeight( 600 )

		self.connect( self.pushOk, SIGNAL("clicked()"), self.accepted )
		self.connect( self.pushCancel, SIGNAL("clicked()"), self.rejected )
		self.group = None
		self.record = None
		self.recordId = None
		self.model = None
		self._recordAdded = False
		self._context = {}
		self._domain = []
		self.devel_mode = Settings.value("client.devel_mode", False)
		if self.devel_mode:
			self.connect( self.pushDevInfo, SIGNAL("clicked()"),self.showLogs)
		else:
			self.pushDevInfo.hide()

	def setup(self, model, id=None):
		if self.group:
			return
		self.group = RecordGroup( model, context=self._context )
		self.model = model
		self.group.setDomain( self._domain )
		self.screen = Screen(self)
		self.screen.setRecordGroup( self.group )
		self.screen.setViewTypes( ['form'] )
		if id:
			self._recordAdded = False 
			self.screen.load([id])
		else:
			self._recordAdded = True
			self.screen.new()
		self.screen.display()
		self.layout().insertWidget( 0, self.screen  )
		self.screen.show()

	def setAttributes(self, attrs):
		if ('string' in attrs) and attrs['string']:
			self.setWindowTitle( unicode(self.windowTitle()) + ' - ' + attrs['string'])

	def setContext(self, context):
		self._context = context

	def setDomain(self, domain):
		self._domain = domain

	def rejected( self ):
		if self._recordAdded:
			self.screen.remove()
		self.reject()

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

		if self.screen.save():
			self.record = self.screen.currentRecord().name()
			self.recordId = self.screen.currentRecord().id
			self.accept()
	
	def showLogs(self):
		id = self.screen.currentId()
		if not (id or self.devel_mode):
			self.updateStatus(_('You have to select one resource!'))
			return False
		if id:
			res = Rpc.session.execute('/object', 'execute', self.model, 'perm_read', [id])
		else:
			res = []
		message = ''
		if self.devel_mode:
			message = "Object: %s\n" %(self.model)
			message += "Domain: %s\nContext: %s\n" %(self._domain, self._context)
			message += "Scr context: %s\n" % (self.screen.context)
			message += "\n"

		todo = [
			('id', _('ID')),
			('str_id', _('Model ID')),
			('create_uid', _('Creation User')),
			('create_date', _('Creation Date')),
			('write_uid', _('Latest Modification by')),
			('write_date', _('Latest Modification Date')),
		]

		for line in res:
			line['str_id'] = None
			try:
				# Using call() because we don't want exception handling
				res2 = Rpc.session.call('/object', 'execute',
					'ir.model.data', 'get_rev_ref', self.model, line['id'])
				
				if res2 and res2[1]:
					line['str_id'] = ', '.join(res2[1])
			except AttributeError:
				pass
			except Exception, e:
				# This can happen, just because old servers don't have
				# this method.
				print "Cannot rev ref id:" % e
		
			for (key,val) in todo:
				if not key in line:
				    continue
				if line[key] and key in ('create_uid','write_uid') \
				    and isinstance(line[key], (tuple, list)):
					line[key] = line[key][1]
				message += val + ': ' + str(line[key] or '-') + '\n'
		QMessageBox.information(self, _('Record log'), message)