eric7/EricWidgets/EricSideBar.py

branch
eric7
changeset 8584
90391fda03d5
parent 8583
aac629a05f8b
child 8587
78971b458d25
equal deleted inserted replaced
8583:aac629a05f8b 8584:90391fda03d5
9 9
10 import enum 10 import enum
11 import json 11 import json
12 12
13 from PyQt6.QtCore import pyqtSlot, Qt, QSize 13 from PyQt6.QtCore import pyqtSlot, Qt, QSize
14 from PyQt6.QtGui import QIcon
15 from PyQt6.QtWidgets import QWidget, QStackedWidget, QBoxLayout 14 from PyQt6.QtWidgets import QWidget, QStackedWidget, QBoxLayout
16 15
17 from .EricIconBar import EricIconBar 16 from .EricIconBar import EricIconBar
18 17
19 18
32 Class implementing a sidebar with a widget area, that is hidden or shown, 31 Class implementing a sidebar with a widget area, that is hidden or shown,
33 if the current tab is clicked again. 32 if the current tab is clicked again.
34 """ 33 """
35 Version = 3 34 Version = 3
36 35
36 # TODO: make icon bar size configurable with default
37 def __init__(self, orientation=None, parent=None): 37 def __init__(self, orientation=None, parent=None):
38 """ 38 """
39 Constructor 39 Constructor
40 40
41 @param orientation orientation of the sidebar widget 41 @param orientation orientation of the sidebar widget
44 @type QWidget 44 @type QWidget
45 """ 45 """
46 super().__init__(parent) 46 super().__init__(parent)
47 47
48 # initial layout is done for NORTH 48 # initial layout is done for NORTH
49 self.__iconBar = EricIconBar(Qt.Orientation.Horizontal) 49 self.__iconBar = EricIconBar(orientation=Qt.Orientation.Horizontal)
50 50
51 self.__stackedWidget = QStackedWidget(self) 51 self.__stackedWidget = QStackedWidget(self)
52 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) 52 self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
53 53
54 self.layout = QBoxLayout(QBoxLayout.Direction.TopToBottom) 54 self.layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
187 Public method to add a tab to the sidebar. 187 Public method to add a tab to the sidebar.
188 188
189 @param widget reference to the widget to add 189 @param widget reference to the widget to add
190 @type QWidget 190 @type QWidget
191 @param icon reference to the icon of the widget 191 @param icon reference to the icon of the widget
192 @type QIcon or QPixmap 192 @type QIcon
193 @param label the label text of the widget 193 @param label the label text of the widget
194 @type str 194 @type str
195 """ 195 """
196 if isinstance(icon, QIcon):
197 icon = icon.pixmap(48, 48)
198 self.__iconBar.addIcon(icon, label) 196 self.__iconBar.addIcon(icon, label)
199 self.__stackedWidget.addWidget(widget) 197 self.__stackedWidget.addWidget(widget)
200 if self.__orientation in ( 198 if self.__orientation in (
201 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 199 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
202 ): 200 ):
211 @param index the index to insert the tab at 209 @param index the index to insert the tab at
212 @type int 210 @type int
213 @param widget reference to the widget to insert 211 @param widget reference to the widget to insert
214 @type QWidget 212 @type QWidget
215 @param icon reference to the icon of the widget 213 @param icon reference to the icon of the widget
216 @type QIcon or QPixmap 214 @type QIcon
217 @param label the label text of the widget 215 @param label the label text of the widget
218 @type str 216 @type str
219 """ 217 """
220 if isinstance(icon, QIcon):
221 icon = icon.pixmap(48, 48)
222 self.__iconBar.insertIcon(index, icon, label) 218 self.__iconBar.insertIcon(index, icon, label)
223 219
224 self.__stackedWidget.insertWidget(index, widget) 220 self.__stackedWidget.insertWidget(index, widget)
225 if self.__orientation in ( 221 if self.__orientation in (
226 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 222 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
385 @return icon bar color 381 @return icon bar color
386 @rtype QColor 382 @rtype QColor
387 """ 383 """
388 return self.__iconBar.color() 384 return self.__iconBar.color()
389 385
386 def setIconBarSize(self, barSize):
387 """
388 Public method to set the icon bar size.
389
390 @param barSize size category for the bar (one of 'xs', 'sm', 'md',
391 'lg', 'xl', 'xxl')
392 @type str
393 """
394 self.__iconBar.setBarSize(barSize)
395
396 def barSize(self):
397 """
398 Public method to get the icon bar size.
399
400 @return barSize size category for the bar (one of 'xs', 'sm', 'md',
401 'lg', 'xl', 'xxl')
402 @rtype str
403 """
404 return self.__iconBar.barSize()
405
390 def saveState(self): 406 def saveState(self):
391 """ 407 """
392 Public method to save the state of the sidebar. 408 Public method to save the state of the sidebar.
393 409
394 @return saved state as a byte array (QByteArray) 410 @return saved state as a byte array (QByteArray)

eric ide

mercurial