src/eric7/EricWidgets/EricIconBar.py

Sat, 31 Dec 2022 16:23:21 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2022 16:23:21 +0100
branch
eric7
changeset 9653
e67609152c5e
parent 9473
3f23dbf37dbe
child 9951
91faf698afe6
permissions
-rw-r--r--

Updated copyright for 2023.

8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
3 # Copyright (c) 2021 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a bar widget showing just icons.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
10 import contextlib
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
11
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
12 from PyQt6.QtCore import QCoreApplication, Qt, pyqtSignal, pyqtSlot
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
13 from PyQt6.QtGui import QColor, QCursor, QIcon, QPalette
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
14 from PyQt6.QtWidgets import QWIDGETSIZE_MAX, QBoxLayout, QMenu, QWidget
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
15
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
16 from eric7.EricGui import EricPixmapCache
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9298
diff changeset
17 from eric7.EricWidgets.EricApplication import ericApp
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .EricClickableLabel import EricClickableLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 class EricIconBar(QWidget):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Class implementing a bar widget showing just icons.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
25
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @signal currentChanged(index) emitted to indicate a change of the current
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 index
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @signal currentClicked(index) emitted to indicate, that the current icon
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 was clicked
9298
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
30 @signal emptyClicked() emitted to indicate a mouse click on the empty part
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
31 of the icon bar
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
34 BarSizes = {
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
35 # tuples with (icon size, border size, translated size string)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36 "xs": (16, 1, QCoreApplication.translate("EricIconBar", "extra small")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37 "sm": (22, 1, QCoreApplication.translate("EricIconBar", "small")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38 "md": (32, 2, QCoreApplication.translate("EricIconBar", "medium")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39 "lg": (48, 2, QCoreApplication.translate("EricIconBar", "large")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40 "xl": (64, 3, QCoreApplication.translate("EricIconBar", "extra large")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41 "xxl": (96, 3, QCoreApplication.translate("EricIconBar", "very large")),
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
42 }
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
43 DefaultBarSize = "md"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
45 MoreLabelAspect = 36 / 96
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
47 MenuStyleSheetTemplate = (
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
48 "QMenu {{ background-color: {0}; "
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
49 "selection-background-color: {1}; "
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
50 "border: 1px solid; }}"
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
51 )
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 WidgetStyleSheetTemplate = "QWidget {{ background-color: {0}; }}"
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 LabelStyleSheetTemplate = "QLabel {{ background-color: {0}; }}"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 currentChanged = pyqtSignal(int)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 currentClicked = pyqtSignal(int)
9298
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
57 emptyClicked = pyqtSignal()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 def __init__(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60 self, orientation=Qt.Orientation.Horizontal, barSize=DefaultBarSize, parent=None
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61 ):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @param orientation orientation for the widget
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @type Qt.Orientation
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
67 @param barSize size category for the bar (one of 'xs', 'sm', 'md',
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
68 'lg', 'xl', 'xxl')
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
69 @type str
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @param parent reference to the parent widget (defaults to None)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @type QWidget (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
75 try:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76 self.__barSize, self.__borderSize = EricIconBar.BarSizes[barSize][:2]
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
77 self.__barSizeKey = barSize
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
78 except KeyError:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79 self.__barSize, self.__borderSize = EricIconBar.BarSizes[
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80 EricIconBar.DefaultBarSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81 ][:2]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82 self.__fixedHeightWidth = self.__barSize + 2 * self.__borderSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
83 self.__minimumHeightWidth = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84 int(self.__barSize * self.MoreLabelAspect) + 2 * self.__borderSize
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 # set initial values
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__color = QColor("#008800")
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__orientation = Qt.Orientation.Horizontal
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__currentIndex = -1
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
91 self.__icons = []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 # initialize with horizontal layout and change later if needed
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.setFixedHeight(self.__fixedHeightWidth)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
96 self.setMinimumWidth(self.__minimumHeightWidth)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__layout = QBoxLayout(QBoxLayout.Direction.LeftToRight)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__layout.setContentsMargins(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100 self.__borderSize, self.__borderSize, self.__borderSize, self.__borderSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
102
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__layout.addStretch()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.setLayout(self.__layout)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if orientation != self.__orientation:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.setOrientation(orientation)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
109
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.setColor(self.__color)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
111
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
112 self.__createAndAddMoreLabel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
114 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 def setOrientation(self, orientation):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 Public method to set the widget orientation.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @param orientation orientation to be set
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @type Qt.Orientation
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 # reset list widget size constraints
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
126 # remove the 'More' icon
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
127 itm = self.__layout.takeAt(self.__layout.count() - 1)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
128 itm.widget().deleteLater()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
129 del itm
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 if orientation == Qt.Orientation.Horizontal:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.setFixedHeight(self.__fixedHeightWidth)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
133 self.setMinimumWidth(self.__minimumHeightWidth)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.__layout.setDirection(QBoxLayout.Direction.LeftToRight)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 elif orientation == Qt.Orientation.Vertical:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.setFixedWidth(self.__fixedHeightWidth)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
137 self.setMinimumHeight(self.__minimumHeightWidth)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.__layout.setDirection(QBoxLayout.Direction.TopToBottom)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
139
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.__orientation = orientation
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
142 self.__createAndAddMoreLabel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
143
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
144 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
145
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def orientation(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Public method to get the orientation of the widget.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @return orientation of the widget
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @rtype Qt.Orientation
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 return self.__orientation
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
154
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
155 def setBarSize(self, barSize):
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
156 """
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
157 Public method to set the icon bar size.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
159 @param barSize size category for the bar (one of 'xs', 'sm', 'md',
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
160 'lg', 'xl', 'xxl')
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
161 @type str
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
162 """
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
163 # remove the 'More' icon
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
164 itm = self.__layout.takeAt(self.__layout.count() - 1)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
165 itm.widget().deleteLater()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
166 del itm
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
167
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
168 self.__barSize, self.__borderSize = EricIconBar.BarSizes[barSize][:2]
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
169 self.__barSizeKey = barSize
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170 self.__fixedHeightWidth = self.__barSize + 2 * self.__borderSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171 self.__minimumHeightWidth = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172 int(self.__barSize * self.MoreLabelAspect) + 2 * self.__borderSize
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
173 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
175 if self.__orientation == Qt.Orientation.Horizontal:
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
176 self.setFixedHeight(self.__fixedHeightWidth)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
177 self.setMinimumWidth(self.__minimumHeightWidth)
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
178 elif self.__orientation == Qt.Orientation.Vertical:
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
179 self.setFixedWidth(self.__fixedHeightWidth)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
180 self.setMinimumHeight(self.__minimumHeightWidth)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
182 self.__layout.setContentsMargins(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
183 self.__borderSize, self.__borderSize, self.__borderSize, self.__borderSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
185
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
186 for index, icon in enumerate(self.__icons):
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
187 iconLabel = self.__layout.itemAt(index)
8587
78971b458d25 Made the height/width of the icons bar configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8584
diff changeset
188 if iconLabel:
78971b458d25 Made the height/width of the icons bar configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8584
diff changeset
189 widget = iconLabel.widget()
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
190 widget.setFixedSize(self.__barSize, self.__barSize)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191 widget.setPixmap(icon.pixmap(self.__barSize, self.__barSize))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
193 self.__createAndAddMoreLabel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
195 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
197 def barSize(self):
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
198 """
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
199 Public method to get the icon bar size.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
200
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
201 @return barSize size category for the bar (one of 'xs', 'sm', 'md',
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
202 'lg', 'xl', 'xxl')
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
203 @rtype str
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
204 """
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
205 return self.__barSizeKey
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 def setColor(self, color):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 Public method to set the color of the widget.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 @param color color of the widget
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 @type QColor
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.__color = color
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.__highlightColor = color.darker()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
216
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217 self.setStyleSheet(EricIconBar.WidgetStyleSheetTemplate.format(color.name()))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
218
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 label = self.__layout.itemAt(self.__currentIndex)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 if label:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 label.widget().setStyleSheet(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
222 EricIconBar.LabelStyleSheetTemplate.format(self.__highlightColor.name())
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
224
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 def color(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 Public method to return the current color.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 @return current color
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 @rtype QColor
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 return self.__color
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
233
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
234 def __createIcon(self, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 Private method to creat an icon label.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
237
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
238 @param icon reference to the icon
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
239 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 @param label label text to be shown as a tooltip (defaults to "")
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @return created and connected label
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 @rtype EricClickableLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 iconLabel = EricClickableLabel(self)
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
246 iconLabel.setFixedSize(self.__barSize, self.__barSize)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 iconLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
248 iconLabel.setPixmap(icon.pixmap(self.__barSize, self.__barSize))
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 if label:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 iconLabel.setToolTip(label)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 iconLabel.clicked.connect(lambda: self.__iconClicked(iconLabel))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
253
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 return iconLabel
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
256 def __createAndAddMoreLabel(self):
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
257 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
258 Private method to create the label to be shown for too many icons.
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
259 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
260 self.__moreLabel = EricClickableLabel(self)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
261 self.__moreLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
262 if self.__orientation == Qt.Orientation.Horizontal:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
263 self.__moreLabel.setFixedSize(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264 int(self.__barSize * self.MoreLabelAspect), self.__barSize
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265 )
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
266 self.__moreLabel.setPixmap(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9298
diff changeset
267 EricPixmapCache.getIcon("sbDotsH96").pixmap(
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
268 int(self.__barSize * self.MoreLabelAspect), self.__barSize
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
269 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
270 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
271 else:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
272 self.__moreLabel.setFixedSize(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 self.__barSize, int(self.__barSize * self.MoreLabelAspect)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 )
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
275 self.__moreLabel.setPixmap(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9298
diff changeset
276 EricPixmapCache.getIcon("sbDotsV96").pixmap(
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
277 self.__barSize, int(self.__barSize * self.MoreLabelAspect)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
278 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
279 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
280
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
281 self.__layout.addWidget(self.__moreLabel)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
283 self.__moreLabel.clicked.connect(self.__moreLabelClicked)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
285 def addIcon(self, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 Public method to add an icon to the bar.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
288
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
289 @param icon reference to the icon
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
290 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 @param label label text to be shown as a tooltip (defaults to "")
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 # the stretch item is always the last one
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
295 self.insertIcon(self.count(), icon, label=label)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
296
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
297 def insertIcon(self, index, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 Public method to insert an icon into the bar.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
300
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 @param index position to insert the icon at
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 @type int
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
303 @param icon reference to the icon
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
304 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 @param label label text to be shown as a tooltip (defaults to "")
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 """
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
308 iconLabel = self.__createIcon(icon, label=label)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 self.__layout.insertWidget(index, iconLabel)
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
310 self.__icons.insert(index, QIcon(icon))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
311
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 if self.__currentIndex < 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 self.setCurrentIndex(index)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 elif index <= self.__currentIndex:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 self.setCurrentIndex(self.__currentIndex + 1)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
316
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
317 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 def removeIcon(self, index):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 Public method to remove an icon from the bar.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
322
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 @param index index of the icon to be removed
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 @type int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 label = self.__layout.itemAt(index)
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
327 if label:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
328 with contextlib.suppress(IndexError):
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
329 del self.__icons[index]
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
330 itm = self.__layout.takeAt(index)
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
331 itm.widget().deleteLater()
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
332 del itm
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
333
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
334 if index == self.__currentIndex:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
335 self.setCurrentIndex(index)
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
336 elif index < self.__currentIndex:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
337 self.setCurrentIndex(self.__currentIndex - 1)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
338
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
339 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
340
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 def __iconClicked(self, label):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 Private slot to handle an icon been clicked.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
345
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 @param label reference to the clicked label
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 @type EricClickableLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 index = self.__layout.indexOf(label)
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
350 if index >= 0:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
351 if index == self.__currentIndex:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
352 self.currentClicked.emit(self.__currentIndex)
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
353 else:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
354 self.setCurrentIndex(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
355
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 def setCurrentIndex(self, index):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 Public method to set the current index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 @param index current index to be set
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 @type int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 if index >= self.count():
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 index = -1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
365
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
366 if index != self.__currentIndex and index >= 0:
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 # reset style of previous current icon
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 oldLabel = self.__layout.itemAt(self.__currentIndex)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 if oldLabel:
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
370 widget = oldLabel.widget()
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
371 if widget is not None:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
372 widget.setStyleSheet("")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 # set style of new current icon
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 newLabel = self.__layout.itemAt(index)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 if newLabel:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 newLabel.widget().setStyleSheet(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
378 EricIconBar.LabelStyleSheetTemplate.format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
379 self.__highlightColor.name()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
380 )
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
382
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 self.__currentIndex = index
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.currentChanged.emit(self.__currentIndex)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
385
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 def currentIndex(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 Public method to get the current index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 @return current index
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 @rtype int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 return self.__currentIndex
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
394
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 def count(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 Public method to get the number of icon labels.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
398
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 @return number of icon labels
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 @rtype int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 """
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
402 return len(self.__icons)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
403
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 def wheelEvent(self, evt):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 Protected method to handle a wheel event.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
407
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 @param evt reference to the wheel event
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 @type QWheelEvent
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 delta = evt.angleDelta().y()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 if delta > 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 self.previousIcon()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 else:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 self.nextIcon()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
416
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 def previousIcon(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 Public slot to set the icon before the current one.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 index = self.__currentIndex - 1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 if index < 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 # wrap around
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 index = self.count() - 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
426
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 self.setCurrentIndex(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
428
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 def nextIcon(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 Public slot to set the icon after the current one.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 index = self.__currentIndex + 1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 if index == self.count():
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 # wrap around
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 index = 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
438
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 self.setCurrentIndex(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
440
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
441 @pyqtSlot()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
442 def __moreLabelClicked(self):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
443 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
444 Private slot to handle a click onto the 'More' label.
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
445 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
446 menu = QMenu(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
447 baseColor = ericApp().palette().color(QPalette.ColorRole.Base)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
448 highlightColor = ericApp().palette().color(QPalette.ColorRole.Highlight)
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
449 menu.setStyleSheet(
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
450 EricIconBar.MenuStyleSheetTemplate.format(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451 baseColor.name(), highlightColor.name()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
452 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
453 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
454
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
455 for index in range(self.count()):
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
456 iconLabel = self.__layout.itemAt(index)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
457 if iconLabel:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
458 widget = iconLabel.widget()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
459 if not widget.isVisible():
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
460 act = menu.addAction(widget.toolTip())
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
461 act.setData(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
462
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
463 selectedAction = menu.exec(QCursor.pos())
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
464 if selectedAction is not None:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
465 index = selectedAction.data()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
466 if index >= 0:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
467 if index == self.__currentIndex:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
468 self.currentClicked.emit(self.__currentIndex)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
469 else:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
470 self.setCurrentIndex(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
471
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
472 def resizeEvent(self, evt):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
473 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
474 Protected method to handle resizing of the icon bar.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
475
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
476 @param evt reference to the event object
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
477 @type QResizeEvent
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
478 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
479 self.__adjustIconLabels()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
481 def __adjustIconLabels(self):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
482 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
483 Private method to adjust the visibility of the icon labels.
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
484 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
485 size = (
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
486 self.width()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
487 if self.orientation() == Qt.Orientation.Horizontal
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
488 else self.height()
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
489 ) - 2 * self.__borderSize
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
491 iconsSize = self.count() * self.__barSize
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
492
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
493 if size < iconsSize:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
494 self.__moreLabel.show()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
495 iconsSize += int(self.__barSize * self.MoreLabelAspect)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
496 for index in range(self.count() - 1, -1, -1):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
497 iconLabel = self.__layout.itemAt(index)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
498 if iconLabel:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
499 if size < iconsSize:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
500 iconLabel.widget().hide()
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
501 iconsSize -= self.__barSize
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
502 else:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
503 iconLabel.widget().show()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
504 else:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
505 self.__moreLabel.hide()
8772
70f9dfe7116a Some fine tuning of the icon bar 'More' button behavior.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8768
diff changeset
506 for index in range(self.count()):
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
507 iconLabel = self.__layout.itemAt(index)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
508 if iconLabel:
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
509 iconLabel.widget().show()
9298
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
510
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
511 def mouseReleaseEvent(self, evt):
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
512 """
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
513 Protected method to handle a click on the empty space.
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
514
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
515 @param evt reference to the mouse event
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
516 @type QMouseEvent
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
517 """
8863f3e970a2 Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
518 self.emptyClicked.emit()

eric ide

mercurial