summaryrefslogtreecommitdiff
path: root/src/main/python/utils/fileWindow.py
diff options
context:
space:
mode:
authorBlaine2020-06-05 12:14:26 +0530
committerBlaine2020-06-08 20:02:45 +0530
commit60380a253a7c4b862fad4d4111301044f28312b5 (patch)
tree600b29625ef7e0440805075973a8c8e028f5ff17 /src/main/python/utils/fileWindow.py
parentf9da12dd4ed6369468871fcc317fe9c07cdf5e48 (diff)
downloadChemical-PFD-60380a253a7c4b862fad4d4111301044f28312b5.tar.gz
Chemical-PFD-60380a253a7c4b862fad4d4111301044f28312b5.tar.bz2
Chemical-PFD-60380a253a7c4b862fad4d4111301044f28312b5.zip
json file format + qsettings
Diffstat (limited to 'src/main/python/utils/fileWindow.py')
-rw-r--r--src/main/python/utils/fileWindow.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py
index ebe509b..3cf0e8c 100644
--- a/src/main/python/utils/fileWindow.py
+++ b/src/main/python/utils/fileWindow.py
@@ -1,4 +1,5 @@
import pickle
+import json
from PyQt5.QtCore import Qt, pyqtSignal, QPoint
from PyQt5.QtGui import QIcon
@@ -24,8 +25,8 @@ class fileWindow(QMdiSubWindow):
def __init__(self, parent = None, title = 'New Project', size = 'A4', ppi = '72'):
super(fileWindow, self).__init__(parent)
self._sideViewTab = None
- self.index = None
-
+ self.index = None
+
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
#Uses a custom QTabWidget that houses a custom new Tab Button, used to house the seperate
# diagrams inside a file
@@ -210,19 +211,20 @@ class fileWindow(QMdiSubWindow):
self.tabber.widget(currentIndex).deleteLater()
self.tabber.removeTab(currentIndex)
- def newDiagram(self):
+ def newDiagram(self, objectName = "New"):
# helper function to add a new tab on pressing new tab button, using the add tab method on QTabWidget
- diagram = canvas(self.tabber)
- diagram.setObjectName("New")
- index = self.tabber.addTab(diagram, "New")
+ diagram = canvas(self.tabber, parentMdiArea = self.mdiArea(), parentFileWindow = self)
+ diagram.setObjectName(objectName)
+ index = self.tabber.addTab(diagram, objectName)
self.tabber.setCurrentIndex(index)
+ return diagram
def saveProject(self, name = None):
# called by dialog.saveEvent, saves the current file
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],'wb') as file:
- pickle.dump(self, file)
+ with open(name[0],'w') as file:
+ json.dump(self.__getstate__(), file, indent=4)
return True
else:
return False
@@ -242,14 +244,12 @@ class fileWindow(QMdiSubWindow):
return {
"_classname_": self.__class__.__name__,
"ObjectName": self.objectName(),
- "ppi": self._ppi,
- "canvasSize": self._canvasSize,
"tabs": [i.__getstate__() for i in self.tabList]
}
def __setstate__(self, dict):
- self.__init__(title = dict['ObjectName'])
+ self.setObjectName = dict['ObjectName']
+ self.setWindowTitle = dict['ObjectName']
for i in dict['tabs']:
- diagram = canvas(self.tabber, size = dict['canvasSize'], ppi = dict['ppi'], fileWindow = self)
+ diagram = self.newDiagram(i['ObjectName'])
diagram.__setstate__(i)
- self.tabber.addTab(diagram, i['ObjectName'])