diff options
author | Blaine | 2020-05-12 20:08:10 +0530 |
---|---|---|
committer | Blaine | 2020-05-12 20:08:10 +0530 |
commit | b228d617e0344bc3922a29ebaf742d855eb91266 (patch) | |
tree | d761d1fada29beb5c50c3cae5972dd305d350b31 /src/main/python | |
parent | 27bc65463dd9867c5d8c011639b7958bd7824518 (diff) | |
download | Chemical-PFD-b228d617e0344bc3922a29ebaf742d855eb91266.tar.gz Chemical-PFD-b228d617e0344bc3922a29ebaf742d855eb91266.tar.bz2 Chemical-PFD-b228d617e0344bc3922a29ebaf742d855eb91266.zip |
toolbar sectioning
Diffstat (limited to 'src/main/python')
-rw-r--r-- | src/main/python/main.py | 11 | ||||
-rw-r--r-- | src/main/python/utils/data.py | 266 | ||||
-rw-r--r-- | src/main/python/utils/funcs.py | 1 | ||||
-rw-r--r-- | src/main/python/utils/layout.py | 88 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 77 |
5 files changed, 412 insertions, 31 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index 583baf0..b54f931 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -65,11 +65,13 @@ class appWindow(QMainWindow): def createToolbar(self): #place holder for toolbar with fixed width, layout may change self.toolbar = toolbar(self.mainWidget) - # self.toolbar.setObjectName("Toolbar") - self.addToolBar(Qt.LeftToolBarArea, self.toolbar) + self.toolbar.setObjectName("Toolbar") + self.addToolBar(Qt.LeftToolBarArea, self.toolbar) + # self.addDockWidget(Qt.LeftDockWidgetArea, self.toolbar) self.toolbar.toolbuttonClicked.connect(self.toolButtonClicked) self.toolbar.populateToolbar() + def toolButtonClicked(self, object): currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter if currentDiagram: @@ -133,6 +135,7 @@ class appWindow(QMainWindow): #overload resize to also handle resize on file windows inside for i in self.mdi.subWindowList(): i.resizeHandler() + # self.toolbar.resize() super(appWindow, self).resizeEvent(event) def closeEvent(self, event): @@ -194,7 +197,7 @@ class appWindow(QMainWindow): if __name__ == '__main__': app = ApplicationContext() # 1. Instantiate ApplicationContext - test = appWindow() - test.show() + main = appWindow() + main.show() exit_code = app.app.exec_() # 2. Invoke appctxt.app.exec_() sys.exit(exit_code) diff --git a/src/main/python/utils/data.py b/src/main/python/utils/data.py index d0b5ca1..593cb1b 100644 --- a/src/main/python/utils/data.py +++ b/src/main/python/utils/data.py @@ -41,7 +41,271 @@ toolbarItems = { 'icon': 'ellipse.png', 'object': 'QGraphicsEllipseItem', 'args': [20, 20, 300, 300] - } + }, + 'Ellipse2': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse3': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse4': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse5': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse6': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse7': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse8': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse9': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse11': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse12': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse13': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse14': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse15': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse16': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse17': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse18': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse19': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse20': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse21': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse22': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse23': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse24': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse25': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse26': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse27': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse28': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse29': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse30': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse31': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse32': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse33': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse34': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse35': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse36': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse37': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse38': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse39': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse40': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse41': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse42': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse43': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse44': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse45': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, + 'Ellipse46': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + }, } defaultToolbarItems = toolbarItems.keys()
\ No newline at end of file diff --git a/src/main/python/utils/funcs.py b/src/main/python/utils/funcs.py index cd2dc65..7796ece 100644 --- a/src/main/python/utils/funcs.py +++ b/src/main/python/utils/funcs.py @@ -1,4 +1,5 @@ from itertools import zip_longest + def grouper(n, iterable, fillvalue=None): args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args)
\ No newline at end of file diff --git a/src/main/python/utils/layout.py b/src/main/python/utils/layout.py new file mode 100644 index 0000000..1aa59ac --- /dev/null +++ b/src/main/python/utils/layout.py @@ -0,0 +1,88 @@ +from PyQt5.QtCore import Qt, QRect, QPoint, QSize +from PyQt5.QtWidgets import QLayout, QSizePolicy + +class flowLayout(QLayout): + def __init__(self, parent=None, margin=0, spacing=-1): + super(flowLayout, self).__init__(parent) + + if parent is not None: + self.setContentsMargins(margin, margin, margin, margin) + + self.setSpacing(spacing) + + self.itemList = [] + + def __del__(self): + item = self.takeAt(0) + while item: + item = self.takeAt(0) + + def addItem(self, item): + self.itemList.append(item) + + def count(self): + return len(self.itemList) + + def itemAt(self, index): + if index >= 0 and index < len(self.itemList): + return self.itemList[index] + + return None + + def takeAt(self, index): + if index >= 0 and index < len(self.itemList): + return self.itemList.pop(index) + + return None + + def expandingDirections(self): + return Qt.Orientations(Qt.Orientation(0)) + + def hasHeightForWidth(self): + return True + + def heightForWidth(self, width): + height = self.doLayout(QRect(0, 0, width, 0), True) + return height + + def setGeometry(self, rect): + super(flowLayout, self).setGeometry(rect) + self.doLayout(rect, False) + + def sizeHint(self): + return self.minimumSize() + + def minimumSize(self): + size = QSize() + + for item in self.itemList: + size = size.expandedTo(item.minimumSize()) + + margin, _, _, _ = self.getContentsMargins() + + size += QSize(2 * margin, 2 * margin) + return size + + def doLayout(self, rect, testOnly): + x = rect.x() + y = rect.y() + lineHeight = 0 + + for item in self.itemList: + wid = item.widget() + spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal) + spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical) + nextX = x + item.sizeHint().width() + spaceX + if nextX - spaceX > rect.right() and lineHeight > 0: + x = rect.x() + y = y + lineHeight + spaceY + nextX = x + item.sizeHint().width() + spaceX + lineHeight = 0 + + if not testOnly: + item.setGeometry(QRect(QPoint(x, y), item.sizeHint())) + + x = nextX + lineHeight = max(lineHeight, item.sizeHint().height()) + + return y + lineHeight - rect.y() diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index 9a48aa9..68e8865 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -1,9 +1,14 @@ -from PyQt5.QtCore import pyqtSignal, QSize +from fbs_runtime.application_context.PyQt5 import ApplicationContext + +from PyQt5.QtCore import pyqtSignal, QSize, Qt from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QToolBar, QWidget, QHBoxLayout, QLineEdit, QToolButton +from PyQt5.QtWidgets import QToolBar, QWidget, QGridLayout, QLineEdit, QToolButton, QScrollArea, QDockWidget, QVBoxLayout from .data import defaultToolbarItems, toolbarItems from .funcs import grouper +from .layout import flowLayout + +resourceManager = ApplicationContext() class toolbar(QToolBar): toolbuttonClicked = pyqtSignal(dict) @@ -11,32 +16,41 @@ class toolbar(QToolBar): def __init__(self, parent = None): super(toolbar, self).__init__(parent) self.toolbarItems = defaultToolbarItems - self.toolbarWidgets = [] - self.setFixedWidth = 200 + # self.widget = QWidget(self) + # self.layout = QVBoxLayout(self.widget) + self.setAllowedAreas(Qt.LeftToolBarArea | Qt.RightToolBarArea) self.searchBox = QLineEdit(self) + # self.searchBox = QLineEdit(self.widget) self.searchBox.textChanged.connect(self.searchQuery) self.addWidget(self.searchBox) + # self.layout.addWidget(self.searchBox) + + self.addSeparator() + self.diagArea = QScrollArea(self) + self.addWidget(self.diagArea) + # self.layout.addWidget(self.diagArea) + self.diagAreaWidget = QWidget() + self.diagAreaWidget.setFixedWidth(200) + # self.setWidget(self.widget) def populateToolbar(self): - # self.clearWidgets() - - for a, b, c in grouper(3, self.toolbarItems): - widget = QWidget(self) - layout = QHBoxLayout(widget) - if a is not None: - item = toolbarItems[a] - button = toolbarButton(self, item) - button.clicked.connect(lambda : self.toolbuttonClicked.emit(item)) - layout.addWidget(button) - # layout.addItem(b) - # layout.addItem(c) - self.toolbarWidgets.append(widget) - self.addWidget(widget) - - def clearWidgets(self): - for i in self.toolbarWidgets(): - i.deleteLater() + # layout = QGridLayout(self.diagAreaWidget) + # n = self.width() // 45 + # for i, items in enumerate(grouper(n, self.toolbarItems)): + # for j, item in enumerate(items): + # if item is not None: + # item = toolbarItems[item] + # button = toolbarButton(self, item) + # button.clicked.connect(lambda : self.toolbuttonClicked.emit(item)) + # layout.addWidget(button, i, j, 1, 1, alignment=Qt.AlignHCenter) + layout = flowLayout(self.diagAreaWidget) + for item in self.toolbarItems: + obj = toolbarItems[item] + button = toolbarButton(self, obj) + button.clicked.connect(lambda : self.toolbuttonClicked.emit(obj)) + layout.addWidget(button) + self.diagArea.setWidget(self.diagAreaWidget) def searchQuery(self): # shorten toolbaritems list with search items @@ -47,12 +61,23 @@ class toolbar(QToolBar): else: pass #implement shortlisting - + + def resize(self): + pass + + def resizeEvent(self, event): + self.resize() + self.setFixedWidth(.11*self.parentWidget().width()) + self.diagAreaWidget.setFixedWidth(.11*self.parentWidget().width() - 30) + self.diagArea.setFixedHeight(.7*self.parentWidget().height()) + return super(toolbar, self).resizeEvent(event) + class toolbarButton(QToolButton): def __init__(self, parent = None, item = None): super(toolbarButton, self).__init__(parent) - self.setIcon(QIcon(f'../../icons/toolbar/{item["icon"]}')) - self.setIconSize(QSize(25, 25)) + self.setIcon(QIcon(resourceManager.get_resource(f'toolbar/{item["icon"]}'))) + self.setIconSize(QSize(40, 40)) self.setText(f'item["name"]') - self.setFixedSize(30, 30)
\ No newline at end of file + self.setFixedSize(30, 30) +
\ No newline at end of file |