|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a horizontal and a vertical toolbox class. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtWidgets import QToolBox, QTabWidget |
|
13 |
|
14 from .E5TabWidget import E5TabWidget |
|
15 |
|
16 |
|
17 class E5VerticalToolBox(QToolBox): |
|
18 """ |
|
19 Class implementing a ToolBox class substituting QToolBox to support wheel |
|
20 events. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent reference to the parent widget (QWidget) |
|
27 """ |
|
28 super(E5VerticalToolBox, self).__init__(parent) |
|
29 |
|
30 |
|
31 class E5HorizontalToolBox(E5TabWidget): |
|
32 """ |
|
33 Class implementing a vertical QToolBox like widget. |
|
34 """ |
|
35 def __init__(self, parent=None): |
|
36 """ |
|
37 Constructor |
|
38 |
|
39 @param parent reference to the parent widget (QWidget) |
|
40 """ |
|
41 E5TabWidget.__init__(self, parent) |
|
42 self.setTabPosition(QTabWidget.West) |
|
43 self.setUsesScrollButtons(True) |
|
44 |
|
45 def addItem(self, widget, icon, text): |
|
46 """ |
|
47 Public method to add a widget to the toolbox. |
|
48 |
|
49 @param widget reference to the widget to be added (QWidget) |
|
50 @param icon the icon to be shown (QIcon) |
|
51 @param text the text to be shown (string) |
|
52 @return index of the added widget (integer) |
|
53 """ |
|
54 index = self.addTab(widget, icon, "") |
|
55 self.setTabToolTip(index, text) |
|
56 return index |
|
57 |
|
58 def insertItem(self, index, widget, icon, text): |
|
59 """ |
|
60 Public method to add a widget to the toolbox. |
|
61 |
|
62 @param index position at which the widget should be inserted (integer) |
|
63 @param widget reference to the widget to be added (QWidget) |
|
64 @param icon the icon to be shown (QIcon) |
|
65 @param text the text to be shown (string) |
|
66 @return index of the added widget (integer) |
|
67 """ |
|
68 index = self.insertTab(index, widget, icon, "") |
|
69 self.setTabToolTip(index, text) |
|
70 return index |
|
71 |
|
72 def removeItem(self, index): |
|
73 """ |
|
74 Public method to remove a widget from the toolbox. |
|
75 |
|
76 @param index index of the widget to remove (integer) |
|
77 """ |
|
78 self.removeTab(index) |
|
79 |
|
80 def setItemToolTip(self, index, toolTip): |
|
81 """ |
|
82 Public method to set the tooltip of an item. |
|
83 |
|
84 @param index index of the item (integer) |
|
85 @param toolTip tooltip text to be set (string) |
|
86 """ |
|
87 self.setTabToolTip(index, toolTip) |
|
88 |
|
89 def setItemEnabled(self, index, enabled): |
|
90 """ |
|
91 Public method to set the enabled state of an item. |
|
92 |
|
93 @param index index of the item (integer) |
|
94 @param enabled flag indicating the enabled state (boolean) |
|
95 """ |
|
96 self.setTabEnabled(index, enabled) |