Compare commits
11 Commits
e1d1946fa5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86ccee18fb | ||
|
|
b2d67f7aea | ||
|
|
71b0a6a112 | ||
|
|
69fa955be1 | ||
|
|
db4716b21b | ||
|
|
7fd369be74 | ||
|
|
30dd9b2bcd | ||
|
|
a6316f27f6 | ||
|
|
6129258f1b | ||
|
|
be07589f24 | ||
|
|
f952879753 |
@@ -1,3 +1,4 @@
|
||||
import enum
|
||||
from typing import Any, cast
|
||||
|
||||
from PySide6.QtCore import (
|
||||
@@ -79,11 +80,19 @@ class activeDelegate(QStyledItemDelegate):
|
||||
|
||||
|
||||
class casesModel(QSqlTableModel):
|
||||
class ColumnNames(enum.IntEnum):
|
||||
case_id = 0
|
||||
docket_id = 1
|
||||
petitioners = 2
|
||||
respondents = 3
|
||||
date = 4
|
||||
active = 5
|
||||
|
||||
def flags(self, index: QModelIndex | QPersistentModelIndex) -> Qt.ItemFlag:
|
||||
if not index.isValid():
|
||||
return Qt.ItemFlag.NoItemFlags
|
||||
flags = super(casesModel, self).flags(index)
|
||||
if index.column() == 5:
|
||||
if index.column() == casesModel.ColumnNames.active:
|
||||
flags = (
|
||||
Qt.ItemFlag.ItemIsEnabled
|
||||
| Qt.ItemFlag.ItemIsEditable
|
||||
@@ -98,7 +107,7 @@ class casesModel(QSqlTableModel):
|
||||
) -> Any:
|
||||
if not index.isValid():
|
||||
return None
|
||||
if index.column() == 5:
|
||||
if index.column() == casesModel.ColumnNames.active:
|
||||
if role == Qt.ItemDataRole.CheckStateRole:
|
||||
value = super(casesModel, self).data(index)
|
||||
return (
|
||||
@@ -116,7 +125,10 @@ class casesModel(QSqlTableModel):
|
||||
value: Any,
|
||||
role: int = Qt.ItemDataRole.DisplayRole,
|
||||
) -> bool:
|
||||
if role == Qt.ItemDataRole.CheckStateRole and index.column() == 5:
|
||||
if (
|
||||
role == Qt.ItemDataRole.CheckStateRole
|
||||
and index.column() == casesModel.ColumnNames.active
|
||||
):
|
||||
super(casesModel, self).setData(index, 1 if value else 0)
|
||||
return True
|
||||
return super().setData(index, value, role)
|
||||
@@ -139,11 +151,27 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
"1=1 ORDER BY SUBSTRING(docket_id, 1, 3), CAST(SUBSTRING(docket_id,4) AS INTEGER)"
|
||||
)
|
||||
model.select()
|
||||
model.setHeaderData(1, Qt.Orientation.Horizontal, "Docket")
|
||||
model.setHeaderData(2, Qt.Orientation.Horizontal, "Petitioners")
|
||||
model.setHeaderData(3, Qt.Orientation.Horizontal, "Respondents")
|
||||
model.setHeaderData(4, Qt.Orientation.Horizontal, "Date")
|
||||
model.setHeaderData(5, Qt.Orientation.Horizontal, "Active")
|
||||
model.setHeaderData(
|
||||
casesModel.ColumnNames.docket_id,
|
||||
Qt.Orientation.Horizontal,
|
||||
"Docket",
|
||||
)
|
||||
model.setHeaderData(
|
||||
casesModel.ColumnNames.petitioners,
|
||||
Qt.Orientation.Horizontal,
|
||||
"Petitioners",
|
||||
)
|
||||
model.setHeaderData(
|
||||
casesModel.ColumnNames.respondents,
|
||||
Qt.Orientation.Horizontal,
|
||||
"Respondents",
|
||||
)
|
||||
model.setHeaderData(
|
||||
casesModel.ColumnNames.date, Qt.Orientation.Horizontal, "Date"
|
||||
)
|
||||
model.setHeaderData(
|
||||
casesModel.ColumnNames.active, Qt.Orientation.Horizontal, "Active"
|
||||
)
|
||||
self.casesView.setModel(model)
|
||||
|
||||
self.casesView.setSelectionMode(
|
||||
@@ -152,23 +180,33 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.casesView.setSelectionBehavior(
|
||||
QAbstractItemView.SelectionBehavior.SelectRows
|
||||
)
|
||||
self.casesView.hideColumn(0)
|
||||
self.casesView.hideColumn(casesModel.ColumnNames.case_id)
|
||||
self.casesView.setItemDelegate(activeDelegate())
|
||||
self.casesView.setItemDelegateForColumn(4, dateDelegate())
|
||||
self.casesView.resizeColumnToContents(1)
|
||||
self.casesView.resizeColumnToContents(4)
|
||||
self.casesView.setItemDelegateForColumn(
|
||||
casesModel.ColumnNames.date, dateDelegate()
|
||||
)
|
||||
self.casesView.resizeColumnToContents(casesModel.ColumnNames.docket_id)
|
||||
self.casesView.resizeColumnToContents(casesModel.ColumnNames.date)
|
||||
header = self.casesView.horizontalHeader()
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
|
||||
header.setSectionResizeMode(3, QHeaderView.ResizeMode.Fixed)
|
||||
header.setSectionResizeMode(
|
||||
casesModel.ColumnNames.petitioners, QHeaderView.ResizeMode.Fixed
|
||||
)
|
||||
header.setSectionResizeMode(
|
||||
casesModel.ColumnNames.respondents, QHeaderView.ResizeMode.Fixed
|
||||
)
|
||||
self.show()
|
||||
remaining = (
|
||||
self.casesView.width()
|
||||
- header.sectionSize(1)
|
||||
- header.sectionSize(4)
|
||||
- header.sectionSize(casesModel.ColumnNames.docket_id)
|
||||
- header.sectionSize(casesModel.ColumnNames.date)
|
||||
- 5
|
||||
)
|
||||
self.casesView.setColumnWidth(2, int(remaining * 0.5))
|
||||
self.casesView.setColumnWidth(3, int(remaining * 0.5))
|
||||
self.casesView.setColumnWidth(
|
||||
casesModel.ColumnNames.petitioners, int(remaining * 0.5)
|
||||
)
|
||||
self.casesView.setColumnWidth(
|
||||
casesModel.ColumnNames.respondents, int(remaining * 0.5)
|
||||
)
|
||||
self.casesView.verticalHeader().hide()
|
||||
self.casesView.resizeRowsToContents()
|
||||
self.casesView.doubleClicked.connect(self.rowClicked)
|
||||
@@ -203,6 +241,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.loadButton.clicked.connect(self.loadCases)
|
||||
self.update_status.connect(self.statusBarUpdate)
|
||||
self.update_status.emit()
|
||||
self.docketLabel.setText("")
|
||||
return
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import datetime
|
||||
from typing import Any, cast
|
||||
import enum
|
||||
from typing import Any
|
||||
|
||||
from PySide6.QtCore import (
|
||||
QAbstractTableModel,
|
||||
QDate,
|
||||
QDateTime,
|
||||
QModelIndex,
|
||||
QPersistentModelIndex,
|
||||
Qt,
|
||||
@@ -18,6 +17,10 @@ from lib.utils import query_error
|
||||
class docketModel(QAbstractTableModel):
|
||||
entries: list[list[str | None]] = []
|
||||
|
||||
class ColumnNames(enum.IntEnum):
|
||||
date = 0
|
||||
text = 1
|
||||
|
||||
def __init__(self, case_id: int | None = None) -> None:
|
||||
super(docketModel, self).__init__()
|
||||
if case_id == None:
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from typing import cast
|
||||
|
||||
from PySide6.QtCore import (
|
||||
QAbstractItemModel,
|
||||
QDir,
|
||||
QFile,
|
||||
QModelIndex,
|
||||
QObject,
|
||||
QPersistentModelIndex,
|
||||
QPoint,
|
||||
QPointF,
|
||||
QRect,
|
||||
QSize,
|
||||
Qt,
|
||||
QUrl,
|
||||
@@ -16,7 +16,7 @@ from PySide6.QtCore import (
|
||||
)
|
||||
from PySide6.QtGui import (
|
||||
QMouseEvent,
|
||||
QPalette,
|
||||
QPainter,
|
||||
QTextDocument,
|
||||
)
|
||||
from PySide6.QtNetwork import (
|
||||
@@ -26,7 +26,7 @@ from PySide6.QtNetwork import (
|
||||
)
|
||||
from PySide6.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QSizePolicy,
|
||||
QStyle,
|
||||
QStyledItemDelegate,
|
||||
QStyleOptionViewItem,
|
||||
QTableView,
|
||||
@@ -34,6 +34,7 @@ from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from lib.utils import QStyleOptionViewItemInit
|
||||
from pdfView import PDFViewer
|
||||
|
||||
|
||||
@@ -47,43 +48,43 @@ class docketEntryDelegate(QStyledItemDelegate):
|
||||
|
||||
def sizeHint(
|
||||
self,
|
||||
_: QStyleOptionViewItem,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
) -> QSize:
|
||||
widget = self.view.indexWidget(index)
|
||||
return widget.sizeHint()
|
||||
|
||||
|
||||
class docketEntry(QTextEdit):
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super(docketEntry, self).__init__(parent)
|
||||
self.setSizePolicy(
|
||||
QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed
|
||||
)
|
||||
return
|
||||
|
||||
def mousePressEvent(self, e: QMouseEvent) -> None:
|
||||
super().mousePressEvent(e)
|
||||
anchor = self.anchorAt(e.pos())
|
||||
if anchor:
|
||||
obj = cast(QObject, self)
|
||||
while not isinstance(obj, docketTableView) and obj is not None:
|
||||
obj = obj.parent()
|
||||
assert obj is not None
|
||||
index = obj.indexAt(obj.mapFromGlobal(self.mapToGlobal(e.pos())))
|
||||
obj.anchorSignal.emit(index, anchor)
|
||||
return
|
||||
|
||||
def sizeHint(self) -> QSize:
|
||||
size = self.size()
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
doc = QTextDocument()
|
||||
doc.setPlainText(self.document().toPlainText())
|
||||
doc.setTextWidth(size.width())
|
||||
docSize = doc.size()
|
||||
return QSize(size.width(), int(docSize.height()))
|
||||
doc.setHtml(options.text)
|
||||
doc.setTextWidth(options.rect.width())
|
||||
return QSize(int(doc.idealWidth()), int(doc.size().height()))
|
||||
|
||||
def paint(
|
||||
self,
|
||||
painter: QPainter,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
) -> None:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
painter.save()
|
||||
|
||||
doc = QTextDocument()
|
||||
doc.setHtml(options.text)
|
||||
doc.setTextWidth(options.rect.width())
|
||||
|
||||
options.text = ""
|
||||
options.widget.style().drawControl(
|
||||
QStyle.ControlElement.CE_ItemViewItem, options, painter
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
class docketTableView(QTableView):
|
||||
|
||||
manager: QNetworkAccessManager
|
||||
clickedEvent = Signal(QPoint)
|
||||
anchorSignal = Signal(QModelIndex, str)
|
||||
@@ -97,12 +98,6 @@ class docketTableView(QTableView):
|
||||
self.manager.finished.connect(self.getDone)
|
||||
return
|
||||
|
||||
def setModel(self, model: QAbstractItemModel | None) -> None:
|
||||
assert model is not None
|
||||
super().setModel(model)
|
||||
self.model().modelReset.connect(self.modelReset)
|
||||
return
|
||||
|
||||
@Slot(QNetworkReply) # type: ignore
|
||||
def getDone(self, reply: QNetworkReply) -> None:
|
||||
dest = QFile("." + reply.url().path())
|
||||
@@ -134,16 +129,36 @@ class docketTableView(QTableView):
|
||||
self.manager.get(QNetworkRequest(url))
|
||||
return
|
||||
|
||||
def modelReset(self) -> None:
|
||||
model = self.model()
|
||||
red = QPalette()
|
||||
red.setColor(QPalette.ColorRole.Base, Qt.GlobalColor.red)
|
||||
for row in range(0, model.rowCount()):
|
||||
index = model.index(row, 1)
|
||||
widget = docketEntry()
|
||||
widget.setHtml(model.data(index, Qt.ItemDataRole.DisplayRole))
|
||||
widget.setAutoFillBackground(False)
|
||||
widget.setReadOnly(True)
|
||||
widget.setPalette(red)
|
||||
self.setIndexWidget(index, widget)
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None:
|
||||
#
|
||||
# The mouse has been pressed somewere in our rect. We need to translate that to a click
|
||||
# within the cell with the document. This will allow the document to find anchors.
|
||||
#
|
||||
index = self.indexAt(event.pos())
|
||||
if not index.isValid():
|
||||
return
|
||||
if index.column() != 1:
|
||||
return
|
||||
doc = QTextDocument()
|
||||
doc.setHtml(index.data(Qt.ItemDataRole.DisplayRole))
|
||||
doc.setTextWidth(self.columnWidth(index.column()))
|
||||
#
|
||||
# We need to map our click position to a position within the cell.
|
||||
#
|
||||
pos = event.position()
|
||||
new_pos = QPointF(
|
||||
pos.x() - self.horizontalScrollBar().value(),
|
||||
pos.y() - self.verticalScrollBar().value(),
|
||||
)
|
||||
rowHeight = 0
|
||||
for row in range(0, index.row()):
|
||||
rowHeight += self.rowHeight(row)
|
||||
cell_pos = QPointF(
|
||||
new_pos.x() - self.columnWidth(0), new_pos.y() - rowHeight
|
||||
)
|
||||
te = QTextEdit()
|
||||
te.setDocument(doc)
|
||||
anchor = te.anchorAt(cell_pos.toPoint())
|
||||
if anchor:
|
||||
self.anchorSignal.emit(index, anchor)
|
||||
return
|
||||
|
||||
17
pdfView.py
17
pdfView.py
@@ -1,7 +1,7 @@
|
||||
import math
|
||||
|
||||
from PySide6.QtCore import QFile, QModelIndex, QPoint, Signal, Slot
|
||||
from PySide6.QtGui import QCloseEvent
|
||||
from PySide6.QtCore import QFile, QModelIndex, QPoint, QSize, Signal, Slot
|
||||
from PySide6.QtGui import QCloseEvent, QGuiApplication
|
||||
from PySide6.QtPdf import QPdfBookmarkModel, QPdfDocument
|
||||
from PySide6.QtPdfWidgets import QPdfView
|
||||
from PySide6.QtWidgets import QComboBox, QDialog, QMenuBar, QSpinBox, QWidget
|
||||
@@ -118,16 +118,13 @@ class PDFViewer(QDialog, Ui_pdfViewer):
|
||||
return
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
print("closeEvent")
|
||||
writeGeometry(self)
|
||||
super().closeEvent(event)
|
||||
return
|
||||
|
||||
@Slot(QFile) # type: ignore
|
||||
def open(self, file: QFile) -> None:
|
||||
# assert file.exists()
|
||||
# if not file.isOpen():
|
||||
# file.open(QFile.OpenModeFlag.ReadOnly)
|
||||
# self.document.load(file)
|
||||
self.document.load(file.fileName())
|
||||
document_title = self.document.metaData(
|
||||
QPdfDocument.MetaDataField.Title
|
||||
@@ -135,6 +132,14 @@ class PDFViewer(QDialog, Ui_pdfViewer):
|
||||
self.setWindowTitle(document_title if document_title else "PDF Viewer")
|
||||
self.page_selected(0)
|
||||
self.pageSelector.setMaximum(self.document.pageCount() - 1)
|
||||
if self.zoomSelector.currentIndex() == 8:
|
||||
pageSize = self.document.pagePointSize(0)
|
||||
dpi = QGuiApplication.primaryScreen().physicalDotsPerInch()
|
||||
size = QSize(
|
||||
int(pageSize.width() / 72 * dpi), self.pdfView.height()
|
||||
)
|
||||
self.pdfView.resize(size)
|
||||
self.splitter.setSizes([100, size.width()])
|
||||
return
|
||||
|
||||
@Slot(QModelIndex) # type: ignore
|
||||
|
||||
@@ -35,8 +35,9 @@ def main() -> int:
|
||||
updateDatabase(settings)
|
||||
db = QSqlDatabase.addDatabase("QMYSQL")
|
||||
db.setHostName(settings.value("hostname"))
|
||||
portStr = cast(str, settings.value("port", "3306"))
|
||||
db.setPort(int(portStr))
|
||||
port = settings.value("port", "3306")
|
||||
assert isinstance(port, str)
|
||||
db.setPort(int(port))
|
||||
db.setDatabaseName(settings.value("databasename", "scotus")) # type: ignore
|
||||
db.setUserName(settings.value("user", "scotus")) # type: ignore
|
||||
db.setPassword(settings.value("password"))
|
||||
|
||||
87
scotusPdfView.py
Normal file
87
scotusPdfView.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from PySide6.QtCore import QEvent, QObject, QPointF, QRect, QRectF, Qt
|
||||
from PySide6.QtGui import QColor, QMouseEvent, QPaintEvent, QPainter, QPen
|
||||
from PySide6.QtPdfWidgets import QPdfView
|
||||
from PySide6.QtWidgets import QApplication, QWidget
|
||||
|
||||
def printParentHierarchy(obj: QObject, indent: int = 0):
|
||||
if obj:
|
||||
indentStr = ' ' * indent * 2
|
||||
print(f"{indentStr}{obj.metaObject().className()}:{obj.objectName()}")
|
||||
printParentHierarchy(obj.parent(), indent + 1)
|
||||
return
|
||||
|
||||
class scotusPdfView(QPdfView):
|
||||
|
||||
drawing: bool
|
||||
start_point: QPointF
|
||||
end_point: QPointF
|
||||
|
||||
def formatRect(self, rect: QRectF|QRect) -> str:
|
||||
return f"({rect.left()},{rect.top()}):({rect.right()},{rect.bottom()})"
|
||||
|
||||
def __init__(self, parent: QWidget) -> None:
|
||||
self.drawing = False
|
||||
super(scotusPdfView, self).__init__(parent)
|
||||
print(self.viewport())
|
||||
return
|
||||
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
super(scotusPdfView,self).paintEvent(event)
|
||||
if self.drawing:
|
||||
page = self.pageNavigator().currentPage()
|
||||
viewport = self.viewport()
|
||||
painter = QPainter(viewport)
|
||||
doc = self.document()
|
||||
dpi = QApplication.primaryScreen().logicalDotsPerInch()
|
||||
#
|
||||
# XXX: Our mouse events are storing coordinates in the "self"
|
||||
# coordinate system. We need them in the viewport system
|
||||
#
|
||||
|
||||
rect = QRectF(viewport.mapFrom(self, self.start_point),
|
||||
viewport.mapFrom(self, self.end_point))
|
||||
redSolid = QPen(Qt.GlobalColor.red, 2, Qt.PenStyle.SolidLine)
|
||||
blueDash = QPen(Qt.GlobalColor.blue, 2, Qt.PenStyle.DashLine)
|
||||
greenDash = QPen(Qt.GlobalColor.green, 2, Qt.PenStyle.DashLine)
|
||||
painter.setPen(redSolid)
|
||||
painter.drawRect(rect) # Mouse drag box
|
||||
|
||||
selectRect = QRectF(rect.left()/dpi*72,
|
||||
rect.top()/dpi*72,
|
||||
rect.right()/dpi*72,
|
||||
rect.bottom()/dpi*72)
|
||||
painter.setPen(blueDash)
|
||||
selection = doc.getSelectionAtIndex(page, 10, 50)
|
||||
selection = doc.getSelection(page, selectRect.topLeft(), selectRect.bottomRight())
|
||||
bb = selection.boundingRectangle()
|
||||
painter.drawRect(bb) # Selection bounding box
|
||||
print(selection.text())
|
||||
print()
|
||||
|
||||
painter.setPen(greenDash)
|
||||
bb.setLeft(bb.left()/72*dpi)
|
||||
bb.setTop(bb.top()/72*dpi)
|
||||
bb.setRight(bb.right()/72*dpi)
|
||||
bb.setBottom(bb.bottom()/72*dpi)
|
||||
painter.drawRect(bb) # Selection translated into viewport coordinates?
|
||||
return
|
||||
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None:
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
self.start_point = event.pos()
|
||||
self.drawing = True
|
||||
return
|
||||
|
||||
def mouseMoveEvent(self, event: QMouseEvent) -> None:
|
||||
if self.drawing:
|
||||
pos = event.pos()
|
||||
self.end_point = pos
|
||||
viewport = self.viewport()
|
||||
viewport.update()
|
||||
return
|
||||
|
||||
def mouseReleaseEvent(self, event: QMouseEvent) -> None:
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
self.drawing = False
|
||||
self.viewport().update()
|
||||
return
|
||||
@@ -16,11 +16,12 @@ from PySide6.QtGui import (QAction, QBrush, QColor, QConicalGradient,
|
||||
QIcon, QImage, QKeySequence, QLinearGradient,
|
||||
QPainter, QPalette, QPixmap, QRadialGradient,
|
||||
QTransform)
|
||||
from PySide6.QtPdfWidgets import QPdfView
|
||||
from PySide6.QtWidgets import (QApplication, QDialog, QHeaderView, QSizePolicy,
|
||||
QSplitter, QTabWidget, QToolBar, QTreeView,
|
||||
QVBoxLayout, QWidget)
|
||||
import ui.resources_rc
|
||||
|
||||
from scotusPdfView import scotusPdfView
|
||||
import resources_rc
|
||||
|
||||
class Ui_pdfViewer(object):
|
||||
def setupUi(self, pdfViewer):
|
||||
@@ -107,7 +108,7 @@ class Ui_pdfViewer(object):
|
||||
self.pagesTab.setObjectName(u"pagesTab")
|
||||
self.tabWidget.addTab(self.pagesTab, "")
|
||||
self.splitter.addWidget(self.tabWidget)
|
||||
self.pdfView = QPdfView(self.splitter)
|
||||
self.pdfView = scotusPdfView(self.splitter)
|
||||
self.pdfView.setObjectName(u"pdfView")
|
||||
sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
sizePolicy1.setHorizontalStretch(10)
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPdfView" name="pdfView" native="true">
|
||||
<widget class="scotusPdfView" name="pdfView" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>10</horstretch>
|
||||
@@ -215,9 +215,9 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QPdfView</class>
|
||||
<class>scotusPdfView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qpdfview.h</header>
|
||||
<header>scotusPdfView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
|
||||
39
workers.py
39
workers.py
@@ -106,7 +106,6 @@ def update_db(case_id: str, db: QSqlDatabase) -> int:
|
||||
#
|
||||
# We assume that case_id == docket_id at this point. If it does not,
|
||||
# then we will build out from the request we get
|
||||
print(f"Updating {case_id}")
|
||||
matches = re.match(r"(\d\d)[-A](\d+)(.*)$", case_id)
|
||||
if matches is None:
|
||||
raise Exception(f"Not a match {case_id}")
|
||||
@@ -129,12 +128,16 @@ def update_db(case_id: str, db: QSqlDatabase) -> int:
|
||||
r = requests.get(
|
||||
f"https://www.supremecourt.gov/docket/docketfiles/html/public/{case_id}.html"
|
||||
)
|
||||
if r.status_code == 404:
|
||||
return -1
|
||||
|
||||
if r.status_code != 200:
|
||||
print(r.status_code)
|
||||
exit(1)
|
||||
bs = BeautifulSoup(r.text, "lxml")
|
||||
#
|
||||
# SCOTUS does not return 404 for page not found.
|
||||
# Feb 27: SCOTUS is returning 404s but I don't trust them.
|
||||
#
|
||||
title = bs.find("title")
|
||||
assert isinstance(title, Tag) and isinstance(title.string, str)
|
||||
@@ -260,13 +263,13 @@ def update_db(case_id: str, db: QSqlDatabase) -> int:
|
||||
query.bindValue(":rhs", linked_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
if re.match(r"\d+-\d+$", docket_id):
|
||||
deactivate = False
|
||||
if deactivate:
|
||||
query.prepare("UPDATE cases SET active=0 WHERE case_id = :cid")
|
||||
query.bindValue(":cid", case_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
if re.match(r"\d+-\d+$", docket_id):
|
||||
deactivate = False
|
||||
if deactivate:
|
||||
query.prepare("UPDATE cases SET active=0 WHERE case_id = :cid")
|
||||
query.bindValue(":cid", case_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
|
||||
#
|
||||
# XXX - Process lower courts
|
||||
@@ -297,7 +300,7 @@ class updateThread(QThread):
|
||||
print(db.lastError())
|
||||
raise Exception("db.open()")
|
||||
|
||||
case_id = update_db(str(self.docket_id), db)
|
||||
update_db(str(self.docket_id), db)
|
||||
db.close()
|
||||
del db
|
||||
QSqlDatabase.removeDatabase("update")
|
||||
@@ -308,6 +311,7 @@ class loadCases(QThread):
|
||||
caseLoaded = Signal(int)
|
||||
year = QDateTime.currentDateTime().toString("yy")
|
||||
number = 0
|
||||
edocket = 0
|
||||
|
||||
def run(self) -> None:
|
||||
db = QSqlDatabase.cloneDatabase("qt_sql_default_connection", "load")
|
||||
@@ -344,15 +348,31 @@ class loadCases(QThread):
|
||||
docket_id = f"{self.year}A{self.number}"
|
||||
else:
|
||||
docket_id = f"{self.year}-{self.number}"
|
||||
print(f"Updating: {docket_id} ", end='')
|
||||
query.bindValue(":did", docket_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
if query.next():
|
||||
if query.value("active") == 0:
|
||||
self.number += 1
|
||||
print("INACTIVE")
|
||||
continue
|
||||
print()
|
||||
result = update_db(docket_id, db)
|
||||
if result < 0:
|
||||
if edocket == 0:
|
||||
edocket = 1
|
||||
self.number = 1
|
||||
query.prepare("UPDATE history SET number = :number, "
|
||||
"edocket=:edocket "
|
||||
"WHERE history_id=:hid")
|
||||
query.bindValue(':number', 1)
|
||||
query.bindValue(':edocket', 1)
|
||||
query.bindValue(':hid', history_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
continue
|
||||
edocket = 0
|
||||
self.year = f"{int(self.year) - 1:02d}"
|
||||
if self.number > 1:
|
||||
query.prepare(
|
||||
@@ -387,6 +407,7 @@ class loadCases(QThread):
|
||||
|
||||
self.number += 1
|
||||
count += 1
|
||||
self.number -= 1
|
||||
if self.number > 1:
|
||||
query.prepare(
|
||||
"UPDATE history SET number= :number WHERE year = :year"
|
||||
|
||||
Reference in New Issue
Block a user