eric7/EricWidgets/EricIconBar.py

Mon, 15 Nov 2021 19:50:39 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 15 Nov 2021 19:50:39 +0100
branch
eric7
changeset 8768
09a4a3c5b161
parent 8725
842ba8a9dbbb
child 8772
70f9dfe7116a
permissions
-rw-r--r--

Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.

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
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
127 self.__createMoreLabel()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 self.__layout.insertWidget(0, self.__moreLabel)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
130 self.__adjustIconLabels()
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 def setOrientation(self, orientation):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 Public method to set the widget orientation.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @param orientation orientation to be set
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @type Qt.Orientation
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 # reset list widget size constraints
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
142 # remove the 'More' icon
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 = self.__layout.takeAt(self.__layout.count() - 2)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
145 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
146
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 if orientation == Qt.Orientation.Horizontal:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 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
149 self.setMinimumWidth(self.__minimumHeightWidth)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.__layout.setDirection(QBoxLayout.Direction.LeftToRight)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 elif orientation == Qt.Orientation.Vertical:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153 self.setMinimumHeight(self.__minimumHeightWidth)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.__layout.setDirection(QBoxLayout.Direction.TopToBottom)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 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
157
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 self.__createMoreLabel()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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.__layout.insertWidget(self.__layout.count() - 1, self.__moreLabel)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
160
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
161 self.__adjustIconLabels()
8583
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 def orientation(self):
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 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
166
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @return orientation of the widget
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @rtype Qt.Orientation
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 return self.__orientation
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
172 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
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 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
175
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
176 @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
177 '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
178 @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
179 """
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 # remove the 'More' icon
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 itm = self.__layout.takeAt(self.__layout.count() - 2)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
183 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
184
8584
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.__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
186 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
187 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
188 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
189 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
190 )
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
191 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
192 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
193
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
194 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
195 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
196 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
197 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
198 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
199 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
200
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.__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
202 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
203 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
204
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
205 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
206 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
207 if iconLabel:
78971b458d25 Made the height/width of the icons bar configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8584
diff changeset
208 widget = iconLabel.widget()
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
209 widget.setFixedSize(self.__barSize, self.__barSize)
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
210 widget.setPixmap(
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
211 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
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.__createMoreLabel()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
214 self.__layout.insertWidget(self.__layout.count() - 1, self.__moreLabel)
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
215
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
216 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
217
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
218 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
219 """
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
220 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
221
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
222 @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
223 '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
224 @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
225 """
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
226 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
227
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 def setColor(self, color):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 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
231
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 @param color color of the widget
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 @type QColor
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.__color = color
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.__highlightColor = color.darker()
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 self.setStyleSheet(
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 EricIconBar.WidgetStyleSheetTemplate.format(color.name()))
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 label = self.__layout.itemAt(self.__currentIndex)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 if label:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 label.widget().setStyleSheet(
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 EricIconBar.LabelStyleSheetTemplate
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 .format(self.__highlightColor.name())
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
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 def color(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 Public method to return the current color.
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 current color
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 @rtype QColor
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 return self.__color
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
257 def __createIcon(self, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 Private method to creat an icon label.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
261 @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
262 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 @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
264 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 @return created and connected label
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 @rtype EricClickableLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 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
269 iconLabel.setFixedSize(self.__barSize, self.__barSize)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 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
271 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
272 if label:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 iconLabel.setToolTip(label)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 iconLabel.clicked.connect(lambda: self.__iconClicked(iconLabel))
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 return iconLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278
8768
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
279 def __createMoreLabel(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
280 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
282 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
283 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
284 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
285 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
286 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
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 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
289 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
290 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
291 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
294 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
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 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
297 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
298 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
299 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
300 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
303
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
304 def addIcon(self, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
308 @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
309 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 @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
311 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 # 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
314 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
315
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
316 def insertIcon(self, index, icon, label=""):
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 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
319
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 @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
321 @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
322 @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
323 @type QIcon
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 @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
325 @type str (optional)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 """
8584
90391fda03d5 Enhanced the icon bar widget (EricIconBar) and adapted its use in EricSideBar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8583
diff changeset
327 iconLabel = self.__createIcon(icon, label=label)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 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
329 self.__icons.insert(index, QIcon(icon))
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 if self.__currentIndex < 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 self.setCurrentIndex(index)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 elif index <= self.__currentIndex:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 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
335
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
336 self.__adjustIconLabels()
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 def removeIcon(self, index):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 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
341
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 @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
343 @type int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 label = self.__layout.itemAt(index)
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
346 if label:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
347 with contextlib.suppress(IndexError):
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
348 del self.__icons[index]
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
349 itm = self.__layout.takeAt(index)
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
350 itm.widget().deleteLater()
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
351 del itm
8591
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
352
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
353 if index == self.__currentIndex:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
354 self.setCurrentIndex(index)
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
355 elif index < self.__currentIndex:
7cf4b7bc3d5a EricIconBar: fixed an issue removing an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8587
diff changeset
356 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
357
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
358 self.__adjustIconLabels()
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 def __iconClicked(self, label):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 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
364
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 @param label reference to the clicked label
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 @type EricClickableLabel
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 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
369 if index >= 0:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
370 if index == self.__currentIndex:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
371 self.currentClicked.emit(self.__currentIndex)
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
372 else:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
373 self.setCurrentIndex(index)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 def setCurrentIndex(self, index):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 Public method to set the current index.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 @param index current index to be set
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 @type int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 if index >= self.count():
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 index = -1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
385 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
386 # reset style of previous current icon
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 oldLabel = self.__layout.itemAt(self.__currentIndex)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 if oldLabel:
8724
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
389 widget = oldLabel.widget()
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
390 if widget is not None:
6ee36599a1f8 EricIconBar: fixed an issue removing a managed item.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8591
diff changeset
391 widget.setStyleSheet("")
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 # set style of new current icon
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 newLabel = self.__layout.itemAt(index)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 if newLabel:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 newLabel.widget().setStyleSheet(
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 EricIconBar.LabelStyleSheetTemplate
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 .format(self.__highlightColor.name())
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
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 self.__currentIndex = index
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 self.currentChanged.emit(self.__currentIndex)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 def currentIndex(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 Public method to get the current index.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 @return current index
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 @rtype int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 return self.__currentIndex
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 def count(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 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
416
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 @return number of icon labels
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 @rtype int
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 """
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
420 return len(self.__icons)
8583
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 def wheelEvent(self, evt):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 Protected method to handle a wheel event.
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 @param evt reference to the wheel event
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 @type QWheelEvent
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 delta = evt.angleDelta().y()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 if delta > 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 self.previousIcon()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 else:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 self.nextIcon()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 def previousIcon(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 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
439 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 index = self.__currentIndex - 1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 if index < 0:
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 # wrap around
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 index = self.count() - 1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 self.setCurrentIndex(index)
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 @pyqtSlot()
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 def nextIcon(self):
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 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
451 """
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 index = self.__currentIndex + 1
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 if index == self.count():
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 # wrap around
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 index = 0
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456
aac629a05f8b Modernized the look of the side bars.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 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
458
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 @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
460 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
461 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
463 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 for index in range(self.__layout.count() - 2):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
475 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
476 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
477 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
478 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
479 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
480
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
481 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
482 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
483 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
484 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
485 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
486 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
487 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
488 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
489
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
491 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
493
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 @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
495 @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
496 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
498
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
500 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
502 """
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
504 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
505 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
506 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
507 ) - 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
508
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
510 self.count() * 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
511 (self.count() - 1) * self.__layout.spacing()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 )
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 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
515 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
516 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
517 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
518 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
519 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
520 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
521 iconLabel.widget().hide()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text 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 iconsSize -= self.__barSize - self.__layout.spacing()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
523 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
524 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
525 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
526 self.__moreLabel.hide()
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
527 for index in range(self.__layout.count() - 2):
09a4a3c5b161 Added a 'More' button to the icon bar to show widget icons text in a menu for those who could not be shown due to size constraints.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8725
diff changeset
528 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
529 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
530 iconLabel.widget().show()

eric ide

mercurial