Remove debug and misc. cleanup
This commit is contained in:
@@ -8,7 +8,6 @@ from PySide6.QtCore import (
|
||||
QObject,
|
||||
QPersistentModelIndex,
|
||||
QPoint,
|
||||
QRect,
|
||||
QSize,
|
||||
Qt,
|
||||
QUrl,
|
||||
@@ -16,11 +15,7 @@ from PySide6.QtCore import (
|
||||
Slot,
|
||||
)
|
||||
from PySide6.QtGui import (
|
||||
QColor,
|
||||
QFont,
|
||||
QMouseEvent,
|
||||
QPaintEvent,
|
||||
QPainter,
|
||||
QPalette,
|
||||
QTextDocument,
|
||||
)
|
||||
@@ -30,8 +25,8 @@ from PySide6.QtNetwork import (
|
||||
QNetworkRequest,
|
||||
)
|
||||
from PySide6.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QSizePolicy,
|
||||
QStyle,
|
||||
QStyledItemDelegate,
|
||||
QStyleOptionViewItem,
|
||||
QTableView,
|
||||
@@ -41,68 +36,16 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from pdfView import PDFViewer
|
||||
|
||||
|
||||
class QStyleOptionViewItemInit(QStyleOptionViewItem):
|
||||
backgroundBrush: QColor
|
||||
rect: QRect
|
||||
widget: QWidget
|
||||
font: QFont
|
||||
text: str
|
||||
|
||||
|
||||
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)
|
||||
class docketEntryDelegate(QStyledItemDelegate):
|
||||
def __init__(self, view: QAbstractItemView, parent: QWidget|None = None) -> None:
|
||||
super(docketEntryDelegate, self).__init__(parent)
|
||||
self.view = view
|
||||
return
|
||||
|
||||
def paint(
|
||||
self,
|
||||
painter: QPainter,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
) -> None:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
painter.save()
|
||||
doc = QTextDocument()
|
||||
doc.setTextWidth(options.rect.width())
|
||||
doc.setHtml(options.text)
|
||||
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
|
||||
|
||||
def sizeHint(
|
||||
self,
|
||||
option: QStyleOptionViewItem,
|
||||
index: QModelIndex | QPersistentModelIndex,
|
||||
) -> QSize:
|
||||
options = cast(QStyleOptionViewItemInit, option)
|
||||
self.initStyleOption(options, index)
|
||||
doc = QTextDocument()
|
||||
doc.setTextWidth(options.rect.width())
|
||||
doc.setHtml(options.text)
|
||||
doc.setTextWidth(options.rect.width())
|
||||
print(f"sizeHint: {doc.idealWidth()}, {doc.size().height()}")
|
||||
return QSize(int(doc.idealWidth()), int(doc.size().height()))
|
||||
|
||||
|
||||
def sizeHint(self, _: 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)
|
||||
@@ -113,9 +56,7 @@ class docketEntry(QTextEdit):
|
||||
def mousePressEvent(self, e: QMouseEvent) -> None:
|
||||
super().mousePressEvent(e)
|
||||
anchor = self.anchorAt(e.pos())
|
||||
print(f"self.size(): {self.size()}")
|
||||
if anchor:
|
||||
print(f"Anchors away: {anchor}")
|
||||
obj = cast(QObject, self)
|
||||
while not isinstance(obj, docketTableView) and obj is not None:
|
||||
obj = obj.parent()
|
||||
@@ -132,20 +73,17 @@ class docketEntry(QTextEdit):
|
||||
docSize = doc.size()
|
||||
return QSize(size.width(), int(docSize.height()))
|
||||
|
||||
def paintEvent(self, e: QPaintEvent) -> None:
|
||||
print(f"event.rect: {e.rect()}, size: {self.size()}")
|
||||
print(self.document().toPlainText())
|
||||
return super().paintEvent(e)
|
||||
|
||||
|
||||
class docketTableView(QTableView):
|
||||
manager = QNetworkAccessManager()
|
||||
manager: QNetworkAccessManager
|
||||
clickedEvent = Signal(QPoint)
|
||||
anchorSignal = Signal(QModelIndex, str)
|
||||
pdf: PDFViewer
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super(docketTableView, self).__init__(parent)
|
||||
self.setItemDelegateForColumn(1,docketEntryDelegate(self))
|
||||
self.anchorSignal.connect(self.doAnchor)
|
||||
self.manager = QNetworkAccessManager()
|
||||
self.manager.finished.connect(self.getDone)
|
||||
return
|
||||
|
||||
@@ -153,7 +91,6 @@ class docketTableView(QTableView):
|
||||
assert model is not None
|
||||
super().setModel(model)
|
||||
self.model().modelReset.connect(self.modelReset)
|
||||
print("Setting Model")
|
||||
return
|
||||
|
||||
@Slot(QNetworkReply) # type: ignore
|
||||
@@ -163,27 +100,27 @@ class docketTableView(QTableView):
|
||||
dest.write(reply.readAll())
|
||||
dest.close()
|
||||
reply.deleteLater()
|
||||
self.pdf = PDFViewer(self)
|
||||
self.pdf.load_pdf(dest)
|
||||
self.pdf.open(dest)
|
||||
self.pdf.show()
|
||||
return
|
||||
|
||||
@Slot(QModelIndex, str) # type: ignore
|
||||
def doAnchor(self, index: QModelIndex, anchor: str) -> None:
|
||||
def doAnchor(self, _: QModelIndex, anchor: str) -> None:
|
||||
url = QUrl(anchor)
|
||||
print(f"{index.row()}, {index.column()} -> {url.path()}")
|
||||
dirs = url.path().split("/")
|
||||
dirs.pop()
|
||||
dirs.pop(0)
|
||||
currentDir = QDir()
|
||||
path = "/".join(dirs)
|
||||
currentDir.mkpath(path)
|
||||
if QDir("." + url.path()).exists():
|
||||
file = QFile("." + url.path())
|
||||
print(f"Checking for .{url.path()} existance.")
|
||||
if not hasattr(self, 'pdf'):
|
||||
self.pdf = PDFViewer(self)
|
||||
self.pdf.load_pdf(file)
|
||||
if QFile("." + url.path()).exists():
|
||||
self.pdf.open(QFile('.' + url.path()))
|
||||
self.pdf.show()
|
||||
else:
|
||||
print(f"Fetching {url}")
|
||||
self.manager.get(QNetworkRequest(url))
|
||||
return
|
||||
|
||||
@@ -200,16 +137,3 @@ class docketTableView(QTableView):
|
||||
widget.setPalette(red)
|
||||
self.setIndexWidget(index, widget)
|
||||
return
|
||||
|
||||
def paintEvent(self, e: QPaintEvent) -> None:
|
||||
|
||||
for row in range(0, self.model().rowCount()):
|
||||
index = self.model().index(row, 1)
|
||||
widget = cast(docketEntry, self.indexWidget(index))
|
||||
print(f"{row}: {widget.toPlainText()}")
|
||||
print(f"{row}: {widget.sizeHint()}")
|
||||
print(f"{row}: {widget.size()}")
|
||||
print()
|
||||
widget.resize(75,27)
|
||||
super().paintEvent(e)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user