E5Network/E5NetworkIcon.py

changeset 5047
04e5dfbd3f3d
parent 4671
59cdebfb658c
child 5389
9b1c800daff3
equal deleted inserted replaced
5042:021d99e03961 5047:04e5dfbd3f3d
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal 12 from PyQt5.QtCore import pyqtSlot, pyqtSignal
13 from PyQt5.QtNetwork import QNetworkConfigurationManager 13 from PyQt5.QtNetwork import QNetworkConfigurationManager
14 from PyQt5.QtWidgets import QLabel 14 from PyQt5.QtWidgets import QLabel
15 15
16 import UI.PixmapCache 16 import UI.PixmapCache
17 import Preferences
17 18
18 19
19 class E5NetworkIcon(QLabel): 20 class E5NetworkIcon(QLabel):
20 """ 21 """
21 Class implementing a statusbar icon tracking the network status. 22 Class implementing a statusbar icon tracking the network status.
32 @param parent reference to the parent widget 33 @param parent reference to the parent widget
33 @type QWidget 34 @type QWidget
34 """ 35 """
35 super(E5NetworkIcon, self).__init__(parent) 36 super(E5NetworkIcon, self).__init__(parent)
36 37
37 self.__networkManager = QNetworkConfigurationManager(self) 38 if Preferences.getUI("DynamicOnlineCheck"):
38 self.__online = self.__networkManager.isOnline() 39 self.__networkManager = QNetworkConfigurationManager(self)
39 self.__onlineStateChanged(self.__online) 40 self.__online = self.__networkManager.isOnline()
40 41 self.__onlineStateChanged(self.__online)
41 self.__networkManager.onlineStateChanged.connect( 42
42 self.__onlineStateChanged) 43 self.__networkManager.onlineStateChanged.connect(
44 self.__onlineStateChanged)
45 else:
46 self.__online = True
47 self.__onlineStateChanged(self.__online)
43 48
44 @pyqtSlot(bool) 49 @pyqtSlot(bool)
45 def __onlineStateChanged(self, online): 50 def __onlineStateChanged(self, online):
46 """ 51 """
47 Private slot handling online state changes. 52 Private slot handling online state changes.
55 self.setPixmap(UI.PixmapCache.getPixmap("network-offline.png")) 60 self.setPixmap(UI.PixmapCache.getPixmap("network-offline.png"))
56 61
57 tooltip = self.tr("<p>Shows the network status<br/><br/>" 62 tooltip = self.tr("<p>Shows the network status<br/><br/>"
58 "<b>Network:</b> {0}</p>") 63 "<b>Network:</b> {0}</p>")
59 64
60 if self.__networkManager.isOnline(): 65 if online:
61 tooltip = tooltip.format(self.tr("Connected")) 66 tooltip = tooltip.format(self.tr("Connected"))
62 else: 67 else:
63 tooltip = tooltip.format(self.tr("Offline")) 68 tooltip = tooltip.format(self.tr("Offline"))
64 69
65 self.setToolTip(tooltip) 70 self.setToolTip(tooltip)
73 Public method to get the online state. 78 Public method to get the online state.
74 79
75 @return online state 80 @return online state
76 @rtype bool 81 @rtype bool
77 """ 82 """
78 return self.__networkManager.isOnline() 83 return self.__online

eric ide

mercurial