7 Module implementing the URL bar widget. |
7 Module implementing the URL bar widget. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, QTimer, QPoint |
10 from PyQt6.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, QTimer, QPoint |
11 from PyQt6.QtGui import QColor, QPalette, QLinearGradient, QIcon |
11 from PyQt6.QtGui import QColor, QPalette, QLinearGradient, QIcon |
12 from PyQt6.QtWidgets import QDialog, QApplication |
12 from PyQt6.QtWidgets import QDialog, QApplication, QLineEdit |
13 from PyQt6.QtWebEngineCore import QWebEnginePage |
13 from PyQt6.QtWebEngineCore import QWebEnginePage |
14 try: |
14 try: |
15 from PyQt6.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ |
15 from PyQt6.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ |
16 except ImportError: |
16 except ImportError: |
17 QSslCertificate = None # __IGNORE_WARNING__ |
17 QSslCertificate = None # __IGNORE_WARNING__ |
18 |
18 |
19 from EricWidgets.EricLineEdit import EricLineEdit, EricLineEditSide |
19 from EricWidgets.EricLineEdit import EricClearableLineEdit, EricLineEditSide |
20 from EricWidgets.EricLineEditButton import EricLineEditButton |
|
21 |
20 |
22 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
21 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
23 |
22 |
24 from WebBrowser.SafeBrowsing.SafeBrowsingLabel import SafeBrowsingLabel |
23 from WebBrowser.SafeBrowsing.SafeBrowsingLabel import SafeBrowsingLabel |
25 |
24 |
29 import UI.PixmapCache |
28 import UI.PixmapCache |
30 import Preferences |
29 import Preferences |
31 import Utilities |
30 import Utilities |
32 |
31 |
33 |
32 |
34 class UrlBar(EricLineEdit): |
33 class UrlBar(EricClearableLineEdit): |
35 """ |
34 """ |
36 Class implementing a line edit for entering URLs. |
35 Class implementing a line edit for entering URLs. |
37 """ |
36 """ |
38 def __init__(self, mainWindow, parent=None): |
37 def __init__(self, mainWindow, parent=None): |
39 """ |
38 """ |
40 Constructor |
39 Constructor |
41 |
40 |
42 @param mainWindow reference to the main window (WebBrowserWindow) |
41 @param mainWindow reference to the main window (WebBrowserWindow) |
43 @param parent reference to the parent widget (WebBrowserView) |
42 @param parent reference to the parent widget (WebBrowserView) |
44 """ |
43 """ |
45 EricLineEdit.__init__(self, parent) |
44 super().__init__(parent) |
46 self.setPlaceholderText(self.tr("Enter the URL here.")) |
45 self.setPlaceholderText(self.tr("Enter the URL here.")) |
47 self.setWhatsThis(self.tr("Enter the URL here.")) |
46 self.setWhatsThis(self.tr("Enter the URL here.")) |
48 |
47 |
49 self.__mw = mainWindow |
48 self.__mw = mainWindow |
50 self.__browser = None |
49 self.__browser = None |
63 |
62 |
64 self.__sslLabel = SslLabel(self) |
63 self.__sslLabel = SslLabel(self) |
65 self.addWidget(self.__sslLabel, EricLineEditSide.LEFT) |
64 self.addWidget(self.__sslLabel, EricLineEditSide.LEFT) |
66 self.__sslLabel.setVisible(False) |
65 self.__sslLabel.setVisible(False) |
67 |
66 |
68 self.__rssButton = EricLineEditButton(self) |
67 self.__rssAction = self.addAction( |
69 self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16")) |
68 UI.PixmapCache.getIcon("rss16"), |
70 self.addWidget(self.__rssButton, EricLineEditSide.RIGHT) |
69 QLineEdit.ActionPosition.TrailingPosition) |
71 self.__rssButton.setVisible(False) |
70 self.__rssAction.setVisible(False) |
72 |
71 |
73 self.__bookmarkButton = EricLineEditButton(self) |
72 self.__bookmarkAction = self.addAction( |
74 self.addWidget(self.__bookmarkButton, EricLineEditSide.RIGHT) |
73 self.__bmInactiveIcon, |
75 self.__bookmarkButton.setVisible(False) |
74 QLineEdit.ActionPosition.TrailingPosition) |
76 |
75 self.__bookmarkAction.setVisible(False) |
77 self.__clearButton = EricLineEditButton(self) |
|
78 self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft")) |
|
79 self.addWidget(self.__clearButton, EricLineEditSide.RIGHT) |
|
80 self.__clearButton.setVisible(False) |
|
81 |
76 |
82 self.__safeBrowsingLabel.clicked.connect(self.__showThreatInfo) |
77 self.__safeBrowsingLabel.clicked.connect(self.__showThreatInfo) |
83 self.__bookmarkButton.clicked.connect(self.__showBookmarkInfo) |
78 self.__bookmarkAction.triggered.connect(self.__showBookmarkInfo) |
84 self.__rssButton.clicked.connect(self.__rssClicked) |
79 self.__rssAction.triggered.connect(self.__rssTriggered) |
85 self.__clearButton.clicked.connect(self.clear) |
|
86 self.textChanged.connect(self.__textChanged) |
|
87 |
80 |
88 self.__mw.bookmarksManager().entryChanged.connect( |
81 self.__mw.bookmarksManager().entryChanged.connect( |
89 self.__bookmarkChanged) |
82 self.__bookmarkChanged) |
90 self.__mw.bookmarksManager().entryAdded.connect( |
83 self.__mw.bookmarksManager().entryAdded.connect( |
91 self.__bookmarkChanged) |
84 self.__bookmarkChanged) |
140 |
133 |
141 def __loadStarted(self): |
134 def __loadStarted(self): |
142 """ |
135 """ |
143 Private slot to perform actions before the page is loaded. |
136 Private slot to perform actions before the page is loaded. |
144 """ |
137 """ |
145 self.__bookmarkButton.setVisible(False) |
138 self.__bookmarkAction.setVisible(False) |
146 self.__rssButton.setVisible(False) |
139 self.__rssAction.setVisible(False) |
147 self.__sslLabel.setVisible(False) |
140 self.__sslLabel.setVisible(False) |
148 |
141 |
149 def __checkBookmark(self): |
142 def __checkBookmark(self): |
150 """ |
143 """ |
151 Private slot to check the current URL for the bookmarked state. |
144 Private slot to check the current URL for the bookmarked state. |
152 """ |
145 """ |
153 manager = self.__mw.bookmarksManager() |
146 manager = self.__mw.bookmarksManager() |
154 if manager.bookmarkForUrl(self.__browser.url()) is not None: |
147 if manager.bookmarkForUrl(self.__browser.url()) is not None: |
155 self.__bookmarkButton.setIcon(self.__bmActiveIcon) |
148 self.__bookmarkAction.setIcon(self.__bmActiveIcon) |
156 bookmarks = manager.bookmarksForUrl(self.__browser.url()) |
149 bookmarks = manager.bookmarksForUrl(self.__browser.url()) |
157 from WebBrowser.Bookmarks.BookmarkNode import BookmarkNode |
150 from WebBrowser.Bookmarks.BookmarkNode import BookmarkNode |
158 for bookmark in bookmarks: |
151 for bookmark in bookmarks: |
159 manager.setTimestamp(bookmark, BookmarkNode.TsVisited, |
152 manager.setTimestamp(bookmark, BookmarkNode.TsVisited, |
160 QDateTime.currentDateTime()) |
153 QDateTime.currentDateTime()) |
161 elif self.__mw.speedDial().pageForUrl(self.__browser.url()).url != "": |
154 elif self.__mw.speedDial().pageForUrl(self.__browser.url()).url != "": |
162 self.__bookmarkButton.setIcon(self.__bmActiveIcon) |
155 self.__bookmarkAction.setIcon(self.__bmActiveIcon) |
163 else: |
156 else: |
164 self.__bookmarkButton.setIcon(self.__bmInactiveIcon) |
157 self.__bookmarkAction.setIcon(self.__bmInactiveIcon) |
165 |
158 |
166 def __loadFinished(self, ok): |
159 def __loadFinished(self, ok): |
167 """ |
160 """ |
168 Private slot to set some data after the page was loaded. |
161 Private slot to set some data after the page was loaded. |
169 |
162 |
170 @param ok flag indicating a successful load (boolean) |
163 @param ok flag indicating a successful load (boolean) |
171 """ |
164 """ |
172 if self.__browser.url().scheme() in ["eric", "about"]: |
165 if self.__browser.url().scheme() in ["eric", "about"]: |
173 self.__bookmarkButton.setVisible(False) |
166 self.__bookmarkAction.setVisible(False) |
174 else: |
167 else: |
175 self.__checkBookmark() |
168 self.__checkBookmark() |
176 self.__bookmarkButton.setVisible(True) |
169 self.__bookmarkAction.setVisible(True) |
177 |
170 |
178 self.__browserUrlChanged(self.__browser.url()) |
171 self.__browserUrlChanged(self.__browser.url()) |
179 self.__safeBrowsingLabel.setVisible( |
172 self.__safeBrowsingLabel.setVisible( |
180 not self.__browser.getSafeBrowsingStatus()) |
173 not self.__browser.getSafeBrowsingStatus()) |
181 |
174 |
182 if ok: |
175 if ok: |
183 QTimer.singleShot(0, self.__setRssButton) |
176 QTimer.singleShot(0, self.__setRssButton) |
184 |
177 |
185 def __textChanged(self, txt): |
|
186 """ |
|
187 Private slot to handle changes of the text. |
|
188 |
|
189 @param txt current text (string) |
|
190 """ |
|
191 self.__clearButton.setVisible(txt != "") |
|
192 |
|
193 def preferencesChanged(self): |
178 def preferencesChanged(self): |
194 """ |
179 """ |
195 Public slot to handle a change of preferences. |
180 Public slot to handle a change of preferences. |
196 """ |
181 """ |
197 self.update() |
182 self.update() |
198 |
183 |
|
184 @pyqtSlot() |
199 def __showBookmarkInfo(self): |
185 def __showBookmarkInfo(self): |
200 """ |
186 """ |
201 Private slot to show a dialog with some bookmark info. |
187 Private slot to show a dialog with some bookmark info. |
202 """ |
188 """ |
203 from .BookmarkActionSelectionDialog import ( |
189 from .BookmarkActionSelectionDialog import ( |
287 gradient.setColorAt(progress / 100.0, backgroundColor) |
273 gradient.setColorAt(progress / 100.0, backgroundColor) |
288 p.setBrush(QPalette.ColorRole.Base, gradient) |
274 p.setBrush(QPalette.ColorRole.Base, gradient) |
289 |
275 |
290 self.setPalette(p) |
276 self.setPalette(p) |
291 |
277 |
292 EricLineEdit.paintEvent(self, evt) |
278 super().paintEvent(evt) |
293 |
279 |
294 def focusOutEvent(self, evt): |
280 def focusOutEvent(self, evt): |
295 """ |
281 """ |
296 Protected method to handle focus out event. |
282 Protected method to handle focus out event. |
297 |
283 |
298 @param evt reference to the focus event (QFocusEvent) |
284 @param evt reference to the focus event (QFocusEvent) |
299 """ |
285 """ |
300 if self.text() == "" and self.__browser is not None: |
286 if self.text() == "" and self.__browser is not None: |
301 self.__browserUrlChanged(self.__browser.url()) |
287 self.__browserUrlChanged(self.__browser.url()) |
302 EricLineEdit.focusOutEvent(self, evt) |
288 super().focusOutEvent(evt) |
303 |
289 |
304 def mousePressEvent(self, evt): |
290 def mousePressEvent(self, evt): |
305 """ |
291 """ |
306 Protected method called by a mouse press event. |
292 Protected method called by a mouse press event. |
307 |
293 |