summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorBlaine2020-06-09 04:53:48 +0530
committerBlaine2020-06-09 04:53:48 +0530
commit994a0f5c1fb80d0065b8fd3134111ca8790b46bd (patch)
tree420407e3c38806ca9e1461713c31bc890dcf3f89 /src/main
parentbfa6cdf2e858e4a08e7e51dbf6d6cddc8d4183b7 (diff)
downloadChemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.tar.gz
Chemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.tar.bz2
Chemical-PFD-994a0f5c1fb80d0065b8fd3134111ca8790b46bd.zip
conflicted commits
Diffstat (limited to 'src/main')
-rw-r--r--src/main/python/main.py5
-rw-r--r--src/main/python/shapes/shapes.py18
-rw-r--r--src/main/python/utils/app.py35
-rw-r--r--src/main/python/utils/canvas.py7
-rw-r--r--src/main/python/utils/fileWindow.py5
-rw-r--r--src/main/python/utils/graphics.py1
-rw-r--r--src/main/python/utils/undo.py2
7 files changed, 63 insertions, 10 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 72eb7f8..40384d5 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -1,4 +1,3 @@
-import json
import sys
from fbs_runtime.application_context.PyQt5 import ApplicationContext
@@ -13,7 +12,7 @@ from utils.fileWindow import fileWindow
from utils.data import ppiList, sheetDimensionList
from utils import dialogs
from utils.toolbar import toolbar
-from utils.app import app, settings
+from utils.app import app, settings, loads
import shapes
@@ -105,7 +104,7 @@ class appWindow(QMainWindow):
if name:
for files in name[0]:
with open(files,'r') as file:
- projectData = json.load(file)
+ projectData = loads(file)
project = fileWindow(self.mdi)
self.mdi.addSubWindow(project)
project.__setstate__(projectData)
diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py
index 3e5cbb2..2da1ca0 100644
--- a/src/main/python/shapes/shapes.py
+++ b/src/main/python/shapes/shapes.py
@@ -499,6 +499,24 @@ class NodeItem(QGraphicsSvgItem):
if action == addLableAction:
self.label = ItemLabel(event.scenePos(), self)
+ def __getstate__(self):
+ return {
+ "_classname_": self.__class__.__name__,
+ "width": self.width,
+ "height": self.height,
+ "pos": (self.pos.x(), self.pos.y())
+ }
+
+ def __setstate__(self, dict):
+ self.prepareGeometryChange()
+ self.width = dict['width']
+ self.height = dict['height']
+ self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height)
+ transform = QTransform()
+ transform.translate(self.width / 2, self.height / 2)
+ self.setTransform(transform, True)
+ self.updateSizeGripItem()
+
# classes of pfd-symbols
class AirBlownCooler(NodeItem):
def __init__(self):
diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py
index 4ee11c3..aa1ce28 100644
--- a/src/main/python/utils/app.py
+++ b/src/main/python/utils/app.py
@@ -4,6 +4,7 @@ Declare fbs application so that it can be imported in other modules.
from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtCore import QSettings
+from json import JSONEncoder, dumps, loads
app = ApplicationContext()
settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemical-PFD")
@@ -11,3 +12,37 @@ settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemic
def fileImporter(file):
# Helper function to fetch files from src/main/resources
return app.get_resource(file)
+
+class JSON_Encoder:
+
+ def _encode(obj):
+ if isinstance(obj, dict):
+ ## We'll need to iterate not just the value that default() usually gets passed
+ ## But also iterate manually over each key: value pair in order to trap the keys.
+
+ for key, val in list(obj.items()):
+ if isinstance(val, dict):
+ val = loads(dumps(val, cls=JSON_Typer)) # This, is a EXTREMELY ugly hack..
+ # But it's the only quick way I can think of to
+ # trigger a encoding of sub-dictionaries. (I'm also very tired, yolo!)
+ else:
+ val = JSON_Encoder._encode(val)
+ del(obj[key])
+ obj[JSON_Encoder._encode(key)] = val
+ return obj
+ elif hasattr(obj, '__getstate__'):
+ return obj.__getstate__()
+ elif isinstance(obj, (list, set, tuple)):
+ r = []
+ for item in obj:
+ r.append(loads(dumps(item, cls=JSON_Typer)))
+ return r
+ else:
+ return obj
+
+class JSON_Typer(JSONEncoder):
+ def _encode(self, obj):
+ return JSON_Encoder._encode(obj)
+
+ def encode(self, obj):
+ return super(JSON_Typer, self).encode(self._encode(obj)) \ No newline at end of file
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index dee0745..10601f2 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -1,5 +1,3 @@
-import json
-
from PyQt5.QtCore import Qt, QPointF
from PyQt5.QtGui import QBrush, QPalette
from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu,
@@ -8,6 +6,7 @@ from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu,
from . import dialogs
from .graphics import customView, customScene
from .data import paperSizes, ppiList, sheetDimensionList
+from .app import dumps, loads, JSON_Typer
import shapes
@@ -129,8 +128,8 @@ class canvas(QWidget):
"ppi": self._ppi,
"canvasSize": self._canvasSize,
"ObjectName": self.objectName(),
- "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)],
+ "symbols": [dumps(i, indent=4, cls=JSON_Typer) for i in self.painter.items() if isinstance(i, shapes.NodeItem)],
+ "lines": [dumps(i, indent=4, cls=JSON_Typer) 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)]
}
diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py
index 6ad4477..215ebfe 100644
--- a/src/main/python/utils/fileWindow.py
+++ b/src/main/python/utils/fileWindow.py
@@ -1,5 +1,3 @@
-import json
-
from PyQt5.QtCore import Qt, pyqtSignal, QPoint
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QFileDialog, QHBoxLayout,
@@ -11,6 +9,7 @@ from .graphics import customView
from .canvas import canvas
from .tabs import customTabWidget
from .undo import resizeCommand
+from .app import dumps, loads, JSON_Typer
class fileWindow(QMdiSubWindow):
@@ -223,7 +222,7 @@ class fileWindow(QMdiSubWindow):
name = QFileDialog.getSaveFileName(self, 'Save File', f'New Diagram', 'Process Flow Diagram (*.pfd)') if not name else name
if name[0]:
with open(name[0],'w') as file:
- json.dump(self.__getstate__(), file, indent=4)
+ dumps(self, file, indent=4, cls=JSON_Typer)
return True
else:
return False
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py
index a997a30..e17fa49 100644
--- a/src/main/python/utils/graphics.py
+++ b/src/main/python/utils/graphics.py
@@ -114,6 +114,7 @@ class customScene(QGraphicsScene):
def itemMoved(self, movedItem, lastPos):
#item move event, checks if item is moved
self.undoStack.push(moveCommand(movedItem, lastPos))
+ self.advance()
def addItemPlus(self, item):
# extended add item method, so that a corresponding undo action is also pushed
diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py
index cf539e7..7979bf3 100644
--- a/src/main/python/utils/undo.py
+++ b/src/main/python/utils/undo.py
@@ -52,9 +52,11 @@ class deleteCommand(QUndoCommand):
def undo(self):
self.scene.addItem(self.diagramItem)
self.scene.update()
+ self.scene.advance()
def redo(self):
self.scene.removeItem(self.diagramItem)
+ self.scene.advance()
class moveCommand(QUndoCommand):
"""