diff options
author | Blaine | 2020-05-27 21:00:23 +0530 |
---|---|---|
committer | Blaine | 2020-05-27 21:00:23 +0530 |
commit | 7606d7bb27ce1f9de890f4c8a84232f4649c62bf (patch) | |
tree | 6ff0270f0e97e3418671edab4b2978a4208df7d7 /src/main/python | |
parent | bbbda804aea58b006ed998bf54e581aa8c09e79b (diff) | |
download | Chemical-PFD-7606d7bb27ce1f9de890f4c8a84232f4649c62bf.tar.gz Chemical-PFD-7606d7bb27ce1f9de890f4c8a84232f4649c62bf.tar.bz2 Chemical-PFD-7606d7bb27ce1f9de890f4c8a84232f4649c62bf.zip |
commit undo modification
Diffstat (limited to 'src/main/python')
-rw-r--r-- | src/main/python/main.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/data.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 6 | ||||
-rw-r--r-- | src/main/python/utils/graphics.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 41 |
5 files changed, 40 insertions, 13 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index bc65035..3ebb2b9 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -78,7 +78,7 @@ class appWindow(QMainWindow): def toolButtonClicked(self, object): currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter if currentDiagram: - graphic = getattr(shapes, object['object'])(**map(lambda x: int(x) if x.isdigit() else x, object['args'])) + graphic = getattr(shapes, object['object'])(*map(lambda x: int(x) if x.isdigit() else x, object['args'])) # graphic.setPen(QPen(Qt.black, 2)) # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) currentDiagram.addItemPlus(graphic) diff --git a/src/main/python/utils/data.py b/src/main/python/utils/data.py index 3b32008..2053ff4 100644 --- a/src/main/python/utils/data.py +++ b/src/main/python/utils/data.py @@ -9,7 +9,7 @@ paperSizes = load(open(fileImporter("config/paperSizes.json"))) sheetDimensionList = list(paperSizes.keys()) -ppiList = paperSizes[sheetDimensionList[0]].keys() +ppiList = list(paperSizes[sheetDimensionList[0]].keys()) toolbarItems = load(open(fileImporter("config/items.json"))) diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 8f2fd32..ebe509b 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -10,6 +10,7 @@ from . import dialogs from .graphics import customView from .canvas import canvas from .tabs import customTabWidget +from .undo import resizeCommand class fileWindow(QMdiSubWindow): @@ -125,10 +126,7 @@ class fileWindow(QMdiSubWindow): currentTab = self.tabber.currentWidget() result = dialogs.paperDims(self, currentTab._canvasSize, currentTab._ppi, currentTab.objectName()).exec_() if result is not None: - currentTab.canvasSize, currentTab.ppi = result - return self.resizeHandler() - else: - return None + currentTab.painter.undoStack.push(resizeCommand(result, currentTab, self)) def sideViewToggle(self): #Function checks if current side view tab is set, and toggles view as required diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index 783748b..a997a30 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -49,7 +49,7 @@ class customView(QGraphicsView): # graphic.setPen(QPen(Qt.black, 2)) # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) self.scene().addItemPlus(graphic) - graphic.setPos(QDropEvent.pos().x()-150, QDropEvent.pos().y()-150) + graphic.setPos(QDropEvent.pos().x(), QDropEvent.pos().y()) QDropEvent.acceptProposedAction() def wheelEvent(self, QWheelEvent): diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 4dbcc46..3a64d41 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -2,6 +2,16 @@ Contains custom undo commands that can be pushed to undo stack """ from PyQt5.QtWidgets import QUndoCommand +from re import compile + +def repl(x): + return f"{x[0][0]} {x[0][1].lower()}" + +regex = compile(r"([a-z][A-Z])") + +def objectName(obj): + name = regex.sub(repl, obj.m_type if obj.__class__.__name__ == 'NodeItem' else obj.__class__.__name__) + return name[0].upper() + name[1:] + ' symbol' class addCommand(QUndoCommand): """ @@ -12,7 +22,7 @@ class addCommand(QUndoCommand): self.scene = scene self.diagramItem = addItem self.itemPos = addItem.pos() - self.setText(f"Add {self.diagramItem} {self.itemPos}") + self.setText(f"Add {objectName(self.diagramItem)}") def undo(self): self.scene.removeItem(self.diagramItem) @@ -33,7 +43,7 @@ class deleteCommand(QUndoCommand): self.scene = scene item.setSelected(False) self.diagramItem = item - self.setText(f"Delete {self.diagramItem} {self.diagramItem.pos()}") + self.setText(f"Delete {objectName(self.diagramItem)} at {self.diagramItem.pos().x()}, {self.diagramItem.y()}") def undo(self): self.scene.addItem(self.diagramItem) @@ -55,11 +65,11 @@ class moveCommand(QUndoCommand): def undo(self): self.diagramItem.setPos(self.lastPos) self.diagramItem.scene().update() - self.setText(f"Move {self.diagramItem} {self.newPos}") + self.setText(f"Move {objectName(self.diagramItem)} to {self.newPos.x()}, {self.newPos.y()}") def redo(self): self.diagramItem.setPos(self.newPos) - self.setText(f"Move {self.diagramItem} {self.newPos}") + self.setText(f"Move {objectName(self.diagramItem)} to {self.newPos.x()}, {self.newPos.y()}") def mergeWith(self, move): #merges multiple move commands so that a move event is not added twice. @@ -69,5 +79,24 @@ class moveCommand(QUndoCommand): return False self.newPos = item.pos() - self.setText(f"Move {self.diagramItem} {self.newPos}") - return True
\ No newline at end of file + self.setText(f"Move {objectName(self.diagramItem)} to {self.newPos.x()}, {self.newPos.y()}") + return True + +class resizeCommand(QUndoCommand): + """ + """ + def __init__(self, new, canvas, widget, parent = None): + super(resizeCommand, self).__init__(parent) + self.parent = canvas + self.old = self.parent.canvasSize, self.parent.ppi + self.new = new + self.widget = widget + self.setText(f'Change canvas dimensions to {new[0]} at {new[1]} ppi') + + def undo(self): + self.parent.canvasSize, self.parent.ppi = self.old + self.widget.resizeHandler() + + def redo(self): + self.parent.canvasSize, self.parent.ppi = self.new + self.widget.resizeHandler()
\ No newline at end of file |