5 |
5 |
6 """ |
6 """ |
7 Module implementing a TabWidget class substituting QTabWidget. |
7 Module implementing a TabWidget class substituting QTabWidget. |
8 """ |
8 """ |
9 |
9 |
|
10 import contextlib |
|
11 |
10 from PyQt5.QtCore import pyqtSignal, Qt, QPoint, QMimeData |
12 from PyQt5.QtCore import pyqtSignal, Qt, QPoint, QMimeData |
11 from PyQt5.QtGui import QDrag |
13 from PyQt5.QtGui import QDrag |
12 from PyQt5.QtWidgets import QTabWidget, QTabBar, QApplication, QStyle |
14 from PyQt5.QtWidgets import QTabWidget, QTabBar, QApplication, QStyle |
13 |
15 |
14 from E5Gui.E5AnimatedLabel import E5AnimatedLabel |
16 from E5Gui.E5AnimatedLabel import E5AnimatedLabel |
23 """ |
25 """ |
24 Constructor |
26 Constructor |
25 |
27 |
26 @param parent reference to the parent widget (QWidget) |
28 @param parent reference to the parent widget (QWidget) |
27 """ |
29 """ |
28 super(E5WheelTabBar, self).__init__(parent) |
30 super().__init__(parent) |
29 self._tabWidget = parent |
31 self._tabWidget = parent |
30 |
32 |
31 def wheelEvent(self, event): |
33 def wheelEvent(self, event): |
32 """ |
34 """ |
33 Protected slot to support wheel events. |
35 Protected slot to support wheel events. |
34 |
36 |
35 @param event reference to the wheel event (QWheelEvent) |
37 @param event reference to the wheel event (QWheelEvent) |
36 """ |
38 """ |
37 try: |
39 with contextlib.suppress(AttributeError): |
38 delta = event.angleDelta().y() |
40 delta = event.angleDelta().y() |
39 if delta > 0: |
41 if delta > 0: |
40 self._tabWidget.prevTab() |
42 self._tabWidget.prevTab() |
41 elif delta < 0: |
43 elif delta < 0: |
42 self._tabWidget.nextTab() |
44 self._tabWidget.nextTab() |
43 |
45 |
44 event.accept() |
46 event.accept() |
45 except AttributeError: |
|
46 pass |
|
47 |
47 |
48 |
48 |
49 class E5DnDTabBar(E5WheelTabBar): |
49 class E5DnDTabBar(E5WheelTabBar): |
50 """ |
50 """ |
51 Class implementing a tab bar class substituting QTabBar. |
51 Class implementing a tab bar class substituting QTabBar. |
145 Constructor |
145 Constructor |
146 |
146 |
147 @param parent reference to the parent widget (QWidget) |
147 @param parent reference to the parent widget (QWidget) |
148 @param dnd flag indicating the support for Drag & Drop (boolean) |
148 @param dnd flag indicating the support for Drag & Drop (boolean) |
149 """ |
149 """ |
150 super(E5TabWidget, self).__init__(parent) |
150 super().__init__(parent) |
151 |
151 |
152 if dnd: |
152 if dnd: |
153 if not hasattr(self, 'setMovable'): |
153 if not hasattr(self, 'setMovable'): |
154 self.__tabBar = E5DnDTabBar(self) |
154 self.__tabBar = E5DnDTabBar(self) |
155 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
155 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
304 @return free side (QTabBar.ButtonPosition) |
304 @return free side (QTabBar.ButtonPosition) |
305 """ |
305 """ |
306 side = self.__tabBar.style().styleHint( |
306 side = self.__tabBar.style().styleHint( |
307 QStyle.StyleHint.SH_TabBar_CloseButtonPosition, |
307 QStyle.StyleHint.SH_TabBar_CloseButtonPosition, |
308 None, None, None) |
308 None, None, None) |
309 if side == QTabBar.ButtonPosition.LeftSide: |
309 side = ( |
310 side = QTabBar.ButtonPosition.RightSide |
310 QTabBar.ButtonPosition.RightSide |
311 else: |
311 if side == QTabBar.ButtonPosition.LeftSide else |
312 side = QTabBar.ButtonPosition.LeftSide |
312 QTabBar.ButtonPosition.LeftSide |
|
313 ) |
313 return side |
314 return side |
314 |
315 |
315 def animationLabel(self, index, animationFile, interval=100): |
316 def animationLabel(self, index, animationFile, interval=100): |
316 """ |
317 """ |
317 Public slot to set an animated icon. |
318 Public slot to set an animated icon. |