Example #1
0
    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)
Example #2
0
    def __init__(self, parent, view, attributes):
        AbstractFieldWidget.__init__(self, parent, view, attributes)

        self.button = QPushButton(self)
        layout = QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.button)

        self.button.setText(
            Common.normalizeLabel(attributes.get('string', 'unknown')))
        if 'icon' in attributes:
            self.button.setIcon(Icons.kdeIcon(attributes['icon']))

        self.connect(self.button, SIGNAL('clicked()'), self.click)
Example #3
0
 def data(self, index, role=Qt.DisplayRole):
     if not self.group:
         return QVariant()
     if role in (Qt.DisplayRole, Qt.EditRole) or (self._showToolTips and
                                                  role == Qt.ToolTipRole):
         value = self.value(index.row(), index.column(),
                            index.internalPointer())
         fieldType = self.fieldType(index.column(), index.internalPointer())
         if fieldType in ['one2many', 'many2many']:
             return QVariant('(%d)' % value.count())
         elif fieldType == 'selection':
             field = self.fields[self.field(index.column())]
             for x in field['selection']:
                 if x[0] == value:
                     return QVariant(str(x[1]))
             return QVariant()
         elif fieldType == 'date' and value:
             return QVariant(
                 Calendar.dateToText(Calendar.storageToDate(value)))
         elif fieldType == 'datetime' and value:
             return QVariant(
                 Calendar.dateTimeToText(Calendar.storageToDateTime(value)))
         elif fieldType == 'float':
             # If we use the default conversion big numbers are shown
             # in scientific notation. Also we have to respect the number
             # of decimal digits given by the server.
             field = self.fields[self.field(index.column())]
             if role == Qt.EditRole:
                 thousands = False
             else:
                 thousands = True
             return QVariant(
                 Numeric.floatToText(value, field.get('digits', None),
                                     thousands))
         elif fieldType == 'integer':
             return QVariant(Numeric.integerToText(value))
         elif fieldType == 'float_time':
             return QVariant(Calendar.floatTimeToText(value))
         elif fieldType == 'binary':
             if value:
                 return QVariant(_('%d bytes') % len(value))
             else:
                 return QVariant()
         elif fieldType == 'boolean':
             return QVariant(bool(value))
         elif fieldType == 'button':
             if role == Qt.ToolTipRole:
                 fieldName = self.field(index.column())
                 return QVariant(self.buttons[fieldName].get('string', ''))
             return QVariant()
         else:
             if value == False or value == None:
                 return QVariant()
             else:
                 # If the text has several lines put them all in a single one
                 return QVariant(str(value).replace('\n', ' '))
     elif role == Qt.DecorationRole:
         fieldType = self.fieldType(index.column(), index.internalPointer())
         if fieldType == 'button':
             fieldName = self.field(index.column())
             return QVariant(
                 Icons.kdeIcon(self.buttons[fieldName].get('icon')))
         if self.field(index.column()) == self.iconField:
             # Not all models necessarily have the icon so check that first
             model = self.record(index.row(), index.internalPointer())
             if model and self.icon in model.values:
                 return QVariant(Icons.kdeIcon(model.value(self.icon)))
             else:
                 return QVariant()
         else:
             return QVariant()
     elif role == Qt.BackgroundRole:
         if not self.showBackgroundColor:
             return QVariant()
         field = self.fields[self.field(index.column())]
         model = self.record(index.row(), index.internalPointer())
         # We need to ensure we're not being asked about a non existent row.
         # This happens in some special cases (an editable tree in a one2many field,
         # such as the case of fiscal year inside sequences).
         # Note that trying to avoid processing this function if index.row() > self.rowCount()-1
         # works to avoid this but has problems with some tree structures (such as the menu).
         # So we need to make the check here.
         if not model:
             return QVariant()
         # Priorize readonly to required as if it's readonly the
         # user doesn't mind if it's required as she won't be able
         # to change it anyway.
         if not model.isFieldValid(self.field(index.column())):
             color = '#FF6969'
         elif 'readonly' in field and field['readonly']:
             color = 'lightgrey'
         elif 'required' in field and field['required']:
             color = '#ddddff'
         else:
             color = 'white'
         return QVariant(QBrush(QColor(color)))
     elif role == Qt.ForegroundRole:
         if not self.colors:
             return QVariant()
         model = self.record(index.row(), index.internalPointer())
         # We need to ensure we're not being asked about a non existent row.
         # This happens in some special cases (an editable tree in a one2many field,
         # such as the case of fiscal year inside sequences).
         # Note that trying to avoid processing this function if index.row() > self.rowCount()-1
         # works to avoid this but has problems with some tree structures (such as the menu).
         # So we need to make the check here.
         if not model:
             return QVariant()
         palette = QPalette()
         color = palette.color(QPalette.WindowText)
         for (c, expression) in self.colors:
             if model.evaluateExpression(expression, checkLoad=False):
                 color = c
                 break
         return QVariant(QBrush(QColor(color)))
     elif role == Qt.TextAlignmentRole:
         fieldType = self.fieldType(index.column(), index.internalPointer())
         if fieldType in [
                 'integer', 'float', 'float_time', 'time', 'date',
                 'datetime'
         ]:
             return QVariant(Qt.AlignRight | Qt.AlignVCenter)
         else:
             return QVariant(Qt.AlignLeft | Qt.AlignVCenter)
     elif role == KooModel.IdRole:
         model = self.record(index.row(), index.internalPointer())
         return QVariant(model.id)
     elif role == KooModel.ValueRole:
         value = self.value(index.row(), index.column(),
                            index.internalPointer())
         fieldType = self.fieldType(index.column(), index.internalPointer())
         if fieldType in ['one2many', 'many2many']:
             # By now, return the same as DisplayRole for these
             return QVariant('(%d)' % value.count())
         elif fieldType == 'selection':
             # By now, return the same as DisplayRole for these
             field = self.fields[self.field(index.column())]
             for x in field['selection']:
                 if x[0] == value:
                     return QVariant(str(x[1]))
             return QVariant()
         elif fieldType == 'date' and value:
             return QVariant(Calendar.storageToDate(value))
         elif fieldType == 'datetime' and value:
             return QVariant(Calendar.storageToDateTime(value))
         elif fieldType == 'float':
             # If we use the default conversion big numbers are shown
             # in scientific notation. Also we have to respect the number
             # of decimal digits given by the server.
             field = self.fields[self.field(index.column())]
             return QVariant(
                 Numeric.floatToText(value, field.get('digits', None)))
         elif fieldType == 'float_time':
             return QVariant(value)
         elif fieldType == 'binary':
             if value:
                 return QVariant(QByteArray.fromBase64(value))
             else:
                 return QVariant()
         elif fieldType == 'boolean':
             return QVariant(bool(value))
         else:
             if value == False or value == None:
                 return QVariant()
             else:
                 return QVariant(str(value))
     else:
         return QVariant()