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