WebBrowser/WebBrowserView.py

Sun, 03 Jul 2016 16:34:45 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Jul 2016 16:34:45 +0200
changeset 5015
ca1d44f0f6b2
parent 5001
08eaee907686
child 5033
d1c2651060ec
permissions
-rw-r--r--

Enhanced the new web browser by adding a visit count to the bookmarks.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
4631
5c1a96925da4 Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4612
diff changeset
3 # Copyright (c) 2008 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
8 Module implementing the web browser using QWebEngineView.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3080
diff changeset
11 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
12 try:
4715
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4713
diff changeset
13 str = unicode # __IGNORE_EXCEPTION__
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
14 except NameError:
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
15 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
16
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
17 from PyQt5.QtCore import pyqtSignal, QUrl, QFileInfo, Qt, QTimer, QEvent, \
5015
ca1d44f0f6b2 Enhanced the new web browser by adding a visit count to the bookmarks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5001
diff changeset
18 QPoint, QDateTime
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
19 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
20 QContextMenuEvent, QPixmap
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
21 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
22 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
24 from E5Gui import E5MessageBox
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
25
4958
ef400197e7d5 Implemented the auto scroller for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4956
diff changeset
26 from WebBrowser.WebBrowserWindow import WebBrowserWindow
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
27 from .WebBrowserPage import WebBrowserPage
4355
40ec6bef4c22 Started to implement the HTML5 feature permission manager and associated dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4353
diff changeset
28
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
29 from .Tools.WebIconLoader import WebIconLoader
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
30 from .Tools import Scripts
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
31
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
32 from . import WebInspector
4903
10910764454a Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4900
diff changeset
33 from .Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
34
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 import Preferences
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 952
diff changeset
36 import UI.PixmapCache
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
37
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
38
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
39 class WebBrowserView(QWebEngineView):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
41 Class implementing the web browser view widget.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 487
diff changeset
43 @signal sourceChanged(QUrl) emitted after the current URL has changed
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @signal forwardAvailable(bool) emitted after the current URL has changed
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @signal backwardAvailable(bool) emitted after the current URL has changed
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 487
diff changeset
46 @signal highlighted(str) emitted, when the mouse hovers over a link
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 487
diff changeset
47 @signal search(QUrl) emitted, when a search is requested
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
48 @signal zoomValueChanged(int) emitted to signal a change of the zoom value
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
49 @signal iconChanged() emitted to signal a changed web site icon
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
51 sourceChanged = pyqtSignal(QUrl)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
52 forwardAvailable = pyqtSignal(bool)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
53 backwardAvailable = pyqtSignal(bool)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
54 highlighted = pyqtSignal(str)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
55 search = pyqtSignal(QUrl)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
56 zoomValueChanged = pyqtSignal(int)
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
57 iconChanged = pyqtSignal()
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
58
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
59 ZoomLevels = [
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
60 30, 40, 50, 67, 80, 90,
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
61 100,
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
62 110, 120, 133, 150, 170, 200, 220, 233, 250, 270, 285, 300,
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
63 ]
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
64 ZoomLevelDefault = 100
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
65
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
66 def __init__(self, mainWindow, parent=None, name=""):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
70 @param mainWindow reference to the main window (WebBrowserWindow)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @param name name of this window (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
74 super(WebBrowserView, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.setObjectName(name)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
76
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
77 self.__rwhvqt = None
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
78 self.installEventFilter(self)
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
79
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4865
diff changeset
80 self.__speedDial = WebBrowserWindow.speedDial()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
82 self.__page = WebBrowserPage(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.setPage(self.__page)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
85 self.__mw = mainWindow
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__isLoading = False
634
7b84cbd2f752 Added tab previews to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 629
diff changeset
87 self.__progress = 0
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
88 self.__siteIconLoader = None
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
89 self.__siteIcon = QIcon()
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
90 self.__menu = QMenu(self)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
91 self.__clickedPos = QPoint()
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
92 self.__firstLoad = False
4900
32f940762654 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
93 self.__preview = QPixmap()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__currentZoom = 100
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
96 self.__zoomLevels = WebBrowserView.ZoomLevels[:]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
98 self.iconUrlChanged.connect(self.__iconUrlChanged)
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
99 self.urlChanged.connect(self.__urlChanged)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
100 self.page().linkHovered.connect(self.__linkHovered)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
102 self.loadStarted.connect(self.__loadStarted)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
103 self.loadProgress.connect(self.__loadProgress)
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
104 self.loadFinished.connect(self.__loadFinished)
4903
10910764454a Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4900
diff changeset
105 self.renderProcessTerminated.connect(self.__renderProcessTerminated)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
107 self.__mw.openSearchManager().currentEngineChanged.connect(
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
108 self.__currentEngineChanged)
952
cc3e2e5558e9 Added support for access keys and drag & drop to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
109
cc3e2e5558e9 Added support for access keys and drag & drop to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
110 self.setAcceptDrops(True)
cc3e2e5558e9 Added support for access keys and drag & drop to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
111
1415
28fa9633d57e Added a dialog to show RSS feeds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1232
diff changeset
112 self.__rss = []
1518
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
113
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
114 self.__clickedFrame = None
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
115
4752
a3bcc42a82a9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
116 self.__mw.personalInformationManager().connectPage(self.page())
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
117
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
118 self.__inspector = None
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
119 WebInspector.registerView(self)
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4326
diff changeset
120
1518
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
121 self.grabGesture(Qt.PinchGesture)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
123 def __currentEngineChanged(self):
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
124 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
125 Private slot to track a change of the current search engine.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
126 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
127 if self.url().toString() == "eric:home":
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
128 self.reload()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
130 def mainWindow(self):
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
131 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
132 Public method to get a reference to the main window.
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
133
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
134 @return reference to the main window
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
135 @rtype WebBrowserWindow
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
136 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
137 return self.__mw
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
138
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
139 def load(self, url):
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
140 """
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
141 Public method to load a web site.
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
142
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
143 @param url URL to be loaded
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
144 @type QUrl
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
145 """
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
146 super(WebBrowserView, self).load(url)
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
147
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
148 if not self.__firstLoad:
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
149 self.__firstLoad = True
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
150 WebInspector.pushView(self)
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
151
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
152 def setSource(self, name, newTab=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 Public method used to set the source to be displayed.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @param name filename to be shown (QUrl)
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
157 @param newTab flag indicating to open the URL in a new tab (bool)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
159 if name is None or not name.isValid():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
162 if newTab:
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
163 # open in a new tab
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
164 self.__mw.newTab(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 if not name.scheme():
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
168 name.setUrl(Preferences.getWebBrowser("DefaultScheme") +
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
169 name.toString())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 if len(name.scheme()) == 1 or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 name.scheme() == "file":
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 # name is a local file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 if name.scheme() and len(name.scheme()) == 1:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 # it is a local path on win os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 name = QUrl.fromLocalFile(name.toString())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 if not QFileInfo(name.toLocalFile()).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
179 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
180 self,
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
181 self.tr("eric6 Web Browser"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
182 self.tr(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
183 """<p>The file <b>{0}</b> does not exist.</p>""")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
184 .format(name.toLocalFile()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if name.toLocalFile().endswith(".pdf") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 name.toLocalFile().endswith(".PDF") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 name.toLocalFile().endswith(".chm") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 name.toLocalFile().endswith(".CHM"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 started = QDesktopServices.openUrl(name)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 if not started:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
193 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
194 self,
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
195 self.tr("eric6 Web Browser"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
196 self.tr(
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
197 """<p>Could not start a viewer"""
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
198 """ for file <b>{0}</b>.</p>""")
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
199 .format(name.path()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 return
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 260
diff changeset
201 elif name.scheme() in ["mailto"]:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 started = QDesktopServices.openUrl(name)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 if not started:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
204 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
205 self,
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
206 self.tr("eric6 Web Browser"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
207 self.tr(
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
208 """<p>Could not start an application"""
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
209 """ for URL <b>{0}</b>.</p>""")
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
210 .format(name.toString()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 if name.toString().endswith(".pdf") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 name.toString().endswith(".PDF") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 name.toString().endswith(".chm") or \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 name.toString().endswith(".CHM"):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 started = QDesktopServices.openUrl(name)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 if not started:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
219 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2999
diff changeset
220 self,
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
221 self.tr("eric6 Web Browser"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
222 self.tr(
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
223 """<p>Could not start a viewer"""
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
224 """ for file <b>{0}</b>.</p>""")
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
225 .format(name.path()))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
228 self.load(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 def source(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 Public method to return the URL of the loaded page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 @return URL loaded in the help browser (QUrl)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 return self.url()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 def documentTitle(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 Public method to return the title of the loaded page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @return title (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 return self.title()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 def backward(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 Public slot to move backwards in history.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
250 self.triggerPageAction(QWebEnginePage.Back)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 self.__urlChanged(self.history().currentItem().url())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 def forward(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 Public slot to move forward in history.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
257 self.triggerPageAction(QWebEnginePage.Forward)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 self.__urlChanged(self.history().currentItem().url())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 def home(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 Public slot to move to the first page loaded.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
264 homeUrl = QUrl(Preferences.getWebBrowser("HomePage"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.setSource(homeUrl)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 self.__urlChanged(self.history().currentItem().url())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 def reload(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 Public slot to reload the current page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
272 self.triggerPageAction(QWebEnginePage.Reload)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
4791
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
274 def reloadBypassingCache(self):
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
275 """
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
276 Public slot to reload the current page bypassing the cache.
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
277 """
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
278 self.triggerPageAction(QWebEnginePage.ReloadAndBypassCache)
a1e53a9ffcf3 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4790
diff changeset
279
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 def copy(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 Public slot to copy the selected text.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
284 self.triggerPageAction(QWebEnginePage.Copy)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
4727
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
286 def cut(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
287 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
288 Public slot to cut the selected text.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
289 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
290 self.triggerPageAction(QWebEnginePage.Cut)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
291
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
292 def paste(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
293 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
294 Public slot to paste text from the clipboard.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
295 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
296 self.triggerPageAction(QWebEnginePage.Paste)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
297
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
298 def undo(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
299 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
300 Public slot to undo the last edit action.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
301 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
302 self.triggerPageAction(QWebEnginePage.Undo)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
303
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
304 def redo(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
305 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
306 Public slot to redo the last edit action.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
307 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
308 self.triggerPageAction(QWebEnginePage.Redo)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
309
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
310 def selectAll(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
311 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
312 Public slot to select all text.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
313 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
314 self.triggerPageAction(QWebEnginePage.SelectAll)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
315
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 def isForwardAvailable(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 Public method to determine, if a forward move in history is possible.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 @return flag indicating move forward is possible (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 return self.history().canGoForward()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 def isBackwardAvailable(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 Public method to determine, if a backwards move in history is possible.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @return flag indicating move backwards is possible (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 return self.history().canGoBack()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 def __levelForZoom(self, zoom):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 Private method determining the zoom level index given a zoom factor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 @param zoom zoom factor (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 @return index of zoom factor (integer)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 index = self.__zoomLevels.index(zoom)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 except ValueError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 for index in range(len(self.__zoomLevels)):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 if zoom <= self.__zoomLevels[index]:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 return index
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
4612
c9982bcd00f8 Added capability to remember the zoom values for each site (incl. a dialog to manage these).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4357
diff changeset
347 def setZoomValue(self, value, saveValue=True):
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
348 """
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
349 Public method to set the zoom value.
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
350
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
351 @param value zoom value (integer)
4612
c9982bcd00f8 Added capability to remember the zoom values for each site (incl. a dialog to manage these).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4357
diff changeset
352 @keyparam saveValue flag indicating to save the zoom value with the
c9982bcd00f8 Added capability to remember the zoom values for each site (incl. a dialog to manage these).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4357
diff changeset
353 zoom manager
c9982bcd00f8 Added capability to remember the zoom values for each site (incl. a dialog to manage these).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4357
diff changeset
354 @type bool
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
355 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
356 if value != self.__currentZoom:
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
357 self.setZoomFactor(value / 100.0)
4612
c9982bcd00f8 Added capability to remember the zoom values for each site (incl. a dialog to manage these).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4357
diff changeset
358 self.__currentZoom = value
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
359 if saveValue and not self.__mw.isPrivate():
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
360 from .ZoomManager import ZoomManager
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
361 ZoomManager.instance().setZoomValue(self.url(), value)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
362 self.zoomValueChanged.emit(value)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
363
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
364 def zoomValue(self):
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
365 """
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
366 Public method to get the current zoom value.
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
367
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
368 @return zoom value (integer)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
369 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
370 val = self.zoomFactor() * 100
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
371 return int(val)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 def zoomIn(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 Public slot to zoom into the page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 index = self.__levelForZoom(self.__currentZoom)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 if index < len(self.__zoomLevels) - 1:
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
379 self.setZoomValue(self.__zoomLevels[index + 1])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 def zoomOut(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 Public slot to zoom out of the page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 index = self.__levelForZoom(self.__currentZoom)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 if index > 0:
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
387 self.setZoomValue(self.__zoomLevels[index - 1])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
389 def zoomReset(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 Public method to reset the zoom factor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
393 index = self.__levelForZoom(WebBrowserView.ZoomLevelDefault)
4846
960e5e18894b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4826
diff changeset
394 self.setZoomValue(self.__zoomLevels[index])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
396 def mapToViewport(self, pos):
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
397 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
398 Public method to map a position to the viewport.
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
399
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
400 @param pos position to be mapped
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
401 @type QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
402 @return viewport position
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
403 @rtype QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
404 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
405 return self.page().mapToViewport(pos)
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
406
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 def hasSelection(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 Public method to determine, if there is some text selected.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 @return flag indicating text has been selected (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 return self.selectedText() != ""
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414
4881
c269212cceac Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4880
diff changeset
415 def findNextPrev(self, txt, case, backwards, callback):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 Public slot to find the next occurrence of a text.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 @param txt text to search for (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 @param case flag indicating a case sensitive search (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 @param backwards flag indicating a backwards search (boolean)
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
422 @param callback reference to a function with a bool parameter
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
423 @type function(bool) or None
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 """
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
425 findFlags = QWebEnginePage.FindFlags()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 if case:
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
427 findFlags |= QWebEnginePage.FindCaseSensitively
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 if backwards:
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
429 findFlags |= QWebEnginePage.FindBackward
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
431 if callback is None:
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
432 self.findText(txt, findFlags)
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
433 else:
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
434 self.findText(txt, findFlags, callback)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 def contextMenuEvent(self, evt):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 """
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
438 Protected method called to create a context menu.
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
439
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
440 This method is overridden from QWebEngineView.
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
441
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
442 @param evt reference to the context menu event object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
443 (QContextMenuEvent)
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
444 """
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
445 pos = evt.pos()
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
446 reason = evt.reason()
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
447 QTimer.singleShot(
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
448 0,
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
449 lambda: self._contextMenuEvent(QContextMenuEvent(reason, pos)))
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
450 # needs to be done this way because contextMenuEvent is blocking
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
451 # the main loop
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
452
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
453 def _contextMenuEvent(self, evt):
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
454 """
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 Protected method called to create a context menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
457 This method is overridden from QWebEngineView.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
459 @param evt reference to the context menu event object
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
460 (QContextMenuEvent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 """
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
462 self.__menu.clear()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
463
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
464 hitTest = self.page().hitTestContent(evt.pos())
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4727
diff changeset
465
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
466 self.__createContextMenu(self.__menu, hitTest)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
467
4880
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
468 if not hitTest.isContentEditable() and not hitTest.isContentSelected():
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
469 self.__menu.addSeparator()
4880
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
470 self.__menu.addAction(self.__mw.adBlockIcon().menuAction())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
471
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
472 if Preferences.getWebBrowser("WebInspectorEnabled"):
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
473 self.__menu.addSeparator()
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
474 self.__menu.addAction(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
475 UI.PixmapCache.getIcon("webInspector.png"),
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
476 self.tr("Inspect Element..."), self.__webInspector)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
477
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
478 if not self.__menu.isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
479 pos = evt.globalPos()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
480 self.__menu.popup(QPoint(pos.x(), pos.y() + 1))
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
481
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
482 def __createContextMenu(self, menu, hitTest):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
483 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
484 Private method to populate the context menu.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
486 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
487 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
488 @param hitTest reference to the hit test object
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
489 @type WebHitTestResult
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
490 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
491 if not hitTest.linkUrl().isEmpty() and \
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
492 hitTest.linkUrl().scheme() != "javascript":
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
493 self.__createLinkContextMenu(menu, hitTest)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
494
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
495 if not hitTest.imageUrl().isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
496 self.__createImageContextMenu(menu, hitTest)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
497
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
498 if not hitTest.mediaUrl().isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
499 self.__createMediaContextMenu(menu, hitTest)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
500
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
501 if hitTest.isContentEditable():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
502 menu.addAction(self.__mw.undoAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
503 menu.addAction(self.__mw.redoAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
504 menu.addSeparator()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
505 menu.addAction(self.__mw.cutAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
506 menu.addAction(self.__mw.copyAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
507 menu.addAction(self.__mw.pasteAct)
4752
a3bcc42a82a9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
508 menu.addSeparator()
a3bcc42a82a9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
509 self.__mw.personalInformationManager().createSubMenu(
a3bcc42a82a9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
510 menu, self, hitTest)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
511
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
512 if hitTest.tagName() == "input":
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
513 menu.addSeparator()
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
514 act = menu.addAction("")
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
515 act.setVisible(False)
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
516 self.__checkForForm(act, hitTest.pos())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
517
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
518 if self.selectedText():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
519 self.__createSelectedTextContextMenu(menu, hitTest)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
520
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
521 if self.__menu.isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
522 self.__createPageContextMenu(menu)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
523
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
524 def __createLinkContextMenu(self, menu, hitTest):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
525 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
526 Private method to populate the context menu for URLs.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
527
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
528 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
529 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
530 @param hitTest reference to the hit test object
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
531 @type WebHitTestResult
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
532 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
533 if not menu.isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
534 menu.addSeparator()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
536 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
537 UI.PixmapCache.getIcon("openNewTab.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
538 self.tr("Open Link in New Tab\tCtrl+LMB"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
539 self.__openLinkInNewTab).setData(hitTest.linkUrl())
4790
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
540 menu.addAction(
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
541 UI.PixmapCache.getIcon("newWindow.png"),
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
542 self.tr("Open Link in New Window"),
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
543 self.__openLinkInNewWindow).setData(hitTest.linkUrl())
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
544 menu.addAction(
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
545 UI.PixmapCache.getIcon("privateMode.png"),
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
546 self.tr("Open Link in New Private Window"),
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
547 self.__openLinkInNewPrivateWindow).setData(hitTest.linkUrl())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
548 menu.addSeparator()
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
549 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
550 UI.PixmapCache.getIcon("download.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
551 self.tr("Save Lin&k"), self.__downloadLink)
4732
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
552 menu.addAction(
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
553 UI.PixmapCache.getIcon("bookmark22.png"),
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
554 self.tr("Bookmark this Link"), self.__bookmarkLink)\
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
555 .setData(hitTest.linkUrl())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
556 menu.addSeparator()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
557 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
558 UI.PixmapCache.getIcon("editCopy.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
559 self.tr("Copy Link to Clipboard"), self.__copyLink)\
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
560 .setData(hitTest.linkUrl())
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
561 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
562 UI.PixmapCache.getIcon("mailSend.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
563 self.tr("Send Link"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
564 self.__sendLink).setData(hitTest.linkUrl())
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
565 if Preferences.getWebBrowser("VirusTotalEnabled") and \
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
566 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
567 menu.addAction(
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
568 UI.PixmapCache.getIcon("virustotal.png"),
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
569 self.tr("Scan Link with VirusTotal"),
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
570 self.__virusTotal).setData(hitTest.linkUrl())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
571
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
572 def __createImageContextMenu(self, menu, hitTest):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
573 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
574 Private method to populate the context menu for images.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
575
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
576 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
577 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
578 @param hitTest reference to the hit test object
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
579 @type WebHitTestResult
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
580 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
581 if not menu.isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
582 menu.addSeparator()
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
583
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
584 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
585 UI.PixmapCache.getIcon("openNewTab.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
586 self.tr("Open Image in New Tab"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
587 self.__openLinkInNewTab).setData(hitTest.imageUrl())
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
588 menu.addSeparator()
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
589 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
590 UI.PixmapCache.getIcon("download.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
591 self.tr("Save Image"), self.__downloadImage)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
592 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
593 self.tr("Copy Image to Clipboard"), self.__copyImage)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
594 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
595 UI.PixmapCache.getIcon("editCopy.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
596 self.tr("Copy Image Location to Clipboard"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
597 self.__copyLink).setData(hitTest.imageUrl())
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
598 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
599 UI.PixmapCache.getIcon("mailSend.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
600 self.tr("Send Image Link"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
601 self.__sendLink).setData(hitTest.imageUrl())
4956
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
602
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
603 if hitTest.imageUrl().scheme() in ["http", "https"]:
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
604 menu.addSeparator()
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
605 engine = WebBrowserWindow.imageSearchEngine()
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
606 searchEngineName = engine.searchEngine()
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
607 menu.addAction(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
608 UI.PixmapCache.getIcon("{0}.png".format(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
609 searchEngineName.lower())),
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
610 self.tr("Search image in {0}").format(searchEngineName),
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
611 self.__searchImage).setData(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
612 engine.getSearchQuery(hitTest.imageUrl()))
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
613 self.__imageSearchMenu = menu.addMenu(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
614 self.tr("Search image with..."))
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
615 for searchEngineName in engine.searchEngineNames():
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
616 self.__imageSearchMenu.addAction(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
617 UI.PixmapCache.getIcon("{0}.png".format(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
618 searchEngineName.lower())),
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
619 self.tr("Search image in {0}").format(searchEngineName),
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
620 self.__searchImage).setData(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
621 engine.getSearchQuery(
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
622 hitTest.imageUrl(), searchEngineName))
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
623
4880
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
624 menu.addSeparator()
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
625 menu.addAction(
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
626 UI.PixmapCache.getIcon("adBlockPlus.png"),
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
627 self.tr("Block Image"), self.__blockImage)\
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
628 .setData(hitTest.imageUrl().toString())
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
629 if Preferences.getWebBrowser("VirusTotalEnabled") and \
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
630 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
631 menu.addAction(
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
632 UI.PixmapCache.getIcon("virustotal.png"),
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
633 self.tr("Scan Image with VirusTotal"),
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
634 self.__virusTotal).setData(hitTest.imageUrl())
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
635
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
636 def __createMediaContextMenu(self, menu, hitTest):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
637 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
638 Private method to populate the context menu for media elements.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
639
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
640 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
641 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
642 @param hitTest reference to the hit test object
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
643 @type WebHitTestResult
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
644 """
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 if not menu.isEmpty():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
646 menu.addSeparator()
1945
47016f5af3b8 Enhanced the web browser by adding a personal information manager to assist in completing form fields through field context menu entries or by pressing Ctrl+Return/Ctrl+Enter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1934
diff changeset
647
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
648 if hitTest.mediaPaused():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
649 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
650 UI.PixmapCache.getIcon("mediaPlaybackStart.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
651 self.tr("Play"), self.__pauseMedia)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
652 else:
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
653 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
654 UI.PixmapCache.getIcon("mediaPlaybackPause.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
655 self.tr("Pause"), self.__pauseMedia)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
656 if hitTest.mediaMuted():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
657 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
658 UI.PixmapCache.getIcon("audioVolumeHigh.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
659 self.tr("Unmute"), self.__muteMedia)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
660 else:
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
661 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
662 UI.PixmapCache.getIcon("audioVolumeMuted.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
663 self.tr("Mute"), self.__muteMedia)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
664 menu.addSeparator()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
665 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
666 UI.PixmapCache.getIcon("editCopy.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
667 self.tr("Copy Media Address to Clipboard"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
668 self.__copyLink).setData(hitTest.mediaUrl())
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
669 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
670 UI.PixmapCache.getIcon("mailSend.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
671 self.tr("Send Media Address"), self.__sendLink)\
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
672 .setData(hitTest.mediaUrl())
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
673 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
674 UI.PixmapCache.getIcon("download.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
675 self.tr("Save Media"), self.__downloadMedia)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
676
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
677 def __createSelectedTextContextMenu(self, menu, hitTest):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
678 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
679 Private method to populate the context menu for selected text.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
680
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
681 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
682 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
683 @param hitTest reference to the hit test object
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
684 @type WebHitTestResult
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
685 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
686 if not menu.isEmpty():
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
687 menu.addSeparator()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
688
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
689 menu.addAction(self.__mw.copyAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
690 menu.addSeparator()
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
691 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
692 UI.PixmapCache.getIcon("mailSend.png"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
693 self.tr("Send Text"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
694 self.__sendLink).setData(self.selectedText())
4818
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
695
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
696 engineName = self.__mw.openSearchManager().currentEngineName()
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
697 if engineName:
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
698 menu.addAction(self.tr("Search with '{0}'").format(engineName),
4818
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
699 self.__searchDefaultRequested)
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
700
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
701 from .OpenSearch.OpenSearchEngineAction import \
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
702 OpenSearchEngineAction
4818
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
703
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
704 self.__searchMenu = menu.addMenu(self.tr("Search with..."))
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
705 engineNames = self.__mw.openSearchManager().allEnginesNames()
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
706 for engineName in engineNames:
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
707 engine = self.__mw.openSearchManager().engine(engineName)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
708 act = OpenSearchEngineAction(engine, self.__searchMenu)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
709 act.setData(engineName)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
710 self.__searchMenu.addAction(act)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
711 self.__searchMenu.triggered.connect(self.__searchRequested)
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
712
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
713 menu.addSeparator()
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
714
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
715 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
716 languages = Preferences.toList(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
717 Preferences.Prefs.settings.value(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
718 "WebBrowser/AcceptLanguages",
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
719 WebBrowserLanguagesDialog.defaultAcceptLanguages()))
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
720 if languages:
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
721 language = languages[0]
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
722 langCode = language.split("[")[1][:2]
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
723 googleTranslatorUrl = QUrl(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
724 "http://translate.google.com/#auto|{0}|{1}".format(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
725 langCode, self.selectedText()))
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
726 menu.addAction(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
727 UI.PixmapCache.getIcon("translate.png"),
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
728 self.tr("Google Translate"), self.__openLinkInNewTab)\
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
729 .setData(googleTranslatorUrl)
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
730 wiktionaryUrl = QUrl(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
731 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
732 .format(langCode, self.selectedText()))
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
733 menu.addAction(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
734 UI.PixmapCache.getIcon("wikipedia.png"),
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
735 self.tr("Dictionary"), self.__openLinkInNewTab)\
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
736 .setData(wiktionaryUrl)
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
737 menu.addSeparator()
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
738
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
739 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
740 if self.__isUrlValid(guessedUrl):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
741 menu.addAction(
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
742 self.tr("Go to web address"),
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
743 self.__openLinkInNewTab).setData(guessedUrl)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
744
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
745 def __createPageContextMenu(self, menu):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
746 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
747 Private method to populate the basic context menu.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
748
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
749 @param menu reference to the menu to be populated
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
750 @type QMenu
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
751 """
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
752 menu.addAction(self.__mw.newTabAct)
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
753 menu.addAction(self.__mw.newAct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 menu.addSeparator()
4910
e97af1181efd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4908
diff changeset
755 # TODO: Qt 5.7: Save
4713
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
756 ## menu.addAction(self.__mw.saveAsAct)
8dca047daf4b Continued with the web view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4711
diff changeset
757 ## menu.addSeparator()
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
758
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
759 if self.url().toString() == "eric:speeddial":
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
760 # special menu for the spedd dial page
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
761 menu.addAction(self.__mw.backAct)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
762 menu.addAction(self.__mw.forwardAct)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
763 menu.addSeparator()
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
764 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
765 UI.PixmapCache.getIcon("plus.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
766 self.tr("Add New Page"), self.__addSpeedDial)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
767 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
768 UI.PixmapCache.getIcon("preferences-general.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
769 self.tr("Configure Speed Dial"), self.__configureSpeedDial)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
770 menu.addSeparator()
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
771 menu.addAction(
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
772 UI.PixmapCache.getIcon("reload.png"),
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
773 self.tr("Reload All Dials"), self.__reloadAllSpeedDials)
4954
36e92a908f3f Improved the web browser Speeddial (both variants).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
774 menu.addSeparator()
36e92a908f3f Improved the web browser Speeddial (both variants).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
775 menu.addAction(
36e92a908f3f Improved the web browser Speeddial (both variants).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
776 self.tr("Reset to Default Dials"), self.__resetSpeedDials)
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
777 return
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
778
4732
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
779 menu.addAction(
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
780 UI.PixmapCache.getIcon("bookmark22.png"),
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
781 self.tr("Bookmark this Page"), self.addBookmark)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
782 menu.addAction(
4727
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
783 UI.PixmapCache.getIcon("editCopy.png"),
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
784 self.tr("Copy Page Link"), self.__copyLink).setData(self.url())
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
785 menu.addAction(
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
786 UI.PixmapCache.getIcon("mailSend.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
787 self.tr("Send Page Link"), self.__sendLink).setData(self.url())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 menu.addSeparator()
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
789
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
790 from .UserAgent.UserAgentMenu import UserAgentMenu
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
791 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
792 url=self.url())
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
793 menu.addMenu(self.__userAgentMenu)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
794 menu.addSeparator()
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
795 menu.addAction(self.__mw.backAct)
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
796 menu.addAction(self.__mw.forwardAct)
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
797 menu.addAction(self.__mw.homeAct)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
798 menu.addAction(self.__mw.reloadAct)
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
799 menu.addAction(self.__mw.stopAct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
800 menu.addSeparator()
4711
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
801 menu.addAction(self.__mw.zoomInAct)
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
802 menu.addAction(self.__mw.zoomResetAct)
0a9162801b8d Started with web browser view.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
803 menu.addAction(self.__mw.zoomOutAct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 menu.addSeparator()
4727
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
805 menu.addAction(self.__mw.selectAllAct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806 menu.addSeparator()
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
807 menu.addAction(self.__mw.findAct)
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
808 menu.addSeparator()
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
809 menu.addAction(self.__mw.pageSourceAct)
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4782
diff changeset
810 menu.addSeparator()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4782
diff changeset
811 menu.addAction(self.__mw.siteInfoAct)
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
812 if self.url().scheme() in ["http", "https"]:
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
813 menu.addSeparator()
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
814
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
815 w3url = QUrl.fromEncoded(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
816 b"http://validator.w3.org/check?uri=" +
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
817 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode()))
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
818 menu.addAction(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
819 UI.PixmapCache.getIcon("w3.png"),
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
820 self.tr("Validate Page"), self.__openLinkInNewTab)\
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
821 .setData(w3url)
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
822
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
823 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
824 languages = Preferences.toList(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
825 Preferences.Prefs.settings.value(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
826 "WebBrowser/AcceptLanguages",
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
827 WebBrowserLanguagesDialog.defaultAcceptLanguages()))
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
828 if languages:
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
829 language = languages[0]
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
830 langCode = language.split("[")[1][:2]
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
831 googleTranslatorUrl = QUrl.fromEncoded(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
832 b"http://translate.google.com/translate?sl=auto&tl=" +
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
833 langCode.encode() +
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
834 b"&u=" +
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
835 QUrl.toPercentEncoding(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
836 bytes(self.url().toEncoded()).decode()))
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
837 menu.addAction(
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
838 UI.PixmapCache.getIcon("translate.png"),
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
839 self.tr("Google Translate"), self.__openLinkInNewTab)\
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
840 .setData(googleTranslatorUrl)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
841
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
842 def __checkForForm(self, act, pos):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
843 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
844 Private method to check the given position for an open search form.
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
845
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
846 @param act reference to the action to be populated upon success
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
847 @type QAction
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
848 @param pos position to be tested
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
849 @type QPoint
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
850 """
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
851 self.__clickedPos = self.mapToViewport(pos)
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
852
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
853 from .Tools import Scripts
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4924
diff changeset
854 script = Scripts.getFormData(self.__clickedPos)
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
855 self.page().runJavaScript(
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4958
diff changeset
856 script,
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4958
diff changeset
857 WebBrowserPage.SafeJsWorld,
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4958
diff changeset
858 lambda res: self.__checkForFormCallback(res, act))
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
859
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
860 def __checkForFormCallback(self, res, act):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
861 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
862 Private method handling the __checkForForm result.
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
863
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
864 @param res result dictionary generated by JavaScript
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
865 @type dict
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
866 @param act reference to the action to be populated upon success
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
867 @type QAction
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
868 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
869 if act is None or not bool(res):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
870 return
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
871
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
872 url = QUrl(res["action"])
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
873 method = res["method"]
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
874
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
875 if not url.isEmpty() and method in ["get", "post"]:
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
876 act.setVisible(True)
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
877 act.setText(self.tr("Add to web search toolbar"))
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
878 act.triggered.connect(self.__addSearchEngine)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
880 def __isUrlValid(self, url):
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
881 """
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
882 Private method to check a URL for validity.
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
883
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
884 @param url URL to be checked (QUrl)
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
885 @return flag indicating a valid URL (boolean)
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
886 """
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
887 return url.isValid() and \
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
888 bool(url.host()) and \
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
889 bool(url.scheme()) and \
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
890 "." in url.host()
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
891
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892 def __openLinkInNewTab(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
894 Private method called by the context menu to open a link in a new
4790
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
895 tab.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
896 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 act = self.sender()
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
898 url = act.data()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
899 if url.isEmpty():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
900 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
901
4908
f1859c36d564 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4906
diff changeset
902 self.setSource(url, newTab=True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
903
4790
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
904 def __openLinkInNewWindow(self):
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
905 """
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
906 Private slot called by the context menu to open a link in a new
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
907 window.
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
908 """
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
909 act = self.sender()
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
910 url = act.data()
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
911 if url.isEmpty():
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
912 return
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
913
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
914 self.__mw.newWindow(url)
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
915
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
916 def __openLinkInNewPrivateWindow(self):
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
917 """
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
918 Private slot called by the context menu to open a link in a new
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
919 private window.
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
920 """
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
921 act = self.sender()
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
922 url = act.data()
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
923 if url.isEmpty():
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
924 return
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
925
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
926 self.__mw.newPrivateWindow(url)
deeea3d64858 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
927
4732
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
928 def __bookmarkLink(self):
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
929 """
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
930 Private slot to bookmark a link via the context menu.
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
931 """
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
932 act = self.sender()
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
933 url = act.data()
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
934 if url.isEmpty():
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
935 return
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
936
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
937 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
938 dlg = AddBookmarkDialog()
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
939 dlg.setUrl(bytes(url.toEncoded()).decode())
5ac4fc1dfc20 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4731
diff changeset
940 dlg.exec_()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
941
1586
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
942 def __sendLink(self):
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
943 """
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
944 Private slot to send a link via email.
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
945 """
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
946 act = self.sender()
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
947 data = act.data()
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
948 if isinstance(data, QUrl) and data.isEmpty():
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
949 return
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
950
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
951 if isinstance(data, QUrl):
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
952 data = data.toString()
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
953 QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
b3e34806b734 Extended the web page context menu by several entries to send links or the selected text, handling the clicked frame, translate the selected text with Google Translate and search it in Wictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1584
diff changeset
954
4727
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
955 def __copyLink(self):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
956 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
957 Private slot to copy a link to the clipboard.
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
958 """
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
959 act = self.sender()
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
960 data = act.data()
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
961 if isinstance(data, QUrl) and data.isEmpty():
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
962 return
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
963
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
964 if isinstance(data, QUrl):
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
965 data = data.toString()
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
966 QApplication.clipboard().setText(data)
62b50a24fb59 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
967
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
968 def __downloadLink(self):
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
969 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
970 Private slot to download a link and save it to disk.
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
971 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
972 self.triggerPageAction(QWebEnginePage.DownloadLinkToDisk)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
973
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
974 def __downloadImage(self):
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
975 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
976 Private slot to download an image and save it to disk.
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
977 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
978 self.triggerPageAction(QWebEnginePage.DownloadImageToDisk)
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
979
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
980 def __copyImage(self):
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
981 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
982 Private slot to copy an image to the clipboard.
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
983 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
984 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
985
4880
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
986 def __blockImage(self):
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
987 """
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
988 Private slot to add a block rule for an image URL.
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
989 """
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
990 act = self.sender()
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
991 url = act.data()
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
992 dlg = WebBrowserWindow.adBlockManager().showDialog()
561f2bd9cfb9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
993 dlg.addCustomRule(url)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
994
4956
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
995 def __searchImage(self):
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
996 """
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
997 Private slot to search for an image URL.
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
998 """
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
999 act = self.sender()
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
1000 url = act.data()
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
1001 self.setSource(url, newTab=True)
1496516b0f2c Finished implementing the image search functionality for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4954
diff changeset
1002
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1003 def __downloadMedia(self):
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1004 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1005 Private slot to download a media and save it to disk.
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1006 """
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1007 self.triggerPageAction(QWebEnginePage.DownloadMediaToDisk)
1934
ad6b7c30fb9f Added context menu entries for HTML5 media elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1823
diff changeset
1008
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1009 def __pauseMedia(self):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1010 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1011 Private slot to pause or play the selected media.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1012 """
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1013 self.triggerPageAction(QWebEnginePage.ToggleMediaPlayPause)
4729
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1014
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1015 def __muteMedia(self):
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1016 """
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1017 Private slot to (un)mute the selected media.
fc8d00860717 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
1018 """
4885
362360f9a979 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
1019 self.triggerPageAction(QWebEnginePage.ToggleMediaMute)
1934
ad6b7c30fb9f Added context menu entries for HTML5 media elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1823
diff changeset
1020
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1021 def __virusTotal(self):
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1022 """
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1023 Private slot to scan the selected URL with VirusTotal.
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1024 """
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1025 act = self.sender()
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1026 url = act.data()
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
1027 self.__mw.requestVirusTotalScan(url)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1028
4818
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1029 def __searchDefaultRequested(self):
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1030 """
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1031 Private slot to search for some text with the current search engine.
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1032 """
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1033 searchText = self.selectedText()
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1034
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1035 if not searchText:
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1036 return
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1037
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1038 engine = self.__mw.openSearchManager().currentEngine()
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1039 if engine:
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1040 self.search.emit(engine.searchUrl(searchText))
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1041
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1042 def __searchRequested(self, act):
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1043 """
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1044 Private slot to search for some text with a selected search engine.
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1045
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1046 @param act reference to the action that triggered this slot (QAction)
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1047 """
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1048 searchText = self.selectedText()
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1049
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1050 if not searchText:
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1051 return
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1052
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1053 engineName = act.data()
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1054 if engineName:
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1055 engine = self.__mw.openSearchManager().engine(engineName)
4818
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1056 else:
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1057 engine = self.__mw.openSearchManager().currentEngine()
9afce2f09ac0 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
1058 if engine:
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
1059 self.search.emit(engine.searchUrl(searchText))
4731
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1060
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1061 def __addSearchEngine(self):
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1062 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1063 Private slot to add a new search engine.
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1064 """
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1065 from .Tools import Scripts
67d861d9e492 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4729
diff changeset
1066 script = Scripts.getFormData(self.__clickedPos)
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
1067 self.page().runJavaScript(
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
1068 script,
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4958
diff changeset
1069 WebBrowserPage.SafeJsWorld,
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
1070 lambda res: self.__mw.openSearchManager().addEngineFromForm(
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4735
diff changeset
1071 res, self))
381
64ae9e09d8bc Extended the Ad-Blocker of the web browser and added capability to configure the text encoding of the web browser (needs Qt >= 4.6).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 376
diff changeset
1072
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1073 def __webInspector(self):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1074 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1075 Private slot to show the web inspector window.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1076 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1077 if self.__inspector is None:
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1078 from .WebInspector import WebInspector
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1079 self.__inspector = WebInspector()
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1080 self.__inspector.setView(self, True)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1081 self.__inspector.show()
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4780
diff changeset
1082 else:
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
1083 self.closeWebInspector()
4781
15d416f1eca5 Continued po