E5Network/E5NetworkIcon.py

Sun, 17 Jan 2016 12:17:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 17 Jan 2016 12:17:40 +0100
changeset 4671
59cdebfb658c
parent 4648
f7386abb53f2
child 5047
04e5dfbd3f3d
permissions
-rw-r--r--

Changed the parent class of the network icon to QLabel.

4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
4631
5c1a96925da4 Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4630
diff changeset
3 # Copyright (c) 2015 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a statusbar icon tracking the network status.
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtNetwork import QNetworkConfigurationManager
4671
59cdebfb658c Changed the parent class of the network icon to QLabel.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4648
diff changeset
14 from PyQt5.QtWidgets import QLabel
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import UI.PixmapCache
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
4671
59cdebfb658c Changed the parent class of the network icon to QLabel.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4648
diff changeset
19 class E5NetworkIcon(QLabel):
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing a statusbar icon tracking the network status.
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
22
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
23 @signal onlineStateChanged(online) emitted to indicate a change of the
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
24 network state
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
26 onlineStateChanged = pyqtSignal(bool)
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
27
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 def __init__(self, parent=None):
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param parent reference to the parent widget
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @type QWidget
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 super(E5NetworkIcon, self).__init__(parent)
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__networkManager = QNetworkConfigurationManager(self)
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
38 self.__online = self.__networkManager.isOnline()
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
39 self.__onlineStateChanged(self.__online)
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__networkManager.onlineStateChanged.connect(
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__onlineStateChanged)
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @pyqtSlot(bool)
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def __onlineStateChanged(self, online):
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Private slot handling online state changes.
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param online flag indicating the online status
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @type bool
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if online:
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.setPixmap(UI.PixmapCache.getPixmap("network-online.png"))
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 else:
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.setPixmap(UI.PixmapCache.getPixmap("network-offline.png"))
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 tooltip = self.tr("<p>Shows the network status<br/><br/>"
4648
f7386abb53f2 Fixed a code style issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
58 "<b>Network:</b> {0}</p>")
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 if self.__networkManager.isOnline():
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 tooltip = tooltip.format(self.tr("Connected"))
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 else:
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 tooltip = tooltip.format(self.tr("Offline"))
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.setToolTip(tooltip)
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
66
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
67 if online != self.__online:
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
68 self.__online = online
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
69 self.onlineStateChanged.emit(online)
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def isOnline(self):
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 Public method to get the online state.
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @return online state
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @rtype bool
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 return self.__networkManager.isOnline()

eric ide

mercurial