src/eric7/WebBrowser/StatusBar/StatusBarIcon.py

Sat, 31 Dec 2022 16:23:21 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2022 16:23:21 +0100
branch
eric7
changeset 9653
e67609152c5e
parent 9413
80c06d472826
child 10439
21c28b0f9e41
permissions
-rw-r--r--

Updated copyright for 2023.

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
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
3 # Copyright (c) 2016 - 2023 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 #
9273
5c6a9210d291 Corrected a misspelling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
11 # This is modeled after the code found in Qupzilla
4962
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
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9273
diff changeset
15 from eric7.EricWidgets.EricClickableLabel import EricClickableLabel
4962
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
18 class StatusBarIcon(EricClickableLabel):
4962
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
b602ac3fe532 Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
22
4962
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
26
4962
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 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
30 super().__init__(window)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31
4962
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33
4962
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37
4962
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)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
4962
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
4962
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)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58
4962
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
4962
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70
4962
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()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72
4962
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76
4962
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
83
4962
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()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
85
4964
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