Пример #1
0
    def flags(self, index: QModelIndex):
        flags = (Qt.NoItemFlags | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable |
                 Qt.ItemIsEnabled)

        if index.isValid():
            node = self.node_from_index(index)
            column = self.columns[index.column()].name

            if isinstance(node, JsonItem):
                if column == 'value' and not node.readonly:
                    if not node.type == 'bool':
                        flags |= Qt.ItemIsEditable
                    else:
                        flags |= Qt.ItemIsUserCheckable
        return flags
Пример #2
0
    def fetchMore(self, parent=None):
        """
        Fetches the children given the model index of a parent node.
        Adds the children to the parent.
        """
        parent = QModelIndex() if parent is None else parent
        if parent.column() > 0:
            return

        parent_item = self.treeItem(parent)
        if parent_item.children_fetched:
            return

        tree_items = self._fetchObjectChildren(parent_item.obj,
                                               parent_item.obj_path)

        self.beginInsertRows(parent, 0, len(tree_items) - 1)
        for tree_item in tree_items:
            parent_item.append_child(tree_item)

        parent_item.children_fetched = True
        self.endInsertRows()
Пример #3
0
    def data(self, index: QModelIndex, role=Qt.DisplayRole) -> Any:
        col = index.column()
        row = index.row()

        if (role in [Qt.DisplayRole, Qt.EditRole] and index.isValid()
                and row < self.rowCount()):
            data = self.col_data[col]
            key = data.key
            if key.startswith(self.TRIGGER):
                key = behead(key, self.TRIGGER)
                value = self.triggers(row).get(key, "")

            else:
                value = getattr(self.channels[row], key)

            if not data.always_show and value == data.default:
                return ""
            if key == "wav_path" and role == Qt.DisplayRole:
                if Path(value).parent != Path():
                    return "..." + Path(value).name
            return str(value)

        return nope
Пример #4
0
    def setData(self,
                index: QModelIndex,
                value: Any,
                role: Qt.ItemDataRole = None) -> bool:
        if role == Qt.EditRole:
            row = index.row()
            col = index.column()

            key = self.keys[col]
            type_ = self.types[col]

            value = type_(value)
            oldValue = getattr(self.images[row], key)
            if oldValue == value:
                return False

            if key == "relpath":
                dstAbspath = value
                dstRelpath = dstAbspath.relative_to(self.basepath /
                                                    Image.images_dir)

                # remove duplicates
                for image in self.images:
                    if dstRelpath == image.relpath:
                        return False

                # move image
                self.images[row].move(self.basepath, dstRelpath)
                self.dataChanged.emit(index, index, Qt.EditRole)
                return True

            else:
                setattr(self.images[row], key, value)
                self.dataChanged.emit(index, index, Qt.EditRole)
                return True

        return False
Пример #5
0
    def data(self, index: QModelIndex,
             role: int = Qt.DisplayRole) -> Union[float, str]:
        if not index.isValid():
            return None
        elif role == Qt.DisplayRole:
            row = index.row()
            col = index.column()
            if col > self.columnCount() or row > self.rowCount():
                return None
            elif col == 0 and self._show_row_index:
                return row
            # offset the index's column number if the first column is
            # the row number
            col = col - int(self._show_row_index)
            # identify which dataset to display values from
            mask = col < self._cum_col_lengths
            dset = self._datasets[mask][-1]
            # determine the column index within the desired dataset
            # if sum(mask) == 1, the column number is high, meaning we're
            # selecting from the last dataset
            if sum(mask) == 1:
                ind = col
            # otherwise, determine the column number within the dataset
            else:
                cum = self._cum_col_lengths[mask]
                ind = cum[-1] - cum[-2]
            value = dset[row, ind]

            # round floating point values to make the table compact
            if isinstance(value, numbers.Integral):
                return value
            elif isinstance(value, numbers.Real):
                return np.round(value, self.decimals)
            else:
                return str(value)
        else:
            return None
Пример #6
0
    def setData(
        self, index: QModelIndex, value: Any, role: Qt.ItemDataRole = None
    ) -> bool:
        if role == Qt.EditRole:
            row = index.row()
            col = index.column()

            key = Formulation.keys[col]
            type_ = Formulation.types[col]

            try:
                value = type_(value)
            except ValueError:
                return False

            if key == "angle":
                self.formulations[row].angle.deg = int(round(value))
            else:
                setattr(self.formulations[row], key, value)

            self.dataChanged.emit(index, index, [Qt.EditRole])
            return True

        return False
Пример #7
0
    def data(self, index: QtCore.QModelIndex, role: int) -> Any:
        if not index.isValid():
            return None

        col = index.column()
        row = index.row()

        if role == QtCore.Qt.DisplayRole:
            if col == 0:
                return self.layers[row].name

            return None

        elif role == QtCore.Qt.BackgroundRole:
            if col == NAME_COL:
                return None

            elif col >= FIRST_VP_COL:
                vp = self.via_pairs[col - FIRST_VP_COL]
                if vp.start_index <= row <= vp.end_index:
                    return QtGui.QBrush(QtGui.QColor(0, 0, 0))
                return None

        return None
Пример #8
0
 def hasChildren(self, parent=None):
     parent = QModelIndex() if parent is None else parent
     if parent.column() > 0:
         return 0
     else:
         return self.treeItem(parent).has_children
Пример #9
0
 def data(self, index: QModelIndex, role: int = ...) -> Any:
     if not index.isValid() or role != Qt.DisplayRole:
         return QVariant()
     else:
         return QVariant(
             self.__data[index.row()][self.__cols[index.column()]])
Пример #10
0
    def data(self, idx: QtCore.QModelIndex, role: Optional[int] = None) -> Any:
        if role == QtCore.Qt.DisplayRole:
            return self._data[idx.row()][idx.column()]

        return None
Пример #11
0
 def data(self, index: QModelIndex, role=Qt.DisplayRole):
     if role == Qt.DisplayRole:
         val = self.dataframe.iloc[index.row(), index.column()]
         if index.column() == 0:
             return "{:3f}".format(val)
         return str(val)