summaryrefslogtreecommitdiff
path: root/src/main/python/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/python/main.py')
-rw-r--r--src/main/python/main.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 7d72bae..db34119 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -7,7 +7,6 @@ from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette, QPen
from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout, QVBoxLayout,
QHBoxLayout, QLabel, QMainWindow, QMenu,
QPushButton, QWidget, QMdiArea, QSplitter, QGraphicsItem)
-from PyQt5 import QtWidgets
from utils.canvas import canvas
from utils.fileWindow import fileWindow
@@ -15,6 +14,8 @@ from utils.data import ppiList, sheetDimensionList
from utils import dialogs
from utils.toolbar import toolbar
+import shapes
+
class appWindow(QMainWindow):
"""
Application entry point, subclasses QMainWindow and implements the main widget,
@@ -32,6 +33,10 @@ class appWindow(QMainWindow):
self.menuFile.addAction("Open", self.openProject)
self.menuFile.addAction("Save", self.saveProject)
+ self.menuEdit = titleMenu.addMenu('Edit')
+ self.undo = self.menuEdit.addAction("Undo")
+ self.redo = self.menuEdit.addAction("Redo")
+
self.menuGenerate = titleMenu.addMenu('Generate') #Generate menu
self.menuGenerate.addAction("Image", self.saveImage)
self.menuGenerate.addAction("Report", self.generateReport)
@@ -53,7 +58,10 @@ class appWindow(QMainWindow):
self.setCentralWidget(self.mdi)
self.resize(1280, 720) #set collapse dim
self.mdi.subWindowActivated.connect(self.tabSwitched)
-
+
+ def updateMenuBar(self):
+ self.undo.setAction(self.activeScene.painter.undoAction)
+ self.redo.setAction(self.activeScene.painter.redoAction)
def createToolbar(self):
#place holder for toolbar with fixed width, layout may change
@@ -67,10 +75,10 @@ class appWindow(QMainWindow):
def toolButtonClicked(self, object):
currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter
if currentDiagram:
- graphic = getattr(QtWidgets, object['object'])(*object['args'])
+ graphic = getattr(shapes, object['object'])(*object['args'])
graphic.setPen(QPen(Qt.black, 2))
graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable)
- currentDiagram.addItem(graphic)
+ currentDiagram.addItemPlus(graphic)
def newProject(self):
#call to create a new file inside mdi area
@@ -81,9 +89,11 @@ class appWindow(QMainWindow):
project.newDiagram() #create a new tab in the new file
project.resizeHandler()
project.fileCloseEvent.connect(self.fileClosed) #closed file signal to switch to sub window view
+ project.tabChangeEvent.connect(self.updateMenuBar)
if self.count > 1: #switch to tab view if needed
self.mdi.setViewMode(QMdiArea.TabbedView)
project.show()
+ project.tabber.currentWidget().painter.createUndoView(self)
def openProject(self):
#show the open file dialog to open a saved file, then unpickle it.
@@ -142,7 +152,7 @@ class appWindow(QMainWindow):
if self.count <= 2 :
self.mdi.setViewMode(QMdiArea.SubWindowView)
- @property
+ @property
def activeFiles(self):
return [i for i in self.mdi.subWindowList() if i.tabCount]
@@ -150,6 +160,10 @@ class appWindow(QMainWindow):
def count(self):
return len(self.mdi.subWindowList())
+ @property
+ def activeScene(self):
+ return self.mdi.currentSubWindow().tabber.currentWidget()
+
#Key input handler
def keyPressEvent(self, event):
#overload key press event for custom keyboard shortcuts
@@ -176,16 +190,18 @@ class appWindow(QMainWindow):
#todo implement selectAll
for item in self.mdi.activeSubWindow().tabber.currentWidget().items:
item.setSelected(True)
-
- #todo copy, paste, undo redo
+ #todo copy, paste, undo redo
+ else:
+ return
+ event.accept()
elif event.key() == Qt.Key_Delete or event.key() == Qt.Key_Backspace:
- for item in self.mdi.activeSubWindow().tabber.currentWidget().painter.selectedItems():
- item.setEnabled(False)
+ for item in reversed(self.mdi.activeSubWindow().tabber.currentWidget().painter.selectedItems()):
+ # self.mdi.currentSubWindow().tabber.currentWidget().deleteItem(item)
+ pass
#donot delete, to manage undo redo
- event.accept()
if __name__ == '__main__':
app = ApplicationContext() # 1. Instantiate ApplicationContext