summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaine2020-04-22 12:38:53 +0530
committerBlaine2020-04-22 12:38:53 +0530
commit89eeec65b7307df11c59d9dca8089f0ae62b3a47 (patch)
tree1cb72e40f2e6dbe33bc3c0f71d25bbc41a257a28
parent6416c34f957b2f0d2c5de318dc7023f9f67e9042 (diff)
downloadChemical-PFD-89eeec65b7307df11c59d9dca8089f0ae62b3a47.tar.gz
Chemical-PFD-89eeec65b7307df11c59d9dca8089f0ae62b3a47.tar.bz2
Chemical-PFD-89eeec65b7307df11c59d9dca8089f0ae62b3a47.zip
Switching tabs, updates combo box values
-rw-r--r--src/main/python/main.py62
-rw-r--r--src/main/python/utils/canvas.py15
-rw-r--r--src/main/python/utils/sizes.py46
3 files changed, 73 insertions, 50 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index c19e7c7..ebc80a2 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -7,6 +7,7 @@ from PyQt5.QtWidgets import (QWidget, QComboBox, QMainWindow, QGraphicsScene,
QPushButton, QMenuBar, QMenu, QFormLayout, QTabWidget)
from utils.canvas import canvas
+from utils.sizes import sheetDimensionList, ppiList
import sys
class appWindow(QMainWindow):
@@ -18,50 +19,62 @@ class appWindow(QMainWindow):
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("New", self.newDiagram)
+ self.menuFile.addAction("Open", self.openDiagram)
+ self.menuFile.addAction("Save", self.saveDiagram)
self.menuGenerate = titleMenu.addMenu('Generate') #Generate menu
self.menuGenerate.addAction("Image", self.saveImage)
self.menuGenerate.addAction("Report", self.generateReport)
-
mainLayout = QGridLayout(self.mainWidget)
+ mainLayout.setObjectName("Main Layout")
+
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)
# add close action to tabs
self.createToolbar()
- mainLayout.addLayout(self.toolbar, 0, 0, -1, 1)
+ mainLayout.addWidget(self.toolbar, 0, 0, -1, 1)
mainLayout.addWidget(self.tabber, 0, 2, -1, 10)
self.mainWidget.setLayout(mainLayout)
self.setCentralWidget(self.mainWidget)
+ def changeTab(self, currentIndex):
+ activeTab = self.tabber.widget(currentIndex)
+ self.sizeComboBox.setCurrentIndex(int(activeTab._canvasSize[1]))
+ self.ppiComboBox.setCurrentIndex(ppiList.index(str(activeTab._ppi)))
+
def closeTab(self, currentIndex):
#todo add save alert
self.tabber.widget(currentIndex).deleteLater()
self.tabber.removeTab(currentIndex)
def createToolbar(self):
- self.toolbar = QFormLayout(self.mainWidget)
- sizeComboBox = QComboBox()
- sizeComboBox.addItems([f'A{i}' for i in range(5)])
- # sizeComboBox.activated[str].connect(lambda: self.tabber.currentWidget().setCanvasSize)
- sizeComboBox.activated[str].connect(self.setCanvasSize)
+ self.toolbar = QWidget(self.mainWidget)
+ self.toolbar.setObjectName("Toolbar")
+ toolbarLayout = QFormLayout(self.toolbar)
+ self.sizeComboBox = QComboBox()
+ self.sizeComboBox.addItems(sheetDimensionList)
+ self.sizeComboBox.activated[str].connect(self.setCanvasSize)
sizeLabel = QLabel("Canvas Size")
- sizeLabel.setBuddy(sizeComboBox)
- self.toolbar.setWidget(0, QFormLayout.LabelRole, sizeLabel)
- self.toolbar.setWidget(0, QFormLayout.FieldRole, sizeComboBox)
+ sizeLabel.setBuddy(self.sizeComboBox)
+ toolbarLayout.setWidget(0, QFormLayout.LabelRole, sizeLabel)
+ toolbarLayout.setWidget(0, QFormLayout.FieldRole, self.sizeComboBox)
- ppiComboBox = QComboBox()
- ppiComboBox.addItems(["72", "96", "150", "300"])
- # ppiComboBox.activated[str].connect(lambda: self.tabber.currentWidget().setCanvasPPI)
- ppiComboBox.activated[str].connect(self.setCanvasPPI)
+ self.ppiComboBox = QComboBox()
+ self.ppiComboBox.addItems(ppiList)
+ self.ppiComboBox.activated[str].connect(self.setCanvasPPI)
ppiLabel = QLabel("Canvas ppi")
- ppiLabel.setBuddy(ppiComboBox)
- self.toolbar.setWidget(1, QFormLayout.LabelRole, ppiLabel)
- self.toolbar.setWidget(1, QFormLayout.FieldRole, ppiComboBox)
+ ppiLabel.setBuddy(self.ppiComboBox)
+ toolbarLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel)
+ toolbarLayout.setWidget(1, QFormLayout.FieldRole, self.ppiComboBox)
+ self.toolbar.setLayout(toolbarLayout)
def setCanvasSize(self, size):
self._defaultCanvasSize = size
@@ -76,12 +89,21 @@ class appWindow(QMainWindow):
activeCanvas.ppi = ppi
def newDiagram(self):
- diagram = canvas(size = self._defaultCanvasSize, ppi = self._defaultPPI)
+ diagram = canvas(size = self.sizeComboBox.currentIndex(), ppi = self.ppiComboBox.currentIndex())
+ diagram.setObjectName("New")
self.tabber.addTab(diagram, "New")
- def saveImage(self):
+ def openDiagram(self):
pass
+ def saveDiagram(self):
+ pass
+
+ def saveImage(self):
+ # activeDiagram = QGraphicsScene()
+ activeDiagram = self.tabber.currentWidget()
+ activeDiagram.painter.addEllipse(10, 10, 100, 100)
+
def generateReport(self):
pass
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index 258d901..a01092c 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -1,15 +1,14 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QBrush
from PyQt5.QtWidgets import QWidget, QGraphicsScene, QGraphicsView, QHBoxLayout
-from .sizes import paperSizes
+from .sizes import paperSizes, sheetDimensionList, ppiList
class canvas(QWidget):
- def __init__(self, parent=None, size= "A0", ppi= 72):
+ def __init__(self, parent=None, size= 0, ppi= 1):
super(canvas, self).__init__(parent)
- self._ppi = ppi
- self._canvasSize = size
+ self._ppi = ppiList[ppi]
+ self._canvasSize = sheetDimensionList[size]
self.resize(1280, 720)
-
self.painter = QGraphicsScene(0, 0, *paperSizes[self.canvasSize][self.ppi])
self.painter.setBackgroundBrush(QBrush(Qt.white))
@@ -36,11 +35,9 @@ class canvas(QWidget):
self._canvasSize = size
if self.painter:
self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
- # print(*paperSizes[self.canvasSize][self.ppi])
@ppi.setter
def ppi(self, ppi):
- self._ppi = int(ppi)
+ self._ppi = ppi
if self.painter:
- self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi])
- # print(*paperSizes[self.canvasSize][self.ppi]) \ No newline at end of file
+ self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi]) \ No newline at end of file
diff --git a/src/main/python/utils/sizes.py b/src/main/python/utils/sizes.py
index fc444cf..4d0686b 100644
--- a/src/main/python/utils/sizes.py
+++ b/src/main/python/utils/sizes.py
@@ -1,32 +1,36 @@
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}
}
-} \ No newline at end of file
+}
+
+sheetDimensionList = [f'A{i}' for i in range(5)]
+
+ppiList = ["72", "96", "150", "300"] \ No newline at end of file