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.py105
1 files changed, 54 insertions, 51 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 4cf1791..35c95c3 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -2,13 +2,13 @@ import sys
from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtCore import QObject, Qt, pyqtSignal, QSize, QPoint
-from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette, QPen
+from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette, QPen, QKeySequence
from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout, QVBoxLayout,
QHBoxLayout, QLabel, QMainWindow, QMenu,
QPushButton, QWidget, QMdiArea, QSplitter, QGraphicsItem)
from utils.canvas import canvas
-from utils.fileWindow import fileWindow
+from utils.fileWindow import FileWindow
from utils.data import ppiList, sheetDimensionList
from utils import dialogs
from utils.toolbar import toolbar
@@ -25,23 +25,7 @@ class appWindow(QMainWindow):
super(appWindow, self).__init__(parent)
#create the menu bar
- titleMenu = self.menuBar() #fetch reference to current menu bar
- # self.mainWidget.setObjectName("Main Widget")
-
- self.menuFile = titleMenu.addMenu('File') #File Menu
- self.menuFile.addAction("New", self.newProject)
- self.menuFile.addAction("Open", self.openProject)
- self.menuFile.addAction("Save", self.saveProject)
-
- self.menuEdit = titleMenu.addMenu('Edit')
- self.undo = self.menuEdit.addAction("Undo", lambda x=self: x.activeScene.painter.undoAction.trigger())
- self.redo = self.menuEdit.addAction("Redo", lambda x=self: x.activeScene.painter.redoAction.trigger())
-
- self.menuEdit.addAction("Show Undo Stack", lambda x=self: x.activeScene.painter.createUndoView(self) )
-
- self.menuGenerate = titleMenu.addMenu('Generate') #Generate menu
- self.menuGenerate.addAction("Image", self.saveImage)
- self.menuGenerate.addAction("Report", self.generateReport)
+ self.createMenuBar()
self.mdi = QMdiArea(self) #create area for files to be displayed
self.mdi.setObjectName('mdi area')
@@ -60,7 +44,39 @@ class appWindow(QMainWindow):
# self.resize(1280, 720) #set collapse dim
self.mdi.subWindowActivated.connect(self.tabSwitched)
self.readSettings()
-
+
+ def createMenuBar(self):
+ # Fetches a reference to the menu bar in the main window, and adds actions to it.
+
+ titleMenu = self.menuBar() #fetch reference to current menu bar
+
+ self.menuFile = titleMenu.addMenu('File') #File Menu
+ newAction = self.menuFile.addAction("New", self.newProject)
+ openAction = self.menuFile.addAction("Open", self.openProject)
+ saveAction = self.menuFile.addAction("Save", self.saveProject)
+
+ newAction.setShortcut(QKeySequence.New)
+ openAction.setShortcut(QKeySequence.Open)
+ saveAction.setShortcut(QKeySequence.Save)
+
+ self.menuEdit = titleMenu.addMenu('Edit')
+ undoAction = self.undo = self.menuEdit.addAction("Undo", lambda x=self: x.activeScene.painter.undoAction.trigger())
+ redoAction = self.redo = self.menuEdit.addAction("Redo", lambda x=self: x.activeScene.painter.redoAction.trigger())
+
+ undoAction.setShortcut(QKeySequence.Undo)
+ redoAction.setShortcut(QKeySequence.Redo)
+
+ self.menuEdit.addAction("Show Undo Stack", lambda x=self: x.activeScene.painter.createUndoView(self) )
+ self.menuEdit.addSeparator()
+ self.menuEdit.addAction("Add new symbols", self.addSymbolWindow)
+
+ self.menuGenerate = titleMenu.addMenu('Generate') #Generate menu
+ imageAction = self.menuGenerate.addAction("Image", self.saveImage)
+ reportAction = self.menuGenerate.addAction("Report", self.generateReport)
+
+ imageAction.setShortcut(QKeySequence("Ctrl+P"))
+ reportAction.setShortcut(QKeySequence("Ctrl+R"))
+
def createToolbar(self):
#place holder for toolbar with fixed width, layout may change
self.toolbar = toolbar(self)
@@ -71,23 +87,26 @@ class appWindow(QMainWindow):
self.toolbar.populateToolbar()
def toolButtonClicked(self, object):
+ # To add the corresponding symbol for the clicked button to active scene.
if self.mdi.currentSubWindow():
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.setPen(QPen(Qt.black, 2))
- # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable)
+ graphic.setPos(50, 50)
currentDiagram.addItemPlus(graphic)
- graphic.setPos(20, 20)
-
+
+ def addSymbolWindow(self):
+ # Opens the add symbol window when requested
+ from utils.custom import ShapeDialog
+ ShapeDialog(self).exec()
+
def newProject(self):
#call to create a new file inside mdi area
- project = fileWindow(self.mdi)
+ project = FileWindow(self.mdi)
project.setObjectName("New Project")
self.mdi.addSubWindow(project)
if not project.tabList: # important when unpickling a file instead
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
if self.count > 1: #switch to tab view if needed
self.mdi.setViewMode(QMdiArea.TabbedView)
@@ -100,8 +119,9 @@ class appWindow(QMainWindow):
for files in name[0]:
with open(files,'r') as file:
projectData = load(file)
- project = fileWindow(self.mdi)
+ project = FileWindow(self.mdi)
self.mdi.addSubWindow(project)
+ #create blank window and set its state
project.__setstate__(projectData)
project.resizeHandler()
project.fileCloseEvent.connect(self.fileClosed)
@@ -111,7 +131,7 @@ class appWindow(QMainWindow):
self.mdi.setViewMode(QMdiArea.TabbedView)
def saveProject(self):
- #pickle all files in mdi area
+ #serialize all files in mdi area
for j, i in enumerate(self.activeFiles): #get list of all windows with atleast one tab
if i.tabCount:
name = QFileDialog.getSaveFileName(self, 'Save File', f'New Diagram {j}', 'Process Flow Diagram (*.pfd)')
@@ -154,6 +174,7 @@ class appWindow(QMainWindow):
self.mdi.setViewMode(QMdiArea.SubWindowView)
def writeSettings(self):
+ # write window state on window close
settings.beginGroup("MainWindow")
settings.setValue("maximized", self.isMaximized())
if not self.isMaximized():
@@ -162,6 +183,7 @@ class appWindow(QMainWindow):
settings.endGroup()
def readSettings(self):
+ # read window state when app launches
settings.beginGroup("MainWindow")
self.resize(settings.value("size", QSize(1280, 720)))
self.move(settings.value("pos", QPoint(320, 124)))
@@ -169,6 +191,7 @@ class appWindow(QMainWindow):
self.showMaximized()
settings.endGroup()
+ #useful one liner properties for getting data
@property
def activeFiles(self):
return [i for i in self.mdi.subWindowList() if i.tabCount]
@@ -185,25 +208,7 @@ class appWindow(QMainWindow):
def keyPressEvent(self, event):
#overload key press event for custom keyboard shortcuts
if event.modifiers() & Qt.ControlModifier:
- if event.key() == Qt.Key_N:
- self.newProject()
-
- elif event.key() == Qt.Key_S:
- self.saveProject()
-
- elif event.key() == Qt.Key_O:
- self.openProject()
-
- elif event.key() == Qt.Key_W:
- self.close()
-
- elif event.key() == Qt.Key_P:
- if Qt.AltModifier:
- self.saveImage()
- else:
- self.generateReport()
-
- elif event.key() == Qt.Key_A:
+ if event.key() == Qt.Key_A:
#todo implement selectAll
for item in self.mdi.activeSubWindow().tabber.currentWidget().items:
item.setSelected(True)
@@ -221,11 +226,9 @@ class appWindow(QMainWindow):
if self.mdi.activeSubWindow() and self.mdi.activeSubWindow().tabber.currentWidget():
for item in self.mdi.activeSubWindow().tabber.currentWidget().painter.selectedItems():
item.rotation += 1
-
-
-
+
if __name__ == '__main__': # 1. Instantiate ApplicationContext
main = appWindow()
main.show()
- exit_code = app.app.exec_() # 2. Invoke appctxt.app.exec_()
+ exit_code = app.app.exec_() # 2. Invoke app.app.exec_()
sys.exit(exit_code)