summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/python/main.py2
-rw-r--r--src/main/python/utils/toolbar.py22
2 files changed, 14 insertions, 10 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py
index ff41413..ed64570 100644
--- a/src/main/python/main.py
+++ b/src/main/python/main.py
@@ -73,7 +73,7 @@ class appWindow(QMainWindow):
# self.addToolBar(Qt.LeftToolBarArea, self.toolbar)
self.addDockWidget(Qt.LeftDockWidgetArea, self.toolbar)
self.toolbar.toolbuttonClicked.connect(self.toolButtonClicked)
- self.toolbar.populateToolbar(self.toolbar.toolbarItemList)
+ self.toolbar.populateToolbar()
def toolButtonClicked(self, object):
currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter
diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py
index 7883136..e488464 100644
--- a/src/main/python/utils/toolbar.py
+++ b/src/main/python/utils/toolbar.py
@@ -2,7 +2,7 @@ from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtCore import QSize, Qt, pyqtSignal, QMimeData
from PyQt5.QtGui import QIcon, QDrag
from PyQt5.QtWidgets import (QBoxLayout, QDockWidget, QGridLayout, QLineEdit,
- QScrollArea, QToolButton, QWidget, QApplication, QStyle)
+ QScrollArea, QToolButton, QWidget, QApplication, QStyle, QLabel)
from re import search, IGNORECASE
from .data import toolbarItems
@@ -20,12 +20,12 @@ class toolbar(QDockWidget):
def __init__(self, parent = None):
super(toolbar, self).__init__(parent)
self.toolbarButtonDict = dict() #initializes empty dict to store toolbar buttons
- self.toolbarButtonClassList = []
+ self.toolbarLabelDict = dict()
self.toolbarItems(toolbarItems.keys()) #creates all necessary buttons
self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable)
#mainly used to disable closeability of QDockWidget
-
+ self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.NoDockWidgetArea)
#declare main widget and layout
self.widget = QWidget(self)
self.layout = QBoxLayout(QBoxLayout.TopToBottom, self.widget)
@@ -57,11 +57,12 @@ class toolbar(QDockWidget):
# since changing parent would effect indexing, its important to go in reverse
self.diagAreaLayout.itemAt(i).widget().setParent(self)
- def populateToolbar(self, list):
+ def populateToolbar(self, filterFunc=None):
#called everytime the button box needs to be updated(incase of a filter)
self.clearLayout() #clears layout
- for itemClass in list:
- for item in self.toolbarButtonDict[itemClass].keys():
+ for itemClass in self.toolbarButtonDict.keys():
+ self.diagAreaLayout.addWidget(self.toolbarLabelDict[itemClass])
+ for item in filter(filterFunc, self.toolbarButtonDict[itemClass].keys()):
self.diagAreaLayout.addWidget(self.toolbarButtonDict[itemClass][item])
self.resize()
@@ -70,10 +71,10 @@ class toolbar(QDockWidget):
# self.populateToolbar() # populate with toolbar items
text = self.searchBox.text() #get text
if text == '':
- self.populateToolbar(self.toolbarItemList) # restore everything on empty string
+ self.populateToolbar() # restore everything on empty string
else:
# use regex to search filter through button list and add the remainder to toolbar
- self.populateToolbar(filter(lambda x: search(text, x, IGNORECASE), self.toolbarItemList))
+ self.populateToolbar(lambda x: search(text, x, IGNORECASE))
def resize(self):
# called when main window resizes, overloading resizeEvent caused issues.
@@ -81,6 +82,8 @@ class toolbar(QDockWidget):
self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later
# self.setFixedHeight(self.height()) #span available height
width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent)
+ for _, label in self.toolbarLabelDict.items():
+ label.setFixedWidth(width)
# the following line, sets the required height for the current width, so that blank space doesnt occur
self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width))
self.setMinimumWidth(.17*parent.width()) #12% of parent width
@@ -92,7 +95,8 @@ class toolbar(QDockWidget):
#helper functions to create required buttons
for itemClass in itemClasses:
self.toolbarButtonDict[itemClass] = {}
- self.toolbarButtonClassList.append(itemClass)
+ label = QLabel(itemClass)
+ self.toolbarLabelDict[itemClass] = label
for item in toolbarItems[itemClass].keys():
obj = toolbarItems[itemClass][item]
button = toolbarButton(self, obj)