From 10e71466e1efc18684641d3aafd5a59bcf055ade Mon Sep 17 00:00:00 2001 From: "Christopher T. Johnson" Date: Sat, 8 Feb 2025 21:25:45 -0500 Subject: [PATCH] Make the display a bit cleaner --- scotus-pull.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scotus-pull.py b/scotus-pull.py index 40e12fc..eb445ac 100755 --- a/scotus-pull.py +++ b/scotus-pull.py @@ -3,7 +3,7 @@ import datetime import re import sys -from PySide6.QtCore import ( +from PySide6.QtCore import ( Qt, QCoreApplication, QModelIndex, QPersistentModelIndex, @@ -12,7 +12,7 @@ from PySide6.QtCore import ( Signal, Slot, ) -from PySide6.QtGui import QPainter, QTextDocument +from PySide6.QtGui import QBrush, QColor, QPainter, QPalette, QTextDocument from PySide6.QtSql import ( QSqlDatabase, QSqlQuery, @@ -37,11 +37,19 @@ translate = QCoreApplication.translate class dateDelegate(QStyledItemDelegate): - def displayText(self, value, locale) -> str: # type: ignore + def displayText(self, value, _) -> str: date = datetime.date.fromtimestamp(value) return date.strftime("%B %-d, %Y") +class activeDelegate(QStyledItemDelegate): + def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex | QPersistentModelIndex, /) -> None: + super().initStyleOption(option, index) + assert isinstance(index, QModelIndex) + if index.siblingAtColumn(6).data() == 0: + option.backgroundBrush = QColor(0x444444) + return + class documentDelegate(QStyledItemDelegate): def paint( self, @@ -104,6 +112,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.casesView.hideColumn(0) self.casesView.hideColumn(2) self.casesView.setItemDelegateForColumn(5, dateDelegate()) + self.casesView.setItemDelegate(activeDelegate()) self.casesView.resizeColumnToContents(1) self.casesView.resizeColumnToContents(5) header = self.casesView.horizontalHeader() @@ -165,6 +174,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): model: QSqlTableModel = self.casesView.model() # type: ignore query = model.query() query.exec() + model.setQuery(query) return