WebBrowser/Navigation/ReloadStopButton.py

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

eric ide

mercurial