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