summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaine2020-04-25 09:13:05 +0530
committerBlaine2020-04-25 09:13:05 +0530
commit2d5481919e2030ad66183b0bea8f9702d5f8a2db (patch)
treef76157b165fb04ce8cb4cb823738f8852b1b6d1d
parentf7ff2e807ff15b1a29093203f7e744810de94435 (diff)
downloadChemical-PFD-2d5481919e2030ad66183b0bea8f9702d5f8a2db.tar.gz
Chemical-PFD-2d5481919e2030ad66183b0bea8f9702d5f8a2db.tar.bz2
Chemical-PFD-2d5481919e2030ad66183b0bea8f9702d5f8a2db.zip
fixed new tab button
-rw-r--r--src/main/python/main.py16
-rw-r--r--src/main/python/utils/canvas.py7
-rw-r--r--src/main/python/utils/tabs.py50
3 files changed, 33 insertions, 40 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index 52a8a33..66748cc 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -8,7 +8,7 @@ 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
@@ -53,8 +53,7 @@ class appWindow(QMainWindow):
self.toolbar.setObjectName("Toolbar")
self.toolbar.setFixedWidth(200)
toolbarLayout = QFormLayout(self.toolbar)
- self.toolbar.setLayout(toolbarLayout)
-
+ self.toolbar.setLayout(toolbarLayout)
def setCanvasSize(self, size):
self._defaultCanvasSize = size
@@ -85,8 +84,7 @@ class appWindow(QMainWindow):
project = pickle.load(file)
self.mdi.addSubWindow(project)
project.show()
- project.resizeHandler(self.mdi)
-
+ project.resizeHandler(self.mdi)
def saveProject(self):
for j, i in enumerate(self.mdi.subWindowList()):
@@ -112,7 +110,7 @@ class appWindow(QMainWindow):
event.ignore()
def saveEvent(self):
- if self.mdi.subWindowList():
+ 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)
@@ -123,7 +121,11 @@ class appWindow(QMainWindow):
if not self.saveProject():
return False
return True
-
+
+ @property
+ def activeFiles(self):
+ return filter(lambda x: x.tabCount()>=1, self.mdi.subWindowList())
+
if __name__ == '__main__':
app = ApplicationContext() # 1. Instantiate ApplicationContext
test = appWindow()
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py
index 9578b1a..fe5b527 100644
--- a/src/main/python/utils/canvas.py
+++ b/src/main/python/utils/canvas.py
@@ -73,6 +73,7 @@ class canvas(QWidget):
def adjustCanvasDialog(self):
dialogBox = QDialog(self)
+ dialogBox.setWindowTitle(self.objectName()+":Canvas Size")
dialogBoxLayout = QFormLayout(dialogBox)
sizeComboBox = QComboBox()
sizeComboBox.addItems(sheetDimensionList)
@@ -94,7 +95,7 @@ class canvas(QWidget):
dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox)
dialogBox.setLayout(dialogBoxLayout)
- dialogBox.show()
+ dialogBox.exec_()
def __getstate__(self) -> dict:
return {
@@ -126,7 +127,7 @@ class fileWindow(QMdiSubWindow):
self.tabber.setObjectName(title)
self.tabber.tabCloseRequested.connect(self.closeTab)
self.tabber.currentChanged.connect(self.changeTab)
- self.tabber.tab.plusClicked.connect(self.newDiagram)
+ self.tabber.plusClicked.connect(self.newDiagram)
self.setWidget(self.tabber)
self.setWindowTitle(title)
@@ -208,7 +209,7 @@ class fileWindow(QMdiSubWindow):
return False
def closeEvent(self, event):
- if self.saveEvent():
+ if self.tabCount or self.saveEvent():
event.accept()
else:
event.ignore()
diff --git a/src/main/python/utils/tabs.py b/src/main/python/utils/tabs.py
index 695a7fc..634a4ff 100644
--- a/src/main/python/utils/tabs.py
+++ b/src/main/python/utils/tabs.py
@@ -2,50 +2,40 @@ from PyQt5.QtWidgets import QTabBar, QPushButton, QTabWidget
from PyQt5.QtCore import pyqtSignal, QSize
class tabBarPlus(QTabBar):
- plusClicked = pyqtSignal()
- def __init__(self):
- super().__init__()
-
- self.plusButton = QPushButton("+", self)
- self.plusButton.setParent(self)
- self.setTabButton(0, QTabBar.RightSide, self.plusButton)
- self.plusButton.setFixedSize(20, 20)
- self.plusButton.clicked.connect(self.plusClicked.emit)
- # self.movePlusButton()
-
- def sizeHint(self):
- sizeHint = QTabBar.sizeHint(self)
- width = sizeHint.width()
- height = sizeHint.height()
- return QSize(width+25, height)
-
+ layoutChanged = pyqtSignal()
def resizeEvent(self, event):
super().resizeEvent(event)
- # self.movePlusButton()
+ self.layoutChanged.emit()
def tabLayoutChange(self):
super().tabLayoutChange()
- # self.movePlusButton()
+ self.layoutChanged.emit()
- def movePlusButton(self):
- size = sum([self.tabRect(i).width() for i in range(self.count())])
- h = self.geometry().top()
- w = self.width()
- if size > w:
- self.plusButton.move(w-54, h)
- else:
- self.plusButton.move(size, h)
class customTabWidget(QTabWidget):
-
+ plusClicked = pyqtSignal()
def __init__(self, parent=None):
super(customTabWidget, self).__init__(parent)
self.tab = tabBarPlus()
self.setTabBar(self.tab)
-
+
+ self.plusButton = QPushButton('+', self)
+ self.plusButton.setFixedSize(20, 20)
+ self.plusButton.clicked.connect(self.plusClicked.emit)
self.setMovable(True)
self.setTabsClosable(True)
+ self.tab.layoutChanged.connect(self.movePlusButton)
# self.tab.tabMoved.connect(self.moveTab)
- # self.tabCloseRequested.connect(self.removeTab) \ No newline at end of file
+ # self.tabCloseRequested.connect(self.removeTab)
+
+ def movePlusButton(self):
+ size = sum([self.tab.tabRect(i).width() for i in range(self.tab.count())])
+ h = max(self.tab.geometry().bottom() - 20, 0)
+ w = self.tab.width()
+ print(size, w, h)
+ if size > w:
+ self.plusButton.move(w-self.plusButton.width(), h)
+ else:
+ self.plusButton.move(size, h) \ No newline at end of file