|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a statusbar icon tracking the network status. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtNetwork import QNetworkConfigurationManager |
|
14 |
|
15 from E5Gui.E5ClickableLabel import E5ClickableLabel |
|
16 |
|
17 import UI.PixmapCache |
|
18 |
|
19 |
|
20 class E5NetworkIcon(E5ClickableLabel): |
|
21 """ |
|
22 Class implementing a statusbar icon tracking the network status. |
|
23 """ |
|
24 def __init__(self, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget |
|
29 @type QWidget |
|
30 """ |
|
31 super(E5NetworkIcon, self).__init__(parent) |
|
32 |
|
33 self.__networkManager = QNetworkConfigurationManager(self) |
|
34 self.__onlineStateChanged(self.__networkManager.isOnline()) |
|
35 |
|
36 self.__networkManager.onlineStateChanged.connect( |
|
37 self.__onlineStateChanged) |
|
38 |
|
39 @pyqtSlot(bool) |
|
40 def __onlineStateChanged(self, online): |
|
41 """ |
|
42 Private slot handling online state changes. |
|
43 |
|
44 @param online flag indicating the online status |
|
45 @type bool |
|
46 """ |
|
47 if online: |
|
48 self.setPixmap(UI.PixmapCache.getPixmap("network-online.png")) |
|
49 else: |
|
50 self.setPixmap(UI.PixmapCache.getPixmap("network-offline.png")) |
|
51 |
|
52 tooltip = self.tr("<p>Shows the network status<br/><br/>" |
|
53 "<b>Network:</b> {0}</p>") |
|
54 |
|
55 if self.__networkManager.isOnline(): |
|
56 tooltip = tooltip.format(self.tr("Connected")) |
|
57 else: |
|
58 tooltip = tooltip.format(self.tr("Offline")) |
|
59 |
|
60 self.setToolTip(tooltip) |
|
61 |
|
62 def isOnline(self): |
|
63 """ |
|
64 Public method to get the online state. |
|
65 |
|
66 @return online state |
|
67 @rtype bool |
|
68 """ |
|
69 return self.__networkManager.isOnline() |