eric6/WebBrowser/StatusBar/StatusBarIcon.py

Tue, 10 Sep 2019 19:30:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Sep 2019 19:30:07 +0200
changeset 7229
53054eb5b15a
parent 6942
2602857055c5
child 7360
9190402e4505
permissions
-rw-r--r--

Removed obsolete "from __future__ import ..." statements.

4962
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2016 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4962
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the status bar icon base class.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 #
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 # This is modelled after the code found in Qupzilla
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 # Copyright (C) 2014 David Rosca <nowrep@gmail.com>
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 #
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from E5Gui.E5ClickableLabel import E5ClickableLabel
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class StatusBarIcon(E5ClickableLabel):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing common methods for all status bar icons.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 def __init__(self, window):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param window reference to the web browser window
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @type WebBrowserWindow
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 super(StatusBarIcon, self).__init__(window)
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self._window = window
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 def _testCurrentPageWebAttribute(self, attr):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Protected method to test a web attribute on the current page.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param attr attribute to test
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @type QWebEngineSettings.WebAttribute
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @return flag indicating the attribute is set
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @rtype bool
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 settings = self._currentPageSettings()
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 return settings is not None and settings.testAttribute(attr)
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def _setCurrentPageWebAttribute(self, attr, val):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Protected method to set a web attribute on the current page.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param attr attribute to sett
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @type QWebEngineSettings.WebAttribute
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @param val value to be set
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @type bool
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 settings = self._currentPageSettings()
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 if settings is not None:
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 settings.setAttribute(attr, val)
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def _currentPageSettings(self):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Protected method to get a reference to the web settings of the
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 current page.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @return reference to the web settings object
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @rtype QWebEngineSettings
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 view = self._window.currentBrowser()
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if view is None:
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 return None
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return view.page().settings()
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def _currentPage(self):
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Protected method to get a reference to the current page.
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @return reference to the current page
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @rtype WebBrowserPage
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 view = self._window.currentBrowser()
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 if view is None:
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 return None
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 return view.page()
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
85
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
86 def preferencesChanged(self):
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
87 """
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
88 Public method to handle changes of the settings.
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
89 """
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
90 # do nothing
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4962
diff changeset
91 pass

eric ide

mercurial