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