WebBrowser/WebBrowserTabWidget.py

Tue, 21 Feb 2017 19:29:29 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 21 Feb 2017 19:29:29 +0100
changeset 5542
520713d0a381
parent 5534
f9368ecf153a
child 5558
858abfcbaf28
permissions
-rw-r--r--

Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).

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
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5192
diff changeset
3 # Copyright (c) 2010 - 2017 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
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
17 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QMenu, QToolButton, \
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
18 QDialog, QApplication
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
19 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
20
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from E5Gui.E5TabWidget import E5TabWidget
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 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
23 from E5Gui.E5Application import e5App
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
25 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
26 from .WebBrowserPage import WebBrowserPage
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
27 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
28 from .Tools import FilePrinter
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
29 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
30
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 import UI.PixmapCache
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
33 import Utilities
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 import Preferences
4795
6e0a26c633b2 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4792
diff changeset
35 import Globals
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
37 from eric6config import getConfig
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
39
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
40 class WebBrowserTabWidget(E5TabWidget):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
44 @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
45 browser has changed
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
46 @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
47 browser has changed
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
48 @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
49 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
50 @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
51 status bar
4979
7ac0959842f9 Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4965
diff changeset
52 @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
53 @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
54 @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
55 current browser's zoom level
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
57 sourceChanged = pyqtSignal(WebBrowserView, QUrl)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
58 currentUrlChanged = pyqtSignal(QUrl)
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
59 titleChanged = pyqtSignal(WebBrowserView, str)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 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
61 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
62 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
63 browserZoomValueChanged = pyqtSignal(int)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def __init__(self, parent):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Constructor
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @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
70 """
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4709
diff changeset
71 super(WebBrowserTabWidget, self).__init__(parent, dnd=True)
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
72
4715
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
73 from .WebBrowserTabBar import WebBrowserTabBar
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
74 self.__tabBar = WebBrowserTabBar(self)
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
75 self.setCustomTabBar(True, self.__tabBar)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__mainWindow = parent
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
1422
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.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
80 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
81 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
82
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
83 from .ClosedTabsManager import ClosedTabsManager
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
84 self.__closedTabsManager = ClosedTabsManager(self)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
85 self.__closedTabsManager.closedTabAvailable.connect(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
86 self.__closedTabAvailable)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
87
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
88 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
89 self.__stackedUrlBar = StackedUrlBar(self)
4715
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
90 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
91
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93 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
94 self.setTabContextMenuPolicy(Qt.CustomContextMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.customTabContextMenuRequested.connect(self.__showContextMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__rightCornerWidget = QWidget(self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget)
2824
858412c29c34 Replaced the obsoleted method setMargin() with setContentsMargins().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
99 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
100 self.__rightCornerWidgetLayout.setSpacing(0)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__navigationMenu = QMenu(self)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 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
107 self.__navigationButton.setIcon(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
108 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
109 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
110 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
111 self.__navigationButton.setPopupMode(QToolButton.InstantPopup)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.__navigationButton.setMenu(self.__navigationMenu)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 self.__navigationButton.setEnabled(False)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.__rightCornerWidgetLayout.addWidget(self.__navigationButton)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
116 self.__closedTabsMenu = QMenu(self)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
117 self.__closedTabsMenu.aboutToShow.connect(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
118 self.__aboutToShowClosedTabsMenu)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
119
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
120 self.__closedTabsButton = QToolButton(self)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
121 self.__closedTabsButton.setIcon(UI.PixmapCache.getIcon("trash.png"))
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
122 self.__closedTabsButton.setToolTip(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
123 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
124 self.__closedTabsButton.setPopupMode(QToolButton.InstantPopup)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
125 self.__closedTabsButton.setMenu(self.__closedTabsMenu)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
126 self.__closedTabsButton.setEnabled(False)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
127 self.__rightCornerWidgetLayout.addWidget(self.__closedTabsButton)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
128
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
129 self.__closeButton = QToolButton(self)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
130 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
131 self.__closeButton.setToolTip(
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 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
133 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
134 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
135 self.__rightCornerWidgetLayout.addWidget(self.__closeButton)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if Preferences.getUI("SingleCloseButton") or \
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 not hasattr(self, 'setTabsClosable'):
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
138 self.__closeButton.show()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.setTabsClosable(True)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.tabCloseRequested.connect(self.closeBrowserAt)
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
142 self.__closeButton.hide()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 self.setCornerWidget(self.__rightCornerWidget, Qt.TopRightCorner)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 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
147 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
148 self.__newTabButton.setToolTip(
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 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
150 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
151 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
152
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 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
154
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
155 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
156
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
157 self.__pdfPrinter = None
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 def __initTabContextMenu(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
161 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
162 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 self.tr('Close All'), self.closeAllBrowsers)
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
186 self.__tabContextMenu.addSeparator()
5542
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
187 # TODO: re-check this once printing on Windows is reliable
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
188 ## if qVersion() >= "5.8.0" or (
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
189 ## not Globals.isWindowsPlatform() and qVersion() < "5.7.0"):
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
190 if not Globals.isWindowsPlatform() and (
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
191 qVersion() < "5.7.0" or qVersion() >= "5.8.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
192 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
193 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
194 self.tr('Print Preview'), self.__tabContextMenuPrintPreview)
5542
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
195 # TODO: re-check this once printing on Windows is reliable
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
196 ## if qVersion() >= "5.8.0" or (
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
197 ## not Globals.isWindowsPlatform() or qVersion() >= "5.7.0"):
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
198 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
199 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
200 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
201 self.tr('Print'), self.__tabContextMenuPrint)
5542
520713d0a381 Disabled printing on Windows platforms for the new web browser because it works unreliably (tends to crash).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5534
diff changeset
202 # TODO: check this on macOS
5181
1948b27d7b21 Fixed a few issues related to printing in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5113
diff changeset
203 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
204 self.__tabContextMenu.addAction(
6e0a26c633b2 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4792
diff changeset
205 UI.PixmapCache.getIcon("printPdf.png"),
6e0a26c633b2 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4792
diff changeset
206 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
207 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
208 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
209 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
210 "", self.__tabContextMenuAudioMute)
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
211 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
212 else:
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
213 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
214 self.__tabContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
215 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
216 self.tr('Reload All'), self.reloadAllBrowsers)
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
217 self.__tabContextMenu.addSeparator()
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
218 self.__tabContextMenu.addAction(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
219 UI.PixmapCache.getIcon("addBookmark.png"),
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
220 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
221
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
222 self.__tabBackContextMenu = QMenu(self)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
223 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
224 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
225 self.__tabBackContextMenu.addAction(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
226 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
227 self.tr('Reload All'), self.reloadAllBrowsers)
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
228 self.__tabBackContextMenu.addAction(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
229 UI.PixmapCache.getIcon("addBookmark.png"),
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
230 self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
231 self.__tabBackContextMenu.addSeparator()
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
232 self.__restoreClosedTabAct = self.__tabBackContextMenu.addAction(
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
233 UI.PixmapCache.getIcon("trash.png"),
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
234 self.tr('Restore Closed Tab'), self.restoreClosedTab)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
235 self.__restoreClosedTabAct.setEnabled(False)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
236 self.__restoreClosedTabAct.setData(0)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 def __showContextMenu(self, coord, index):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 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
241
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @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
243 @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
244 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 coord = self.mapToGlobal(coord)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
246 if index == -1:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
247 self.__tabBackContextMenu.popup(coord)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
248 else:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
249 self.__tabContextMenuIndex = index
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
250 self.leftMenuAct.setEnabled(index > 0)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
251 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
252
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
253 self.tabContextCloseOthersAct.setEnabled(self.count() > 1)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
254
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
255 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
256 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
257 .isAudioMuted():
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
258 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
259 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
260 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
261 else:
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
262 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
263 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
264 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
265
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
266 self.__tabContextMenu.popup(coord)
638
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 def __tabContextMenuMoveLeft(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 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
271 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
272 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
273 self.__tabContextMenuIndex - 1)
638
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 def __tabContextMenuMoveRight(self):
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 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
278 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
279 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
280 self.__tabContextMenuIndex + 1)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 def __tabContextMenuClone(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 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
285 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 idx = self.__tabContextMenuIndex
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 if idx < 0:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 idx = self.currentIndex()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 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
290 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
292 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
293 self.newBrowser(url)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 def __tabContextMenuClose(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 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
298 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.closeBrowserAt(self.__tabContextMenuIndex)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 def __tabContextMenuCloseOthers(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 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
304 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 index = self.__tabContextMenuIndex
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307 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
308 self.closeBrowserAt(i)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
310 def __tabContextMenuPrint(self):
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 Private method to print the selected tab.
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
313 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
314 browser = self.widget(self.__tabContextMenuIndex)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
315 self.printBrowser(browser)
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 def __tabContextMenuPrintPdf(self):
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 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
320 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
321 browser = self.widget(self.__tabContextMenuIndex)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
322 self.printBrowserPdf(browser)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
323
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
324 def __tabContextMenuPrintPreview(self):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
325 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
326 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
327 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
328 browser = self.widget(self.__tabContextMenuIndex)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
329 self.printPreviewBrowser(browser)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
330
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
331 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
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 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
334 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
335 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
336 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
337 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
338
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
339 @pyqtSlot(bool)
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
340 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
341 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
342 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
343
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
344 @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
345 @type bool
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
346 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
347 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
348 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
349 return
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
350
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
351 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
352 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
353 return
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
354
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
355 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
356 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
357
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366 else:
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
367 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
368 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
369 painter.end()
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
370 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
371 else:
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5039
diff changeset
372 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
373
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
374 @pyqtSlot()
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
375 def __newBrowser(self):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
377 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
378 """
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
379 self.newBrowser()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
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
381 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
382 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 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
384
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 @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
386 @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
387 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
388 @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
389 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
390 @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
391 @rtype WebBrowserView
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 if link is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 linkName = ""
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 elif isinstance(link, QUrl):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 linkName = link.toString()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 linkName = link
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
400 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
401 urlbar = UrlBar(self.__mainWindow, self)
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
402 if self.__historyCompleter is None:
4749
750577d35452 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
403 import WebBrowser.WebBrowserWindow
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
404 from .History.HistoryCompleter import HistoryCompletionModel, \
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
405 HistoryCompleter
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
406 self.__historyCompletionModel = HistoryCompletionModel(self)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
407 self.__historyCompletionModel.setSourceModel(
4749
750577d35452 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
408 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager()
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
409 .historyFilterModel())
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
410 self.__historyCompleter = HistoryCompleter(
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
411 self.__historyCompletionModel, self)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
412 self.__historyCompleter.activated[str].connect(self.__pathSelected)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
413 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
414 urlbar.returnPressed.connect(self.__lineEditReturnPressed)
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
415 if position == -1:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
416 self.__stackedUrlBar.addWidget(urlbar)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
417 else:
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
418 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
419
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
420 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
421 urlbar.setBrowser(browser)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 browser.sourceChanged.connect(self.__sourceChanged)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 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
425 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
426 browser.backwardAvailable.connect(
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 self.__recentlyAudibleChanged)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
440 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
441 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
442 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
443 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
444 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
445 self.setCurrentIndex(index)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446
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
447 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
448 self.__mainWindow.closeAllAct.setEnabled(True)
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
449 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
450 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
451
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4846
diff changeset
452 if not linkName:
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
453 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
454 linkName = Preferences.getWebBrowser("HomePage")
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
455 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
456 linkName = "eric:speeddial"
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 if linkName:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 browser.setSource(QUrl(linkName))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 if not browser.documentTitle():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 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
462 self.setTabToolTip(index, linkName)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 else:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
464 self.setTabText(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
465 index,
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 self.__elide(browser.documentTitle().replace("&", "&&")))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 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
468
7ac0959842f9 Added a tab manager window to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4965
diff changeset
469 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
470
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 return browser
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472
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
473 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
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 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
476
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
477 @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
478 @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
479 @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
480 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
481 @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
482 @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
483 """
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
484 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
485 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
486 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
487 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
488 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
489
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 def __showNavigationMenu(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 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
493 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 self.__navigationMenu.clear()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 for index in range(self.count()):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 act = self.__navigationMenu.addAction(
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 self.tabIcon(index), self.tabText(index))
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 act.setData(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 def __navigationMenuTriggered(self, act):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 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
503
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 @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
505 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 index = act.data()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 if index is not None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 self.setCurrentIndex(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 def __windowCloseRequested(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 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
513 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 page = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 if page is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 browser = page.view()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 if browser is None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 return
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 self.closeBrowserAt(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
525 def reloadAllBrowsers(self):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
526 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
527 Public slot to reload all browsers.
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
528 """
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
529 for index in range(self.count()):
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
530 browser = self.widget(index)
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
531 browser and browser.reload()
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
532
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
533 @pyqtSlot()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 def closeBrowser(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
536 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
537 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 self.closeBrowserAt(self.currentIndex())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
540 def closeAllBrowsers(self, shutdown=False):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 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
543
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
544 @param shutdown flag indicating a shutdown action
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
545 @type bool
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 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
548 self.closeBrowserAt(index, shutdown=shutdown)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
550 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
551 """
2763
e4794166ad70 Fixed a serious typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
552 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
553
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
554 @param index index of browser to close
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
555 @type int
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
556 @param shutdown flag indicating a shutdown action
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
557 @type bool
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 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
560 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
561 return
1694
648466a9451b Added the capability to restore closed tabs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1673
diff changeset
562
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
563 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
564 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
565 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
566 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
567
4735
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
568 self.__closedTabsManager.recordBrowser(browser, index)
84e78ee0f361 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4732
diff changeset
569
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4749
diff changeset
570 browser.closeWebInspector()
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
571 WebInspector.unregisterView(browser)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 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
573 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
574 browser.deleteLater()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
575 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
576
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
577 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
578 self.newBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
579 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
580 self.currentChanged[int].emit(self.currentIndex())
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
582 def currentBrowser(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 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
585
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 current 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.currentWidget()
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 browserAt(self, index):
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 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
593
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 @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
595 @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
596 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597 return self.widget(index)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
598
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 def browsers(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601 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
602
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
603 @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
604 """
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
605 li = []
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606 for index in range(self.count()):
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
607 li.append(self.widget(index))
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
608 return li
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
610 @pyqtSlot()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
611 def printBrowser(self, browser=None):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
612 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
613 Public slot called to print the displayed page.
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
614
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
615 @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
616 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
617 if browser is None:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
618 browser = self.currentBrowser()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
619
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
620 printer = QPrinter(mode=QPrinter.HighResolution)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
621 if Preferences.getPrinter("ColorMode"):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
622 printer.setColorMode(QPrinter.Color)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
623 else:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
624 printer.setColorMode(QPrinter.GrayScale)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
625 if Preferences.getPrinter("FirstPageFirst"):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
626 printer.setPageOrder(QPrinter.FirstPageFirst)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
627 else:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
628 printer.setPageOrder(QPrinter.LastPageFirst)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
629 printer.setPageMargins(
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
630 Preferences.getPrinter("LeftMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
631 Preferences.getPrinter("TopMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
632 Preferences.getPrinter("RightMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
633 Preferences.getPrinter("BottomMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
634 QPrinter.Millimeter
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
635 )
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
636 printerName = Preferences.getPrinter("PrinterName")
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
637 if printerName:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
638 printer.setPrinterName(printerName)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
639 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
640 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
641 printer.setDocName(documentName)
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
642
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
643 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
644 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
645 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
646 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
647 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
648 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
649 printDialog.setOption(QAbstractPrintDialog.PrintPageRange)
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
650 if printDialog.exec_() == QDialog.Accepted:
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
651 if hasattr(browser.page(), "print"):
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
652 # Qt >= 5.8.0
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
653 browser.page().execPrintPage(printer)
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
654 elif hasattr(browser.page(), "printToPdf"):
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5526
diff changeset
655 # Qt >= 5.7.0
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
656 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
657 # 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
658 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
659 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
660 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
661 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
662 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
663 # 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
664 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
665 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
666 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
667 printer.pageLayout())
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
668 else:
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
669 browser.render(printer)
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
670
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
671 @pyqtSlot()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
672 def printBrowserPdf(self, browser=None):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
673 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
674 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
675
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
676 @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
677 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
678 if browser is None:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
679 browser = self.currentBrowser()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
680
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
681 name = WebBrowserTools.getFileNameFromUrl(browser.url())
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
682 if name:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
683 name = name.rsplit('.', 1)[0]
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
684 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
685 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
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693 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
694 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
695 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
696 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
697 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
698 """ 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
699 """ 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
700 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
701 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
702 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
703 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
704 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
705 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
706 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
707 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
708 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
709 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
710 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
711 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
712 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
713 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
714 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
715 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
716 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
717 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
718 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
719 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
720 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
721 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
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 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
724 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
725 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
726
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 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
728 """
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
729 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
730
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
731 @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
732 @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
733 @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
734 @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
735 """
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
736 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
737 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
738
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
739 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
740 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
741 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
742 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
743 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
744 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
745 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
746 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
747 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
748 """</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
749 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
750 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
751 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
752
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 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
754 """
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 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
756
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 @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
758 @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
759 """
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
760 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
761 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
762
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
763 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
764 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
765 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
766 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
767 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
768 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
769 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
770 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
771 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
772 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
773 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
774 '"{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
775 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
776 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
777 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
778 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
779 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
780 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
781 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
782
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
783 self.__pdfPrinter = None
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
784
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
785 @pyqtSlot()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
786 def printPreviewBrowser(self, browser=None):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
787 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
788 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
789
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
790 @param browser reference to the browser to be printed (WebBrowserView)
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
791 """
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
792 from PyQt5.QtPrintSupport import QPrintPreviewDialog
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
793
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
794 if browser is None:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
795 browser = self.currentBrowser()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
796
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
797 printer = QPrinter(mode=QPrinter.HighResolution)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
798 if Preferences.getPrinter("ColorMode"):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
799 printer.setColorMode(QPrinter.Color)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
800 else:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
801 printer.setColorMode(QPrinter.GrayScale)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
802 if Preferences.getPrinter("FirstPageFirst"):
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
803 printer.setPageOrder(QPrinter.FirstPageFirst)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
804 else:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
805 printer.setPageOrder(QPrinter.LastPageFirst)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
806 printer.setPageMargins(
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
807 Preferences.getPrinter("LeftMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
808 Preferences.getPrinter("TopMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
809 Preferences.getPrinter("RightMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
810 Preferences.getPrinter("BottomMargin") * 10,
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
811 QPrinter.Millimeter
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
812 )
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
813 printerName = Preferences.getPrinter("PrinterName")
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
814 if printerName:
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
815 printer.setPrinterName(printerName)
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
816 printer.setResolution(Preferences.getPrinter("Resolution"))
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
817
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
818 preview = QPrintPreviewDialog(printer, self)
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
819 preview.resize(800, 750)
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
820 if qVersion() >= "5.8.0":
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
821 preview.paintRequested.connect(
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
822 lambda p: self.__printPreviewRequested(p, browser))
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
823 else:
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
824 preview.paintRequested.connect(lambda p: browser.render(p))
4792
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
825 preview.exec_()
f55fa7eb3cf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
826
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
827 def __printPreviewRequested(self, printer, browser):
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
828 """
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
829 Private slot to generate the print preview.
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
830
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
831 @param printer reference to the printer object
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
832 @type QPrinter
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
833 @param browser reference to the browser to be printed
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
834 @type WebBrowserView
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
835 """
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
836 QApplication.setOverrideCursor(Qt.WaitCursor);
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
837 browser.page().execPrintPage(printer, 10 * 1000)
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
838 QApplication.restoreOverrideCursor();
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
839
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840 def __sourceChanged(self, url):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
841 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
842 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
843
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
844 @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
845 """
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
846 browser = self.sender()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
847
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
848 if browser is not None:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
849 self.sourceChanged.emit(browser, url)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
850
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
851 if browser == self.currentBrowser():
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
852 self.currentUrlChanged.emit(url)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
854 def __titleChanged(self, title):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856 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
857
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 @param title new title (string)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
859 """
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
860 browser = self.sender()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
861
4321
28d39909a480 Made the code of the web browser tab widget more robust.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4314
diff changeset
862 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
863 index = self.indexOf(browser)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
864 if title == "":
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
865 title = browser.url().toString()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
866
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
867 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
868 self.setTabToolTip(index, title)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
869
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
870 self.titleChanged.emit(browser, title)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
872 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
873 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874 Private method to elide some text.
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
875
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876 @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
877 @keyparam mode elide mode (Qt.TextElideMode)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878 @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
879 @return the elided text (string)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 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
882 return txt
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
883 elif mode == Qt.ElideLeft:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884 return "...{0}".format(txt[-length:])
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885 elif mode == Qt.ElideMiddle:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 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
887 elif mode == Qt.ElideRight:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 return "{0}...".format(txt[:length])
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 # just in case
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 return txt
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893 def preferencesChanged(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
894 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895 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
896 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 for browser in self.browsers():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
898 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
899
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
900 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
901 urlbar.preferencesChanged()
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
902
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
903 if Preferences.getUI("SingleCloseButton"):
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
904 self.setTabsClosable(False)
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
905 try:
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
906 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
907 except TypeError:
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
908 pass
1645
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
909 self.__closeButton.show()
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
910 else:
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
911 self.setTabsClosable(True)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
912 self.tabCloseRequested.connect(self.closeBrowserAt)
73904ca06d2d A few fixes for the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1636
diff changeset
913 self.__closeButton.hide()
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
914
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
915 def __loadStarted(self):
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 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
918 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 browser = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
920
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 if browser is not None:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923 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
924 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
925 100)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
926 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
927 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
928 "loading.gif"))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
929 self.setTabIcon(index, loading)
1539
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
930 else:
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
931 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
932 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
933 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
934 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
935
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
936 self.__mainWindow.setLoadingActions(True)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
937
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
938 def __loadFinished(self, ok):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
939 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
940 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
941
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
942 @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
943 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
944 browser = self.sender()
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
945 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
946 return
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
947
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
948 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
949 import WebBrowser.WebBrowserWindow
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
950 index = self.indexOf(browser)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
951 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
952 self.setTabIcon(
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
953 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
954 browser.url()))
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
955 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
956 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
957 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
958 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
959
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
960 self.__mainWindow.setLoadingActions(False)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
961
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
962 def __iconChanged(self):
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
963 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
964 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
965 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
966 browser = self.sender()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
967
4321
28d39909a480 Made the code of the web browser tab widget more robust.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4314
diff changeset
968 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
969 self.setTabIcon(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
970 self.indexOf(browser),
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
971 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
972 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
973
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
974 def getSourceFileList(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
975 """
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
976 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
977
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
978 @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
979 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
980 sourceList = {}
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
981 for i in range(self.count()):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
982 browser = self.widget(i)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
983 if browser is not None and \
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
984 browser.source().isValid():
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
985 sourceList[i] = browser.source().host()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
986
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
987 return sourceList
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
988
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
989 def shallShutDown(self):
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
990 """
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
991 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
992
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
993 @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
994 """
4715
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
995 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
996 "WarnOnMultipleClose"):
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
997 mb = E5MessageBox.E5MessageBox(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
998 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
999 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
1000 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
1001 """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
1002 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
1003 parent=self)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1004 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
1005 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
1006 self.tr("&Close"), E5MessageBox.AcceptRole)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1007 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
1008 else:
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2824
diff changeset
1009 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
1010 self.tr("&Quit"), E5MessageBox.AcceptRole)
638
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1011 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
1012 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
1013 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
1014 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
1015 mb.addButton(E5MessageBox.Cancel)
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1016 mb.exec_()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1017 if mb.clickedButton() == quitButton:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1018 return True
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1019 else:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1020 if mb.clickedButton() == closeTabButton:
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1021 self.closeBrowser()
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1022 return False
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1023
265c31231d9d Did some refactoring of the web browser code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1024 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
1025
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1026 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
1027 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1028 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
1029
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1030 @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
1031 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1032 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
1033
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1034 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
1035 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1036 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
1037
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1038 @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
1039 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1040 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
1041
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1042 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
1043 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1044 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
1045 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 646
diff changeset
1046 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
1047 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
1048 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
1049 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
1050 else:
4709
8612533a223f Started porting the eric web browser to use QtWebEngine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
1051 self.currentBrowser().setSource(url)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-