summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/python/main.py36
-rw-r--r--src/main/python/utils/canvas.py27
2 files changed, 49 insertions, 14 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 23c01e8..7ae9d63 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -7,7 +7,7 @@ from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette
from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout,
QGraphicsScene, QGraphicsView, QGridLayout,
QHBoxLayout, QLabel, QMainWindow, QMenu, QMenuBar,
- QPushButton, QTabWidget, QWidget, QMdiArea)
+ QPushButton, QTabWidget, QWidget, QMdiArea, QMessageBox)
from utils.canvas import canvas, fileWindow
from utils.sizes import ppiList, sheetDimensionList
@@ -39,10 +39,8 @@ class appWindow(QMainWindow):
#ImpsaveProject
self.mdi = QMdiArea(self)
- # self.mdi.closeEvent().connect(self.closeProject)
# add close action to tabs
-
self.createToolbar()
mainLayout.addWidget(self.toolbar)
mainLayout.addWidget(self.mdi)
@@ -75,7 +73,8 @@ class appWindow(QMainWindow):
def setCanvasSize(self, size):
self._defaultCanvasSize = size
- activeCanvas = self.tabber.currentWidget()
+ activeCanvas = self.mdi.currentSubWindow()
+ activeCanvas._defaultCanvasSize = size
if activeCanvas:
activeCanvas.canvasSize = size
# self.tabber.resize(*activeCanvas.dimensions)
@@ -83,18 +82,20 @@ class appWindow(QMainWindow):
def setCanvasPPI(self, ppi):
self._defaultPPI = ppi
- activeCanvas = self.tabber.currentWidget()
+ activeCanvas = self.mdi.currentSubWindow()
+ activeCanvas._defaultPPI = ppi
if activeCanvas:
activeCanvas.ppi = ppi
# self.tabber.resize(*activeCanvas.dimensions)
def newProject(self):
- project = fileWindow(self.mdi)
+ project = fileWindow(self.mdi, size = self._defaultCanvasSize, ppi = self._defaultPPI)
project.setObjectName("New Project")
self.mdi.addSubWindow(project)
if not project.tabList:
project.newDiagram()
project.show()
+ project.resizeHandler(self.mdi)
def openProject(self):
name = QFileDialog.getOpenFileNames(self, 'Open File(s)', '', 'Process Flow Diagram (*pfd)')
@@ -104,6 +105,8 @@ class appWindow(QMainWindow):
project = pickle.load(file)
self.mdi.addSubWindow(project)
project.show()
+ project.resizeHandler(self.mdi)
+
def saveProject(self):
for j, i in enumerate(self.mdi.subWindowList()):
@@ -116,6 +119,27 @@ class appWindow(QMainWindow):
def generateReport(self):
pass
+
+ def resizeEvent(self, event):
+ self.mdi.activeSubWindow().resizeHandler(self.mdi)
+ super(appWindow, self).resizeEvent(event)
+
+ def closeEvent(self, event):
+ if self.saveEvent():
+ event.accept()
+ else:
+ event.ignore()
+
+ def saveEvent(self, event):
+ alert = QMessageBox.question(self, self.objectName(), "All unsaved progress will be LOST!",
+ QMessageBox.StandardButtons(QMessageBox.Save|QMessageBox.Ignore|QMessageBox.Cancel), QMessageBox.Save)
+ if alert == QMessageBox.Cancel:
+ return False
+ else:
+ if alert == QMessageBox.Save:
+ if not self.saveProject():
+ return False
+ return True
if __name__ == '__main__':
app = ApplicationContext() # 1. Instantiate ApplicationContext
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index 4a1ec6b..2e2e0d9 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -4,7 +4,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import QBrush
from PyQt5.QtWidgets import (QFileDialog, QGraphicsScene, QGraphicsView,
QHBoxLayout, QMainWindow, QMdiSubWindow,
- QMessageBox, QTabWidget, QWidget, QMenuBar, QVBoxLayout)
+ QMessageBox, QTabWidget, QWidget, QMenuBar, QHBoxLayout)
from . import graphics
from .sizes import paperSizes, ppiList, sheetDimensionList
@@ -81,11 +81,13 @@ class canvas(QWidget):
self.painter.addItem(graphic)
class fileWindow(QMdiSubWindow):
- def __init__(self, parent = None, title = 'New Project'):
+ def __init__(self, parent = None, title = 'New Project', size = 4, ppi = 1):
super(fileWindow, self).__init__(parent)
+ self._ppi = ppiList[ppi]
+ self._canvasSize = sheetDimensionList[size]
self.widget = QWidget(self)
- layout = QVBoxLayout(self.widget)
+ layout = QHBoxLayout(self.widget)
self.tabber = QTabWidget(self.widget)
self.tabber.setObjectName(title)
@@ -98,11 +100,10 @@ class fileWindow(QMdiSubWindow):
menuFile = titleMenu.addMenu('File') #File Menu
menuFile.addAction("New", self.newDiagram)
layout.setMenuBar(titleMenu)
-
self.widget.setLayout(layout)
self.setWidget(self.widget)
self.setWindowTitle(title)
-
+
def changeTab(self, currentIndex):
pass
@@ -112,10 +113,18 @@ class fileWindow(QMdiSubWindow):
self.tabber.removeTab(currentIndex)
def newDiagram(self):
- diagram = canvas()
+ diagram = canvas(self.tabber, size = self._canvasSize, ppi = self._ppi)
diagram.setObjectName("New")
self.tabber.addTab(diagram, "New")
+ def resizeHandler(self, parent = None):
+ parentRect = parent.rect() if parent else self.parent().rect()
+ self.resize(parentRect().width(), parentRect().height())
+ self.setMaximumHeight(parentRect().height())
+ self.tabber.setMaximumHeight(parentRect().height())
+ for i in self.tabList:
+ i.setMaximumHeight(parentRect().height())
+
@property
def tabList(self):
return [self.tabber.widget(i) for i in range(self.tabCount)]
@@ -128,13 +137,15 @@ class fileWindow(QMdiSubWindow):
return {
"_classname_": self.__class__.__name__,
"ObjectName": self.objectName(),
+ "ppi": self._ppi,
+ "canvasSize": self._canvasSize,
"tabs": [i.__getstate__() for i in self.tabList]
}
def __setstate__(self, dict):
self.__init__(title = dict['ObjectName'])
for i in dict['tabs']:
- diagram = canvas()
+ diagram = canvas(self.tabber, size = dict['canvasSize'], ppi = dict['ppi'])
diagram.__setstate__(i)
self.tabber.addTab(diagram, i['ObjectName'])
@@ -152,7 +163,7 @@ class fileWindow(QMdiSubWindow):
event.accept()
else:
event.ignore()
- # super(fileWindow, self).closeEvent(event)
+
def saveEvent(self):
alert = QMessageBox.question(self, self.objectName(), "All unsaved progress will be LOST!",
QMessageBox.StandardButtons(QMessageBox.Save|QMessageBox.Ignore|QMessageBox.Cancel), QMessageBox.Save)