summaryrefslogtreecommitdiff
path: root/src/main/python/utils
diff options
context:
space:
mode:
authorBlaine2020-06-08 19:36:25 +0530
committerBlaine2020-06-08 19:36:25 +0530
commitad22f9ed828ec6ae2101950459a16f5f79e13ab0 (patch)
treeaf55025e9d8978e1f2fd024943501daf5176474c /src/main/python/utils
parent82a30cddc6f268fe87237cf14b4c3f636cbe50c8 (diff)
downloadChemical-PFD-ad22f9ed828ec6ae2101950459a16f5f79e13ab0.tar.gz
Chemical-PFD-ad22f9ed828ec6ae2101950459a16f5f79e13ab0.tar.bz2
Chemical-PFD-ad22f9ed828ec6ae2101950459a16f5f79e13ab0.zip
serialization for scene items
Diffstat (limited to 'src/main/python/utils')
-rw-r--r--src/main/python/utils/canvas.py35
-rw-r--r--src/main/python/utils/fileWindow.py1
2 files changed, 26 insertions, 10 deletions
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