WebBrowser/WebBrowserTabWidget.py

Wed, 12 Dec 2018 19:52:24 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 12 Dec 2018 19:52:24 +0100
changeset 6625
a67fee7bc09c
parent 6221
35ec993034e1
child 6645
ad476851d7e0
permissions
-rw-r--r--

Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.

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