summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/python/main.py39
-rw-r--r--src/main/python/utils/canvas.py48
-rw-r--r--src/main/python/utils/dialogs.py53
3 files changed, 66 insertions, 74 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 0e29d88..953c6c8 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -8,16 +8,15 @@ from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout,
QGraphicsScene, QGraphicsView, QGridLayout,
QHBoxLayout, QLabel, QMainWindow, QMenu, QMenuBar,
QPushButton, QTabWidget, QWidget, QMdiArea, QMessageBox)
-#
+
from utils.canvas import canvas, fileWindow
from utils.sizes import ppiList, sheetDimensionList
+from utils import dialogs
class appWindow(QMainWindow):
def __init__(self, parent=None):
super(appWindow, self).__init__(parent)
- self._defaultPPI = '72'
- self._defaultCanvasSize = "A4"
titleMenu = self.menuBar()
self.mainWidget = QWidget(self)
@@ -53,22 +52,10 @@ class appWindow(QMainWindow):
self.toolbar.setObjectName("Toolbar")
self.toolbar.setFixedWidth(200)
toolbarLayout = QFormLayout(self.toolbar)
- self.toolbar.setLayout(toolbarLayout)
-
- def setCanvasSize(self, size):
- self._defaultCanvasSize = size
- activeCanvas = self.mdi.currentSubWindow()
- if activeCanvas:
- activeCanvas.canvasSize = size
-
- def setCanvasPPI(self, ppi):
- self._defaultPPI = ppi
- activeCanvas = self.mdi.currentSubWindow()
- if activeCanvas:
- activeCanvas.ppi = ppi
+ self.toolbar.setLayout(toolbarLayout)
def newProject(self):
- project = fileWindow(self.mdi, size = self._defaultCanvasSize, ppi = self._defaultPPI)
+ project = fileWindow(self.mdi)
project.setObjectName("New Project")
self.mdi.addSubWindow(project)
if not project.tabList:
@@ -91,6 +78,9 @@ class appWindow(QMainWindow):
if i.tabCount:
name = QFileDialog.getSaveFileName(self, 'Save File', f'New Diagram {j}', 'Process Flow Diagram (*.pfd)')
i.saveProject(name)
+ else:
+ return False
+ return True
def saveImage(self):
pass
@@ -104,23 +94,10 @@ class appWindow(QMainWindow):
super(appWindow, self).resizeEvent(event)
def closeEvent(self, event):
- if self.saveEvent():
+ if len(self.activeFiles) and dialogs.saveEvent(self):
event.accept()
else:
event.ignore()
-
- def saveEvent(self):
- if len(self.activeFiles):
- 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
@property
def activeFiles(self):
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index 270cf17..330d3be 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -7,11 +7,10 @@ from PyQt5.QtWidgets import (QComboBox, QDialog, QFileDialog, QFormLayout,
QLabel, QMainWindow, QMdiSubWindow, QMenu,
QMessageBox, QTabWidget, QWidget)
-from . import graphics
+from . import graphics, dialogs
from .sizes import paperSizes, ppiList, sheetDimensionList
from .tabs import customTabWidget
-
class canvas(QWidget):
def __init__(self, parent=None, size= 'A4', ppi= '72'):
super(canvas, self).__init__(parent)
@@ -72,30 +71,7 @@ class canvas(QWidget):
menu.exec_(self.mapToGlobal(point))
def adjustCanvasDialog(self):
- dialogBox = QDialog(self)
- dialogBox.setWindowTitle(self.objectName()+":Canvas Size")
- dialogBoxLayout = QFormLayout(dialogBox)
- sizeComboBox = QComboBox()
- sizeComboBox.addItems(sheetDimensionList)
- sizeComboBox.setCurrentIndex(4)
- sizeComboBox.activated[str].connect(self.setCanvasSize)
- sizeLabel = QLabel("Canvas Size")
- sizeLabel.setBuddy(sizeComboBox)
- sizeComboBox.setCurrentIndex(sheetDimensionList.index(self.canvasSize))
- dialogBoxLayout.setWidget(0, QFormLayout.LabelRole, sizeLabel)
- dialogBoxLayout.setWidget(0, QFormLayout.FieldRole, sizeComboBox)
-
- ppiComboBox = QComboBox()
- ppiComboBox.addItems(ppiList)
- ppiComboBox.activated[str].connect(self.setCanvasPPI)
- ppiLabel = QLabel("Canvas ppi")
- ppiLabel.setBuddy(ppiComboBox)
- ppiComboBox.setCurrentIndex(ppiList.index(self.ppi))
- dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel)
- dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox)
- dialogBox.setLayout(dialogBoxLayout)
-
- dialogBox.exec_()
+ self.canvasSize, self.ppi = dialogs.paperDims(self, self._canvasSize, self._ppi, self.objectName).exec_()
def __getstate__(self) -> dict:
return {
@@ -120,9 +96,6 @@ class fileWindow(QMdiSubWindow):
def __init__(self, parent = None, title = 'New Project', size = 'A4', ppi = '72'):
super(fileWindow, self).__init__(parent)
- self._ppi = ppi
- self._canvasSize = size
-
self.tabber = customTabWidget(self)
self.tabber.setObjectName(title)
self.tabber.tabCloseRequested.connect(self.closeTab)
@@ -158,12 +131,12 @@ class fileWindow(QMdiSubWindow):
pass
def closeTab(self, currentIndex):
- if self.saveEvent():
+ if dialogs.saveEvent(self):
self.tabber.widget(currentIndex).deleteLater()
self.tabber.removeTab(currentIndex)
def newDiagram(self):
- diagram = canvas(self.tabber, size = self._canvasSize, ppi = self._ppi)
+ diagram = canvas(self.tabber)
diagram.setObjectName("New")
self.tabber.addTab(diagram, "New")
@@ -209,19 +182,8 @@ class fileWindow(QMdiSubWindow):
return False
def closeEvent(self, event):
- if self.tabCount==0 or self.saveEvent():
+ if self.tabCount==0 or dialogs.saveEvent(self):
event.accept()
self.deleteLater()
else:
event.ignore()
-
- 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
diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py
new file mode 100644
index 0000000..d2b872c
--- /dev/null
+++ b/src/main/python/utils/dialogs.py
@@ -0,0 +1,53 @@
+from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox
+from .sizes import sheetDimensionList, ppiList
+
+class paperDims(QDialog):
+ def __init__(self, parent=None, size='A4', ppi='72', name='Canvas Size'):
+ super(paperDims, self).__init__(parent)
+
+ self._canvasSize = size
+ self._ppi = ppi
+
+ self.setWindowTitle(name+":Canvas Size")
+ dialogBoxLayout = QFormLayout(self)
+ sizeComboBox = QComboBox()
+ sizeComboBox.addItems(sheetDimensionList)
+ sizeComboBox.setCurrentIndex(4)
+ sizeComboBox.activated[str].connect(self.setCanvasSize)
+ sizeLabel = QLabel("Canvas Size")
+ sizeLabel.setBuddy(sizeComboBox)
+ sizeComboBox.setCurrentIndex(sheetDimensionList.index(self._canvasSize))
+ dialogBoxLayout.setWidget(0, QFormLayout.LabelRole, sizeLabel)
+ dialogBoxLayout.setWidget(0, QFormLayout.FieldRole, sizeComboBox)
+
+ ppiComboBox = QComboBox()
+ ppiComboBox.addItems(ppiList)
+ ppiComboBox.activated[str].connect(self.setCanvasPPI)
+ ppiLabel = QLabel("Canvas ppi")
+ ppiLabel.setBuddy(ppiComboBox)
+ ppiComboBox.setCurrentIndex(ppiList.index(self._ppi))
+ dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel)
+ dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox)
+ self.setLayout(dialogBoxLayout)
+ self.resize(400,300)
+
+ def setCanvasSize(self, size):
+ self._canvasSize = size
+
+ def setCanvasPPI(self, ppi):
+ self._ppi = ppi
+
+ def exec_(self):
+ super(paperDims, self).exec_()
+ return self._canvasSize, self._ppi
+
+def saveEvent(parent = None):
+ alert = QMessageBox.question(parent, parent.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 parent.saveProject():
+ return False
+ return True \ No newline at end of file