diff options
author | Blaine | 2020-06-09 20:59:54 +0530 |
---|---|---|
committer | Blaine | 2020-06-10 11:29:50 +0530 |
commit | 08344c77962dced303078c2cc798348278183daa (patch) | |
tree | c5dec33a05d93898dd0a45473a4e3db68db03f76 /src/main | |
parent | f4aac3c926ee71c18516442c0a2440c27d4dd7a3 (diff) | |
download | Chemical-PFD-08344c77962dced303078c2cc798348278183daa.tar.gz Chemical-PFD-08344c77962dced303078c2cc798348278183daa.tar.bz2 Chemical-PFD-08344c77962dced303078c2cc798348278183daa.zip |
implement labels and version info to saved file
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/shapes/__init__.py | 2 | ||||
-rw-r--r-- | src/main/python/shapes/line.py | 14 | ||||
-rw-r--r-- | src/main/python/shapes/shapes.py | 12 | ||||
-rw-r--r-- | src/main/python/utils/app.py | 1 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 22 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 3 |
6 files changed, 42 insertions, 12 deletions
diff --git a/src/main/python/shapes/__init__.py b/src/main/python/shapes/__init__.py index af92a6a..536caf6 100644 --- a/src/main/python/shapes/__init__.py +++ b/src/main/python/shapes/__init__.py @@ -1,4 +1,4 @@ from .shapes import * -# from .line import * +from .line import LineLabel from PyQt5.QtWidgets import * dir()
\ No newline at end of file diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 85c5753..466e22b 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -259,6 +259,19 @@ class LineLabel(QGraphicsTextItem): def focusOutEvent(self, event): super(LineLabel, self).focusOutEvent(event) self.setTextInteractionFlags(Qt.NoTextInteraction) + + def __getstate__(self): + return { + "text": self.toPlainText(), + "index": self.index, + "gap": self.gap, + "pos": (self.pos().x(), self.pos().y()) + } + + def __setstate__(self, dict): + self.setPlainText(dict['text']) + self.index = dict['index'] + self.gap = dict['gap'] def findIndex(line, pos): @@ -924,6 +937,7 @@ class Line(QGraphicsPathItem): "endGripItem": hex(id(self.endGripItem)) if self.endGripItem else 0, "refLine": hex(id(self.refLine)) if self.refLine else 0, "refIndex": self.refIndex, + "label": [i for i in self.label], "id": hex(id(self)) } def __setstate__(self, dict): diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 774951d..9683d87 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -32,7 +32,16 @@ class ItemLabel(QGraphicsTextItem): def focusOutEvent(self, event): super(ItemLabel, self).focusOutEvent(event) self.setTextInteractionFlags(Qt.NoTextInteraction) + + def __getstate__(self): + return { + "text": self.toPlainText(), + "pos": (self.pos().x(), self.pos().y()) + } + def __setstate__(self, dict): + self.setPlainText(dict['text']) + self.setPos(*dict['pos']) class GripItem(QGraphicsPathItem): """ @@ -498,7 +507,8 @@ class NodeItem(QGraphicsSvgItem): "width": self.width, "height": self.height, "pos": (self.pos().x(), self.pos().y()), - "lineGripItems": [(hex(id(i)), i.m_index) for i in self.lineGripItems] + "lineGripItems": [(hex(id(i)), i.m_index) for i in self.lineGripItems], + "label": self.label } def __setstate__(self, dict): diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py index 92c403c..9812fda 100644 --- a/src/main/python/utils/app.py +++ b/src/main/python/utils/app.py @@ -8,6 +8,7 @@ from json import JSONEncoder, dumps, loads, dump, load app = ApplicationContext() settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemical-PFD") +version = app.build_settings['version'] def fileImporter(file): # Helper function to fetch files from src/main/resources diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 93a7722..94661aa 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -6,7 +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, shapeGrips, lines +from .app import shapeGrips, lines import shapes @@ -129,9 +129,7 @@ class canvas(QWidget): "canvasSize": self._canvasSize, "ObjectName": self.objectName(), "symbols": [i for i in self.painter.items() if isinstance(i, shapes.NodeItem)], - "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0), - # "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)] + "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0) } def __setstate__(self, dict): @@ -148,6 +146,10 @@ class canvas(QWidget): graphic.updateSizeGripItem() for gripitem in item['lineGripItems']: shapeGrips[gripitem[0]] = (graphic, gripitem[1]) + if item['label']: + graphicLabel = shapes.ItemLabel(pos = QPointF(*item['label']['pos']), parent = graphic) + graphicLabel.__setstate__(item['label']) + self.painter.addItem(graphicLabel) for item in dict['lines']: line = shapes.Line(QPointF(*item['startPoint']), QPointF(*item['endPoint'])) @@ -166,16 +168,18 @@ class canvas(QWidget): line.refLine = lines[item['refLine']] lines[item['refLine']].midLines.append(line) line.refIndex = item['refIndex'] + for label in item['label']: + labelItem = shapes.LineLabel(QPointF(*label['pos']), line) + line.label.append(labelItem) + labelItem.__setstate__(label) + self.painter.addItem(labelItem) line.updateLine() line.addGrabber() - + shapeGrips.clear() lines.clear() 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 a0b4024..663a7f3 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -9,7 +9,7 @@ from .graphics import customView from .canvas import canvas from .tabs import customTabWidget from .undo import resizeCommand -from .app import dump, loads, JSON_Typer +from .app import dump, loads, JSON_Typer, version class fileWindow(QMdiSubWindow): @@ -243,6 +243,7 @@ class fileWindow(QMdiSubWindow): def __getstate__(self) -> dict: return { "_classname_": self.__class__.__name__, + "version": version, "ObjectName": self.objectName(), "tabs": [i.__getstate__() for i in self.tabList] } |