eric6/E5Network/E5NetworkIcon.py

Sun, 29 Nov 2020 14:10:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Nov 2020 14:10:18 +0100
changeset 7844
cb108454eda7
parent 7780
41420f82c0ac
child 7923
91e843545d9a
permissions
-rw-r--r--

WebBrowserWindow: removed the use of QTextCodec to prepare the Qt6 migration.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2015 - 2020 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
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
10 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
11 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
12 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
13
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import UI.PixmapCache
5047
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
15 import Preferences
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
4671
59cdebfb658c Changed the parent class of the network icon to QLabel.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4648
diff changeset
18 class E5NetworkIcon(QLabel):
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
22 @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
23 network state
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
25 onlineStateChanged = pyqtSignal(bool)
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
26
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 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
28 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @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
32 @type QWidget
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 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
35
5047
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
36 if Preferences.getUI("DynamicOnlineCheck"):
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
37 self.__networkManager = QNetworkConfigurationManager(self)
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
38 self.__online = self.__networkManager.isOnline()
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
39 self.__onlineStateChanged(self.__online)
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
40
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
41 self.__networkManager.onlineStateChanged.connect(
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
42 self.__onlineStateChanged)
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
43 else:
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
44 self.__online = True
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
45 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
46
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @pyqtSlot(bool)
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 def __onlineStateChanged(self, online):
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 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
51
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @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
53 @type bool
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 if online:
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
56 self.setPixmap(UI.PixmapCache.getPixmap("network-online"))
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 else:
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
58 self.setPixmap(UI.PixmapCache.getPixmap("network-offline"))
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 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
61 "<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
62
5047
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
63 if online:
4629
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 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
65 else:
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.setToolTip(tooltip)
4630
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
69
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
70 if online != self.__online:
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
71 self.__online = online
7b0e38956b5c Refined the online state change behaviour.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4629
diff changeset
72 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
73
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def isOnline(self):
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 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
77
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @return online state
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @rtype bool
99aaac59be4f Added a status bar icon to show the online status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
5047
04e5dfbd3f3d Added a configuration option to override the online status check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4671
diff changeset
81 return self.__online

eric ide

mercurial