|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 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 __future__ import unicode_literals |
|
16 |
|
17 from E5Gui.E5ClickableLabel import E5ClickableLabel |
|
18 |
|
19 |
|
20 class StatusBarIcon(E5ClickableLabel): |
|
21 """ |
|
22 Class implementing common methods for all status bar icons. |
|
23 """ |
|
24 def __init__(self, window): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param window reference to the web browser window |
|
29 @type WebBrowserWindow |
|
30 """ |
|
31 super(StatusBarIcon, self).__init__(window) |
|
32 |
|
33 self._window = window |
|
34 |
|
35 def _testCurrentPageWebAttribute(self, attr): |
|
36 """ |
|
37 Protected method to test a web attribute on the current page. |
|
38 |
|
39 @param attr attribute to test |
|
40 @type QWebEngineSettings.WebAttribute |
|
41 @return flag indicating the attribute is set |
|
42 @rtype bool |
|
43 """ |
|
44 settings = self._currentPageSettings() |
|
45 return settings is not None and settings.testAttribute(attr) |
|
46 |
|
47 def _setCurrentPageWebAttribute(self, attr, val): |
|
48 """ |
|
49 Protected method to set a web attribute on the current page. |
|
50 |
|
51 @param attr attribute to sett |
|
52 @type QWebEngineSettings.WebAttribute |
|
53 @param val value to be set |
|
54 @type bool |
|
55 """ |
|
56 settings = self._currentPageSettings() |
|
57 if settings is not None: |
|
58 settings.setAttribute(attr, val) |
|
59 |
|
60 def _currentPageSettings(self): |
|
61 """ |
|
62 Protected method to get a reference to the web settings of the |
|
63 current page. |
|
64 |
|
65 @return reference to the web settings object |
|
66 @rtype QWebEngineSettings |
|
67 """ |
|
68 view = self._window.currentBrowser() |
|
69 if view is None: |
|
70 return None |
|
71 |
|
72 return view.page().settings() |
|
73 |
|
74 def _currentPage(self): |
|
75 """ |
|
76 Protected method to get a reference to the current page. |
|
77 |
|
78 @return reference to the current page |
|
79 @rtype WebBrowserPage |
|
80 """ |
|
81 view = self._window.currentBrowser() |
|
82 if view is None: |
|
83 return None |
|
84 |
|
85 return view.page() |