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