diff options
author | Blaine | 2020-05-15 18:08:40 +0530 |
---|---|---|
committer | Blaine | 2020-05-15 18:08:40 +0530 |
commit | a7ac738d66a385ce1c5b89ca21cb5f69d4b8e801 (patch) | |
tree | 93c27651fbb52d2a16ac6b8e373498ebe4ea9eb3 | |
parent | e666d20c72138e1cb679b2877d90604c06130926 (diff) | |
download | Chemical-PFD-a7ac738d66a385ce1c5b89ca21cb5f69d4b8e801.tar.gz Chemical-PFD-a7ac738d66a385ce1c5b89ca21cb5f69d4b8e801.tar.bz2 Chemical-PFD-a7ac738d66a385ce1c5b89ca21cb5f69d4b8e801.zip |
implement search box
-rw-r--r-- | src/main/python/utils/toolbar.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index 5abdbd4..93eb653 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -3,11 +3,13 @@ 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) +from re import search, IGNORECASE -from .data import defaultToolbarItems, toolbarItems +from .data import toolbarItems from .funcs import grouper from .layout import flowLayout + resourceManager = ApplicationContext() class toolbar(QDockWidget): @@ -16,8 +18,7 @@ class toolbar(QDockWidget): def __init__(self, parent = None): super(toolbar, self).__init__(parent) self.toolbarButtonDict = dict() - self.toolbarItems(defaultToolbarItems) - self.diagAreaLayout = None + self.toolbarItems(toolbarItems.keys()) self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) @@ -33,13 +34,16 @@ class toolbar(QDockWidget): self.diagArea = QScrollArea(self) self.layout.addWidget(self.diagArea) self.diagAreaWidget = QWidget() + self.diagAreaLayout = flowLayout(self.diagAreaWidget) self.setWidget(self.widget) - + + def clearLayout(self): + for i in reversed(range(self.diagAreaLayout.count())): + self.diagAreaLayout.itemAt(i).widget().setParent(self) + def populateToolbar(self, list): - if self.diagAreaLayout: - self.diagAreaLayout.deleteLater() - self.diagAreaLayout = flowLayout(self.diagAreaWidget) + self.clearLayout() for item in list: self.diagAreaLayout.addWidget(self.toolbarButtonDict[item]) self.diagArea.setWidget(self.diagAreaWidget) @@ -51,12 +55,10 @@ class toolbar(QDockWidget): if text == '': self.populateToolbar(self.toolbarItemList) else: - pass - #implement shortlisting + self.populateToolbar(filter(lambda x: search(text, x, IGNORECASE), self.toolbarItemList)) def resize(self): parent = self.parentWidget() - # print(self.orientation()) if parent.dockWidgetArea in [Qt.TopDockWidgetArea, Qt.BottomDockWidgetArea] and not self.isFloating(): self.layout.setDirection(QBoxLayout.LeftToRight) self.setFixedHeight(.12*parent.height()) @@ -78,11 +80,6 @@ class toolbar(QDockWidget): self.diagAreaWidget.setFixedHeight(self.diagAreaLayout.heightForWidth(width)) return super(toolbar, self).resizeEvent(event) - # @property - # def toolbarItems(self): - # return self._toolbarItems - - # @toolbarItems.setter def toolbarItems(self, items): for item in items: obj = toolbarItems[item] |