Skip to content

Commit

Permalink
Restore previous warning icon in the drives table
Browse files Browse the repository at this point in the history
- Doesn't have jagged edges due to resizing
- Is clearly visible on a white background, instead of being tiny and light yellow on white
- Being placed to the left visually separates drives to be erased from drives that shouldn't be erased
  (I also tried moving it to right but it doesn't look good and doesn't visually separate the drives)
- Makes the drives table header less crammed, with one less column
- Makes the drives table less crammed in general
- The icon is part of the same theme of all the other icons that appear on the left side of the window,
  instead of being the only icon from the right side that appears on the left
- Doesn't require a delegate (doing more with less code is always fun)
  • Loading branch information
lvps committed Nov 15, 2024
1 parent 60d9c27 commit 6bdf72c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
5 changes: 2 additions & 3 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
]

DRIVES_TABLE_NAME = 0
DRIVES_TABLE_STATUS = 1
DRIVES_TABLE_TARALLO_ID = 2
DRIVES_TABLE_DRIVE_SIZE = 3
DRIVES_TABLE_TARALLO_ID = 1
DRIVES_TABLE_DRIVE_SIZE = 2

QUEUE_TABLE = ["ID", "Process", "Disk", "Status", "Eta", "Progress"]

Expand Down
52 changes: 21 additions & 31 deletions pinolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def __init__(self):
def setup(self):
# Drives table
self.drivesTableView.setModel(self.drivesTableViewModel)
delegate = DrivesStatusIconDelegate(self.drivesTableView)
self.drivesTableView.setItemDelegateForColumn(DRIVES_TABLE_STATUS, delegate)
# delegate = DrivesStatusIconDelegate(self.drivesTableView)
# self.drivesTableView.setItemDelegateForColumn(DRIVES_TABLE_NAME, delegate)
self.drivesTableView.addActions([self.actionSleep, self.actionUmount, self.actionShow_SMART_data, self.actionUpload_to_Tarallo])
self.actionSleep.triggered.connect(self.sleep)
self.actionUmount.triggered.connect(self.umount)
Expand Down Expand Up @@ -802,13 +802,11 @@ def __init__(self, drive_data: dict):
self.mountpoints = drive_data["mountpoint"] if self.mounted else None
self.serial = drive_data["serial"]
self.size = drive_data["size"]
self.status = "warning" if self.mounted else None
self.tarallo_id = drive_data["code"]

def update(self, drive_data: dict):
self.mounted = True if drive_data["mountpoint"] else False
self.mountpoints = drive_data["mountpoint"] if self.mounted else None
self.status = "warning" if self.mounted else None
self.tarallo_id = drive_data["code"]


Expand All @@ -817,7 +815,12 @@ def __init__(self, parent: QTableView):
super().__init__()
self.parent = parent
self.drives: List[Drive] = []
self.header_labels = ["Drive", "Status", "Tarallo ID", "Size"]
self.header_labels = ["Drive", "Tarallo ID", "Size"]

if QIcon.hasThemeIcon("data-warning"):
self._mount_warning_icon = QIcon.fromTheme("data-warning")
else:
self._mount_warning_icon = QIcon.fromTheme("security-medium")

def rowCount(self, parent=...) -> int:
return len(self.drives)
Expand All @@ -839,19 +842,20 @@ def data(self, index: QModelIndex, role=...):
match attribute:
case "Drive":
return drive.name
case "Status":
return drive.status
case "Tarallo ID":
return drive.tarallo_id
case "Size":
return format_size(drive.size, True, False)

case Qt.DecorationRole:
if index.column() == DRIVES_TABLE_NAME:
return self._mount_warning_icon
case Qt.TextAlignmentRole:
return Qt.AlignLeft | Qt.AlignVCenter
case Qt.ToolTipRole:
drive = self.drives[index.row()]
if index.column() == DRIVES_TABLE_STATUS:
return drive.status
if index.column() == DRIVES_TABLE_NAME:
if drive.mounted:
return "Drive has mounted partitions"
case _:
return None

Expand Down Expand Up @@ -888,27 +892,13 @@ def clear(self):
self.endResetModel()


class DrivesStatusIconDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
super(DrivesStatusIconDelegate, self).__init__(parent)
self.icons = {
"started": QIcon("assets/table/progress.png"),
"pending": QIcon("assets/table/pending.png"),
"finished": QIcon("assets/table/ok.png"),
"warning": QIcon("assets/table/warning.png"),
}
self.margin = 5

def paint(self, painter, option, index):
if index.column() == DRIVES_TABLE_STATUS:
status: str = index.data()
if status in self.icons:
icon: QIcon = self.icons[status]
rect = option.rect.adjusted(self.margin, self.margin, -self.margin, -self.margin)
icon.paint(painter, rect)
return

super().paint(painter, option, index)
# class DrivesStatusIconDelegate(QStyledItemDelegate):
# def __init__(self, parent=None):
# super(DrivesStatusIconDelegate, self).__init__(parent)
#
# def initStyleOption(self, option, index):
# super().initStyleOption(option, index)
# option.decorationPosition = QtWidgets.QStyleOptionViewItem.Right


class LocalServer(QThread):
Expand Down

0 comments on commit 6bdf72c

Please sign in to comment.