From cba8aa778e74a68462fb30fe7e1e5a1f14951d22 Mon Sep 17 00:00:00 2001 From: Blaine Date: Sat, 13 Jun 2020 16:45:05 +0530 Subject: implement streamTable base --- src/main/python/utils/canvas.py | 22 +++++++++--- src/main/python/utils/fileWindow.py | 2 ++ src/main/python/utils/streamTable.py | 70 ++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 src/main/python/utils/streamTable.py (limited to 'src/main') diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 480a2e1..4d1fda4 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -1,12 +1,13 @@ -from PyQt5.QtCore import Qt, QPointF +from PyQt5.QtCore import Qt, QPointF, QRectF from PyQt5.QtGui import QBrush, QPalette from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu, - QTabWidget, QWidget, QSpacerItem, QStyle,) + QTabWidget, QWidget, QSpacerItem, QStyle, QGraphicsProxyWidget) from . import dialogs from .graphics import customView, customScene from .data import paperSizes, ppiList, sheetDimensionList from .app import shapeGrips, lines +from .streamTable import streamTable, moveRect import shapes @@ -24,7 +25,7 @@ class canvas(customView): self._ppi = ppi self._canvasSize = size self._landscape = landscape - # self.setFixedSize(parent.size()) + self.streamTable = None #Create area for the graphic items to be placed, this is just here right now for the future # when we will draw items on this, this might be changed if QGraphicScene is subclassed. @@ -38,7 +39,20 @@ class canvas(customView): self.parentMdiArea = parentMdiArea self.parentFileWindow = parentFileWindow self.customContextMenuRequested.connect(self.sideViewContextMenu) - + + def addStreamTable(self, pos=QPointF(0, 0), table=None): + self.streamTable = table if table else streamTable(5, 5, canvas=self) + + self.streamTableRect = moveRect(-10, -10, 10, 10) + self.streamTableRect.setFlags(moveRect.ItemIsMovable | + moveRect.ItemIsSelectable) + self.streamTableProxy = QGraphicsProxyWidget(self.streamTableRect) + self.streamTableProxy.setWidget(self.streamTable) + self.painter.addItem(self.streamTableRect) + self.streamTableRect.setPos(pos) + # proxy = self.painter.addWidget(self.streamTable) + # proxy.setPos(pos) + def sideViewContextMenu(self, pos): self.parentFileWindow.sideViewContextMenu(self.mapTo(self.parentFileWindow, pos)) diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 6d35437..e85d513 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -109,6 +109,8 @@ class fileWindow(QMdiSubWindow): menu.addAction("Remove Side View" if self.sideViewTab == self.tabber.currentWidget() else "View Side-By-Side", self.sideViewMode) menu.addAction("Reset Zoom", lambda : setattr(self.tabber.currentWidget().view, 'zoom', 1)) + if self.tabber.currentWidget().streamTable is None: + menu.addAction("Add Stream Table", lambda x=self, pos=point: x.tabber.currentWidget().addStreamTable(pos)) menu.exec_(self.tabber.mapToGlobal(point)) def sideViewMode(self): diff --git a/src/main/python/utils/streamTable.py b/src/main/python/utils/streamTable.py new file mode 100644 index 0000000..708a303 --- /dev/null +++ b/src/main/python/utils/streamTable.py @@ -0,0 +1,70 @@ +from PyQt5.QtCore import Qt, QSize, QRectF, QPoint +from PyQt5.QtGui import QBrush, QColor +from PyQt5.QtWidgets import QTableWidget, QMenu, QGraphicsRectItem + +class streamTable(QTableWidget): + + def __init__(self, int, int_, canvas=None, parent=None): + super(streamTable, self).__init__(int, int_, parent=parent) + self.canvas = canvas + + def mousePressEvent(self, event): + if event.button() == Qt.RightButton: + point = event.pos() + menu = QMenu("Context Menu", self) + menu.addAction("Insert Column to right", lambda x=point: self.insertColRight(x.x())) + menu.addAction("Insert Row to bottom", lambda x=point: self.insertRowBottom(x.y())) + menu.exec_(self.mapToGlobal(point)+ QPoint(20, 25)) + event.accept() + return super(streamTable, self).mousePressEvent(event) + + # def mouseDoubleClickEvent(self): + # return super(streamTable, self).mouseDoubleClickEvent() + + def insertRowBottom(self, point): + h = self.horizontalHeader().height() + i = 0 + while (h < point): + h += self.rowHeight(i) + i += 1 + self.insertRow(i + 1) + self.resize(self.sizeHint()) + + def insertColRight(self, point): + w = self.verticalHeader().width() + i = 0 + while (w < point): + w += self.columnWidth(i) + i += 1 + self.insertColumn(i + 1) + self.resize(self.sizeHint()) + + def resizeHandler(self): + self.resize(self.sizeHint()) + # self.canvas.streamTableRect.setRect(streamTable.rect().adjusted(-10, -10, 10, 10)) + + def sizeHint(self): + w = self.verticalHeader().width() + 4 + for i in range(self.columnCount()): + w += self.columnWidth(i) + h = self.horizontalHeader().height() + 4 + for i in range(self.rowCount()): + h += self.rowHeight(i) + return QSize(w, h) + + def rect(self): + w = self.verticalHeader().width() + 4 + for i in range(self.columnCount()): + w += self.columnWidth(i) + h = self.horizontalHeader().height() + 4 + for i in range(self.rowCount()): + h += self.rowHeight(i) + return QRectF(0, 0, w, h) + + def cellEntered(self, row, column): + print(row, column) + +class moveRect(QGraphicsRectItem): + def __init__(self, *args): + super(moveRect, self).__init__(*args) + self.setBrush(QBrush(QColor(0, 0, 0, 120))) \ No newline at end of file -- cgit