summaryrefslogtreecommitdiff
path: root/src/main/python/utils/canvas.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/python/utils/canvas.py')
-rw-r--r--src/main/python/utils/canvas.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
new file mode 100644
index 0000000..ad72544
--- /dev/null
+++ b/src/main/python/utils/canvas.py
@@ -0,0 +1,46 @@
+from PyQt5.QtCore import Qt
+from PyQt5.QtGui import QBrush
+from PyQt5.QtWidgets import QWidget, QGraphicsScene, QGraphicsView, QHBoxLayout
+from .sizes import paperSizes
+class canvas(QWidget):
+ def __init__(self, parent=None):
+ super(canvas, self).__init__(parent)
+
+ self._ppi = 72
+ self._canvasSize = "A0"
+ self.resize(1280, 720)
+
+
+ self.painter = QGraphicsScene(0, 0, *paperSizes[self.canvasSize][self.ppi])
+ self.painter.setBackgroundBrush(QBrush(Qt.white))
+ self.view = QGraphicsView(self.painter)
+ self.layout = QHBoxLayout(self)
+ self.layout.addWidget(self.view)
+ self.setLayout(self.layout)
+
+ def setCanvasSize(self, size):
+ self.canvasSize = size
+
+ def setCanvasPPI(self, ppi):
+ self.ppi = ppi
+
+ @property
+ def canvasSize(self):
+ return self._canvasSize
+ @property
+ def ppi(self):
+ return self._ppi
+
+ @canvasSize.setter
+ def canvasSize(self, size):
+ self._canvasSize = size
+ if self.painter:
+ self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
+ # print(*paperSizes[self.canvasSize][self.ppi])
+
+ @ppi.setter
+ def ppi(self, ppi):
+ self._ppi = int(ppi)
+ if self.painter:
+ self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
+ # print(*paperSizes[self.canvasSize][self.ppi]) \ No newline at end of file