diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/main.py | 5 | ||||
-rw-r--r-- | src/main/python/shapes/line.py | 11 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 35 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 1 |
4 files changed, 39 insertions, 13 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index 025961b..72eb7f8 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -1,4 +1,3 @@ -import pickle import json import sys @@ -60,8 +59,8 @@ class appWindow(QMainWindow): #declare main window layout self.setCentralWidget(self.mdi) # self.resize(1280, 720) #set collapse dim - self.readSettings() self.mdi.subWindowActivated.connect(self.tabSwitched) + self.readSettings() def updateMenuBar(self): # used to update menu bar undo-redo buttons to current scene @@ -154,7 +153,7 @@ class appWindow(QMainWindow): event.ignore() else: event.accept() - self.writeSettings() + self.writeSettings() def fileClosed(self, index): #checks if the file tab menu needs to be removed diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 310b496..216c2b5 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -302,3 +302,14 @@ class Line(QGraphicsPathItem): def setPenStyle(self, style): """change current pen style for line""" self.penStyle = style + + def __getstate__(self): + return { + "_classname_": self.__class__.__name__, + "startPoint": (self.startPoint.x(), self.startPoint.y()), + "endPoint": (self.endPoint.x(), self.endPoint.y()), + "points": [(point.x(), point.y()) for point in self.points] + } + + def __setstate__(self, dict): + self.points = [QPointF(x, y) for x, y in dict["points"]]
\ No newline at end of file diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 5da4487..dee0745 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -1,6 +1,6 @@ -import pickle +import json -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, QPointF from PyQt5.QtGui import QBrush, QPalette from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu, QTabWidget, QWidget, QSpacerItem, QStyle) @@ -9,6 +9,8 @@ from . import dialogs from .graphics import customView, customScene from .data import paperSizes, ppiList, sheetDimensionList +import shapes + class canvas(QWidget): """ Defines the work area for a single sheet. Contains a QGraphicScene along with necessary properties @@ -27,7 +29,7 @@ class canvas(QWidget): # when we will draw items on this, this might be changed if QGraphicScene is subclassed. #set layout and background color - self.painter = customScene() + self.painter = customScene() self.painter.setBackgroundBrush(QBrush(Qt.white)) #set white background self.view = customView(self.painter, self) #create a viewport for the canvas board @@ -39,8 +41,6 @@ class canvas(QWidget): #set initial paper size for the scene self.painter.setSceneRect(0, 0, *paperSizes[self._canvasSize][self._ppi]) - # self.parentMdiArea = self.parent().parentWidget().parentWidget().parentWidget().parentWidget() - # self.parentFileWindow = self.parent().parentWidget().parentWidget() self.parentMdiArea = parentMdiArea self.parentFileWindow = parentFileWindow @@ -129,16 +129,33 @@ class canvas(QWidget): "ppi": self._ppi, "canvasSize": self._canvasSize, "ObjectName": self.objectName(), - "items": [i.__getState__() for i in self.painter.items()] + "symbols": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.NodeItem)], + "lines": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.Line)], + # "lineLabels": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.LineLabel)], + # "itemLabels": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.itemLabel)] } def __setstate__(self, dict): self._ppi = dict['ppi'] self._canvasSize = dict['canvasSize'] self.setObjectName(dict['ObjectName']) - for item in dict['items']: - graphic = getattr(graphics, dict['_classname_']) - graphic.__setstate__(item) + + for item in dict['symbols']: + graphic = getattr(shapes, item['_classname_'])() + graphic.__setstate__(dict = item) self.painter.addItem(graphic) + graphic.setPos(*item['pos']) + + for item in dict['lines']: + line = shapes.Line(QPointF(*item['startPoint']), QPointF(*item['endPoint'])) + line.__setstate__(dict = item) + self.painter.addItem(line) + + self.painter.advance() + + # for item in dict['lineLabels']: + # pass + # for item in dict['itemLabels']: + # pass
\ No newline at end of file diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 3cf0e8c..6ad4477 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -1,4 +1,3 @@ -import pickle import json from PyQt5.QtCore import Qt, pyqtSignal, QPoint |