Lint
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user