summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorBlaine2020-04-23 14:52:57 +0530
committerBlaine2020-04-23 14:52:57 +0530
commit031cf7132bb1d622e8b49cfa9cbc5d1918869c21 (patch)
treed19d3532b4d501e90580a33104d40e155946cadb /src/main
parent1d2b1cec812101d941907c1a2976a74439e67afa (diff)
downloadChemical-PFD-031cf7132bb1d622e8b49cfa9cbc5d1918869c21.tar.gz
Chemical-PFD-031cf7132bb1d622e8b49cfa9cbc5d1918869c21.tar.bz2
Chemical-PFD-031cf7132bb1d622e8b49cfa9cbc5d1918869c21.zip
Added tabs and extended save feature
Diffstat (limited to 'src/main')
-rw-r--r--src/main/python/main.py81
-rw-r--r--src/main/python/utils/canvas.py116
-rw-r--r--src/main/python/utils/sizes.py40
3 files changed, 154 insertions, 83 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 79fb2c6..23c01e8 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -7,27 +7,28 @@ 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)
+ QPushButton, QTabWidget, QWidget, QMdiArea)
-from utils.canvas import canvas
+from utils.canvas import canvas, fileWindow
from utils.sizes import ppiList, sheetDimensionList
class appWindow(QMainWindow):
def __init__(self, parent=None):
super(appWindow, self).__init__(parent)
- # self.resize(1280, 720)
+ self.resize(1280, 720)
+ # self.setWindowState(Qt.WindowMaximized)
self._defaultPPI = 72
- self._defaultCanvasSize = "A0"
+ self._defaultCanvasSize = "A4"
titleMenu = self.menuBar()
self.mainWidget = QWidget(self)
self.mainWidget.setObjectName("Main Widget")
self.menuFile = titleMenu.addMenu('File') #File Menu
- self.menuFile.addAction("New", self.newDiagram)
- self.menuFile.addAction("Open", self.openDiagram)
- self.menuFile.addAction("Save", self.saveDiagram)
+ self.menuFile.addAction("New", self.newProject)
+ self.menuFile.addAction("Open", self.openProject)
+ self.menuFile.addAction("Save", self.saveProject)
self.menuGenerate = titleMenu.addMenu('Generate') #Generate menu
self.menuGenerate.addAction("Image", self.saveImage)
self.menuGenerate.addAction("Report", self.generateReport)
@@ -36,36 +37,18 @@ class appWindow(QMainWindow):
mainLayout = QHBoxLayout(self.mainWidget)
mainLayout.setObjectName("Main Layout")
- #Implement tabs
- self.tabber = QTabWidget(self.mainWidget)
- self.tabber.setObjectName("Tab windows")
- self.tabber.setTabsClosable(True)
- self.tabber.tabCloseRequested.connect(self.closeTab)
- self.tabber.currentChanged.connect(self.changeTab)
+ #ImpsaveProject
+ self.mdi = QMdiArea(self)
+ # self.mdi.closeEvent().connect(self.closeProject)
# add close action to tabs
self.createToolbar()
- # mainLayout.addWidget(self.toolbar, 0, 0, -1, 1)
- # mainLayout.addWidget(self.tabber, 0, 2, -1, 6)
mainLayout.addWidget(self.toolbar)
- mainLayout.addWidget(self.tabber)
+ mainLayout.addWidget(self.mdi)
#declare main window layout
self.mainWidget.setLayout(mainLayout)
self.setCentralWidget(self.mainWidget)
-
- def changeTab(self, currentIndex):
- activeTab = self.tabber.widget(currentIndex)
- if activeTab:
- self.sizeComboBox.setCurrentIndex(sheetDimensionList.index(activeTab._canvasSize))
- self.ppiComboBox.setCurrentIndex(ppiList.index(str(activeTab._ppi)))
- print(activeTab.dimensions)
- self.tabber.resize(*activeTab.dimensions)
-
- def closeTab(self, currentIndex):
- #todo add save alert
- self.tabber.widget(currentIndex).deleteLater()
- self.tabber.removeTab(currentIndex)
def createToolbar(self):
self.toolbar = QWidget(self.mainWidget)
@@ -74,6 +57,7 @@ class appWindow(QMainWindow):
toolbarLayout = QFormLayout(self.toolbar)
self.sizeComboBox = QComboBox()
self.sizeComboBox.addItems(sheetDimensionList)
+ self.sizeComboBox.setCurrentIndex(4)
self.sizeComboBox.activated[str].connect(self.setCanvasSize)
sizeLabel = QLabel("Canvas Size")
sizeLabel.setBuddy(self.sizeComboBox)
@@ -94,39 +78,38 @@ class appWindow(QMainWindow):
activeCanvas = self.tabber.currentWidget()
if activeCanvas:
activeCanvas.canvasSize = size
- self.tabber.resize(*activeCanvas.dimensions)
+ # self.tabber.resize(*activeCanvas.dimensions)
+ print(activeCanvas.dimensions)
def setCanvasPPI(self, ppi):
self._defaultPPI = ppi
activeCanvas = self.tabber.currentWidget()
if activeCanvas:
activeCanvas.ppi = ppi
- self.tabber.resize(*activeCanvas.dimensions)
+ # self.tabber.resize(*activeCanvas.dimensions)
- def newDiagram(self):
- diagram = canvas(size = self.sizeComboBox.currentIndex(), ppi = self.ppiComboBox.currentIndex())
- diagram.setObjectName("New")
- self.tabber.resize(*diagram.dimensions)
- self.tabber.addTab(diagram, "New")
+ def newProject(self):
+ project = fileWindow(self.mdi)
+ project.setObjectName("New Project")
+ self.mdi.addSubWindow(project)
+ if not project.tabList:
+ project.newDiagram()
+ project.show()
- def openDiagram(self):
+ def openProject(self):
name = QFileDialog.getOpenFileNames(self, 'Open File(s)', '', 'Process Flow Diagram (*pfd)')
if name:
- tabs = []
for files in name[0]:
with open(files,'rb') as file:
- tabs += pickle.load(file)
- for i in tabs:
- self.tabber.addTab(i, i.objectName())
+ project = pickle.load(file)
+ self.mdi.addSubWindow(project)
+ project.show()
- def saveDiagram(self):
- name = QFileDialog.getSaveFileName(self, 'Save File', 'New Diagram', 'Process Flow Diagram (*.pfd)')
- if name:
- with open(name[0],'wb') as file:
- tabs = []
- for i in range(self.tabber.count()):
- tabs.append(self.tabber.widget(i))
- pickle.dump(tabs, file)
+ def saveProject(self):
+ for j, i in enumerate(self.mdi.subWindowList()):
+ if i.tabCount:
+ name = QFileDialog.getSaveFileName(self, 'Save File', f'New Diagram {j}', 'Process Flow Diagram (*.pfd)')
+ i.saveProject(name)
def saveImage(self):
pass
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index 49c0bdb..4a1ec6b 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -1,26 +1,33 @@
+import pickle
+
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QBrush
-from PyQt5.QtWidgets import QGraphicsScene, QGraphicsView, QHBoxLayout, QWidget
+from PyQt5.QtWidgets import (QFileDialog, QGraphicsScene, QGraphicsView,
+ QHBoxLayout, QMainWindow, QMdiSubWindow,
+ QMessageBox, QTabWidget, QWidget, QMenuBar, QVBoxLayout)
from . import graphics
from .sizes import paperSizes, ppiList, sheetDimensionList
class canvas(QWidget):
- def __init__(self, parent=None, size= 0, ppi= 1):
+ def __init__(self, parent=None, size= 4, ppi= 1):
super(canvas, self).__init__(parent)
self._ppi = ppiList[ppi]
- self._canvasSize = sheetDimensionList[size]
- self.painter = QGraphicsScene(0, 0, *paperSizes[self.canvasSize][self.ppi])
+ self._canvasSize = sheetDimensionList[size]
+
+ self.painter = QGraphicsScene()
self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
- self.setMaximumSize(*paperSizes[self.canvasSize][self.ppi])
- self.resize(*paperSizes[self.canvasSize][self.ppi])
+
self.painter.setBackgroundBrush(QBrush(Qt.white))
+
self.view = QGraphicsView(self.painter)
- self.view.setMaximumSize(794, 1123)
+ self.view.setMinimumSize(595, 842)
+ self.view.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
+
self.layout = QHBoxLayout(self)
- self.layout.addWidget(self.view)
+ self.layout.addWidget(self.view)
self.setLayout(self.layout)
def setCanvasSize(self, size):
@@ -41,17 +48,14 @@ class canvas(QWidget):
self._canvasSize = size
if self.painter:
self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
- self.setMaximumSize(*paperSizes[self.canvasSize][self.ppi])
- self.resize(*paperSizes[self.canvasSize][self.ppi])
-
+ self.view.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
@ppi.setter
def ppi(self, ppi):
self._ppi = ppi
if self.painter:
self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
- self.setMaximumSize(*paperSizes[self.canvasSize][self.ppi])
- self.resize(*paperSizes[self.canvasSize][self.ppi])
+ self.view.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
@property
def dimensions(self):
@@ -73,5 +77,89 @@ class canvas(QWidget):
self.setObjectName(dict['ObjectName'])
for item in dict['items']:
graphic = getattr(graphics, dict['_classname_'])
- graphic.setstate(item)
+ graphic.__setstate__(item)
self.painter.addItem(graphic)
+
+class fileWindow(QMdiSubWindow):
+ def __init__(self, parent = None, title = 'New Project'):
+ super(fileWindow, self).__init__(parent)
+
+ self.widget = QWidget(self)
+ layout = QVBoxLayout(self.widget)
+
+ self.tabber = QTabWidget(self.widget)
+ self.tabber.setObjectName(title)
+ self.tabber.setTabsClosable(True)
+ self.tabber.tabCloseRequested.connect(self.closeTab)
+ self.tabber.currentChanged.connect(self.changeTab)
+ layout.addWidget(self.tabber)
+
+ titleMenu = QMenuBar(self)
+ 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
+
+ def closeTab(self, currentIndex):
+ if self.saveEvent():
+ self.tabber.widget(currentIndex).deleteLater()
+ self.tabber.removeTab(currentIndex)
+
+ def newDiagram(self):
+ diagram = canvas()
+ diagram.setObjectName("New")
+ self.tabber.addTab(diagram, "New")
+
+ @property
+ def tabList(self):
+ return [self.tabber.widget(i) for i in range(self.tabCount)]
+
+ @property
+ def tabCount(self):
+ return self.tabber.count()
+
+ def __getstate__(self) -> dict:
+ return {
+ "_classname_": self.__class__.__name__,
+ "ObjectName": self.objectName(),
+ "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.__setstate__(i)
+ self.tabber.addTab(diagram, i['ObjectName'])
+
+ def saveProject(self, name = None):
+ name = QFileDialog.getSaveFileName(self, 'Save File', f'New Diagram', 'Process Flow Diagram (*.pfd)') if not name else name
+ if name:
+ with open(name[0],'wb') as file:
+ pickle.dump(self, file)
+ return True
+ else:
+ return False
+
+ def closeEvent(self, event):
+ if self.saveEvent():
+ 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)
+ if alert == QMessageBox.Cancel:
+ return False
+ else:
+ if alert == QMessageBox.Save:
+ if not self.saveProject():
+ return False
+ return True \ No newline at end of file
diff --git a/src/main/python/utils/sizes.py b/src/main/python/utils/sizes.py
index 4d0686b..b0aa70a 100644
--- a/src/main/python/utils/sizes.py
+++ b/src/main/python/utils/sizes.py
@@ -1,33 +1,33 @@
paperSizes = {
"A0": {
- "72": {2384, 3370},
- "96": {3179, 4494},
- "150": {4967, 7022},
- "300": {9933, 14043}
+ "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}
+ "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}
+ "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}
+ "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}
+ "72": [595, 842],
+ "96": [794, 1123],
+ "150": [1240, 1754],
+ "300": [2480, 3508]
}
}