7 Module implementing a statusbar icon tracking the network status. |
7 Module implementing a statusbar icon tracking the network status. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal |
13 from PyQt5.QtNetwork import QNetworkConfigurationManager |
13 from PyQt5.QtNetwork import QNetworkConfigurationManager |
14 |
14 |
15 from E5Gui.E5ClickableLabel import E5ClickableLabel |
15 from E5Gui.E5ClickableLabel import E5ClickableLabel |
16 |
16 |
17 import UI.PixmapCache |
17 import UI.PixmapCache |
18 |
18 |
19 |
19 |
20 class E5NetworkIcon(E5ClickableLabel): |
20 class E5NetworkIcon(E5ClickableLabel): |
21 """ |
21 """ |
22 Class implementing a statusbar icon tracking the network status. |
22 Class implementing a statusbar icon tracking the network status. |
|
23 |
|
24 @signal onlineStateChanged(online) emitted to indicate a change of the |
|
25 network state |
23 """ |
26 """ |
|
27 onlineStateChanged = pyqtSignal(bool) |
|
28 |
24 def __init__(self, parent=None): |
29 def __init__(self, parent=None): |
25 """ |
30 """ |
26 Constructor |
31 Constructor |
27 |
32 |
28 @param parent reference to the parent widget |
33 @param parent reference to the parent widget |
29 @type QWidget |
34 @type QWidget |
30 """ |
35 """ |
31 super(E5NetworkIcon, self).__init__(parent) |
36 super(E5NetworkIcon, self).__init__(parent) |
32 |
37 |
33 self.__networkManager = QNetworkConfigurationManager(self) |
38 self.__networkManager = QNetworkConfigurationManager(self) |
34 self.__onlineStateChanged(self.__networkManager.isOnline()) |
39 self.__online = self.__networkManager.isOnline() |
|
40 self.__onlineStateChanged(self.__online) |
35 |
41 |
36 self.__networkManager.onlineStateChanged.connect( |
42 self.__networkManager.onlineStateChanged.connect( |
37 self.__onlineStateChanged) |
43 self.__onlineStateChanged) |
38 |
44 |
39 @pyqtSlot(bool) |
45 @pyqtSlot(bool) |
56 tooltip = tooltip.format(self.tr("Connected")) |
62 tooltip = tooltip.format(self.tr("Connected")) |
57 else: |
63 else: |
58 tooltip = tooltip.format(self.tr("Offline")) |
64 tooltip = tooltip.format(self.tr("Offline")) |
59 |
65 |
60 self.setToolTip(tooltip) |
66 self.setToolTip(tooltip) |
|
67 |
|
68 if online != self.__online: |
|
69 self.__online = online |
|
70 self.onlineStateChanged.emit(online) |
61 |
71 |
62 def isOnline(self): |
72 def isOnline(self): |
63 """ |
73 """ |
64 Public method to get the online state. |
74 Public method to get the online state. |
65 |
75 |