Lint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from typing import Any
|
||||
|
||||
from PySide6.QtCore import (
|
||||
QAbstractTableModel,
|
||||
@@ -54,9 +55,11 @@ class docketModel(QAbstractTableModel):
|
||||
) -> int:
|
||||
return 2
|
||||
|
||||
def data(self, index: QModelIndex | QPersistentModelIndex, role: int = 0):
|
||||
def data(
|
||||
self, index: QModelIndex | QPersistentModelIndex, role: int = 0
|
||||
) -> Any:
|
||||
if not index.isValid():
|
||||
return ""
|
||||
return None
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
return self.entries[index.row()][index.column()]
|
||||
if role == Qt.ItemDataRole.TextAlignmentRole and index.column() == 0:
|
||||
@@ -65,13 +68,13 @@ class docketModel(QAbstractTableModel):
|
||||
|
||||
def headerData(
|
||||
self, section: int, orientation: Qt.Orientation, role: int = 0
|
||||
):
|
||||
) -> str | None | QFont:
|
||||
if orientation == Qt.Orientation.Vertical:
|
||||
return
|
||||
return None
|
||||
if role == Qt.ItemDataRole.FontRole:
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
return font
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return
|
||||
return None
|
||||
return ["Date", "Proceedings and Orders"][section]
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
import datetime
|
||||
import re
|
||||
import sys
|
||||
from typing import Any, cast
|
||||
|
||||
from PySide6.QtCore import ( Qt,
|
||||
from PySide6.QtCore import (
|
||||
QCoreApplication,
|
||||
QModelIndex,
|
||||
QPersistentModelIndex,
|
||||
@@ -12,7 +13,7 @@ from PySide6.QtCore import ( Qt,
|
||||
Signal,
|
||||
Slot,
|
||||
)
|
||||
from PySide6.QtGui import QBrush, QColor, QPainter, QPalette, QTextDocument
|
||||
from PySide6.QtGui import QColor, QPainter, QTextDocument
|
||||
from PySide6.QtSql import (
|
||||
QSqlDatabase,
|
||||
QSqlQuery,
|
||||
@@ -26,51 +27,79 @@ from PySide6.QtWidgets import (
|
||||
QStyle,
|
||||
QStyledItemDelegate,
|
||||
QStyleOptionViewItem,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from docketModel import docketModel
|
||||
from lib.utils import query_error
|
||||
from ui.MainWindow import Ui_MainWindow
|
||||
from workers import updateThread
|
||||
from workers import loadCases, updateThread
|
||||
|
||||
translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class dateDelegate(QStyledItemDelegate):
|
||||
def displayText(self, value, _) -> str:
|
||||
def displayText(self, value: int, _: Any) -> str:
|
||||
date = datetime.date.fromtimestamp(value)
|
||||
return date.strftime("%B %-d, %Y")
|
||||
|
||||
|
||||
class QStyleOptionViewItemInit(QStyleOptionViewItem):
|
||||
backgroundBrush: QColor
|
||||
rect: QRect
|
||||
widget: QWidget
|
||||
text: str
|
||||
|
||||
|
||||
class activeDelegate(QStyledItemDelegate):
|
||||
def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex | QPersistentModelIndex, /) -> None:
|
||||
super().initStyleOption(option, index)
|
||||
def initStyleOption(
|
||||
self,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
/,
|
||||
) -> None:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
super().initStyleOption(options, index)
|
||||
assert isinstance(index, QModelIndex)
|
||||
if index.siblingAtColumn(6).data() == 0:
|
||||
option.backgroundBrush = QColor(0x444444)
|
||||
return
|
||||
options.backgroundBrush = QColor(0x444444)
|
||||
return
|
||||
|
||||
|
||||
class documentDelegate(QStyledItemDelegate):
|
||||
def initStyleOption(
|
||||
self,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
/,
|
||||
) -> None:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
super().initStyleOption(options, index)
|
||||
assert index.isValid() and isinstance(index, QModelIndex)
|
||||
if index.siblingAtColumn(6).data() == 0:
|
||||
options.backgroundBrush = QColor(0x444444)
|
||||
return
|
||||
|
||||
def paint(
|
||||
self,
|
||||
painter: QPainter,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
):
|
||||
options = option
|
||||
) -> None:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
painter.save()
|
||||
doc = QTextDocument()
|
||||
doc.setTextWidth(option.rect.width()) # type: ignore
|
||||
doc.setHtml(option.text) # type: ignore
|
||||
option.text = "" # type: ignore
|
||||
option.widget.style().drawControl( # type: ignore
|
||||
doc.setTextWidth(options.rect.width())
|
||||
doc.setHtml(options.text)
|
||||
options.text = ""
|
||||
options.widget.style().drawControl(
|
||||
QStyle.ControlElement.CE_ItemViewItem,
|
||||
option,
|
||||
options,
|
||||
painter,
|
||||
)
|
||||
painter.translate(option.rect.left(), options.rect.top()) # type: ignore
|
||||
clip = QRect(0, 0, option.rect.width(), option.rect.height()) # type: ignore
|
||||
painter.translate(options.rect.left(), options.rect.top())
|
||||
clip = QRect(0, 0, options.rect.width(), options.rect.height())
|
||||
doc.drawContents(painter, clip)
|
||||
painter.restore()
|
||||
return
|
||||
@@ -80,24 +109,33 @@ class documentDelegate(QStyledItemDelegate):
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
) -> QSize:
|
||||
self.initStyleOption(option, index)
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
doc = QTextDocument()
|
||||
doc.setTextWidth(option.rect.width()) # type: ignore
|
||||
doc.setHtml(option.text) # type: ignore
|
||||
doc.setTextWidth(option.rect.width()) # type: ignore
|
||||
doc.setTextWidth(options.rect.width())
|
||||
doc.setHtml(options.text)
|
||||
doc.setTextWidth(options.rect.width())
|
||||
return QSize(int(doc.idealWidth()), int(doc.size().height()))
|
||||
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
show_entries = Signal(int)
|
||||
|
||||
loadThread = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
self.setupUi(self)
|
||||
self.loadThread = loadCases()
|
||||
self.loadThread.finished.connect(self.updateDone)
|
||||
self.loadThread.start()
|
||||
|
||||
# model = QSqlQueryModel()
|
||||
model = QSqlTableModel()
|
||||
query = QSqlQuery("SELECT * FROM cases ORDER BY docket_id")
|
||||
query = QSqlQuery(
|
||||
"SELECT * FROM cases ORDER BY SUBSTR(docket_id,1,3), "
|
||||
"CAST(SUBSTR(docket_id,4) AS INT)"
|
||||
)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
model.setQuery(query)
|
||||
@@ -156,7 +194,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
updateThread = None
|
||||
|
||||
@Slot()
|
||||
def on_updateButton_clicked(self):
|
||||
def on_updateButton_clicked(self) -> None:
|
||||
text = self.docketInput.toPlainText()
|
||||
print(f"on_updateButton_clicked(): {text}")
|
||||
if not self.updateThread:
|
||||
@@ -168,10 +206,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
return
|
||||
|
||||
@Slot()
|
||||
def updateDone(self):
|
||||
def updateDone(self) -> None:
|
||||
self.updateThread = None
|
||||
print("Done updating")
|
||||
model: QSqlTableModel = self.casesView.model() # type: ignore
|
||||
model: QSqlTableModel = cast(QSqlTableModel, self.casesView.model())
|
||||
query = model.query()
|
||||
query.exec()
|
||||
model.setQuery(query)
|
||||
@@ -302,7 +340,7 @@ def main() -> int:
|
||||
db.setDatabaseName("scotus.db")
|
||||
db.open()
|
||||
schema_update(db)
|
||||
window = MainWindow()
|
||||
MainWindow()
|
||||
return app.exec()
|
||||
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ def update_db(case_id) -> int:
|
||||
else:
|
||||
active = True
|
||||
if not active:
|
||||
return query.value("case_id")
|
||||
return int(query.value("case_id"))
|
||||
|
||||
r = requests.get(
|
||||
f"https://www.supremecourt.gov/docket/docketfiles/html/public/{case_id}.html"
|
||||
|
||||
Reference in New Issue
Block a user