Sat, 03 Dec 2016 12:49:53 +0100
Re-merged with the default branch.
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
4631
5c1a96925da4
Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4341
diff
changeset
|
3 | # Copyright (c) 2010 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the central widget showing the web pages. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3080
diff
changeset
|
10 | from __future__ import unicode_literals |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2403
diff
changeset
|
11 | |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | import os |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
14 | from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QDir, QFile, \ |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
15 | QFileDevice, QTemporaryFile, qVersion |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
16 | from PyQt5.QtGui import QIcon, QPixmap, QPainter |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
17 | from PyQt5.QtWidgets import QWidget, QHBoxLayout, QMenu, QToolButton, QDialog |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
18 | from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | from E5Gui.E5TabWidget import E5TabWidget |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | from E5Gui import E5MessageBox |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
22 | from E5Gui.E5Application import e5App |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
24 | from .WebBrowserView import WebBrowserView |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
25 | from .WebBrowserPage import WebBrowserPage |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
26 | from .Tools import WebBrowserTools |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
27 | from .Tools import FilePrinter |
4782
4ad656e4ebec
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4781
diff
changeset
|
28 | from . import WebInspector |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
29 | |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | import UI.PixmapCache |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
32 | import Utilities |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | import Preferences |
4795
6e0a26c633b2
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4792
diff
changeset
|
34 | import Globals |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
3670
f0cb7579c0b4
Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
36 | from eric6config import getConfig |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
38 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
39 | class WebBrowserTabWidget(E5TabWidget): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | Class implementing the central widget showing the web pages. |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
42 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
43 | @signal sourceChanged(WebBrowserView, QUrl) emitted after the URL of a |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
44 | browser has changed |
4965
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
45 | @signal currentUrlChanged(QUrl) emitted after the URL of the current |
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
46 | browser has changed |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
47 | @signal titleChanged(WebBrowserView, str) emitted after the title of a |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
48 | browser has changed |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
49 | @signal showMessage(str) emitted to show a message in the main window |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
50 | status bar |
4979
7ac0959842f9
Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4965
diff
changeset
|
51 | @signal browserOpened(QWidget) emitted after a new browser was created |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
52 | @signal browserClosed(QWidget) emitted after a browser was closed |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
53 | @signal browserZoomValueChanged(int) emitted to signal a change of the |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
54 | current browser's zoom level |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | """ |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
56 | sourceChanged = pyqtSignal(WebBrowserView, QUrl) |
4965
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
57 | currentUrlChanged = pyqtSignal(QUrl) |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
58 | titleChanged = pyqtSignal(WebBrowserView, str) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | showMessage = pyqtSignal(str) |
4979
7ac0959842f9
Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4965
diff
changeset
|
60 | browserOpened = pyqtSignal(QWidget) |
1196
77da430b4080
Added an action to preview the file in the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1155
diff
changeset
|
61 | browserClosed = pyqtSignal(QWidget) |
2334
fc69ad77e18a
Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
62 | browserZoomValueChanged = pyqtSignal(int) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | def __init__(self, parent): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | Constructor |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | @param parent reference to the parent widget (QWidget) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | """ |
4713
8dca047daf4b
Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4709
diff
changeset
|
70 | super(WebBrowserTabWidget, self).__init__(parent, dnd=True) |
2403
e3d7a861547c
Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2334
diff
changeset
|
71 | |
4715
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
72 | from .WebBrowserTabBar import WebBrowserTabBar |
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
73 | self.__tabBar = WebBrowserTabBar(self) |
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
74 | self.setCustomTabBar(True, self.__tabBar) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | self.__mainWindow = parent |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | |
1422
47f1dffa398e
Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1232
diff
changeset
|
78 | self.setUsesScrollButtons(True) |
47f1dffa398e
Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1232
diff
changeset
|
79 | self.setDocumentMode(True) |
47f1dffa398e
Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1232
diff
changeset
|
80 | self.setElideMode(Qt.ElideNone) |
47f1dffa398e
Fixed the tab bar issue observed for some styles (like Mac Aqua).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1232
diff
changeset
|
81 | |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
82 | from .ClosedTabsManager import ClosedTabsManager |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
83 | self.__closedTabsManager = ClosedTabsManager(self) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
84 | self.__closedTabsManager.closedTabAvailable.connect( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
85 | self.__closedTabAvailable) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
86 | |
2403
e3d7a861547c
Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2334
diff
changeset
|
87 | from .UrlBar.StackedUrlBar import StackedUrlBar |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
88 | self.__stackedUrlBar = StackedUrlBar(self) |
4715
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
89 | self.__tabBar.tabMoved.connect(self.__stackedUrlBar.moveBar) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
90 | |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | self.__tabContextMenuIndex = -1 |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
92 | self.currentChanged[int].connect(self.__currentChanged) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | self.setTabContextMenuPolicy(Qt.CustomContextMenu) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | self.customTabContextMenuRequested.connect(self.__showContextMenu) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | self.__rightCornerWidget = QWidget(self) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget) |
2824
858412c29c34
Replaced the obsoleted method setMargin() with setContentsMargins().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2763
diff
changeset
|
98 | self.__rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | self.__rightCornerWidgetLayout.setSpacing(0) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | self.__navigationMenu = QMenu(self) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | self.__navigationButton = QToolButton(self) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
106 | self.__navigationButton.setIcon( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
107 | UI.PixmapCache.getIcon("1downarrow.png")) |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
108 | self.__navigationButton.setToolTip( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
109 | self.tr("Show a navigation menu")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | self.__navigationButton.setPopupMode(QToolButton.InstantPopup) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | self.__navigationButton.setMenu(self.__navigationMenu) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | self.__navigationButton.setEnabled(False) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | self.__rightCornerWidgetLayout.addWidget(self.__navigationButton) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
115 | self.__closedTabsMenu = QMenu(self) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
116 | self.__closedTabsMenu.aboutToShow.connect( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
117 | self.__aboutToShowClosedTabsMenu) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
118 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
119 | self.__closedTabsButton = QToolButton(self) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
120 | self.__closedTabsButton.setIcon(UI.PixmapCache.getIcon("trash.png")) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
121 | self.__closedTabsButton.setToolTip( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
122 | self.tr("Show a navigation menu for closed tabs")) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
123 | self.__closedTabsButton.setPopupMode(QToolButton.InstantPopup) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
124 | self.__closedTabsButton.setMenu(self.__closedTabsMenu) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
125 | self.__closedTabsButton.setEnabled(False) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
126 | self.__rightCornerWidgetLayout.addWidget(self.__closedTabsButton) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
127 | |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
128 | self.__closeButton = QToolButton(self) |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
129 | self.__closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
130 | self.__closeButton.setToolTip( |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
131 | self.tr("Close the current web browser")) |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
132 | self.__closeButton.setEnabled(False) |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
133 | self.__closeButton.clicked.connect(self.closeBrowser) |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
134 | self.__rightCornerWidgetLayout.addWidget(self.__closeButton) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | if Preferences.getUI("SingleCloseButton") or \ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | not hasattr(self, 'setTabsClosable'): |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
137 | self.__closeButton.show() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | else: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | self.setTabsClosable(True) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | self.tabCloseRequested.connect(self.closeBrowserAt) |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
141 | self.__closeButton.hide() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.setCornerWidget(self.__rightCornerWidget, Qt.TopRightCorner) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | self.__newTabButton = QToolButton(self) |
1652
4719bf3fe8d8
Change the icon on the "Add tab" button of the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1651
diff
changeset
|
146 | self.__newTabButton.setIcon(UI.PixmapCache.getIcon("plus.png")) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
147 | self.__newTabButton.setToolTip( |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
148 | self.tr("Open a new web browser tab")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | self.setCornerWidget(self.__newTabButton, Qt.TopLeftCorner) |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
150 | self.__newTabButton.clicked.connect(self.__newBrowser) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | self.__initTabContextMenu() |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
153 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
154 | self.__historyCompleter = None |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
155 | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
156 | self.__pdfPrinter = None |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | def __initTabContextMenu(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | """ |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
160 | Private method to create the tab context menu. |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | self.__tabContextMenu = QMenu(self) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
163 | self.tabContextNewAct = self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
164 | UI.PixmapCache.getIcon("tabNew.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
165 | self.tr('New Tab'), self.newBrowser) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | self.__tabContextMenu.addSeparator() |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
167 | self.leftMenuAct = self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
168 | UI.PixmapCache.getIcon("1leftarrow.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
169 | self.tr('Move Left'), self.__tabContextMenuMoveLeft) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
170 | self.rightMenuAct = self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
171 | UI.PixmapCache.getIcon("1rightarrow.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
172 | self.tr('Move Right'), self.__tabContextMenuMoveRight) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | self.__tabContextMenu.addSeparator() |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
174 | self.tabContextCloneAct = self.__tabContextMenu.addAction( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
175 | self.tr("Duplicate Page"), self.__tabContextMenuClone) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | self.__tabContextMenu.addSeparator() |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
177 | self.tabContextCloseAct = self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
178 | UI.PixmapCache.getIcon("tabClose.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
179 | self.tr('Close'), self.__tabContextMenuClose) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
180 | self.tabContextCloseOthersAct = self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
181 | UI.PixmapCache.getIcon("tabCloseOther.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
182 | self.tr("Close Others"), self.__tabContextMenuCloseOthers) |
3022
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
183 | self.__tabContextMenu.addAction( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
184 | self.tr('Close All'), self.closeAllBrowsers) |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
185 | self.__tabContextMenu.addSeparator() |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
186 | if not Globals.isWindowsPlatform() and qVersion() < "5.7.0": |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
187 | self.__tabContextMenu.addAction( |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
188 | UI.PixmapCache.getIcon("printPreview.png"), |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
189 | self.tr('Print Preview'), self.__tabContextMenuPrintPreview) |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
190 | if not Globals.isWindowsPlatform() or qVersion() >= "5.7.0": |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
191 | self.__tabContextMenu.addAction( |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
192 | UI.PixmapCache.getIcon("print.png"), |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
193 | self.tr('Print'), self.__tabContextMenuPrint) |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
194 | if Globals.isLinuxPlatform() or qVersion() >= "5.7.0": |
4795
6e0a26c633b2
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4792
diff
changeset
|
195 | self.__tabContextMenu.addAction( |
6e0a26c633b2
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4792
diff
changeset
|
196 | UI.PixmapCache.getIcon("printPdf.png"), |
6e0a26c633b2
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4792
diff
changeset
|
197 | self.tr('Print as PDF'), self.__tabContextMenuPrintPdf) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | self.__tabContextMenu.addSeparator() |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
199 | if hasattr(WebBrowserPage, "isAudioMuted"): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
200 | self.__audioAct = self.__tabContextMenu.addAction( |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
201 | "", self.__tabContextMenuAudioMute) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
202 | self.__tabContextMenu.addSeparator() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
203 | else: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
204 | self.__audioAct = None |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
205 | self.__tabContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
206 | UI.PixmapCache.getIcon("reload.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
207 | self.tr('Reload All'), self.reloadAllBrowsers) |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
208 | self.__tabContextMenu.addSeparator() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
209 | self.__tabContextMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
210 | UI.PixmapCache.getIcon("addBookmark.png"), |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
211 | self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
212 | |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
213 | self.__tabBackContextMenu = QMenu(self) |
3022
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
214 | self.__tabBackContextMenu.addAction( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
215 | self.tr('Close All'), self.closeAllBrowsers) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
216 | self.__tabBackContextMenu.addAction( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
217 | UI.PixmapCache.getIcon("reload.png"), |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
218 | self.tr('Reload All'), self.reloadAllBrowsers) |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
219 | self.__tabBackContextMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
220 | UI.PixmapCache.getIcon("addBookmark.png"), |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
221 | self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
222 | self.__tabBackContextMenu.addSeparator() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
223 | self.__restoreClosedTabAct = self.__tabBackContextMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
224 | UI.PixmapCache.getIcon("trash.png"), |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
225 | self.tr('Restore Closed Tab'), self.restoreClosedTab) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
226 | self.__restoreClosedTabAct.setEnabled(False) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
227 | self.__restoreClosedTabAct.setData(0) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | def __showContextMenu(self, coord, index): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | Private slot to show the tab context menu. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | @param coord the position of the mouse pointer (QPoint) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | @param index index of the tab the menu is requested for (integer) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | coord = self.mapToGlobal(coord) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
237 | if index == -1: |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
238 | self.__tabBackContextMenu.popup(coord) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
239 | else: |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
240 | self.__tabContextMenuIndex = index |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
241 | self.leftMenuAct.setEnabled(index > 0) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
242 | self.rightMenuAct.setEnabled(index < self.count() - 1) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
243 | |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
244 | self.tabContextCloseOthersAct.setEnabled(self.count() > 1) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
245 | |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
246 | if self.__audioAct is not None: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
247 | if self.widget(self.__tabContextMenuIndex).page()\ |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
248 | .isAudioMuted(): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
249 | self.__audioAct.setText(self.tr("Unmute Tab")) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
250 | self.__audioAct.setIcon( |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
251 | UI.PixmapCache.getIcon("audioVolumeHigh.png")) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
252 | else: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
253 | self.__audioAct.setText(self.tr("Mute Tab")) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
254 | self.__audioAct.setIcon( |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
255 | UI.PixmapCache.getIcon("audioVolumeMuted.png")) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
256 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
257 | self.__tabContextMenu.popup(coord) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | def __tabContextMenuMoveLeft(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | Private method to move a tab one position to the left. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | """ |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
263 | self.moveTab(self.__tabContextMenuIndex, |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
264 | self.__tabContextMenuIndex - 1) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | def __tabContextMenuMoveRight(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | Private method to move a tab one position to the right. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | """ |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
270 | self.moveTab(self.__tabContextMenuIndex, |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
271 | self.__tabContextMenuIndex + 1) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | def __tabContextMenuClone(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | Private method to clone the selected tab. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | idx = self.__tabContextMenuIndex |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | if idx < 0: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | idx = self.currentIndex() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | if idx < 0 or idx > self.count(): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | return |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
283 | url = self.widget(idx).url() |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
284 | self.newBrowser(url) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | def __tabContextMenuClose(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | Private method to close the selected tab. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | self.closeBrowserAt(self.__tabContextMenuIndex) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | def __tabContextMenuCloseOthers(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | Private slot to close all other tabs. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | index = self.__tabContextMenuIndex |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | for i in list(range(self.count() - 1, index, -1)) + \ |
3035
36e9f388958b
Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3034
diff
changeset
|
298 | list(range(index - 1, -1, -1)): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | self.closeBrowserAt(i) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
301 | def __tabContextMenuPrint(self): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
302 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
303 | Private method to print the selected tab. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
304 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
305 | browser = self.widget(self.__tabContextMenuIndex) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
306 | self.printBrowser(browser) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
307 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
308 | def __tabContextMenuPrintPdf(self): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
309 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
310 | Private method to print the selected tab as PDF. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
311 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
312 | browser = self.widget(self.__tabContextMenuIndex) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
313 | self.printBrowserPdf(browser) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
314 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
315 | def __tabContextMenuPrintPreview(self): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
316 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
317 | Private method to show a print preview of the selected tab. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
318 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
319 | browser = self.widget(self.__tabContextMenuIndex) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
320 | self.printPreviewBrowser(browser) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
321 | |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
322 | def __tabContextMenuAudioMute(self): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
323 | """ |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
324 | Private method to mute or unmute the selected tab. |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
325 | """ |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
326 | page = self.widget(self.__tabContextMenuIndex).page() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
327 | muted = page.isAudioMuted() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
328 | page.setAudioMuted(not muted) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
329 | |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
330 | @pyqtSlot(bool) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
331 | def __recentlyAudibleChanged(self, recentlyAudible): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
332 | """ |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
333 | Private slot to react on the audible state of a page. |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
334 | |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
335 | @param recentlyAudible flag indicating the new audible state |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
336 | @type bool |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
337 | """ |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
338 | page = self.sender() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
339 | if page is None: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
340 | return |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
341 | |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
342 | browser = page.view() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
343 | if browser is None: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
344 | return |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
345 | |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
346 | index = self.indexOf(browser) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
347 | icon = page.icon() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
348 | |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
349 | if page.isAudioMuted() or ( |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
350 | not page.isAudioMuted() and recentlyAudible): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
351 | pix = QPixmap(32, 32) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
352 | pix.fill(Qt.transparent) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
353 | painter = QPainter(pix) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
354 | icon.paint(painter, 0, 0, 22, 22) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
355 | if page.isAudioMuted(): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
356 | audioIcon = UI.PixmapCache.getIcon("audioMuted.png") |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
357 | else: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
358 | audioIcon = UI.PixmapCache.getIcon("audioPlaying.png") |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
359 | audioIcon.paint(painter, 13, 13, 18, 18) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
360 | painter.end() |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
361 | self.setTabIcon(index, QIcon(pix)) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
362 | else: |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
363 | self.setTabIcon(index, icon) |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
364 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
365 | @pyqtSlot() |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
366 | def __newBrowser(self): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | """ |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
368 | Private slot to open a new browser tab. |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | """ |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
370 | self.newBrowser() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
372 | def newBrowser(self, link=None, position=-1, background=False): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | Public method to create a new web browser tab. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | @param link link to be shown (string or QUrl) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
377 | @keyparam position position to create the new tab at or -1 to add it |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
378 | to the end (integer) |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
379 | @keyparam background flag indicating to open the tab in the |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
380 | background (bool) |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
381 | @return reference to the new browser |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
382 | @rtype WebBrowserView |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | if link is None: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | linkName = "" |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | elif isinstance(link, QUrl): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | linkName = link.toString() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | else: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | linkName = link |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | |
2403
e3d7a861547c
Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2334
diff
changeset
|
391 | from .UrlBar.UrlBar import UrlBar |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
392 | urlbar = UrlBar(self.__mainWindow, self) |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
393 | if self.__historyCompleter is None: |
4749
750577d35452
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4745
diff
changeset
|
394 | import WebBrowser.WebBrowserWindow |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
395 | from .History.HistoryCompleter import HistoryCompletionModel, \ |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
396 | HistoryCompleter |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
397 | self.__historyCompletionModel = HistoryCompletionModel(self) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
398 | self.__historyCompletionModel.setSourceModel( |
4749
750577d35452
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4745
diff
changeset
|
399 | WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager() |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
400 | .historyFilterModel()) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
401 | self.__historyCompleter = HistoryCompleter( |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
402 | self.__historyCompletionModel, self) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
403 | self.__historyCompleter.activated[str].connect(self.__pathSelected) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
404 | urlbar.setCompleter(self.__historyCompleter) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
405 | urlbar.returnPressed.connect(self.__lineEditReturnPressed) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
406 | if position == -1: |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
407 | self.__stackedUrlBar.addWidget(urlbar) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
408 | else: |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
409 | self.__stackedUrlBar.insertWidget(position, urlbar) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
410 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
411 | browser = WebBrowserView(self.__mainWindow, self) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
412 | urlbar.setBrowser(browser) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | browser.sourceChanged.connect(self.__sourceChanged) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | browser.titleChanged.connect(self.__titleChanged) |
641
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
416 | browser.highlighted.connect(self.showMessage) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
417 | browser.backwardAvailable.connect( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
418 | self.__mainWindow.setBackwardAvailable) |
641
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
419 | browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable) |
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
420 | browser.loadStarted.connect(self.__loadStarted) |
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
421 | browser.loadFinished.connect(self.__loadFinished) |
5039
200f12184a43
Renamed the iconChanged signal of WebBrowserView to faviconChanged in order to get rid of a name clash with Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5038
diff
changeset
|
422 | browser.faviconChanged.connect(self.__iconChanged) |
641
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
423 | browser.search.connect(self.newBrowser) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
424 | browser.page().windowCloseRequested.connect( |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
425 | self.__windowCloseRequested) |
2334
fc69ad77e18a
Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
426 | browser.zoomValueChanged.connect(self.browserZoomValueChanged) |
5113
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
427 | if hasattr(WebBrowserPage, "recentlyAudibleChanged"): |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
428 | browser.page().recentlyAudibleChanged.connect( |
d394e20f7467
Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5039
diff
changeset
|
429 | self.__recentlyAudibleChanged) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
431 | if position == -1: |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
432 | index = self.addTab(browser, self.tr("...")) |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
433 | else: |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
434 | index = self.insertTab(position, browser, self.tr("...")) |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
435 | if not background: |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
436 | self.setCurrentIndex(index) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | |
641
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
438 | self.__mainWindow.closeAct.setEnabled(True) |
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
439 | self.__mainWindow.closeAllAct.setEnabled(True) |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
440 | self.__closeButton.setEnabled(True) |
641
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
441 | self.__navigationButton.setEnabled(True) |
b06d4df23797
Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
638
diff
changeset
|
442 | |
4908
f1859c36d564
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4846
diff
changeset
|
443 | if not linkName: |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
444 | if Preferences.getWebBrowser("StartupBehavior") == 0: |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
445 | linkName = Preferences.getWebBrowser("HomePage") |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
446 | elif Preferences.getWebBrowser("StartupBehavior") == 1: |
1670
6fd889391d2c
Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1665
diff
changeset
|
447 | linkName = "eric:speeddial" |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | if linkName: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | browser.setSource(QUrl(linkName)) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | if not browser.documentTitle(): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | self.setTabText(index, self.__elide(linkName, Qt.ElideMiddle)) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | self.setTabToolTip(index, linkName) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | else: |
3022
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
455 | self.setTabText( |
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
456 | index, |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | self.__elide(browser.documentTitle().replace("&", "&&"))) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | self.setTabToolTip(index, browser.documentTitle()) |
4979
7ac0959842f9
Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4965
diff
changeset
|
459 | |
7ac0959842f9
Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4965
diff
changeset
|
460 | self.browserOpened.emit(browser) |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
461 | |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
462 | return browser |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
464 | def newBrowserAfter(self, browser, link=None, background=False): |
3077
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
465 | """ |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
466 | Public method to create a new web browser tab after a given one. |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
467 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
468 | @param browser reference to the browser to add after (WebBrowserView) |
3077
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
469 | @param link link to be shown (string or QUrl) |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
470 | @keyparam background flag indicating to open the tab in the |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
471 | background (bool) |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
472 | @return reference to the new browser |
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
473 | @rtype WebBrowserView |
3077
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
474 | """ |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
475 | if browser: |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
476 | position = self.indexOf(browser) + 1 |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
477 | else: |
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
478 | position = -1 |
5038
df7103c3f2a6
Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5036
diff
changeset
|
479 | return self.newBrowser(link, position, background) |
3077
8d2e69e02e19
Change web browser code to show windows requested by JavaScript next to the requesting tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3048
diff
changeset
|
480 | |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | def __showNavigationMenu(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | Private slot to show the navigation button menu. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | self.__navigationMenu.clear() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | for index in range(self.count()): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | act = self.__navigationMenu.addAction( |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | self.tabIcon(index), self.tabText(index)) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | act.setData(index) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | def __navigationMenuTriggered(self, act): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | Private slot called to handle the navigation button menu selection. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | @param act reference to the selected action (QAction) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | index = act.data() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | if index is not None: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | self.setCurrentIndex(index) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
500 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | def __windowCloseRequested(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
502 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | Private slot to handle the windowCloseRequested signal of a browser. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | page = self.sender() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | if page is None: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | return |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | browser = page.view() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | if browser is None: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | return |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
512 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | index = self.indexOf(browser) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
514 | self.closeBrowserAt(index) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
516 | def reloadAllBrowsers(self): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
517 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
518 | Public slot to reload all browsers. |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
519 | """ |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
520 | for index in range(self.count()): |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
521 | browser = self.widget(index) |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
522 | browser and browser.reload() |
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
523 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
524 | @pyqtSlot() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | def closeBrowser(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | Public slot called to handle the close action. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | self.closeBrowserAt(self.currentIndex()) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
531 | def closeAllBrowsers(self, shutdown=False): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | Public slot called to handle the close all action. |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
534 | |
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
535 | @param shutdown flag indicating a shutdown action |
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
536 | @type bool |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | for index in range(self.count() - 1, -1, -1): |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
539 | self.closeBrowserAt(index, shutdown=shutdown) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
541 | def closeBrowserAt(self, index, shutdown=False): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | """ |
2763
e4794166ad70
Fixed a serious typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
543 | Public slot to close a browser based on its index. |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
545 | @param index index of browser to close |
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
546 | @type int |
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
547 | @param shutdown flag indicating a shutdown action |
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
548 | @type bool |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
549 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | browser = self.widget(index) |
1670
6fd889391d2c
Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1665
diff
changeset
|
551 | if browser is None: |
6fd889391d2c
Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1665
diff
changeset
|
552 | return |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
553 | |
4314
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
554 | urlbar = self.__stackedUrlBar.widget(index) |
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
555 | self.__stackedUrlBar.removeWidget(urlbar) |
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
556 | urlbar.deleteLater() |
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
557 | del urlbar |
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
558 | |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
559 | self.__closedTabsManager.recordBrowser(browser, index) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
560 | |
4781
15d416f1eca5
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4749
diff
changeset
|
561 | browser.closeWebInspector() |
4782
4ad656e4ebec
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4781
diff
changeset
|
562 | WebInspector.unregisterView(browser) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | self.removeTab(index) |
1196
77da430b4080
Added an action to preview the file in the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1155
diff
changeset
|
564 | self.browserClosed.emit(browser) |
4314
2d9133f4cc10
Modified the web browser such, that it will ask the user, if he wants to close a modified page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
565 | browser.deleteLater() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | del browser |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
567 | |
4745
285bfd224a1b
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4741
diff
changeset
|
568 | if self.count() == 0 and not shutdown: |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
569 | self.newBrowser() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | else: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
571 | self.currentChanged[int].emit(self.currentIndex()) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
573 | def currentBrowser(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
575 | Public method to get a reference to the current browser. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
576 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
577 | @return reference to the current browser (WebBrowserView) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | return self.currentWidget() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
580 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
581 | def browserAt(self, index): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
582 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
583 | Public method to get a reference to the browser with the given index. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
584 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | @param index index of the browser to get (integer) |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
586 | @return reference to the indexed browser (WebBrowserView) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
587 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
588 | return self.widget(index) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
590 | def browsers(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
591 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
592 | Public method to get a list of references to all browsers. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
593 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
594 | @return list of references to browsers (list of WebBrowserView) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
595 | """ |
3034
7ce719013078
Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3022
diff
changeset
|
596 | li = [] |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | for index in range(self.count()): |
3034
7ce719013078
Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3022
diff
changeset
|
598 | li.append(self.widget(index)) |
7ce719013078
Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3022
diff
changeset
|
599 | return li |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
600 | |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
601 | @pyqtSlot() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
602 | def printBrowser(self, browser=None): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
603 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
604 | Public slot called to print the displayed page. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
605 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
606 | @param browser reference to the browser to be printed (WebBrowserView) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
607 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
608 | if browser is None: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
609 | browser = self.currentBrowser() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
610 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
611 | printer = QPrinter(mode=QPrinter.HighResolution) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
612 | if Preferences.getPrinter("ColorMode"): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
613 | printer.setColorMode(QPrinter.Color) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
614 | else: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
615 | printer.setColorMode(QPrinter.GrayScale) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
616 | if Preferences.getPrinter("FirstPageFirst"): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
617 | printer.setPageOrder(QPrinter.FirstPageFirst) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
618 | else: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
619 | printer.setPageOrder(QPrinter.LastPageFirst) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
620 | printer.setPageMargins( |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
621 | Preferences.getPrinter("LeftMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
622 | Preferences.getPrinter("TopMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
623 | Preferences.getPrinter("RightMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
624 | Preferences.getPrinter("BottomMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
625 | QPrinter.Millimeter |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
626 | ) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
627 | printerName = Preferences.getPrinter("PrinterName") |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
628 | if printerName: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
629 | printer.setPrinterName(printerName) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
630 | printer.setResolution(Preferences.getPrinter("Resolution")) |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
631 | documentName = WebBrowserTools.getFileNameFromUrl(browser.url()) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
632 | printer.setDocName(documentName) |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
633 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
634 | printDialog = QPrintDialog(printer, self) |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
635 | printDialog.setOptions(QAbstractPrintDialog.PrintToFile | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
636 | QAbstractPrintDialog.PrintShowPageSize) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
637 | if not Globals.isWindowsPlatform(): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
638 | if FilePrinter.isCupsAvailable(): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
639 | printDialog.setOption(QAbstractPrintDialog.PrintCollateCopies) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
640 | printDialog.setOption(QAbstractPrintDialog.PrintPageRange) |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
641 | if printDialog.exec_() == QDialog.Accepted: |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
642 | if not hasattr(browser.page(), "printToPdf"): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
643 | browser.render(printer) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
644 | else: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
645 | if printer.outputFormat() == QPrinter.PdfFormat: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
646 | # print to PDF file selected |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
647 | browser.page().printToPdf( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
648 | lambda pdf: self.__pdfGeneratedForSave( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
649 | printer.outputFileName(), pdf), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
650 | printer.pageLayout()) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
651 | else: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
652 | # print to printer |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
653 | self.__pdfPrinter = printer |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
654 | browser.page().printToPdf( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
655 | self.__pdfGeneratedForPrinting, |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
656 | printer.pageLayout()) |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
657 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
658 | @pyqtSlot() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
659 | def printBrowserPdf(self, browser=None): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
660 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
661 | Public slot called to print the displayed page to PDF. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
662 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
663 | @param browser reference to the browser to be printed (HelpBrowser) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
664 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
665 | if browser is None: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
666 | browser = self.currentBrowser() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
667 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
668 | name = WebBrowserTools.getFileNameFromUrl(browser.url()) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
669 | if name: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
670 | name = name.rsplit('.', 1)[0] |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
671 | name += '.pdf' |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
672 | if hasattr(browser.page(), "printToPdf"): |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
673 | from .Tools.PrintToPdfDialog import PrintToPdfDialog |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
674 | if not name: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
675 | name = "printout.pdf" |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
676 | dlg = PrintToPdfDialog(name, self) |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
677 | if dlg.exec_() == QDialog.Accepted: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
678 | filePath, pageLayout = dlg.getData() |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
679 | if filePath: |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
680 | if os.path.exists(filePath): |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
681 | res = E5MessageBox.warning( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
682 | self, |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
683 | self.tr("Print to PDF"), |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
684 | self.tr("""<p>The file <b>{0}</b> exists""" |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
685 | """ already. Shall it be""" |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
686 | """ overwritten?</p>""").format(filePath), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
687 | E5MessageBox.StandardButtons( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
688 | E5MessageBox.No | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
689 | E5MessageBox.Yes), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
690 | E5MessageBox.No) |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
691 | if res == E5MessageBox.No: |
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
692 | return |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
693 | browser.page().printToPdf( |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
694 | lambda pdf: self.__pdfGeneratedForSave(filePath, pdf), |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
695 | pageLayout) |
5181
1948b27d7b21
Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5113
diff
changeset
|
696 | elif Globals.isLinuxPlatform(): |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
697 | printer = QPrinter(mode=QPrinter.HighResolution) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
698 | if Preferences.getPrinter("ColorMode"): |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
699 | printer.setColorMode(QPrinter.Color) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
700 | else: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
701 | printer.setColorMode(QPrinter.GrayScale) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
702 | printerName = Preferences.getPrinter("PrinterName") |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
703 | if printerName: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
704 | printer.setPrinterName(printerName) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
705 | printer.setOutputFormat(QPrinter.PdfFormat) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
706 | if name: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
707 | printer.setOutputFileName(name) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
708 | printer.setResolution(Preferences.getPrinter("Resolution")) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
709 | |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
710 | printDialog = QPrintDialog(printer, self) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
711 | if printDialog.exec_() == QDialog.Accepted: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
712 | browser.render(printer) |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
713 | |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
714 | def __pdfGeneratedForSave(self, filePath, pdfData): |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
715 | """ |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
716 | Private slot to save the generated PDF data to a file. |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
717 | |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
718 | @param filePath path to save the PDF to |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
719 | @type str |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
720 | @param pdfData generated PDF document |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
721 | @type QByteArray |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
722 | """ |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
723 | if pdfData.size() == 0: |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
724 | return |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
725 | |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
726 | pdfFile = QFile(filePath) |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
727 | if pdfFile.open(QFile.WriteOnly): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
728 | pdfFile.write(pdfData) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
729 | pdfFile.close() |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
730 | if pdfFile.error() != QFileDevice.NoError: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
731 | E5MessageBox.critical( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
732 | self, |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
733 | self.tr("Print to PDF"), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
734 | self.tr("""<p>The PDF could not be written to file <b>{0}""" |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
735 | """</b>.</p><p><b>Error:</b> {1}</p>""").format( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
736 | filePath, pdfFile.errorString()), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
737 | E5MessageBox.StandardButtons( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
738 | E5MessageBox.Ok)) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
739 | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
740 | def __pdfGeneratedForPrinting(self, pdfData): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
741 | """ |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
742 | Private slot to print the generated PDF data. |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
743 | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
744 | @param pdfData generated PDF document |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
745 | @type QByteArray |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
746 | """ |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
747 | if self.__pdfPrinter is None or pdfData.isEmpty(): |
5036
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
748 | return |
318e879a37fa
Added an improved "Print to PDF" to the new web browser for Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4979
diff
changeset
|
749 | |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
750 | tempFile = QTemporaryFile(QDir.tempPath() + "/ericBrowserXXXXXX.pdf") |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
751 | tempFile.setAutoRemove(False) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
752 | if tempFile.open(): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
753 | bytesWritten = tempFile.write(pdfData) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
754 | tempFile.close() |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
755 | if bytesWritten == pdfData.size(): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
756 | if Globals.isWindowsPlatform(): |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
757 | printerName = self.__pdfPrinter.printerName() |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
758 | import ctypes |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
759 | ctypes.windll.shell32.ShellExecuteW( |
5192
a10fb04f3edd
Fixed the new web browser print function for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5182
diff
changeset
|
760 | None, "printto", tempFile.fileName(), |
5182
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
761 | '"{0}"'.format(printerName), None, 0) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
762 | else: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
763 | FilePrinter.printFile( |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
764 | self.__pdfPrinter, tempFile.fileName(), |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
765 | FilePrinter.FilePrinter.SystemDeletesFiles, |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
766 | FilePrinter.FilePrinter.SystemSelectsPages) |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
767 | else: |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
768 | tempFile.remove() |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
769 | |
e2782c9a43d4
Started to implement real printing support for the new web browser and Qt >= 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5181
diff
changeset
|
770 | self.__pdfPrinter = None |
4792
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
771 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
772 | @pyqtSlot() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
773 | def printPreviewBrowser(self, browser=None): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
774 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
775 | Public slot called to show a print preview of the displayed file. |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
776 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
777 | @param browser reference to the browser to be printed (HelpBrowserWV) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
778 | """ |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
779 | from PyQt5.QtPrintSupport import QPrintPreviewDialog |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
780 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
781 | if browser is None: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
782 | browser = self.currentBrowser() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
783 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
784 | printer = QPrinter(mode=QPrinter.HighResolution) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
785 | if Preferences.getPrinter("ColorMode"): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
786 | printer.setColorMode(QPrinter.Color) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
787 | else: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
788 | printer.setColorMode(QPrinter.GrayScale) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
789 | if Preferences.getPrinter("FirstPageFirst"): |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
790 | printer.setPageOrder(QPrinter.FirstPageFirst) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
791 | else: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
792 | printer.setPageOrder(QPrinter.LastPageFirst) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
793 | printer.setPageMargins( |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
794 | Preferences.getPrinter("LeftMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
795 | Preferences.getPrinter("TopMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
796 | Preferences.getPrinter("RightMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
797 | Preferences.getPrinter("BottomMargin") * 10, |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
798 | QPrinter.Millimeter |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
799 | ) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
800 | printerName = Preferences.getPrinter("PrinterName") |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
801 | if printerName: |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
802 | printer.setPrinterName(printerName) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
803 | printer.setResolution(Preferences.getPrinter("Resolution")) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
804 | |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
805 | preview = QPrintPreviewDialog(printer, self) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
806 | preview.paintRequested.connect(lambda p: browser.render(p)) |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
807 | preview.exec_() |
f55fa7eb3cf3
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4790
diff
changeset
|
808 | |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
809 | def __sourceChanged(self, url): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
810 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
811 | Private slot to handle a change of a browsers source. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
812 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
813 | @param url URL of the new site (QUrl) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
814 | """ |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
815 | browser = self.sender() |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
816 | |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
817 | if browser is not None: |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
818 | self.sourceChanged.emit(browser, url) |
4965
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
819 | |
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
820 | if browser == self.currentBrowser(): |
a9a4b632fe48
Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4913
diff
changeset
|
821 | self.currentUrlChanged.emit(url) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
822 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
823 | def __titleChanged(self, title): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
824 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
825 | Private slot to handle a change of a browsers title. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
826 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
827 | @param title new title (string) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
828 | """ |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
829 | browser = self.sender() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
830 | |
4321
28d39909a480
Made the code of the web browser tab widget more robust.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4314
diff
changeset
|
831 | if browser is not None and isinstance(browser, QWidget): |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
832 | index = self.indexOf(browser) |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
833 | if title == "": |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
834 | title = browser.url().toString() |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
835 | |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
836 | self.setTabText(index, self.__elide(title.replace("&", "&&"))) |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
837 | self.setTabToolTip(index, title) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
838 | |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
839 | self.titleChanged.emit(browser, title) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
840 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
841 | def __elide(self, txt, mode=Qt.ElideRight, length=40): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
842 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
843 | Private method to elide some text. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
844 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
845 | @param txt text to be elided (string) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
846 | @keyparam mode elide mode (Qt.TextElideMode) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
847 | @keyparam length amount of characters to be used (integer) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
848 | @return the elided text (string) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
849 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
850 | if mode == Qt.ElideNone or len(txt) < length: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
851 | return txt |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
852 | elif mode == Qt.ElideLeft: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
853 | return "...{0}".format(txt[-length:]) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
854 | elif mode == Qt.ElideMiddle: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
855 | return "{0}...{1}".format(txt[:length // 2], txt[-(length // 2):]) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
856 | elif mode == Qt.ElideRight: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
857 | return "{0}...".format(txt[:length]) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
858 | else: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
859 | # just in case |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
860 | return txt |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
861 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
862 | def preferencesChanged(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
863 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
864 | Public slot to handle a change of preferences. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
865 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
866 | for browser in self.browsers(): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
867 | browser.preferencesChanged() |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
868 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
869 | for urlbar in self.__stackedUrlBar.urlBars(): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
870 | urlbar.preferencesChanged() |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
871 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
872 | if Preferences.getUI("SingleCloseButton"): |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
873 | self.setTabsClosable(False) |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
874 | try: |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
875 | self.tabCloseRequested.disconnect(self.closeBrowserAt) |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
876 | except TypeError: |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
877 | pass |
1645
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
878 | self.__closeButton.show() |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
879 | else: |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
880 | self.setTabsClosable(True) |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
881 | self.tabCloseRequested.connect(self.closeBrowserAt) |
73904ca06d2d
A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1636
diff
changeset
|
882 | self.__closeButton.hide() |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
883 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
884 | def __loadStarted(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
885 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
886 | Private method to handle the loadStarted signal. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
887 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
888 | browser = self.sender() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
889 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
890 | if browser is not None: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
891 | index = self.indexOf(browser) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
892 | anim = self.animationLabel( |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
893 | index, os.path.join(getConfig("ericPixDir"), "loading.gif"), |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
894 | 100) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
895 | if not anim: |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
896 | loading = QIcon(os.path.join(getConfig("ericPixDir"), |
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
897 | "loading.gif")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
898 | self.setTabIcon(index, loading) |
1539
b2d98c2e2e43
Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
899 | else: |
b2d98c2e2e43
Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
900 | self.setTabIcon(index, QIcon()) |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
901 | self.setTabText(index, self.tr("Loading...")) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
902 | self.setTabToolTip(index, self.tr("Loading...")) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
903 | self.showMessage.emit(self.tr("Loading...")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
904 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
905 | self.__mainWindow.setLoadingActions(True) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
906 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
907 | def __loadFinished(self, ok): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
908 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
909 | Private method to handle the loadFinished signal. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
910 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
911 | @param ok flag indicating the result (boolean) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
912 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
913 | browser = self.sender() |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
914 | if not isinstance(browser, WebBrowserView): |
1670
6fd889391d2c
Added a Speed Dial to the web browser including the capability to select the first ten pages by pressing Meta+1 to Meta+0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1665
diff
changeset
|
915 | return |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
916 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
917 | if browser is not None: |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
918 | import WebBrowser.WebBrowserWindow |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
919 | index = self.indexOf(browser) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
920 | self.resetAnimation(index) |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
921 | self.setTabIcon( |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
922 | index, WebBrowser.WebBrowserWindow.WebBrowserWindow.icon( |
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
923 | browser.url())) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
924 | if ok: |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
925 | self.showMessage.emit(self.tr("Finished loading")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
926 | else: |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
927 | self.showMessage.emit(self.tr("Failed to load")) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
928 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
929 | self.__mainWindow.setLoadingActions(False) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
930 | |
4726
c26e2a2dc0cb
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4715
diff
changeset
|
931 | def __iconChanged(self): |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
932 | """ |
4726
c26e2a2dc0cb
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4715
diff
changeset
|
933 | Private slot to handle a change of the web site icon. |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
934 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
935 | browser = self.sender() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
936 | |
4321
28d39909a480
Made the code of the web browser tab widget more robust.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4314
diff
changeset
|
937 | if browser is not None and isinstance(browser, QWidget): |
3022
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
938 | self.setTabIcon( |
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3020
diff
changeset
|
939 | self.indexOf(browser), |
4726
c26e2a2dc0cb
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4715
diff
changeset
|
940 | browser.icon()) |
5039
200f12184a43
Renamed the iconChanged signal of WebBrowserView to faviconChanged in order to get rid of a name clash with Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5038
diff
changeset
|
941 | self.__mainWindow.bookmarksManager().faviconChanged(browser.url()) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
942 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
943 | def getSourceFileList(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
944 | """ |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
945 | Public method to get a list of all opened Qt help files. |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
946 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
947 | @return dictionary with tab id as key and host/namespace as value |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
948 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
949 | sourceList = {} |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
950 | for i in range(self.count()): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
951 | browser = self.widget(i) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
952 | if browser is not None and \ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
953 | browser.source().isValid(): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
954 | sourceList[i] = browser.source().host() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
955 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
956 | return sourceList |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
957 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
958 | def shallShutDown(self): |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
959 | """ |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
960 | Public method to check, if the application should be shut down. |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
961 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
962 | @return flag indicating a shut down (boolean) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
963 | """ |
4715
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
964 | if self.count() > 1 and Preferences.getWebBrowser( |
79009bc4acd5
Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4713
diff
changeset
|
965 | "WarnOnMultipleClose"): |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2999
diff
changeset
|
966 | mb = E5MessageBox.E5MessageBox( |
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2999
diff
changeset
|
967 | E5MessageBox.Information, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
968 | self.tr("Are you sure you want to close the window?"), |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
969 | self.tr("""Are you sure you want to close the window?\n""" |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
970 | """You have %n tab(s) open.""", "", self.count()), |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
971 | modal=True, |
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
972 | parent=self) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
973 | if self.__mainWindow.fromEric: |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
974 | quitButton = mb.addButton( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
975 | self.tr("&Close"), E5MessageBox.AcceptRole) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
976 | quitButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
977 | else: |
2999
28c75409a78f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2824
diff
changeset
|
978 | quitButton = mb.addButton( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
979 | self.tr("&Quit"), E5MessageBox.AcceptRole) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
980 | quitButton.setIcon(UI.PixmapCache.getIcon("exit.png")) |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2999
diff
changeset
|
981 | closeTabButton = mb.addButton( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
982 | self.tr("C&lose Current Tab"), E5MessageBox.AcceptRole) |
638
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
983 | closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose.png")) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
984 | mb.addButton(E5MessageBox.Cancel) |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
985 | mb.exec_() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
986 | if mb.clickedButton() == quitButton: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
987 | return True |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
988 | else: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
989 | if mb.clickedButton() == closeTabButton: |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
990 | self.closeBrowser() |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
991 | return False |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
992 | |
265c31231d9d
Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
993 | return True |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
994 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
995 | def stackedUrlBar(self): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
996 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
997 | Public method to get a reference to the stacked url bar. |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
998 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
999 | @return reference to the stacked url bar (StackedUrlBar) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1000 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1001 | return self.__stackedUrlBar |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1002 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1003 | def currentUrlBar(self): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1004 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1005 | Public method to get a reference to the current url bar. |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1006 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1007 | @return reference to the current url bar (UrlBar) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1008 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1009 | return self.__stackedUrlBar.currentWidget() |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1010 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1011 | def __lineEditReturnPressed(self): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1012 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1013 | Private slot to handle the entering of an URL. |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1014 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1015 | edit = self.sender() |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1016 | url = self.__guessUrlFromPath(edit.text()) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1017 | if e5App().keyboardModifiers() == Qt.AltModifier: |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
1018 | self.newBrowser(url) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1019 | else: |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
1020 | self.currentBrowser().setSource(url) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1021 | self.currentBrowser().setFocus() |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1022 | |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1023 | def __pathSelected(self, path): |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1024 | """ |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1025 | Private slot called when a URL is selected from the completer. |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1026 | |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1027 | @param path path to be shown (string) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1028 | """ |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1029 | url = self.__guessUrlFromPath(path) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1030 | self.currentBrowser().setSource(url) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1031 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1032 | def __guessUrlFromPath(self, path): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1033 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1034 | Private method to guess an URL given a path string. |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1035 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1036 | @param path path string to guess an URL for (string) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1037 | @return guessed URL (QUrl) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1038 | """ |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1039 | manager = self.__mainWindow.openSearchManager() |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1040 | path = Utilities.fromNativeSeparators(path) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1041 | url = manager.convertKeywordSearchToUrl(path) |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1042 | if url.isValid(): |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1043 | return url |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1044 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1045 | try: |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1046 | url = QUrl.fromUserInput(path) |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1047 | except AttributeError: |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1048 | url = QUrl(path) |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1049 | |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1050 | if url.scheme() == "about" and \ |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1051 | url.path() == "home": |
1665
b248526d3a1b
Reworked some stuff in the web browser to use Qt resources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1652
diff
changeset
|
1052 | url = QUrl("eric:home") |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1053 | |
4741
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1054 | if url.scheme() in ["s", "search"]: |
f9e1adc69076
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4735
diff
changeset
|
1055 | url = manager.currentEngine().searchUrl(url.path().strip()) |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1056 | |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1057 | if url.scheme() != "" and \ |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1058 | (url.host() != "" or url.path() != ""): |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1059 | return url |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1060 | |
4709
8612533a223f
Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
1061 | urlString = Preferences.getWebBrowser("DefaultScheme") + path.strip() |
4331
711e7c35a49b
Changed code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4326
diff
changeset
|
1062 | url = QUrl.fromEncoded(urlString.encode("utf-8"), QUrl.TolerantMode) |
953
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1063 | |
7c42d54ba205
Added support for search schemes ("s:" or "search:") and "about:home" to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
1064 | return url |
653
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1065 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1066 | def __currentChanged(self, index): |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1067 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1068 | Private slot to handle an index change. |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1069 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1070 | @param index new index (integer) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1071 | """ |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1072 | self.__stackedUrlBar.setCurrentIndex(index) |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1073 | |
0540f3c52b46
Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
646
diff
changeset
|
1074 | browser = self.browserAt(index) |
717
3ebae1fae98d
Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
653
diff
changeset
|
1075 | if browser is not None: |
3ebae1fae98d
Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
653
diff
changeset
|
1076 | if browser.url() == "" and browser.hasFocus(): |
3ebae1fae98d
Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
653
diff
changeset
|
1077 | self.__stackedUrlBar.currentWidget.setFocus() |
3ebae1fae98d
Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
653
diff
changeset
|
1078 | elif browser.url() != "": |
3ebae1fae98d
Fixed an issue in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
653
diff
changeset
|
1079 | browser.setFocus() |
1694
648466a9451b
Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1673
diff
changeset
|
1080 | |
4735
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1081 | def restoreClosedTab(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1082 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1083 | Public slot to restore the most recently closed tab. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1084 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1085 | if not self.canRestoreClosedTab(): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1086 | return |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1087 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1088 | act = self.sender() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1089 | tab = self.__closedTabsManager.getClosedTabAt(act.data()) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1090 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1091 | self.newBrowser(tab.url.toString(), position=tab.position) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1092 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1093 | def canRestoreClosedTab(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1094 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1095 | Public method to check, if closed tabs can be restored. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1096 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1097 | @return flag indicating that closed tabs can be restored (boolean) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1098 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1099 | return self.__closedTabsManager.isClosedTabAvailable() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1100 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1101 | def restoreAllClosedTabs(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1102 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1103 | Public slot to restore all closed tabs. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1104 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1105 | if not self.canRestoreClosedTab(): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1106 | return |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1107 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1108 | for tab in self.__closedTabsManager.allClosedTabs(): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1109 | self.newBrowser(tab.url.toString(), position=tab.position) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1110 | self.__closedTabsManager.clearList() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1111 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1112 | def clearClosedTabsList(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1113 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1114 | Public slot to clear the list of closed tabs. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1115 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1116 | self.__closedTabsManager.clearList() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1117 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1118 | def __aboutToShowClosedTabsMenu(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1119 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1120 | Private slot to populate the closed tabs menu. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1121 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1122 | fm = self.__closedTabsMenu.fontMetrics() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1123 | maxWidth = fm.width('m') * 40 |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1124 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1125 | self.__closedTabsMenu.clear() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1126 | index = 0 |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1127 | for tab in self.__closedTabsManager.allClosedTabs(): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1128 | title = fm.elidedText(tab.title, Qt.ElideRight, maxWidth) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1129 | self.__closedTabsMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1130 | self.__mainWindow.icon(tab.url), title, |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1131 | self.restoreClosedTab).setData(index) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1132 | index += 1 |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1133 | self.__closedTabsMenu.addSeparator() |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1134 | self.__closedTabsMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1135 | self.tr("Restore All Closed Tabs"), self.restoreAllClosedTabs) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1136 | self.__closedTabsMenu.addAction( |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1137 | self.tr("Clear List"), self.clearClosedTabsList) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1138 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1139 | def closedTabsManager(self): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1140 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1141 | Public slot to get a reference to the closed tabs manager. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1142 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1143 | @return reference to the closed tabs manager (ClosedTabsManager) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1144 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1145 | return self.__closedTabsManager |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1146 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1147 | def __closedTabAvailable(self, avail): |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1148 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1149 | Private slot to handle changes of the availability of closed tabs. |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1150 | |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1151 | @param avail flag indicating the availability of closed tabs (boolean) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1152 | """ |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1153 | self.__closedTabsButton.setEnabled(avail) |
84e78ee0f361
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4732
diff
changeset
|
1154 | self.__restoreClosedTabAct.setEnabled(avail) |