eric7/EricWidgets/EricIconBar.py

Tue, 16 Nov 2021 18:00:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 16 Nov 2021 18:00:40 +0100
branch
eric7
changeset 8772
70f9dfe7116a
parent 8768
09a4a3c5b161
child 8881
54e42bc2437a
permissions
-rw-r--r--

Some fine tuning of the icon bar 'More' button behavior.

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

eric ide

mercurial