diff options
author | Blaine | 2020-04-23 15:35:49 +0530 |
---|---|---|
committer | Blaine | 2020-04-23 15:35:49 +0530 |
commit | 9879d34bb984c7d4ef466c79472b3193275365b1 (patch) | |
tree | 28282b37e0d1e490e1b84b61209bcdfd8cdddca4 /src/main | |
parent | 38568178ac8541700ca19cf73843fc3f1b2a928f (diff) | |
download | Chemical-PFD-9879d34bb984c7d4ef466c79472b3193275365b1.tar.gz Chemical-PFD-9879d34bb984c7d4ef466c79472b3193275365b1.tar.bz2 Chemical-PFD-9879d34bb984c7d4ef466c79472b3193275365b1.zip |
can change canvas and ppi sizes
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/main.py | 36 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 34 |
2 files changed, 45 insertions, 25 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index 7ae9d63..8f11944 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -15,10 +15,9 @@ from utils.sizes import ppiList, sheetDimensionList class appWindow(QMainWindow): def __init__(self, parent=None): - super(appWindow, self).__init__(parent) - self.resize(1280, 720) + super(appWindow, self).__init__(parent) # self.setWindowState(Qt.WindowMaximized) - self._defaultPPI = 72 + self._defaultPPI = '72' self._defaultCanvasSize = "A4" titleMenu = self.menuBar() @@ -47,6 +46,7 @@ class appWindow(QMainWindow): #declare main window layout self.mainWidget.setLayout(mainLayout) self.setCentralWidget(self.mainWidget) + self.resize(1280, 720) def createToolbar(self): self.toolbar = QWidget(self.mainWidget) @@ -74,19 +74,14 @@ class appWindow(QMainWindow): def setCanvasSize(self, size): self._defaultCanvasSize = size activeCanvas = self.mdi.currentSubWindow() - activeCanvas._defaultCanvasSize = size if activeCanvas: activeCanvas.canvasSize = size - # self.tabber.resize(*activeCanvas.dimensions) - print(activeCanvas.dimensions) def setCanvasPPI(self, ppi): self._defaultPPI = ppi activeCanvas = self.mdi.currentSubWindow() - activeCanvas._defaultPPI = ppi if activeCanvas: - activeCanvas.ppi = ppi - # self.tabber.resize(*activeCanvas.dimensions) + activeCanvas.ppi = ppi def newProject(self): project = fileWindow(self.mdi, size = self._defaultCanvasSize, ppi = self._defaultPPI) @@ -121,7 +116,8 @@ class appWindow(QMainWindow): pass def resizeEvent(self, event): - self.mdi.activeSubWindow().resizeHandler(self.mdi) + if self.mdi.activeSubWindow(): + self.mdi.activeSubWindow().resizeHandler(self.mdi) super(appWindow, self).resizeEvent(event) def closeEvent(self, event): @@ -130,15 +126,17 @@ class appWindow(QMainWindow): 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 + def saveEvent(self): + if self.mdi.subWindowList(): + 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__': diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 2e2e0d9..2d840f6 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -11,11 +11,11 @@ from .sizes import paperSizes, ppiList, sheetDimensionList class canvas(QWidget): - def __init__(self, parent=None, size= 4, ppi= 1): + def __init__(self, parent=None, size= 'A4', ppi= '72'): super(canvas, self).__init__(parent) - self._ppi = ppiList[ppi] - self._canvasSize = sheetDimensionList[size] + self._ppi = ppi + self._canvasSize = size self.painter = QGraphicsScene() self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi]) @@ -81,11 +81,11 @@ class canvas(QWidget): self.painter.addItem(graphic) class fileWindow(QMdiSubWindow): - def __init__(self, parent = None, title = 'New Project', size = 4, ppi = 1): + def __init__(self, parent = None, title = 'New Project', size = 'A4', ppi = '72'): super(fileWindow, self).__init__(parent) - self._ppi = ppiList[ppi] - self._canvasSize = sheetDimensionList[size] + self._ppi = ppi + self._canvasSize = size self.widget = QWidget(self) layout = QHBoxLayout(self.widget) @@ -104,6 +104,28 @@ class fileWindow(QMdiSubWindow): self.setWidget(self.widget) self.setWindowTitle(title) + @property + def canvasSize(self): + return self._canvasSize + @property + def ppi(self): + return self._ppi + + @canvasSize.setter + def canvasSize(self, size): + self._canvasSize = sheetDimensionList.index(size) + if self.tabCount: + activeTab = self.tabber.currentWidget() + activeTab.canvasSize = size + + @ppi.setter + def ppi(self, ppi): + self._ppi = ppiList.index(ppi) + if self.tabCount: + activeTab = self.tabber.currentWidget() + activeTab.ppi = ppi + + def changeTab(self, currentIndex): pass |