|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a button alternating between reload and stop. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt |
|
11 |
|
12 from E5Gui.E5ToolButton import E5ToolButton |
|
13 |
|
14 import UI.PixmapCache |
|
15 |
|
16 |
|
17 class ReloadStopButton(E5ToolButton): |
|
18 """ |
|
19 Class implementing a button alternating between reload and stop. |
|
20 |
|
21 @signal reloadClicked() emitted to initiate a reload action |
|
22 @signal stopClicked() emitted to initiate a stop action |
|
23 """ |
|
24 reloadClicked = pyqtSignal() |
|
25 stopClicked = pyqtSignal() |
|
26 |
|
27 def __init__(self, parent=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param parent reference to the parent widget |
|
32 @type QWidget |
|
33 """ |
|
34 super().__init__(parent) |
|
35 |
|
36 self.setObjectName("navigation_reloadstop_button") |
|
37 self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly) |
|
38 self.setFocusPolicy(Qt.FocusPolicy.NoFocus) |
|
39 self.setAutoRaise(True) |
|
40 |
|
41 self.__loading = False |
|
42 |
|
43 self.clicked.connect(self.__buttonClicked) |
|
44 |
|
45 self.__updateButton() |
|
46 |
|
47 @pyqtSlot() |
|
48 def __buttonClicked(self): |
|
49 """ |
|
50 Private slot handling a user clicking the button. |
|
51 """ |
|
52 if self.__loading: |
|
53 self.stopClicked.emit() |
|
54 else: |
|
55 self.reloadClicked.emit() |
|
56 |
|
57 @pyqtSlot() |
|
58 def __updateButton(self): |
|
59 """ |
|
60 Private slot to update the button. |
|
61 """ |
|
62 if self.__loading: |
|
63 self.setIcon(UI.PixmapCache.getIcon("stopLoading")) |
|
64 self.setToolTip(self.tr("Stop loading")) |
|
65 else: |
|
66 self.setIcon(UI.PixmapCache.getIcon("reload")) |
|
67 self.setToolTip(self.tr("Reload the current screen")) |
|
68 |
|
69 def setLoading(self, loading): |
|
70 """ |
|
71 Public method to set the loading state. |
|
72 |
|
73 @param loading flag indicating the new loading state |
|
74 @type bool |
|
75 """ |
|
76 self.__loading = loading |
|
77 self.__updateButton() |