diff options
author | Blaine | 2020-04-29 16:19:42 +0530 |
---|---|---|
committer | Blaine | 2020-04-29 16:19:42 +0530 |
commit | d772066ac2a8f440990eba0632cf77b168d8849d (patch) | |
tree | ba8bba82cbb6cb3f279bffbadcef06412d310b9f | |
parent | 2268074e30d34d40a716ede92ef7bf1e1795d958 (diff) | |
download | Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.tar.gz Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.tar.bz2 Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.zip |
file dock working
-rw-r--r-- | src/main/python/main.py | 42 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 29 |
2 files changed, 47 insertions, 24 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index 8302b09..8bed5b3 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -2,10 +2,10 @@ import pickle import sys from fbs_runtime.application_context.PyQt5 import ApplicationContext -from PyQt5.QtCore import QObject, Qt, pyqtSignal, pyqtSlot +from PyQt5.QtCore import QObject, Qt, pyqtSignal from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout, QVBoxLayout, - QHBoxLayout, QLabel, QMainWindow, QMenu, QMenuBar, + QHBoxLayout, QLabel, QMainWindow, QMenu, QTabBar, QPushButton, QWidget, QMdiArea, QListWidget) from utils.canvas import canvas @@ -13,7 +13,6 @@ from utils.fileWindow import fileWindow from utils.sizes import ppiList, sheetDimensionList from utils import dialogs - class appWindow(QMainWindow): """ Application entry point, subclasses QMainWindow and implements the main widget, @@ -44,7 +43,6 @@ class appWindow(QMainWindow): self.mdi = QMdiArea(self) #create area for files to be displayed self.mdi.setObjectName('mdi area') - #create toolbar and add the toolbar plus mdi to layout self.createToolbar() mainLayout.addWidget(self.toolbar) @@ -60,6 +58,7 @@ class appWindow(QMainWindow): self.setCentralWidget(self.mainWidget) self.resize(1280, 720) #set collapse dim self.setWindowState(Qt.WindowMaximized) #launch maximized + self.mdi.subWindowActivated.connect(lambda x: self.tabSpace.setCurrentIndex(x.index) if (x is not None) else False) def createToolbar(self): #place holder for toolbar with fixed width, layout may change @@ -70,9 +69,17 @@ class appWindow(QMainWindow): self.toolbar.setLayout(toolbarLayout) def createTabSpace(self): - self.tabSpace = QListWidget(self.mainWidget) - self.tabSpace.setFlow(QListWidget.LeftToRight) + self.tabSpace = QTabBar(self.mainWidget) + # self.tabSpace.setFlow(QListWidget.LeftToRight) self.tabSpace.setFixedHeight(25) + self.tabSpace.currentChanged.connect(self.switchProject) + self.tabSpace.setVisible(False) + + def switchProject(self, index): + i = self.mdi.subWindowList(order=QMdiArea.CreationOrder)[index] + if not i.isVisible(): + i.show() + self.mdi.setActiveSubWindow(i) def newProject(self): #call to create a new file inside mdi area @@ -81,9 +88,12 @@ class appWindow(QMainWindow): self.mdi.addSubWindow(project) if not project.tabList: # important when unpickling a file instead project.newDiagram() #create a new tab in the new file - project.show() project.resizeHandler() - + project.fileCloseEvent.connect(self.fileClosed) + project.index = self.tabSpace.addTab("New Project") + if self.tabSpace.count() > 1: + self.tabSpace.setVisible(True) + def openProject(self): #show the open file dialog to open a saved file, then unpickle it. name = QFileDialog.getOpenFileNames(self, 'Open File(s)', '', 'Process Flow Diagram (*pfd)') @@ -92,8 +102,12 @@ class appWindow(QMainWindow): with open(files,'rb') as file: project = pickle.load(file) self.mdi.addSubWindow(project) - project.show() - + project.show() + project.resizeHandler() + project.fileCloseEvent.connect(self.fileClosed) + if self.tabSpace.count() > 1: + self.tabSpace.setVisible(True) + def saveProject(self): #pickle all files in mdi area for j, i in enumerate(self.mdi.activeFiles): #get list of all windows with atleast one tab @@ -125,6 +139,14 @@ class appWindow(QMainWindow): else: event.accept() + def fileClosed(self, index): + self.tabSpace.removeTab(index) + i = self.mdi.subWindowList(order=QMdiArea.CreationOrder)[self.tabSpace.currentIndex()] + i.show() + self.mdi.setActiveSubWindow(i) + if self.tabSpace.count() <=1 : + self.tabSpace.setVisible(False) + @property def activeFiles(self): return [i for i in self.mdi.subWindowList() if i.tabCount] diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 26aa165..1e8258d 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -1,22 +1,24 @@ import pickle -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtWidgets import QMdiSubWindow, QFileDialog, QMenu, QSizePolicy from . import dialogs from .canvas import canvas from .tabs import customTabWidget - class fileWindow(QMdiSubWindow): """ This defines a single file, inside the application, consisting of multiple tabs that contain canvases. Pre-Defined so that a file can be instantly created without defining the structure again. """ + fileCloseEvent = pyqtSignal(int) + fileMinimized = pyqtSignal(int) def __init__(self, parent = None, title = 'New Project', size = 'A4', ppi = '72'): super(fileWindow, self).__init__(parent) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + self.index = None #Uses a custom QTabWidget that houses a custom new Tab Button, used to house the seperate # diagrams inside a file self.tabber = customTabWidget(self) @@ -77,22 +79,20 @@ class fileWindow(QMdiSubWindow): def resizeEvent(self, event): # self.resizeHandler() - # super(fileWindow, self).resizeEvent(event) - pass + super(fileWindow, self).resizeEvent(event) + # pass def stateChange(self, oldState, newState): - areaRect = self.mdiArea().rect() if newState == Qt.WindowMinimized: - pass - elif newState == Qt.WindowMaximized: - pass + self.hide() else: - if oldState == Qt.WindowMinimized: - # print("min to full") - pass - else: - # print("max to full") - pass + if not self.isVisible(): + self.show() + if newState == Qt.WindowMaximized: + self.setFixedSize(self.mdiArea().size()) + + def showShaded(self): + self.hide() @property def tabList(self): @@ -119,6 +119,7 @@ class fileWindow(QMdiSubWindow): if self.tabCount==0 or dialogs.saveEvent(self): event.accept() self.deleteLater() + self.fileCloseEvent.emit(self.index) else: event.ignore() |