diff options
Diffstat (limited to 'src/main/python/utils')
-rw-r--r-- | src/main/python/utils/app.py | 6 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 42 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 11 | ||||
-rw-r--r-- | src/main/python/utils/tabs.py | 23 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 21 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 3 |
6 files changed, 79 insertions, 27 deletions
diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py index 5d85cb7..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 @@ -49,4 +50,7 @@ class JSON_Typer(JSONEncoder): return JSON_Encoder._encode(obj) def encode(self, obj): - return super(JSON_Typer, self).encode(self._encode(obj))
\ No newline at end of file + return super(JSON_Typer, self).encode(self._encode(obj)) + +shapeGrips = {} +lines = {}
\ No newline at end of file diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index a83aeb2..3f9cee5 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 +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": [i 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)] + "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): @@ -144,17 +142,43 @@ class canvas(QWidget): graphic.__setstate__(dict = item) self.painter.addItem(graphic) graphic.setPos(*item['pos']) + graphic.updateLineGripItem() + 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'])) + lines[item['id']] = line line.__setstate__(dict = item) self.painter.addItem(line) - + graphic, index = shapeGrips[item['startGripItem']] + line.startGripItem = graphic.lineGripItems[index] + graphic.lineGripItems[index].line = line + if item['endGripItem']: + graphic, index = shapeGrips[item['endGripItem']] + line.endGripItem = graphic.lineGripItems[index] + graphic.lineGripItems[index].line = line + else: + 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 04ed81a..663a7f3 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -3,13 +3,13 @@ from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QFileDialog, QHBoxLayout, QMdiSubWindow, QMenu, QPushButton, QSizePolicy, QSplitter, QWidget, QStyle) - +from os import path from . import dialogs 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): @@ -221,6 +221,8 @@ class fileWindow(QMdiSubWindow): # 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]: + self.setObjectName(path.basename(name[0]).split(".")[0]) + self.setWindowTitle(self.objectName()) with open(name[0],'w') as file: dump(self, file, indent=4, cls=JSON_Typer) return True @@ -241,13 +243,14 @@ 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] } def __setstate__(self, dict): - self.setObjectName = dict['ObjectName'] - self.setWindowTitle = dict['ObjectName'] + self.setObjectName(dict['ObjectName']) + self.setWindowTitle(dict['ObjectName']) for i in dict['tabs']: diagram = self.newDiagram(i['ObjectName']) diagram.__setstate__(i) diff --git a/src/main/python/utils/tabs.py b/src/main/python/utils/tabs.py index eab056a..5196557 100644 --- a/src/main/python/utils/tabs.py +++ b/src/main/python/utils/tabs.py @@ -1,11 +1,12 @@ -from PyQt5.QtWidgets import QTabBar, QPushButton, QTabWidget -from PyQt5.QtCore import pyqtSignal, QSize +from PyQt5.QtWidgets import QTabBar, QPushButton, QTabWidget, QInputDialog +from PyQt5.QtCore import pyqtSignal, QSize, Qt class tabBarPlus(QTabBar): """ Just implemented to overload resize and layout change to emit a signal """ layoutChanged = pyqtSignal() + nameChanged = pyqtSignal(int, str) def resizeEvent(self, event): super().resizeEvent(event) self.layoutChanged.emit() @@ -14,7 +15,17 @@ class tabBarPlus(QTabBar): super().tabLayoutChange() self.layoutChanged.emit() - + def mouseDoubleClickEvent(self, event): + if event.button() != Qt.LeftButton: + return super().mouseDoubleClickEvent() + index = self.currentIndex() + newName, bool = QInputDialog.getText(self, "Change Diagram Name", "Enter new name", + text = self.tabText(index)) + if bool: + self.setTabText(index, newName) + self.nameChanged.emit(index, newName) + + class customTabWidget(QTabWidget): """ QTabWidget with a new tab button, also catches layoutChange signal by @@ -50,6 +61,7 @@ class customTabWidget(QTabWidget): self.tab.layoutChanged.connect(self.movePlusButton) #connect layout change # to dynamically move the button. + self.tab.nameChanged.connect(self.changeWidgetName) #set custom stylesheet for the widget area self.setStyleSheet("""QTabWidget::pane { @@ -68,4 +80,7 @@ class customTabWidget(QTabWidget): if size > w: #if all the tabs do not overflow the tab bar, add at the end self.plusButton.move(w-self.plusButton.width(), h) else: - self.plusButton.move(size-3, h)
\ No newline at end of file + self.plusButton.move(size-3, h) + + def changeWidgetName(self, index, newName): + self.widget(index).setObjectName(newName)
\ No newline at end of file diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index af6feae..7883136 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -20,6 +20,7 @@ class toolbar(QDockWidget): def __init__(self, parent = None): super(toolbar, self).__init__(parent) self.toolbarButtonDict = dict() #initializes empty dict to store toolbar buttons + self.toolbarButtonClassList = [] self.toolbarItems(toolbarItems.keys()) #creates all necessary buttons self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) @@ -59,8 +60,9 @@ class toolbar(QDockWidget): def populateToolbar(self, list): #called everytime the button box needs to be updated(incase of a filter) self.clearLayout() #clears layout - for item in list: - self.diagAreaLayout.addWidget(self.toolbarButtonDict[item]) + for itemClass in list: + for item in self.toolbarButtonDict[itemClass].keys(): + self.diagAreaLayout.addWidget(self.toolbarButtonDict[itemClass][item]) self.resize() def searchQuery(self): @@ -86,13 +88,16 @@ class toolbar(QDockWidget): self.diagAreaWidget.setLayout(self.diagAreaLayout) self.diagArea.setWidget(self.diagAreaWidget) - def toolbarItems(self, items): + def toolbarItems(self, itemClasses): #helper functions to create required buttons - for item in items: - obj = toolbarItems[item] - button = toolbarButton(self, obj) - button.clicked.connect(lambda : self.toolbuttonClicked.emit(obj)) - self.toolbarButtonDict[item] = button + for itemClass in itemClasses: + self.toolbarButtonDict[itemClass] = {} + self.toolbarButtonClassList.append(itemClass) + for item in toolbarItems[itemClass].keys(): + obj = toolbarItems[itemClass][item] + button = toolbarButton(self, obj) + button.clicked.connect(lambda : self.toolbuttonClicked.emit(obj)) + self.toolbarButtonDict[itemClass][item] = button @property def toolbarItemList(self): diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 7979bf3..b060550 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -31,12 +31,13 @@ class addCommand(QUndoCommand): def undo(self): self.scene.removeItem(self.diagramItem) self.scene.update() + self.scene.advance() def redo(self): self.scene.addItem(self.diagramItem) self.diagramItem.setPos(self.itemPos) self.scene.clearSelection() - self.scene.update() + self.scene.advance() class deleteCommand(QUndoCommand): """ |