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