eric6/WebBrowser/WebBrowserTabWidget.py

Wed, 08 Jan 2020 18:58:31 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 08 Jan 2020 18:58:31 +0100
changeset 7366
bd743eacfbca
parent 7360
9190402e4505
child 7514
0960c7c1f497
permissions
-rw-r--r--

Changed code to avoid some obsoleted Qt functions.

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