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 /src/main/python/main.py | |
parent | 2268074e30d34d40a716ede92ef7bf1e1795d958 (diff) | |
download | Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.tar.gz Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.tar.bz2 Chemical-PFD-d772066ac2a8f440990eba0632cf77b168d8849d.zip |
file dock working
Diffstat (limited to 'src/main/python/main.py')
-rw-r--r-- | src/main/python/main.py | 42 |
1 files changed, 32 insertions, 10 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] |