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()
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)