Sat, 31 Dec 2016 13:34:21 +0100
Updated copyright for 2017.
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 | |
5389
9b1c800daff3
Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4964
diff
changeset
|
3 | # Copyright (c) 2016 - 2017 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 | from __future__ import unicode_literals |
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 | 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
|
18 | |
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 StatusBarIcon(E5ClickableLabel): |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | 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
|
23 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | 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
|
25 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | Constructor |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | @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
|
29 | @type WebBrowserWindow |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | 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
|
32 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | self._window = window |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | 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
|
36 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | 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
|
38 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @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
|
40 | @type QWebEngineSettings.WebAttribute |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @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
|
42 | @rtype bool |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | settings = self._currentPageSettings() |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | 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
|
46 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | 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
|
48 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | 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
|
50 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | @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
|
52 | @type QWebEngineSettings.WebAttribute |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | @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
|
54 | @type bool |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | settings = self._currentPageSettings() |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | 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
|
58 | 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
|
59 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | def _currentPageSettings(self): |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | 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
|
63 | current page. |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | @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
|
66 | @rtype QWebEngineSettings |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | 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
|
69 | 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
|
70 | return None |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | 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
|
73 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | def _currentPage(self): |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | 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
|
77 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | @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
|
79 | @rtype WebBrowserPage |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | """ |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | 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
|
82 | 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
|
83 | return None |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | |
b602ac3fe532
Started implementing the status bar icons for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | return view.page() |
4964
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
86 | |
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
87 | def preferencesChanged(self): |
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
88 | """ |
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
89 | 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
|
90 | """ |
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
91 | # do nothing |
a894e8c92369
Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4962
diff
changeset
|
92 | pass |