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