Пример #1
0
 def on_tableview_clicked(self, index: Qt.QModelIndex) -> None:
     if index.column() in (SceningList.START_FRAME_COLUMN,
                           SceningList.END_FRAME_COLUMN):
         self.main.current_frame = self.scening_list.data(index)
     if index.column() in (SceningList.START_TIME_COLUMN,
                           SceningList.END_TIME_COLUMN):
         self.main.current_time = self.scening_list.data(index)
Пример #2
0
    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return self.image_names[index.row()].name
            return None

        if role == Qt.DecorationRole and index.column() == 1:
            average_snow_height = self.camera.average_snow_height(
                self.image_names[index.row()].name)
            if average_snow_height > 0:
                if average_snow_height == 1:
                    return self.snow_level1
                elif average_snow_height == 2:
                    return self.snow_level2
                elif average_snow_height >= 3:
                    return self.snow_level3
            return None

        if role == Qt.DecorationRole and index.column() == 0:
            return self.thumbnails.get_thumbnail(index.row(), self.dragging)

        if role == Qt.BackgroundRole:
            photo_state = self.camera.photo_state(index.row())
            if photo_state == PhotoState.Processed:
                quality = self.camera.image_quality(
                    self.image_names[index.row()].name)
                if quality < 0.33:
                    color = self.quality_colors['BAD']
                elif quality < 0.66:
                    color = self.quality_colors['OK']
                else:
                    color = self.quality_colors['GOOD']
                return QBrush(color)
            elif photo_state == PhotoState.Skipped:
                return QBrush(QColor(150, 150, 150, 255))
            else:
                QBrush(QColor(0, 0, 0, 200))

        if role == Qt.UserRole:
            return self.image_names[index.row()]

        if role == Qt.UserRole + 1:
            return self.camera.is_snowy(self.image_names[index.row()].name)

        if role == Qt.UserRole + 2:
            return 'snow' if self.camera.is_snowy(
                self.image_names[index.row()].name) else 'ground'

        if role == Qt.ForegroundRole and index.row(
        ) < self.processed_images_count:
            return QBrush(QColor(0, 150, 0))
        return None
 def data(self, index: QModelIndex, role: int = ...) -> typing.Any:
     if role == Qt.DisplayRole:
         if index.column() == HeaderEnum.PID:
             return self.processes[index.row()].pid
         if index.column() == HeaderEnum.NAME:
             return self.processes[index.row()].name()
         if index.column() == HeaderEnum.USER:
             return self.processes[index.row()].username()
         if index.column() == HeaderEnum.PATH:
             try:
                 return self.processes[index.row()].exe()
             except psutil.AccessDenied:
                 return ""
     return None
Пример #4
0
    def setData(self, index: QModelIndex, value: typing.Any, role: int = Qt.EditRole) -> bool:
        if not index.isValid():
            return False

        if role == Qt.EditRole:
            row = index.row()
            if index.column() == HeaderEnum.CURRENT_VALUE:
                self.values[row].value = value
            elif index.column() == HeaderEnum.PREVIOUS_VALUE:
                self.values[row].previous_value = value
            elif index.column() == HeaderEnum.ADDRESS:
                self.values[row].address = value

            self.dataChanged.emit(index, index)
            return True

        return False
Пример #5
0
 def data(self, index: QModelIndex, role=Qt.DisplayRole) -> QVariant:
     """возвращает отображаемое значение"""
     if not index.isValid():
         return QVariant()
     row, col = index.row(), index.column()
     data = self._data[row]
     if role == Qt.UserRole:
         return QVariant(data)
     if role == Qt.DisplayRole:
         key = self._display[col]
         return data[key] if key in data.keys() else QVariant()
     return QVariant()
Пример #6
0
    def data(self, index: Qt.QModelIndex, role: int):
        if role == QtCore.Qt.DisplayRole:
            return None

        elif role == QtCore.Qt.SizeHintRole:
            return Qt.QSize(0, 0)
        elif role == QtCore.Qt.BackgroundRole:
            num = index.column()
            if num < len(self._data):
                val = self._data[num]
                MASK = 1 << index.row()
                return self.ON if MASK & val else self.OFF
            return self.OFF
Пример #7
0
    def data(self, index: QModelIndex, role: int = ...) -> typing.Any:
        if not index.isValid():
            return None
        row = index.row()
        column = index.column()

        if role == Qt.DisplayRole:
            if column == HeaderEnum.ADDRESS:
                return hex(self.values[row].address)
            if column == HeaderEnum.CURRENT_VALUE:
                return self.values[row].value
            if column == HeaderEnum.PREVIOUS_VALUE:
                return self.values[row].previous_value
        return None
Пример #8
0
    def data(self, index: Qt.QModelIndex, role: int = Qt.Qt.UserRole) -> Any:
        if not index.isValid():
            return None
        row = index.row()
        if row >= len(self.items):
            return None
        column = index.column()
        if column >= self.COLUMN_COUNT:
            return None

        if role in (Qt.Qt.DisplayRole, Qt.Qt.EditRole):
            if column == self.START_FRAME_COLUMN:
                return str(self.items[row].start)
            if column == self.END_FRAME_COLUMN:
                if self.items[row].end != self.items[row].start:
                    return str(self.items[row].end)
                else:
                    return ''
            if column == self.START_TIME_COLUMN:
                return str(Time(self.items[row].start))
            if column == self.END_TIME_COLUMN:
                if self.items[row].end != self.items[row].start:
                    return str(Time(self.items[row].end))
                else:
                    return ''
            if column == self.LABEL_COLUMN:
                return str(self.items[row].label)

        if role == Qt.Qt.UserRole:
            if column == self.START_FRAME_COLUMN:
                return self.items[row].start
            if column == self.END_FRAME_COLUMN:
                return self.items[row].end
            if column == self.START_TIME_COLUMN:
                return Time(self.items[row].start)
            if column == self.END_TIME_COLUMN:
                return Time(self.items[row].end)
            if column == self.LABEL_COLUMN:
                return self.items[row].label

        return None
Пример #9
0
    def setData(self,
                index: Qt.QModelIndex,
                value: Any,
                role: int = Qt.Qt.EditRole) -> bool:
        from copy import deepcopy

        if not index.isValid():
            return False
        if role not in (Qt.Qt.EditRole, Qt.Qt.UserRole):
            return False

        row = index.row()
        column = index.column()
        scene = deepcopy(self.items[row])

        if column == self.START_FRAME_COLUMN:
            if not isinstance(value, Frame):
                raise TypeError
            if scene.start != scene.end:
                if value > scene.end:
                    return False
                scene.start = value
            else:
                scene.start = value
                scene.end = value
            proper_update = True
        elif column == self.END_FRAME_COLUMN:
            if not isinstance(value, Frame):
                raise TypeError
            if scene.start != scene.end:
                if value < scene.start:
                    return False
                scene.end = value
            else:
                scene.start = value
                scene.end = value
            proper_update = True
        elif column == self.START_TIME_COLUMN:
            if not isinstance(value, Time):
                raise TypeError
            frame = Frame(value)
            if scene.start != scene.end:
                if frame > scene.end:
                    return False
                scene.start = frame
            else:
                scene.start = frame
                scene.end = frame
            proper_update = True
        elif column == self.END_TIME_COLUMN:
            if not isinstance(value, Time):
                raise TypeError
            frame = Frame(value)
            if scene.start != scene.end:
                if frame < scene.start:
                    return False
                scene.end = frame
            else:
                scene.start = frame
                scene.end = frame
            proper_update = True
        elif column == self.LABEL_COLUMN:
            if not isinstance(value, str):
                raise TypeError
            scene.label = value
            proper_update = False

        if proper_update is True:
            i = bisect_right(self.items, scene)
            if i > row:
                i -= 1
            if i != row:
                self.beginMoveRows(self.createIndex(row, 0), row, row,
                                   self.createIndex(i, 0), i)
                del self.items[row]
                self.items.insert(i, scene)
                self.endMoveRows()
            else:
                self.items[index.row()] = scene
                self.dataChanged.emit(index, index)
        else:
            self.items[index.row()] = scene
            self.dataChanged.emit(index, index)
        return True