summaryrefslogtreecommitdiff
path: root/src/main/python/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/python/utils')
-rw-r--r--src/main/python/utils/app.py10
-rw-r--r--src/main/python/utils/data.py321
-rw-r--r--src/main/python/utils/dialogs.py4
-rw-r--r--src/main/python/utils/fileWindow.py6
-rw-r--r--src/main/python/utils/funcs.py5
-rw-r--r--src/main/python/utils/graphics.py48
-rw-r--r--src/main/python/utils/toolbar.py35
-rw-r--r--src/main/python/utils/undo.py61
8 files changed, 127 insertions, 363 deletions
diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py
new file mode 100644
index 0000000..4540a43
--- /dev/null
+++ b/src/main/python/utils/app.py
@@ -0,0 +1,10 @@
+"""
+Declare fbs application so that it can be imported in other modules.
+"""
+
+from fbs_runtime.application_context.PyQt5 import ApplicationContext
+app = ApplicationContext()
+
+def fileImporter(file):
+ # Helper function to fetch files from src/main/resources
+ return app.get_resource(file)
diff --git a/src/main/python/utils/data.py b/src/main/python/utils/data.py
index 593cb1b..2053ff4 100644
--- a/src/main/python/utils/data.py
+++ b/src/main/python/utils/data.py
@@ -1,311 +1,18 @@
-paperSizes = {
- "A0": {
- "72": [2384, 3370],
- "96": [3179, 4494],
- "150": [4967, 7022],
- "300": [9933, 14043]
- },
- "A1": {
- "72": [1684, 2384],
- "96": [2245, 3179],
- "150": [3508, 4967],
- "300": [7016, 9933]
- },
- "A2": {
- "72": [1191, 1684],
- "96": [1587, 2245],
- "150": [2480, 3508],
- "300": [4960, 7016]
- },
- "A3": {
- "72": [842, 1191],
- "96": [1123, 1587],
- "150": [1754, 2480],
- "300": [3508, 4960]
- },
- "A4": {
- "72": [595, 842],
- "96": [794, 1123],
- "150": [1240, 1754],
- "300": [2480, 3508]
- }
-}
+"""
+Imports data from json configs, so that they can be imported from this module.
+"""
-sheetDimensionList = [f'A{i}' for i in range(5)]
+from json import load
+from .app import fileImporter
-ppiList = ["72", "96", "150", "300"]
+paperSizes = load(open(fileImporter("config/paperSizes.json")))
+
+sheetDimensionList = list(paperSizes.keys())
+
+ppiList = list(paperSizes[sheetDimensionList[0]].keys())
+
+toolbarItems = load(open(fileImporter("config/items.json")))
+
+defaultToolbarItems = toolbarItems.keys()
-toolbarItems = {
- 'Ellipse': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse2': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse3': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse4': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse5': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse6': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse7': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse8': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse9': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse11': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse12': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse13': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse14': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse15': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse16': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse17': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse18': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse19': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse20': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse21': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse22': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse23': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse24': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse25': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse26': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse27': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse28': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse29': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse30': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse31': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse32': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse33': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse34': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse35': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse36': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse37': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse38': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse39': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse40': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse41': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse42': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse43': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse44': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse45': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
- 'Ellipse46': {
- 'name': 'Ellipse',
- 'icon': 'ellipse.png',
- 'object': 'QGraphicsEllipseItem',
- 'args': [20, 20, 300, 300]
- },
-}
-defaultToolbarItems = toolbarItems.keys() \ No newline at end of file
diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py
index 3791599..fa3b5f1 100644
--- a/src/main/python/utils/dialogs.py
+++ b/src/main/python/utils/dialogs.py
@@ -1,4 +1,4 @@
-from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox, QDialogButtonBox
+from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox, QDialogButtonBox, QHBoxLayout
from .data import sheetDimensionList, ppiList
class paperDims(QDialog):
@@ -104,7 +104,7 @@ def saveEvent(parent = None):
def showUndoDialog(undoView, parent):
dialogBox = QDialog(parent)
dialogBox.resize(400, 400)
- layout = QFormLayout(dialogBox)
+ layout = QHBoxLayout(dialogBox)
layout.addWidget(undoView)
dialogBox.setWindowTitle("Undo Stack")
dialogBox.show() \ No newline at end of file
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/funcs.py b/src/main/python/utils/funcs.py
deleted file mode 100644
index 7796ece..0000000
--- a/src/main/python/utils/funcs.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from itertools import zip_longest
-
-def grouper(n, iterable, fillvalue=None):
- args = [iter(iterable)] * n
- return zip_longest(fillvalue=fillvalue, *args) \ No newline at end of file
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py
index 62c62f7..a997a30 100644
--- a/src/main/python/utils/graphics.py
+++ b/src/main/python/utils/graphics.py
@@ -20,6 +20,7 @@ class customView(QGraphicsView):
self.setDragMode(True) #sets pannable using mouse
self.setAcceptDrops(True) #sets ability to accept drops
if scene:
+ #create necessary undo redo actions to accept keyboard shortcuts
self.addAction(scene.undoAction)
self.addAction(scene.redoAction)
self.addAction(scene.deleteAction)
@@ -43,10 +44,12 @@ class customView(QGraphicsView):
#defines item drop, fetches text, creates corresponding QGraphicItem and adds it to scene
if QDropEvent.mimeData().hasText():
#QDropEvent.mimeData().text() defines intended drop item, the pos values define position
- graphic = getattr(shapes, QDropEvent.mimeData().text())(QDropEvent.pos().x()-150, QDropEvent.pos().y()-150, 300, 300)
- graphic.setPen(QPen(Qt.black, 2))
- graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable)
- self.scene().addItemPlus(graphic)
+ obj = QDropEvent.mimeData().text().split('/')
+ graphic = getattr(shapes, obj[0])(*map(lambda x: int(x) if x.isdigit() else x, obj[1:]))
+ # graphic.setPen(QPen(Qt.black, 2))
+ # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable)
+ self.scene().addItemPlus(graphic)
+ graphic.setPos(QDropEvent.pos().x(), QDropEvent.pos().y())
QDropEvent.acceptProposedAction()
def wheelEvent(self, QWheelEvent):
@@ -78,17 +81,16 @@ class customView(QGraphicsView):
class customScene(QGraphicsScene):
"""
- re-implement QGraphicsScene for future functionality
- hint: QUndoFramework
+ Extends QGraphicsScene with undo-redo functionality
"""
def __init__(self, *args, parent=None):
super(customScene, self).__init__(*args, parent=parent)
- self.undoStack = QUndoStack(self)
- self.createActions()
-
+ self.undoStack = QUndoStack(self) #Used to store undo-redo moves
+ self.createActions() #creates necessary actions that need to be called for undo-redo
def createActions(self):
+ # helper function to create delete, undo and redo shortcuts
self.deleteAction = QAction("Delete Item", self)
self.deleteAction.setShortcut(Qt.Key_Delete)
self.deleteAction.triggered.connect(self.deleteItem)
@@ -99,38 +101,40 @@ class customScene(QGraphicsScene):
self.redoAction.setShortcut(QKeySequence.Redo)
def createUndoView(self, parent):
+ # creates an undo stack view for current QGraphicsScene
undoView = QUndoView(self.undoStack, parent)
- # undoView.resize(400, 400)
- # undoView.show()
- # undoView.setAttribute(Qt.WA_QuitOnClose, False)
showUndoDialog(undoView, parent)
def deleteItem(self):
+ # (slot) used to delete all selected items, and add undo action for each of them
if self.selectedItems():
for item in self.selectedItems():
self.undoStack.push(deleteCommand(item, self))
def itemMoved(self, movedItem, lastPos):
+ #item move event, checks if item is moved
self.undoStack.push(moveCommand(movedItem, lastPos))
def addItemPlus(self, item):
- # returnVal = self.addItem(item)
+ # extended add item method, so that a corresponding undo action is also pushed
self.undoStack.push(addCommand(item, self))
- # return returnVal
-
+
def mousePressEvent(self, event):
- bdsp = event.buttonDownScenePos(Qt.LeftButton)
- point = QPointF(bdsp.x(), bdsp.y())
- itemList = self.items(point)
- self.movingItem = itemList[0] if itemList else None
+ # overloaded mouse press event to check if an item was moved
+ bdsp = event.buttonDownScenePos(Qt.LeftButton) #get click pos
+ point = QPointF(bdsp.x(), bdsp.y()) #create a Qpoint from click pos
+ itemList = self.items(point) #get items at said point
+ self.movingItem = itemList[0] if itemList else None #set first item in list as moving item
if self.movingItem and event.button() == Qt.LeftButton:
- self.oldPos = self.movingItem.pos()
- self.clearSelection()
+ self.oldPos = self.movingItem.pos() #if left click is held, then store old pos
+ self.clearSelection() #clears selected items
return super(customScene, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
+ # overloaded mouse release event to check if an item was moved
if self.movingItem and event.button() == Qt.LeftButton:
if self.oldPos != self.movingItem.pos():
+ #if item pos had changed, when mouse was realeased, emit itemMoved signal
self.itemMoved(self.movingItem, self.oldPos)
- self.movingItem = None
+ self.movingItem = None #clear movingitem reference
return super(customScene, self).mouseReleaseEvent(event)
diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py
index ec3b6a8..af6feae 100644
--- a/src/main/python/utils/toolbar.py
+++ b/src/main/python/utils/toolbar.py
@@ -2,14 +2,14 @@ from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtCore import QSize, Qt, pyqtSignal, QMimeData
from PyQt5.QtGui import QIcon, QDrag
from PyQt5.QtWidgets import (QBoxLayout, QDockWidget, QGridLayout, QLineEdit,
- QScrollArea, QToolButton, QWidget, QApplication)
+ QScrollArea, QToolButton, QWidget, QApplication, QStyle)
from re import search, IGNORECASE
from .data import toolbarItems
-from .funcs import grouper
+from .app import fileImporter
from .layout import flowLayout
-resourceManager = ApplicationContext() #Used to load images, mainly toolbar icons
+# resourceManager = ApplicationContext() #Used to load images, mainly toolbar icons
class toolbar(QDockWidget):
"""
@@ -38,13 +38,15 @@ class toolbar(QDockWidget):
#create a scrollable area to house all buttons
self.diagArea = QScrollArea(self)
- self.layout.addWidget(self.diagArea)
+ self.diagArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
+ self.diagArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
+ self.diagArea.setWidgetResizable(True)
+ self.layout.addWidget(self.diagArea, stretch=1)
self.diagAreaWidget = QWidget(self.diagArea) #inner widget for scroll area
#custom layout for inner widget
self.diagAreaLayout = flowLayout(self.diagAreaWidget)
- # self.diagArea.setWidget() #set inner widget to scroll area
- self.setWidget(self.widget) #set main widget to dockwidget
+ self.setWidget(self.widget) #set main widget to dockwidget
def clearLayout(self):
# used to clear all items from toolbar, by parenting it to the toolbar instead
@@ -59,6 +61,7 @@ class toolbar(QDockWidget):
self.clearLayout() #clears layout
for item in list:
self.diagAreaLayout.addWidget(self.toolbarButtonDict[item])
+ self.resize()
def searchQuery(self):
# shorten toolbaritems list with search items
@@ -74,12 +77,14 @@ class toolbar(QDockWidget):
# called when main window resizes, overloading resizeEvent caused issues.
parent = self.parentWidget() #used to get parent dimensions
self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later
- self.setFixedWidth(.12*parent.width()) #12% of parent width
- self.setFixedHeight(self.height()) #span available height
- width = .12*parent.width() #12% of parent width
- self.diagAreaWidget.setFixedWidth(width) #set inner widget width
+ # self.setFixedHeight(self.height()) #span available height
+ width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent)
# the following line, sets the required height for the current width, so that blank space doesnt occur
- self.diagAreaWidget.setFixedHeight(self.diagAreaLayout.heightForWidth(width))
+ self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width))
+ self.setMinimumWidth(.17*parent.width()) #12% of parent width
+ # self.setMinimumWidth(self.diagAreaLayout.minimumSize().width()) #12% of parent width
+ self.diagAreaWidget.setLayout(self.diagAreaLayout)
+ self.diagArea.setWidget(self.diagAreaWidget)
def toolbarItems(self, items):
#helper functions to create required buttons
@@ -103,10 +108,12 @@ class toolbarButton(QToolButton):
def __init__(self, parent = None, item = None):
super(toolbarButton, self).__init__(parent)
#uses fbs resource manager to get icons
- self.setIcon(QIcon(resourceManager.get_resource(f'toolbar/{item["icon"]}')))
- self.setIconSize(QSize(40, 40)) #unecessary but left for future references
+ self.setIcon(QIcon(fileImporter(f'toolbar/{item["icon"]}')))
+ self.setIconSize(QSize(64, 64)) #unecessary but left for future references
self.dragStartPosition = None #intialize value for drag event
self.itemObject = item['object'] #refer current item object, to handle drag mime
+ for i in item['args']:
+ self.itemObject += f"/{i}"
self.setText(item["name"]) #button text
self.setToolTip(item["name"]) #button tooltip
@@ -135,4 +142,4 @@ class toolbarButton(QToolButton):
def minimumSizeHint(self):
#defines button size
- return QSize(30, 30) \ No newline at end of file
+ return QSize(40, 40) \ No newline at end of file
diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py
index 7832483..cf539e7 100644
--- a/src/main/python/utils/undo.py
+++ b/src/main/python/utils/undo.py
@@ -1,13 +1,32 @@
+"""
+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__)
+ # if obj.__class__.__name__ != 'line':
+ # name = 'Draw ' + name[0].upper() + name[1:]
+ # else:
+ # name = 'Add ' +
+ return name[0].upper() + name[1:] + ' symbol'
class addCommand(QUndoCommand):
-
+ """
+ QUndoCommand for add item event
+ """
def __init__(self, addItem, scene, parent = None):
super(addCommand, self).__init__(parent)
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)
@@ -20,13 +39,15 @@ class addCommand(QUndoCommand):
self.scene.update()
class deleteCommand(QUndoCommand):
-
+ """
+ QUndoCommand for delete item event
+ """
def __init__(self, item, scene, parent = None):
super(deleteCommand, self).__init__(parent)
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)
@@ -36,7 +57,9 @@ class deleteCommand(QUndoCommand):
self.scene.removeItem(self.diagramItem)
class moveCommand(QUndoCommand):
-
+ """
+ QUndoCommand for move item event
+ """
def __init__(self, item, lastPos, parent = None):
super(moveCommand, self).__init__(parent)
self.diagramItem = item
@@ -46,18 +69,38 @@ 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.
item = move.diagramItem
if self.diagramItem != item:
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