src/eric7/EricWidgets/EricIconBar.py

Fri, 26 Aug 2022 14:49:15 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 26 Aug 2022 14:49:15 +0200
branch
eric7
changeset 9298
8863f3e970a2
parent 9221
bf71ee032bb4
child 9413
80c06d472826
permissions
-rw-r--r--

Interface
- added capability to expand or shrink the sidebar by clicking on the empty part of the icon bar (see Issue 441)

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

eric ide

mercurial