summaryrefslogtreecommitdiff
path: root/src/main/python/utils/toolbar.py
diff options
context:
space:
mode:
authorBlaine2020-05-22 19:19:08 +0530
committerBlaine2020-05-22 19:19:08 +0530
commit7417af719f678f3b00d513e8e21b4759bf19e960 (patch)
treea7accce7dcf842fc92d635df92c3e4b271322ee8 /src/main/python/utils/toolbar.py
parent10b6c82b0a173f462740172f38c8da3db9f9f615 (diff)
downloadChemical-PFD-7417af719f678f3b00d513e8e21b4759bf19e960.tar.gz
Chemical-PFD-7417af719f678f3b00d513e8e21b4759bf19e960.tar.bz2
Chemical-PFD-7417af719f678f3b00d513e8e21b4759bf19e960.zip
rename funcs to app, and fix toolbar resizing
Diffstat (limited to 'src/main/python/utils/toolbar.py')
-rw-r--r--src/main/python/utils/toolbar.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py
index 8e1f8d2..4152f81 100644
--- a/src/main/python/utils/toolbar.py
+++ b/src/main/python/utils/toolbar.py
@@ -2,11 +2,11 @@ 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)
+ QScrollArea, QToolButton, QWidget, QApplication, QStyle)
from re import search, IGNORECASE
from .data import toolbarItems
-from .funcs import fileImporter
+from .app import fileImporter
from .layout import flowLayout
# resourceManager = ApplicationContext() #Used to load images, mainly toolbar icons
@@ -38,13 +38,15 @@ class toolbar(QDockWidget):
#create a scrollable area to house all buttons
self.diagArea = QScrollArea(self)
- self.layout.addWidget(self.diagArea)
+ self.diagArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
+ self.diagArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
+ self.diagArea.setWidgetResizable(True)
+ self.layout.addWidget(self.diagArea, stretch=1)
self.diagAreaWidget = QWidget(self.diagArea) #inner widget for scroll area
#custom layout for inner widget
self.diagAreaLayout = flowLayout(self.diagAreaWidget)
- # self.diagArea.setWidget() #set inner widget to scroll area
- self.setWidget(self.widget) #set main widget to dockwidget
+ self.setWidget(self.widget) #set main widget to dockwidget
def clearLayout(self):
# used to clear all items from toolbar, by parenting it to the toolbar instead
@@ -59,6 +61,7 @@ class toolbar(QDockWidget):
self.clearLayout() #clears layout
for item in list:
self.diagAreaLayout.addWidget(self.toolbarButtonDict[item])
+ self.resize()
def searchQuery(self):
# shorten toolbaritems list with search items
@@ -74,12 +77,14 @@ class toolbar(QDockWidget):
# called when main window resizes, overloading resizeEvent caused issues.
parent = self.parentWidget() #used to get parent dimensions
self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later
- self.setFixedWidth(.12*parent.width()) #12% of parent width
- self.setFixedHeight(self.height()) #span available height
- width = .12*parent.width() #12% of parent width
- self.diagAreaWidget.setFixedWidth(width) #set inner widget width
+ # self.setFixedHeight(self.height()) #span available height
+ width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent)
# the following line, sets the required height for the current width, so that blank space doesnt occur
- self.diagAreaWidget.setFixedHeight(self.diagAreaLayout.heightForWidth(width))
+ self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width))
+ self.setMinimumWidth(.17*parent.width()) #12% of parent width
+ # self.setMinimumWidth(self.diagAreaLayout.minimumSize().width()) #12% of parent width
+ self.diagAreaWidget.setLayout(self.diagAreaLayout)
+ self.diagArea.setWidget(self.diagAreaWidget)
def toolbarItems(self, items):
#helper functions to create required buttons
@@ -104,7 +109,7 @@ class toolbarButton(QToolButton):
super(toolbarButton, self).__init__(parent)
#uses fbs resource manager to get icons
self.setIcon(QIcon(fileImporter(f'toolbar/{item["icon"]}')))
- self.setIconSize(QSize(40, 40)) #unecessary but left for future references
+ self.setIconSize(QSize(64, 64)) #unecessary but left for future references
self.dragStartPosition = None #intialize value for drag event
self.itemObject = item['object'] #refer current item object, to handle drag mime
self.setText(item["name"]) #button text
@@ -135,4 +140,4 @@ class toolbarButton(QToolButton):
def minimumSizeHint(self):
#defines button size
- return QSize(30, 30) \ No newline at end of file
+ return QSize(40, 40) \ No newline at end of file