def __init__(self, title, fields):
     super().__init__()
     self.setWindowTitle(title)
     self.inputs = []
     layout = QFormLayout(self)
     for field in fields:
         value = field[1]
         if type(value) is str:
             entry = QLineEdit(self)
             width = 200
             if len(field[1]) > 50:
                 width = 400
             entry.setMinimumWidth(width)
             entry.setText(value)
         elif isinstance(value, list):
             entry = QComboBox()
             entry.addItems(value)
         self.inputs.append(entry)
         layout.addRow(field[0], entry)
     buttonBox = QDialogButtonBox(
         QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
     layout.addWidget(buttonBox)
     buttonBox.accepted.connect(self.accept)
     buttonBox.rejected.connect(self.reject)
Beispiel #2
0
 def createEditor(self, parent, option, index):
     if (self._parent.isLocked()): return None
     if (index.internalPointer().sidsIsCGNSTree()): return None
     if (index.internalPointer().sidsIsLink()): return None
     if (index.internalPointer().sidsIsLinkChild()): return None
     ws = option.rect.width()
     hs = option.rect.height() + 4
     xs = option.rect.x()
     ys = option.rect.y() - 2
     if (not index.internalPointer().hasEditCheck() or
             (index.column() in [NMT.COLUMN_NAME])):
         self._mode = CELLTEXT
         editor = QLineEdit(parent)
         editor.transgeometry = (xs, ys, ws, hs)
         editor.installEventFilter(self)
         self.setEditorData(editor, index)
         return editor
     if index.column() in [NMT.COLUMN_VALUE]:
         node = self._parent.modelData(index)
         if node.hasValueView():
             pt = node.sidsPath().split('/')[1:]
             lt = node.sidsTypePath()
             fc = self._parent._control._control.userFunctionFromPath(pt, lt)
             if (fc is not None):
                 en = fc.getEnumerate(pt, lt)
             else:
                 en = node.sidsValueEnum()
             if (en is None):
                 self._mode = CELLTEXT
                 editor = QLineEdit(parent)
                 editor.transgeometry = (xs, ys, ws, hs)
             else:
                 self._mode = CELLCOMBO
                 editor = QComboBox(parent)
                 editor.transgeometry = (xs, ys, ws, hs)
                 editor.addItems(en)
                 try:
                     tix = en.index(node.sidsValue().tostring().decode('ascii'))
                 except ValueError:
                     editor.insertItem(0, node.sidsValue().tostring().decode('ascii'))
                     tix = 0
                 editor.setCurrentIndex(tix)
             editor.installEventFilter(self)
             self.setEditorData(editor, index)
             return editor
     if (index.column() == NMT.COLUMN_SIDS):
         self._mode = CELLCOMBO
         editor = QComboBox(parent)
         editor.transgeometry = (xs, ys, ws, hs)
         tnode = self._parent.modelData(index)
         itemslist = tnode.sidsTypeList()
         editor.addItems(itemslist)
         try:
             tix = itemslist.index(tnode.sidsType())
         except ValueError:
             editor.insertItem(0, tnode.sidsType())
             tix = 0
         editor.setCurrentIndex(tix)
         editor.installEventFilter(self)
         self.setEditorData(editor, index)
         return editor
     if (index.column() == NMT.COLUMN_DATATYPE):
         self._mode = CELLCOMBO
         editor = QComboBox(parent)
         editor.transgeometry = (xs, ys, ws, hs)
         editor.setProperty("Q7SIDSDataTypeComboBox", "True")
         itemslist = self._parent.modelData(index).sidsDataType(all=True)
         editor.addItems(itemslist)
         editor.installEventFilter(self)
         sizePolicy = QSizePolicy(QSizePolicy.Minimum,QSizePolicy.Minimum)
         editor.setSizePolicy(sizePolicy)
         self.setEditorData(editor, index)
         return editor
     return None
class DrillSetting(QObject):
    """
    Class that groups needed data of a single setting that will be displayed
    on the dialog.
    """

    valueChanged = Signal(str)
    fileChecked = Signal(bool)

    def __init__(self, name, values, settingType, doc):
        """
        Initialize the setting by providing its name, allowed values, type and
        documentation. This constructor chooses a widget to represent the
        setting on the basis of its type.

        Args:
            name (str): setting name
            values (list(str)): allowed values. This is only used with combobox
                                type settings
            settingType (str): a str that represents the setting type
            doc (str): setting documentation
        """
        super(DrillSetting, self).__init__()
        self._doc = doc

        if ((settingType == "file") or (settingType == "files")):
            self._widget = FileFinderWidget()
            self._widget.isOptional(True)
            if (settingType == "files"):
                self._widget.allowMultipleFiles(True)
            self._widget.setLabelText("")
            self._widget.fileInspectionFinished.connect(
                    lambda : self.fileChecked.emit(self._widget.isValid())
                    )
            self._setter = self._widget.setUserInput
            self._getter = self._widget.getUserInput

        if (settingType == "workspace"):
            self._widget = WorkspaceSelector()
            self._widget.setOptional(True)
            self._widget.currentTextChanged.connect(
                    lambda t : self.valueChanged.emit(name)
                    )
            self._setter = self._widget.setCurrentText
            self._getter = self._widget.currentText

        elif (settingType == "combobox"):
            self._widget = QComboBox()
            self._widgetEventFilter = MouseScrollEventFilter()
            self._widget.installEventFilter(self._widgetEventFilter)
            self._widget.addItems(values)
            self._widget.currentTextChanged.connect(
                    lambda t : self.valueChanged.emit(name)
                    )
            self._setter = self._widget.setCurrentText
            self._getter = self._widget.currentText

        elif (settingType == "bool"):
            self._widget = QCheckBox()
            self._widget.stateChanged.connect(
                    lambda s : self.valueChanged.emit(name)
                    )
            self._setter = self._widget.setChecked
            self._getter = self._widget.isChecked

        elif (settingType == "floatArray") or (settingType == "intArray"):
            self._widget = QLineEdit()
            self._widget.textChanged.connect(
                    lambda _ : self.valueChanged.emit(name)
                    )
            self._setter = lambda v : self._widget.setText(','.join(str(e)
                                                           for e in v))

            if (settingType == "floatArray"):
                self._getter = (
                        lambda : [float(v)
                                  for v in self._widget.text().split(',')
                                  if v])
            else:
                self._getter = (
                        lambda : [int(v)
                                  for v in self._widget.text().split(',')
                                  if v])

        elif (settingType == "string"):
            self._widget = QLineEdit()
            self._widget.textChanged.connect(
                    lambda _ : self.valueChanged.emit(name)
                    )
            self._setter = lambda v : self._widget.setText(str(v))
            self._getter = self._widget.text

    @property
    def doc(self):
        """
        Get the documentation.

        Returns:
            str: documentation
        """
        return self._doc

    @property
    def widget(self):
        """
        Get the widget.

        Returns
            QWidget: widget
        """
        return self._widget

    @property
    def setter(self):
        """
        Get the function that could be used to set the widget value.

        Returns
            fn: setter function
        """
        return self._setter

    @property
    def getter(self):
        """
        Get the function that could be used to get the widget value.

        Returns
            fn: getter function
        """
        return self._getter
Beispiel #4
0
 def createEditor(self, parent, option, index):
     tnode = self._model.nodeFromPath(self._parent._data[index.row()])
     if tnode.sidsIsCGNSTree():
         return None
     if tnode.sidsIsLink():
         return None
     if tnode.sidsIsLinkChild():
         return None
     ws = option.rect.width()
     hs = option.rect.height() + 4
     xs = option.rect.x()
     ys = option.rect.y() - 2
     if index.column() == 2:
         self._lastCol = COLUMN_SIDS
         if self._parent.cForce.checkState() != Qt.Checked:
             self._mode = CELLTEXT
             editor = QLineEdit(parent)
             editor.transgeometry = (xs, ys, ws, hs)
         else:
             self._mode = CELLCOMBO
             editor = QComboBox(parent)
             editor.transgeometry = (xs, ys, ws, hs)
             itemslist = tnode.sidsTypeList()
             editor.addItems(itemslist)
             try:
                 tix = itemslist.index(tnode.sidsType())
             except ValueError:
                 editor.insertItem(0, tnode.sidsType())
                 tix = 0
             editor.setCurrentIndex(tix)
         editor.installEventFilter(self)
         self.setEditorData(editor, index)
         return editor
     if index.column() == 3:
         self._lastCol = COLUMN_DATATYPE
         self._mode = CELLCOMBO
         editor = QComboBox(parent)
         editor.transgeometry = (xs, ys, ws, hs)
         itemslist = tnode.sidsDataType(all=True)
         editor.addItems(itemslist)
         editor.setCurrentIndex(0)
         editor.installEventFilter(self)
         self.setEditorData(editor, index)
         return editor
     if index.column() == 4:
         self._lastCol = COLUMN_VALUE
         if tnode.hasValueView():
             pt = tnode.sidsPath().split('/')[1:]
             lt = tnode.sidsTypePath()
             fc = self._parent._control.userFunctionFromPath(pt, lt)
             if fc is not None:
                 en = fc.getEnumerate(pt, lt)
             else:
                 en = tnode.sidsValueEnum()
             if en is None:
                 self._mode = CELLTEXT
                 editor = QLineEdit(parent)
                 editor.transgeometry = (xs, ys, ws, hs)
             else:
                 self._mode = CELLCOMBO
                 editor = QComboBox(parent)
                 editor.transgeometry = (xs, ys, ws, hs)
                 editor.addItems(en)
                 try:
                     tix = en.index(
                         tnode.sidsValue().tostring().decode('ascii'))
                 except ValueError:
                     editor.insertItem(
                         0,
                         tnode.sidsValue().tostring().decode('ascii'))
                     tix = 0
                 editor.setCurrentIndex(tix)
             editor.installEventFilter(self)
             self.setEditorData(editor, index)
             return editor
     return None