65 @signal browserOpened(QWidget) emitted after a new browser was created |
63 @signal browserOpened(QWidget) emitted after a new browser was created |
66 @signal browserClosed(QWidget) emitted after a browser was closed |
64 @signal browserClosed(QWidget) emitted after a browser was closed |
67 @signal browserZoomValueChanged(int) emitted to signal a change of the |
65 @signal browserZoomValueChanged(int) emitted to signal a change of the |
68 current browser's zoom level |
66 current browser's zoom level |
69 """ |
67 """ |
|
68 |
70 sourceChanged = pyqtSignal(WebBrowserView, QUrl) |
69 sourceChanged = pyqtSignal(WebBrowserView, QUrl) |
71 currentUrlChanged = pyqtSignal(QUrl) |
70 currentUrlChanged = pyqtSignal(QUrl) |
72 titleChanged = pyqtSignal(WebBrowserView, str) |
71 titleChanged = pyqtSignal(WebBrowserView, str) |
73 showMessage = pyqtSignal(str) |
72 showMessage = pyqtSignal(str) |
74 browserOpened = pyqtSignal(QWidget) |
73 browserOpened = pyqtSignal(QWidget) |
75 browserClosed = pyqtSignal(QWidget) |
74 browserClosed = pyqtSignal(QWidget) |
76 browserZoomValueChanged = pyqtSignal(int) |
75 browserZoomValueChanged = pyqtSignal(int) |
77 |
76 |
78 def __init__(self, parent): |
77 def __init__(self, parent): |
79 """ |
78 """ |
80 Constructor |
79 Constructor |
81 |
80 |
82 @param parent reference to the parent widget (QWidget) |
81 @param parent reference to the parent widget (QWidget) |
83 """ |
82 """ |
84 super().__init__(parent, dnd=True) |
83 super().__init__(parent, dnd=True) |
85 |
84 |
86 from .WebBrowserTabBar import WebBrowserTabBar |
85 from .WebBrowserTabBar import WebBrowserTabBar |
|
86 |
87 self.__tabBar = WebBrowserTabBar(self) |
87 self.__tabBar = WebBrowserTabBar(self) |
88 self.setCustomTabBar(True, self.__tabBar) |
88 self.setCustomTabBar(True, self.__tabBar) |
89 |
89 |
90 self.__mainWindow = parent |
90 self.__mainWindow = parent |
91 |
91 |
92 self.setUsesScrollButtons(True) |
92 self.setUsesScrollButtons(True) |
93 self.setDocumentMode(True) |
93 self.setDocumentMode(True) |
94 self.setElideMode(Qt.TextElideMode.ElideNone) |
94 self.setElideMode(Qt.TextElideMode.ElideNone) |
95 |
95 |
96 from .ClosedTabsManager import ClosedTabsManager |
96 from .ClosedTabsManager import ClosedTabsManager |
|
97 |
97 self.__closedTabsManager = ClosedTabsManager(self) |
98 self.__closedTabsManager = ClosedTabsManager(self) |
98 self.__closedTabsManager.closedTabAvailable.connect( |
99 self.__closedTabsManager.closedTabAvailable.connect(self.__closedTabAvailable) |
99 self.__closedTabAvailable) |
100 |
100 |
|
101 from .UrlBar.StackedUrlBar import StackedUrlBar |
101 from .UrlBar.StackedUrlBar import StackedUrlBar |
|
102 |
102 self.__stackedUrlBar = StackedUrlBar(self) |
103 self.__stackedUrlBar = StackedUrlBar(self) |
103 self.__tabBar.tabMoved.connect(self.__stackedUrlBar.moveBar) |
104 self.__tabBar.tabMoved.connect(self.__stackedUrlBar.moveBar) |
104 |
105 |
105 self.__tabContextMenuIndex = -1 |
106 self.__tabContextMenuIndex = -1 |
106 self.currentChanged[int].connect(self.__currentChanged) |
107 self.currentChanged[int].connect(self.__currentChanged) |
107 self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
108 self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
108 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
109 self.customTabContextMenuRequested.connect(self.__showContextMenu) |
109 |
110 |
110 self.__rightCornerWidget = QWidget(self) |
111 self.__rightCornerWidget = QWidget(self) |
111 self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget) |
112 self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget) |
112 self.__rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) |
113 self.__rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) |
113 self.__rightCornerWidgetLayout.setSpacing(0) |
114 self.__rightCornerWidgetLayout.setSpacing(0) |
114 |
115 |
115 self.__navigationMenu = QMenu(self) |
116 self.__navigationMenu = QMenu(self) |
116 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
117 self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) |
117 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
118 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) |
118 |
119 |
119 self.__navigationButton = QToolButton(self) |
120 self.__navigationButton = QToolButton(self) |
120 self.__navigationButton.setIcon( |
121 self.__navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
121 UI.PixmapCache.getIcon("1downarrow")) |
122 self.__navigationButton.setToolTip(self.tr("Show a navigation menu")) |
122 self.__navigationButton.setToolTip( |
|
123 self.tr("Show a navigation menu")) |
|
124 self.__navigationButton.setPopupMode( |
123 self.__navigationButton.setPopupMode( |
125 QToolButton.ToolButtonPopupMode.InstantPopup) |
124 QToolButton.ToolButtonPopupMode.InstantPopup |
|
125 ) |
126 self.__navigationButton.setMenu(self.__navigationMenu) |
126 self.__navigationButton.setMenu(self.__navigationMenu) |
127 self.__navigationButton.setEnabled(False) |
127 self.__navigationButton.setEnabled(False) |
128 self.__rightCornerWidgetLayout.addWidget(self.__navigationButton) |
128 self.__rightCornerWidgetLayout.addWidget(self.__navigationButton) |
129 |
129 |
130 self.__closedTabsMenu = QMenu(self) |
130 self.__closedTabsMenu = QMenu(self) |
131 self.__closedTabsMenu.aboutToShow.connect( |
131 self.__closedTabsMenu.aboutToShow.connect(self.__aboutToShowClosedTabsMenu) |
132 self.__aboutToShowClosedTabsMenu) |
132 |
133 |
|
134 self.__closedTabsButton = QToolButton(self) |
133 self.__closedTabsButton = QToolButton(self) |
135 self.__closedTabsButton.setIcon(UI.PixmapCache.getIcon("trash")) |
134 self.__closedTabsButton.setIcon(UI.PixmapCache.getIcon("trash")) |
136 self.__closedTabsButton.setToolTip( |
135 self.__closedTabsButton.setToolTip( |
137 self.tr("Show a navigation menu for closed tabs")) |
136 self.tr("Show a navigation menu for closed tabs") |
|
137 ) |
138 self.__closedTabsButton.setPopupMode( |
138 self.__closedTabsButton.setPopupMode( |
139 QToolButton.ToolButtonPopupMode.InstantPopup) |
139 QToolButton.ToolButtonPopupMode.InstantPopup |
|
140 ) |
140 self.__closedTabsButton.setMenu(self.__closedTabsMenu) |
141 self.__closedTabsButton.setMenu(self.__closedTabsMenu) |
141 self.__closedTabsButton.setEnabled(False) |
142 self.__closedTabsButton.setEnabled(False) |
142 self.__rightCornerWidgetLayout.addWidget(self.__closedTabsButton) |
143 self.__rightCornerWidgetLayout.addWidget(self.__closedTabsButton) |
143 |
144 |
144 self.setTabsClosable(True) |
145 self.setTabsClosable(True) |
145 self.tabCloseRequested.connect(self.closeBrowserAt) |
146 self.tabCloseRequested.connect(self.closeBrowserAt) |
146 |
147 |
147 self.setCornerWidget( |
148 self.setCornerWidget(self.__rightCornerWidget, Qt.Corner.TopRightCorner) |
148 self.__rightCornerWidget, Qt.Corner.TopRightCorner) |
149 |
149 |
|
150 self.__newTabButton = QToolButton(self) |
150 self.__newTabButton = QToolButton(self) |
151 self.__newTabButton.setIcon(UI.PixmapCache.getIcon("plus")) |
151 self.__newTabButton.setIcon(UI.PixmapCache.getIcon("plus")) |
152 self.__newTabButton.setToolTip( |
152 self.__newTabButton.setToolTip(self.tr("Open a new web browser tab")) |
153 self.tr("Open a new web browser tab")) |
|
154 self.setCornerWidget(self.__newTabButton, Qt.Corner.TopLeftCorner) |
153 self.setCornerWidget(self.__newTabButton, Qt.Corner.TopLeftCorner) |
155 self.__newTabButton.clicked.connect(self.__newBrowser) |
154 self.__newTabButton.clicked.connect(self.__newBrowser) |
156 |
155 |
157 self.__initTabContextMenu() |
156 self.__initTabContextMenu() |
158 |
157 |
159 self.__historyCompleter = None |
158 self.__historyCompleter = None |
160 |
159 |
161 def __initTabContextMenu(self): |
160 def __initTabContextMenu(self): |
162 """ |
161 """ |
163 Private method to create the tab context menu. |
162 Private method to create the tab context menu. |
164 """ |
163 """ |
165 self.__tabContextMenu = QMenu(self) |
164 self.__tabContextMenu = QMenu(self) |
166 self.tabContextNewAct = self.__tabContextMenu.addAction( |
165 self.tabContextNewAct = self.__tabContextMenu.addAction( |
167 UI.PixmapCache.getIcon("tabNew"), |
166 UI.PixmapCache.getIcon("tabNew"), self.tr("New Tab"), self.newBrowser |
168 self.tr('New Tab'), self.newBrowser) |
167 ) |
169 self.__tabContextMenu.addSeparator() |
168 self.__tabContextMenu.addSeparator() |
170 self.leftMenuAct = self.__tabContextMenu.addAction( |
169 self.leftMenuAct = self.__tabContextMenu.addAction( |
171 UI.PixmapCache.getIcon("1leftarrow"), |
170 UI.PixmapCache.getIcon("1leftarrow"), |
172 self.tr('Move Left'), self.__tabContextMenuMoveLeft) |
171 self.tr("Move Left"), |
|
172 self.__tabContextMenuMoveLeft, |
|
173 ) |
173 self.rightMenuAct = self.__tabContextMenu.addAction( |
174 self.rightMenuAct = self.__tabContextMenu.addAction( |
174 UI.PixmapCache.getIcon("1rightarrow"), |
175 UI.PixmapCache.getIcon("1rightarrow"), |
175 self.tr('Move Right'), self.__tabContextMenuMoveRight) |
176 self.tr("Move Right"), |
|
177 self.__tabContextMenuMoveRight, |
|
178 ) |
176 self.__tabContextMenu.addSeparator() |
179 self.__tabContextMenu.addSeparator() |
177 self.tabContextCloneAct = self.__tabContextMenu.addAction( |
180 self.tabContextCloneAct = self.__tabContextMenu.addAction( |
178 self.tr("Duplicate Page"), self.__tabContextMenuClone) |
181 self.tr("Duplicate Page"), self.__tabContextMenuClone |
|
182 ) |
179 self.__tabContextMenu.addSeparator() |
183 self.__tabContextMenu.addSeparator() |
180 self.tabContextCloseAct = self.__tabContextMenu.addAction( |
184 self.tabContextCloseAct = self.__tabContextMenu.addAction( |
181 UI.PixmapCache.getIcon("tabClose"), |
185 UI.PixmapCache.getIcon("tabClose"), |
182 self.tr('Close'), self.__tabContextMenuClose) |
186 self.tr("Close"), |
|
187 self.__tabContextMenuClose, |
|
188 ) |
183 self.tabContextCloseOthersAct = self.__tabContextMenu.addAction( |
189 self.tabContextCloseOthersAct = self.__tabContextMenu.addAction( |
184 UI.PixmapCache.getIcon("tabCloseOther"), |
190 UI.PixmapCache.getIcon("tabCloseOther"), |
185 self.tr("Close Others"), self.__tabContextMenuCloseOthers) |
191 self.tr("Close Others"), |
186 self.__tabContextMenu.addAction( |
192 self.__tabContextMenuCloseOthers, |
187 self.tr('Close All'), self.closeAllBrowsers) |
193 ) |
|
194 self.__tabContextMenu.addAction(self.tr("Close All"), self.closeAllBrowsers) |
188 self.__tabContextMenu.addSeparator() |
195 self.__tabContextMenu.addSeparator() |
189 self.__tabContextMenu.addAction( |
196 self.__tabContextMenu.addAction( |
190 UI.PixmapCache.getIcon("printPreview"), |
197 UI.PixmapCache.getIcon("printPreview"), |
191 self.tr('Print Preview'), self.__tabContextMenuPrintPreview) |
198 self.tr("Print Preview"), |
|
199 self.__tabContextMenuPrintPreview, |
|
200 ) |
192 self.__tabContextMenu.addAction( |
201 self.__tabContextMenu.addAction( |
193 UI.PixmapCache.getIcon("print"), |
202 UI.PixmapCache.getIcon("print"), |
194 self.tr('Print'), self.__tabContextMenuPrint) |
203 self.tr("Print"), |
|
204 self.__tabContextMenuPrint, |
|
205 ) |
195 self.__tabContextMenu.addAction( |
206 self.__tabContextMenu.addAction( |
196 UI.PixmapCache.getIcon("printPdf"), |
207 UI.PixmapCache.getIcon("printPdf"), |
197 self.tr('Print as PDF'), self.__tabContextMenuPrintPdf) |
208 self.tr("Print as PDF"), |
|
209 self.__tabContextMenuPrintPdf, |
|
210 ) |
198 self.__tabContextMenu.addSeparator() |
211 self.__tabContextMenu.addSeparator() |
199 if hasattr(WebBrowserPage, "isAudioMuted"): |
212 if hasattr(WebBrowserPage, "isAudioMuted"): |
200 self.__audioAct = self.__tabContextMenu.addAction( |
213 self.__audioAct = self.__tabContextMenu.addAction( |
201 "", self.__tabContextMenuAudioMute) |
214 "", self.__tabContextMenuAudioMute |
|
215 ) |
202 self.__tabContextMenu.addSeparator() |
216 self.__tabContextMenu.addSeparator() |
203 else: |
217 else: |
204 self.__audioAct = None |
218 self.__audioAct = None |
205 self.__tabContextMenu.addAction( |
219 self.__tabContextMenu.addAction( |
206 UI.PixmapCache.getIcon("reload"), |
220 UI.PixmapCache.getIcon("reload"), |
207 self.tr('Reload All'), self.reloadAllBrowsers) |
221 self.tr("Reload All"), |
|
222 self.reloadAllBrowsers, |
|
223 ) |
208 self.__tabContextMenu.addSeparator() |
224 self.__tabContextMenu.addSeparator() |
209 self.__tabContextMenu.addAction( |
225 self.__tabContextMenu.addAction( |
210 UI.PixmapCache.getIcon("addBookmark"), |
226 UI.PixmapCache.getIcon("addBookmark"), |
211 self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll) |
227 self.tr("Bookmark All Tabs"), |
212 |
228 self.__mainWindow.bookmarkAll, |
|
229 ) |
|
230 |
213 self.__tabBackContextMenu = QMenu(self) |
231 self.__tabBackContextMenu = QMenu(self) |
214 self.__tabBackContextMenu.addAction( |
232 self.__tabBackContextMenu.addAction(self.tr("Close All"), self.closeAllBrowsers) |
215 self.tr('Close All'), self.closeAllBrowsers) |
|
216 self.__tabBackContextMenu.addAction( |
233 self.__tabBackContextMenu.addAction( |
217 UI.PixmapCache.getIcon("reload"), |
234 UI.PixmapCache.getIcon("reload"), |
218 self.tr('Reload All'), self.reloadAllBrowsers) |
235 self.tr("Reload All"), |
|
236 self.reloadAllBrowsers, |
|
237 ) |
219 self.__tabBackContextMenu.addAction( |
238 self.__tabBackContextMenu.addAction( |
220 UI.PixmapCache.getIcon("addBookmark"), |
239 UI.PixmapCache.getIcon("addBookmark"), |
221 self.tr('Bookmark All Tabs'), self.__mainWindow.bookmarkAll) |
240 self.tr("Bookmark All Tabs"), |
|
241 self.__mainWindow.bookmarkAll, |
|
242 ) |
222 self.__tabBackContextMenu.addSeparator() |
243 self.__tabBackContextMenu.addSeparator() |
223 self.__restoreClosedTabAct = self.__tabBackContextMenu.addAction( |
244 self.__restoreClosedTabAct = self.__tabBackContextMenu.addAction( |
224 UI.PixmapCache.getIcon("trash"), |
245 UI.PixmapCache.getIcon("trash"), self.tr("Restore Closed Tab") |
225 self.tr('Restore Closed Tab')) |
246 ) |
226 self.__restoreClosedTabAct.setEnabled(False) |
247 self.__restoreClosedTabAct.setEnabled(False) |
227 self.__restoreClosedTabAct.setData(0) |
248 self.__restoreClosedTabAct.setData(0) |
228 self.__restoreClosedTabAct.triggered.connect( |
249 self.__restoreClosedTabAct.triggered.connect( |
229 lambda: self.restoreClosedTab(self.__restoreClosedTabAct)) |
250 lambda: self.restoreClosedTab(self.__restoreClosedTabAct) |
230 |
251 ) |
|
252 |
231 def __showContextMenu(self, coord, index): |
253 def __showContextMenu(self, coord, index): |
232 """ |
254 """ |
233 Private slot to show the tab context menu. |
255 Private slot to show the tab context menu. |
234 |
256 |
235 @param coord the position of the mouse pointer (QPoint) |
257 @param coord the position of the mouse pointer (QPoint) |
236 @param index index of the tab the menu is requested for (integer) |
258 @param index index of the tab the menu is requested for (integer) |
237 """ |
259 """ |
238 coord = self.mapToGlobal(coord) |
260 coord = self.mapToGlobal(coord) |
239 if index == -1: |
261 if index == -1: |
240 self.__tabBackContextMenu.popup(coord) |
262 self.__tabBackContextMenu.popup(coord) |
241 else: |
263 else: |
242 self.__tabContextMenuIndex = index |
264 self.__tabContextMenuIndex = index |
243 self.leftMenuAct.setEnabled(index > 0) |
265 self.leftMenuAct.setEnabled(index > 0) |
244 self.rightMenuAct.setEnabled(index < self.count() - 1) |
266 self.rightMenuAct.setEnabled(index < self.count() - 1) |
245 |
267 |
246 self.tabContextCloseOthersAct.setEnabled(self.count() > 1) |
268 self.tabContextCloseOthersAct.setEnabled(self.count() > 1) |
247 |
269 |
248 if self.__audioAct is not None: |
270 if self.__audioAct is not None: |
249 if ( |
271 if self.widget(self.__tabContextMenuIndex).page().isAudioMuted(): |
250 self.widget(self.__tabContextMenuIndex).page() |
|
251 .isAudioMuted() |
|
252 ): |
|
253 self.__audioAct.setText(self.tr("Unmute Tab")) |
272 self.__audioAct.setText(self.tr("Unmute Tab")) |
254 self.__audioAct.setIcon( |
273 self.__audioAct.setIcon(UI.PixmapCache.getIcon("audioVolumeHigh")) |
255 UI.PixmapCache.getIcon("audioVolumeHigh")) |
|
256 else: |
274 else: |
257 self.__audioAct.setText(self.tr("Mute Tab")) |
275 self.__audioAct.setText(self.tr("Mute Tab")) |
258 self.__audioAct.setIcon( |
276 self.__audioAct.setIcon(UI.PixmapCache.getIcon("audioVolumeMuted")) |
259 UI.PixmapCache.getIcon("audioVolumeMuted")) |
277 |
260 |
|
261 self.__tabContextMenu.popup(coord) |
278 self.__tabContextMenu.popup(coord) |
262 |
279 |
263 def __tabContextMenuMoveLeft(self): |
280 def __tabContextMenuMoveLeft(self): |
264 """ |
281 """ |
265 Private method to move a tab one position to the left. |
282 Private method to move a tab one position to the left. |
266 """ |
283 """ |
267 self.moveTab(self.__tabContextMenuIndex, |
284 self.moveTab(self.__tabContextMenuIndex, self.__tabContextMenuIndex - 1) |
268 self.__tabContextMenuIndex - 1) |
285 |
269 |
|
270 def __tabContextMenuMoveRight(self): |
286 def __tabContextMenuMoveRight(self): |
271 """ |
287 """ |
272 Private method to move a tab one position to the right. |
288 Private method to move a tab one position to the right. |
273 """ |
289 """ |
274 self.moveTab(self.__tabContextMenuIndex, |
290 self.moveTab(self.__tabContextMenuIndex, self.__tabContextMenuIndex + 1) |
275 self.__tabContextMenuIndex + 1) |
291 |
276 |
|
277 def __tabContextMenuClone(self): |
292 def __tabContextMenuClone(self): |
278 """ |
293 """ |
279 Private method to clone the selected tab. |
294 Private method to clone the selected tab. |
280 """ |
295 """ |
281 idx = self.__tabContextMenuIndex |
296 idx = self.__tabContextMenuIndex |
282 if idx < 0: |
297 if idx < 0: |
283 idx = self.currentIndex() |
298 idx = self.currentIndex() |
284 if idx < 0 or idx > self.count(): |
299 if idx < 0 or idx > self.count(): |
285 return |
300 return |
286 |
301 |
287 url = self.widget(idx).url() |
302 url = self.widget(idx).url() |
288 self.newBrowser(url) |
303 self.newBrowser(url) |
289 |
304 |
290 def __tabContextMenuClose(self): |
305 def __tabContextMenuClose(self): |
291 """ |
306 """ |
292 Private method to close the selected tab. |
307 Private method to close the selected tab. |
293 """ |
308 """ |
294 self.closeBrowserAt(self.__tabContextMenuIndex) |
309 self.closeBrowserAt(self.__tabContextMenuIndex) |
295 |
310 |
296 def __tabContextMenuCloseOthers(self): |
311 def __tabContextMenuCloseOthers(self): |
297 """ |
312 """ |
298 Private slot to close all other tabs. |
313 Private slot to close all other tabs. |
299 """ |
314 """ |
300 index = self.__tabContextMenuIndex |
315 index = self.__tabContextMenuIndex |
301 for i in ( |
316 for i in list(range(self.count() - 1, index, -1)) + list( |
302 list(range(self.count() - 1, index, -1)) + |
317 range(index - 1, -1, -1) |
303 list(range(index - 1, -1, -1)) |
|
304 ): |
318 ): |
305 self.closeBrowserAt(i) |
319 self.closeBrowserAt(i) |
306 |
320 |
307 def __tabContextMenuPrint(self): |
321 def __tabContextMenuPrint(self): |
308 """ |
322 """ |
309 Private method to print the selected tab. |
323 Private method to print the selected tab. |
310 """ |
324 """ |
311 browser = self.widget(self.__tabContextMenuIndex) |
325 browser = self.widget(self.__tabContextMenuIndex) |
312 self.printBrowser(browser) |
326 self.printBrowser(browser) |
313 |
327 |
314 def __tabContextMenuPrintPdf(self): |
328 def __tabContextMenuPrintPdf(self): |
315 """ |
329 """ |
316 Private method to print the selected tab as PDF. |
330 Private method to print the selected tab as PDF. |
317 """ |
331 """ |
318 browser = self.widget(self.__tabContextMenuIndex) |
332 browser = self.widget(self.__tabContextMenuIndex) |
319 self.printBrowserPdf(browser) |
333 self.printBrowserPdf(browser) |
320 |
334 |
321 def __tabContextMenuPrintPreview(self): |
335 def __tabContextMenuPrintPreview(self): |
322 """ |
336 """ |
323 Private method to show a print preview of the selected tab. |
337 Private method to show a print preview of the selected tab. |
324 """ |
338 """ |
325 browser = self.widget(self.__tabContextMenuIndex) |
339 browser = self.widget(self.__tabContextMenuIndex) |
326 self.printPreviewBrowser(browser) |
340 self.printPreviewBrowser(browser) |
327 |
341 |
328 def __tabContextMenuAudioMute(self): |
342 def __tabContextMenuAudioMute(self): |
329 """ |
343 """ |
330 Private method to mute or unmute the selected tab. |
344 Private method to mute or unmute the selected tab. |
331 """ |
345 """ |
332 page = self.widget(self.__tabContextMenuIndex).page() |
346 page = self.widget(self.__tabContextMenuIndex).page() |
333 muted = page.isAudioMuted() |
347 muted = page.isAudioMuted() |
334 page.setAudioMuted(not muted) |
348 page.setAudioMuted(not muted) |
335 |
349 |
336 @pyqtSlot(bool) |
350 @pyqtSlot(bool) |
337 def __recentlyAudibleChanged(self, recentlyAudible, page): |
351 def __recentlyAudibleChanged(self, recentlyAudible, page): |
338 """ |
352 """ |
339 Private slot to react on the audible state of a page. |
353 Private slot to react on the audible state of a page. |
340 |
354 |
341 @param recentlyAudible flag indicating the new audible state |
355 @param recentlyAudible flag indicating the new audible state |
342 @type bool |
356 @type bool |
343 @param page reference to the web page |
357 @param page reference to the web page |
344 @type WebBrowserPage |
358 @type WebBrowserPage |
345 """ |
359 """ |
346 browser = page.view() |
360 browser = page.view() |
347 if browser is None: |
361 if browser is None: |
348 return |
362 return |
349 |
363 |
350 index = self.indexOf(browser) |
364 index = self.indexOf(browser) |
351 icon = page.icon() |
365 icon = page.icon() |
352 |
366 |
353 if page.isAudioMuted() or ( |
367 if page.isAudioMuted() or (not page.isAudioMuted() and recentlyAudible): |
354 not page.isAudioMuted() and recentlyAudible): |
|
355 pix = QPixmap(32, 32) |
368 pix = QPixmap(32, 32) |
356 pix.fill(Qt.GlobalColor.transparent) |
369 pix.fill(Qt.GlobalColor.transparent) |
357 painter = QPainter(pix) |
370 painter = QPainter(pix) |
358 icon.paint(painter, 0, 0, 22, 22) |
371 icon.paint(painter, 0, 0, 22, 22) |
359 if page.isAudioMuted(): |
372 if page.isAudioMuted(): |
395 linkName = "" |
409 linkName = "" |
396 elif isinstance(link, QUrl): |
410 elif isinstance(link, QUrl): |
397 linkName = link.toString() |
411 linkName = link.toString() |
398 else: |
412 else: |
399 linkName = link |
413 linkName = link |
400 |
414 |
401 from .UrlBar.UrlBar import UrlBar |
415 from .UrlBar.UrlBar import UrlBar |
|
416 |
402 urlbar = UrlBar(self.__mainWindow, self) |
417 urlbar = UrlBar(self.__mainWindow, self) |
403 if self.__historyCompleter is None: |
418 if self.__historyCompleter is None: |
404 import WebBrowser.WebBrowserWindow |
419 import WebBrowser.WebBrowserWindow |
405 from .History.HistoryCompleter import ( |
420 from .History.HistoryCompleter import ( |
406 HistoryCompletionModel, HistoryCompleter |
421 HistoryCompletionModel, |
|
422 HistoryCompleter, |
407 ) |
423 ) |
|
424 |
|
425 histMgr = WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager() |
408 self.__historyCompletionModel = HistoryCompletionModel(self) |
426 self.__historyCompletionModel = HistoryCompletionModel(self) |
409 self.__historyCompletionModel.setSourceModel( |
427 self.__historyCompletionModel.setSourceModel(histMgr.historyFilterModel()) |
410 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager() |
|
411 .historyFilterModel()) |
|
412 self.__historyCompleter = HistoryCompleter( |
428 self.__historyCompleter = HistoryCompleter( |
413 self.__historyCompletionModel, self) |
429 self.__historyCompletionModel, self |
|
430 ) |
414 self.__historyCompleter.activated[str].connect(self.__pathSelected) |
431 self.__historyCompleter.activated[str].connect(self.__pathSelected) |
415 urlbar.setCompleter(self.__historyCompleter) |
432 urlbar.setCompleter(self.__historyCompleter) |
416 urlbar.returnPressed.connect( |
433 urlbar.returnPressed.connect(lambda: self.__lineEditReturnPressed(urlbar)) |
417 lambda: self.__lineEditReturnPressed(urlbar)) |
|
418 if position == -1: |
434 if position == -1: |
419 self.__stackedUrlBar.addWidget(urlbar) |
435 self.__stackedUrlBar.addWidget(urlbar) |
420 else: |
436 else: |
421 self.__stackedUrlBar.insertWidget(position, urlbar) |
437 self.__stackedUrlBar.insertWidget(position, urlbar) |
422 |
438 |
423 browser = WebBrowserView(self.__mainWindow, self) |
439 browser = WebBrowserView(self.__mainWindow, self) |
424 urlbar.setBrowser(browser) |
440 urlbar.setBrowser(browser) |
425 |
441 |
426 browser.sourceChanged.connect( |
442 browser.sourceChanged.connect(lambda url: self.__sourceChanged(url, browser)) |
427 lambda url: self.__sourceChanged(url, browser)) |
443 browser.titleChanged.connect(lambda title: self.__titleChanged(title, browser)) |
428 browser.titleChanged.connect( |
|
429 lambda title: self.__titleChanged(title, browser)) |
|
430 browser.highlighted.connect(self.showMessage) |
444 browser.highlighted.connect(self.showMessage) |
431 browser.backwardAvailable.connect( |
445 browser.backwardAvailable.connect(self.__mainWindow.setBackwardAvailable) |
432 self.__mainWindow.setBackwardAvailable) |
|
433 browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable) |
446 browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable) |
434 browser.loadProgress.connect( |
447 browser.loadProgress.connect( |
435 lambda progress: self.__loadProgress(progress, browser)) |
448 lambda progress: self.__loadProgress(progress, browser) |
436 browser.loadFinished.connect( |
449 ) |
437 lambda ok: self.__loadFinished(ok, browser)) |
450 browser.loadFinished.connect(lambda ok: self.__loadFinished(ok, browser)) |
438 browser.faviconChanged.connect( |
451 browser.faviconChanged.connect(lambda: self.__iconChanged(browser)) |
439 lambda: self.__iconChanged(browser)) |
|
440 browser.search.connect(self.newBrowser) |
452 browser.search.connect(self.newBrowser) |
441 browser.page().windowCloseRequested.connect( |
453 browser.page().windowCloseRequested.connect( |
442 lambda: self.__windowCloseRequested(browser.page())) |
454 lambda: self.__windowCloseRequested(browser.page()) |
|
455 ) |
443 browser.zoomValueChanged.connect(self.browserZoomValueChanged) |
456 browser.zoomValueChanged.connect(self.browserZoomValueChanged) |
444 if hasattr(WebBrowserPage, "recentlyAudibleChanged"): |
457 if hasattr(WebBrowserPage, "recentlyAudibleChanged"): |
445 browser.page().recentlyAudibleChanged.connect( |
458 browser.page().recentlyAudibleChanged.connect( |
446 lambda audible: self.__recentlyAudibleChanged( |
459 lambda audible: self.__recentlyAudibleChanged(audible, browser.page()) |
447 audible, browser.page())) |
460 ) |
448 browser.page().printRequested.connect( |
461 browser.page().printRequested.connect(lambda: self.printBrowser(browser)) |
449 lambda: self.printBrowser(browser)) |
|
450 browser.showMessage.connect(self.showMessage) |
462 browser.showMessage.connect(self.showMessage) |
451 |
463 |
452 index = ( |
464 index = ( |
453 self.addTab(browser, self.tr("...")) |
465 self.addTab(browser, self.tr("...")) |
454 if position == -1 else |
466 if position == -1 |
455 self.insertTab(position, browser, self.tr("...")) |
467 else self.insertTab(position, browser, self.tr("...")) |
456 ) |
468 ) |
457 if not background: |
469 if not background: |
458 self.setCurrentIndex(index) |
470 self.setCurrentIndex(index) |
459 |
471 |
460 self.__mainWindow.closeAct.setEnabled(True) |
472 self.__mainWindow.closeAct.setEnabled(True) |
461 self.__mainWindow.closeAllAct.setEnabled(True) |
473 self.__mainWindow.closeAllAct.setEnabled(True) |
462 self.__navigationButton.setEnabled(True) |
474 self.__navigationButton.setEnabled(True) |
463 |
475 |
464 if not restoreSession and not linkName: |
476 if not restoreSession and not linkName: |
465 if Preferences.getWebBrowser("NewTabBehavior") == 0: |
477 if Preferences.getWebBrowser("NewTabBehavior") == 0: |
466 linkName = "about:blank" |
478 linkName = "about:blank" |
467 elif Preferences.getWebBrowser("NewTabBehavior") == 1: |
479 elif Preferences.getWebBrowser("NewTabBehavior") == 1: |
468 linkName = Preferences.getWebBrowser("HomePage") |
480 linkName = Preferences.getWebBrowser("HomePage") |
469 elif Preferences.getWebBrowser("NewTabBehavior") == 2: |
481 elif Preferences.getWebBrowser("NewTabBehavior") == 2: |
470 linkName = "eric:speeddial" |
482 linkName = "eric:speeddial" |
471 |
483 |
472 if linkName == "eric:blank": |
484 if linkName == "eric:blank": |
473 linkName = "about:blank" |
485 linkName = "about:blank" |
474 |
486 |
475 if linkName: |
487 if linkName: |
476 browser.setSource(QUrl(linkName)) |
488 browser.setSource(QUrl(linkName)) |
477 if not browser.documentTitle(): |
489 if not browser.documentTitle(): |
478 self.setTabText( |
490 self.setTabText( |
479 index, |
491 index, self.__elide(linkName, Qt.TextElideMode.ElideMiddle) |
480 self.__elide(linkName, Qt.TextElideMode.ElideMiddle) |
|
481 ) |
492 ) |
482 self.setTabToolTip(index, linkName) |
493 self.setTabToolTip(index, linkName) |
483 else: |
494 else: |
484 self.setTabText( |
495 self.setTabText( |
485 index, |
496 index, self.__elide(browser.documentTitle().replace("&", "&&")) |
486 self.__elide(browser.documentTitle().replace("&", "&&"))) |
497 ) |
487 self.setTabToolTip(index, browser.documentTitle()) |
498 self.setTabToolTip(index, browser.documentTitle()) |
488 |
499 |
489 self.browserOpened.emit(browser) |
500 self.browserOpened.emit(browser) |
490 |
501 |
491 return browser |
502 return browser |
492 |
503 |
493 def newBrowserAfter(self, browser, link=None, background=False): |
504 def newBrowserAfter(self, browser, link=None, background=False): |
494 """ |
505 """ |
495 Public method to create a new web browser tab after a given one. |
506 Public method to create a new web browser tab after a given one. |
496 |
507 |
497 @param browser reference to the browser to add after (WebBrowserView) |
508 @param browser reference to the browser to add after (WebBrowserView) |
498 @param link link to be shown (string or QUrl) |
509 @param link link to be shown (string or QUrl) |
499 @param background flag indicating to open the tab in the |
510 @param background flag indicating to open the tab in the |
500 background (bool) |
511 background (bool) |
501 @return reference to the new browser |
512 @return reference to the new browser |
502 @rtype WebBrowserView |
513 @rtype WebBrowserView |
503 """ |
514 """ |
504 position = self.indexOf(browser) + 1 if browser else -1 |
515 position = self.indexOf(browser) + 1 if browser else -1 |
505 return self.newBrowser(link, position, background) |
516 return self.newBrowser(link, position, background) |
506 |
517 |
507 def __showNavigationMenu(self): |
518 def __showNavigationMenu(self): |
508 """ |
519 """ |
509 Private slot to show the navigation button menu. |
520 Private slot to show the navigation button menu. |
510 """ |
521 """ |
511 self.__navigationMenu.clear() |
522 self.__navigationMenu.clear() |
512 for index in range(self.count()): |
523 for index in range(self.count()): |
513 act = self.__navigationMenu.addAction( |
524 act = self.__navigationMenu.addAction( |
514 self.tabIcon(index), self.tabText(index)) |
525 self.tabIcon(index), self.tabText(index) |
|
526 ) |
515 act.setData(index) |
527 act.setData(index) |
516 |
528 |
517 def __navigationMenuTriggered(self, act): |
529 def __navigationMenuTriggered(self, act): |
518 """ |
530 """ |
519 Private slot called to handle the navigation button menu selection. |
531 Private slot called to handle the navigation button menu selection. |
520 |
532 |
521 @param act reference to the selected action (QAction) |
533 @param act reference to the selected action (QAction) |
522 """ |
534 """ |
523 index = act.data() |
535 index = act.data() |
524 if index is not None: |
536 if index is not None: |
525 self.setCurrentIndex(index) |
537 self.setCurrentIndex(index) |
526 |
538 |
527 def __windowCloseRequested(self, page): |
539 def __windowCloseRequested(self, page): |
528 """ |
540 """ |
529 Private slot to handle the windowCloseRequested signal of a browser. |
541 Private slot to handle the windowCloseRequested signal of a browser. |
530 |
542 |
531 @param page reference to the web page |
543 @param page reference to the web page |
532 @type WebBrowserPage |
544 @type WebBrowserPage |
533 """ |
545 """ |
534 browser = page.view() |
546 browser = page.view() |
535 if browser is None: |
547 if browser is None: |
536 return |
548 return |
537 |
549 |
538 index = self.indexOf(browser) |
550 index = self.indexOf(browser) |
539 self.closeBrowserAt(index) |
551 self.closeBrowserAt(index) |
540 |
552 |
541 def reloadAllBrowsers(self): |
553 def reloadAllBrowsers(self): |
542 """ |
554 """ |
543 Public slot to reload all browsers. |
555 Public slot to reload all browsers. |
544 """ |
556 """ |
545 for index in range(self.count()): |
557 for index in range(self.count()): |
546 browser = self.widget(index) |
558 browser = self.widget(index) |
547 browser and browser.reload() |
559 browser and browser.reload() |
548 |
560 |
549 @pyqtSlot() |
561 @pyqtSlot() |
550 def closeBrowser(self): |
562 def closeBrowser(self): |
551 """ |
563 """ |
552 Public slot called to handle the close action. |
564 Public slot called to handle the close action. |
553 """ |
565 """ |
554 self.closeBrowserAt(self.currentIndex()) |
566 self.closeBrowserAt(self.currentIndex()) |
555 |
567 |
556 def closeAllBrowsers(self, shutdown=False): |
568 def closeAllBrowsers(self, shutdown=False): |
557 """ |
569 """ |
558 Public slot called to handle the close all action. |
570 Public slot called to handle the close all action. |
559 |
571 |
560 @param shutdown flag indicating a shutdown action |
572 @param shutdown flag indicating a shutdown action |
561 @type bool |
573 @type bool |
562 """ |
574 """ |
563 for index in range(self.count() - 1, -1, -1): |
575 for index in range(self.count() - 1, -1, -1): |
564 self.closeBrowserAt(index, shutdown=shutdown) |
576 self.closeBrowserAt(index, shutdown=shutdown) |
565 |
577 |
566 def closeBrowserView(self, browser): |
578 def closeBrowserView(self, browser): |
567 """ |
579 """ |
568 Public method to close the given browser. |
580 Public method to close the given browser. |
569 |
581 |
570 @param browser reference to the web browser view to be closed |
582 @param browser reference to the web browser view to be closed |
571 @type WebBrowserView |
583 @type WebBrowserView |
572 """ |
584 """ |
573 index = self.indexOf(browser) |
585 index = self.indexOf(browser) |
574 self.closeBrowserAt(index) |
586 self.closeBrowserAt(index) |
575 |
587 |
576 def closeBrowserAt(self, index, shutdown=False): |
588 def closeBrowserAt(self, index, shutdown=False): |
577 """ |
589 """ |
578 Public slot to close a browser based on its index. |
590 Public slot to close a browser based on its index. |
579 |
591 |
580 @param index index of browser to close |
592 @param index index of browser to close |
581 @type int |
593 @type int |
582 @param shutdown flag indicating a shutdown action |
594 @param shutdown flag indicating a shutdown action |
583 @type bool |
595 @type bool |
584 """ |
596 """ |
585 browser = self.widget(index) |
597 browser = self.widget(index) |
586 if browser is None: |
598 if browser is None: |
587 return |
599 return |
588 |
600 |
589 urlbar = self.__stackedUrlBar.widget(index) |
601 urlbar = self.__stackedUrlBar.widget(index) |
590 self.__stackedUrlBar.removeWidget(urlbar) |
602 self.__stackedUrlBar.removeWidget(urlbar) |
591 urlbar.deleteLater() |
603 urlbar.deleteLater() |
592 del urlbar |
604 del urlbar |
593 |
605 |
594 self.__closedTabsManager.recordBrowser(browser, index) |
606 self.__closedTabsManager.recordBrowser(browser, index) |
595 |
607 |
596 browser.closeWebInspector() |
608 browser.closeWebInspector() |
597 WebInspector.unregisterView(browser) |
609 WebInspector.unregisterView(browser) |
598 self.removeTab(index) |
610 self.removeTab(index) |
599 self.browserClosed.emit(browser) |
611 self.browserClosed.emit(browser) |
600 browser.deleteLater() |
612 browser.deleteLater() |
601 del browser |
613 del browser |
602 |
614 |
603 if self.count() == 0 and not shutdown: |
615 if self.count() == 0 and not shutdown: |
604 self.newBrowser() |
616 self.newBrowser() |
605 else: |
617 else: |
606 self.currentChanged[int].emit(self.currentIndex()) |
618 self.currentChanged[int].emit(self.currentIndex()) |
607 |
619 |
608 def currentBrowser(self): |
620 def currentBrowser(self): |
609 """ |
621 """ |
610 Public method to get a reference to the current browser. |
622 Public method to get a reference to the current browser. |
611 |
623 |
612 @return reference to the current browser (WebBrowserView) |
624 @return reference to the current browser (WebBrowserView) |
613 """ |
625 """ |
614 return self.currentWidget() |
626 return self.currentWidget() |
615 |
627 |
616 def browserAt(self, index): |
628 def browserAt(self, index): |
617 """ |
629 """ |
618 Public method to get a reference to the browser with the given index. |
630 Public method to get a reference to the browser with the given index. |
619 |
631 |
620 @param index index of the browser to get (integer) |
632 @param index index of the browser to get (integer) |
621 @return reference to the indexed browser (WebBrowserView) |
633 @return reference to the indexed browser (WebBrowserView) |
622 """ |
634 """ |
623 return self.widget(index) |
635 return self.widget(index) |
624 |
636 |
625 def browsers(self): |
637 def browsers(self): |
626 """ |
638 """ |
627 Public method to get a list of references to all browsers. |
639 Public method to get a list of references to all browsers. |
628 |
640 |
629 @return list of references to browsers (list of WebBrowserView) |
641 @return list of references to browsers (list of WebBrowserView) |
630 """ |
642 """ |
631 li = [] |
643 li = [] |
632 for index in range(self.count()): |
644 for index in range(self.count()): |
633 li.append(self.widget(index)) |
645 li.append(self.widget(index)) |
634 return li |
646 return li |
635 |
647 |
636 @pyqtSlot() |
648 @pyqtSlot() |
637 def printBrowser(self, browser=None): |
649 def printBrowser(self, browser=None): |
638 """ |
650 """ |
639 Public slot called to print the displayed page. |
651 Public slot called to print the displayed page. |
640 |
652 |
641 @param browser reference to the browser to be printed (WebBrowserView) |
653 @param browser reference to the browser to be printed (WebBrowserView) |
642 """ |
654 """ |
643 if browser is None: |
655 if browser is None: |
644 browser = self.currentBrowser() |
656 browser = self.currentBrowser() |
645 |
657 |
646 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
658 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
647 if Preferences.getPrinter("ColorMode"): |
659 if Preferences.getPrinter("ColorMode"): |
648 printer.setColorMode(QPrinter.ColorMode.Color) |
660 printer.setColorMode(QPrinter.ColorMode.Color) |
649 else: |
661 else: |
650 printer.setColorMode(QPrinter.ColorMode.GrayScale) |
662 printer.setColorMode(QPrinter.ColorMode.GrayScale) |
651 if Preferences.getPrinter("FirstPageFirst"): |
663 if Preferences.getPrinter("FirstPageFirst"): |
652 printer.setPageOrder(QPrinter.PageOrder.FirstPageFirst) |
664 printer.setPageOrder(QPrinter.PageOrder.FirstPageFirst) |
653 else: |
665 else: |
654 printer.setPageOrder(QPrinter.PageOrder.LastPageFirst) |
666 printer.setPageOrder(QPrinter.PageOrder.LastPageFirst) |
655 printer.setPageMargins(QMarginsF( |
667 printer.setPageMargins( |
656 Preferences.getPrinter("LeftMargin") * 10, |
668 QMarginsF( |
657 Preferences.getPrinter("TopMargin") * 10, |
669 Preferences.getPrinter("LeftMargin") * 10, |
658 Preferences.getPrinter("RightMargin") * 10, |
670 Preferences.getPrinter("TopMargin") * 10, |
659 Preferences.getPrinter("BottomMargin") * 10), |
671 Preferences.getPrinter("RightMargin") * 10, |
660 QPageLayout.Unit.Millimeter |
672 Preferences.getPrinter("BottomMargin") * 10, |
|
673 ), |
|
674 QPageLayout.Unit.Millimeter, |
661 ) |
675 ) |
662 printerName = Preferences.getPrinter("PrinterName") |
676 printerName = Preferences.getPrinter("PrinterName") |
663 if printerName: |
677 if printerName: |
664 printer.setPrinterName(printerName) |
678 printer.setPrinterName(printerName) |
665 printer.setResolution(Preferences.getPrinter("Resolution")) |
679 printer.setResolution(Preferences.getPrinter("Resolution")) |
666 documentName = WebBrowserTools.getFileNameFromUrl(browser.url()) |
680 documentName = WebBrowserTools.getFileNameFromUrl(browser.url()) |
667 printer.setDocName(documentName) |
681 printer.setDocName(documentName) |
668 |
682 |
669 printDialog = QPrintDialog(printer, self) |
683 printDialog = QPrintDialog(printer, self) |
670 printDialog.setOptions( |
684 printDialog.setOptions( |
671 QAbstractPrintDialog.PrintDialogOption.PrintToFile | |
685 QAbstractPrintDialog.PrintDialogOption.PrintToFile |
672 QAbstractPrintDialog.PrintDialogOption.PrintShowPageSize |
686 | QAbstractPrintDialog.PrintDialogOption.PrintShowPageSize |
673 ) |
687 ) |
674 if not Globals.isWindowsPlatform(): |
688 if not Globals.isWindowsPlatform(): |
675 if isCupsAvailable(): |
689 if isCupsAvailable(): |
676 printDialog.setOption( |
690 printDialog.setOption( |
677 QAbstractPrintDialog.PrintDialogOption.PrintCollateCopies) |
691 QAbstractPrintDialog.PrintDialogOption.PrintCollateCopies |
678 printDialog.setOption( |
692 ) |
679 QAbstractPrintDialog.PrintDialogOption.PrintPageRange) |
693 printDialog.setOption(QAbstractPrintDialog.PrintDialogOption.PrintPageRange) |
680 if printDialog.exec() == QDialog.DialogCode.Accepted: |
694 if printDialog.exec() == QDialog.DialogCode.Accepted: |
681 browser.page().execPrintPage(printer, 10 * 1000) |
695 browser.page().execPrintPage(printer, 10 * 1000) |
682 |
696 |
683 @pyqtSlot() |
697 @pyqtSlot() |
684 def printBrowserPdf(self, browser=None): |
698 def printBrowserPdf(self, browser=None): |
685 """ |
699 """ |
686 Public slot called to print the displayed page to PDF. |
700 Public slot called to print the displayed page to PDF. |
687 |
701 |
688 @param browser reference to the browser to be printed (HelpBrowser) |
702 @param browser reference to the browser to be printed (HelpBrowser) |
689 """ |
703 """ |
690 if browser is None: |
704 if browser is None: |
691 browser = self.currentBrowser() |
705 browser = self.currentBrowser() |
692 |
706 |
693 name = WebBrowserTools.getFileNameFromUrl(browser.url()) |
707 name = WebBrowserTools.getFileNameFromUrl(browser.url()) |
694 if name: |
708 if name: |
695 name = name.rsplit('.', 1)[0] |
709 name = name.rsplit(".", 1)[0] |
696 name += '.pdf' |
710 name += ".pdf" |
697 if hasattr(browser.page(), "printToPdf"): |
711 if hasattr(browser.page(), "printToPdf"): |
698 from .Tools.PrintToPdfDialog import PrintToPdfDialog |
712 from .Tools.PrintToPdfDialog import PrintToPdfDialog |
|
713 |
699 if not name: |
714 if not name: |
700 name = "printout.pdf" |
715 name = "printout.pdf" |
701 dlg = PrintToPdfDialog(name, self) |
716 dlg = PrintToPdfDialog(name, self) |
702 if dlg.exec() == QDialog.DialogCode.Accepted: |
717 if dlg.exec() == QDialog.DialogCode.Accepted: |
703 filePath, pageLayout = dlg.getData() |
718 filePath, pageLayout = dlg.getData() |
704 if filePath: |
719 if filePath: |
705 if os.path.exists(filePath): |
720 if os.path.exists(filePath): |
706 res = EricMessageBox.warning( |
721 res = EricMessageBox.warning( |
707 self, |
722 self, |
708 self.tr("Print to PDF"), |
723 self.tr("Print to PDF"), |
709 self.tr("""<p>The file <b>{0}</b> exists""" |
724 self.tr( |
710 """ already. Shall it be""" |
725 """<p>The file <b>{0}</b> exists""" |
711 """ overwritten?</p>""").format(filePath), |
726 """ already. Shall it be""" |
|
727 """ overwritten?</p>""" |
|
728 ).format(filePath), |
712 EricMessageBox.No | EricMessageBox.Yes, |
729 EricMessageBox.No | EricMessageBox.Yes, |
713 EricMessageBox.No) |
730 EricMessageBox.No, |
|
731 ) |
714 if res == EricMessageBox.No: |
732 if res == EricMessageBox.No: |
715 return |
733 return |
716 browser.page().printToPdf( |
734 browser.page().printToPdf( |
717 lambda pdf: self.__pdfGeneratedForSave(filePath, pdf), |
735 lambda pdf: self.__pdfGeneratedForSave(filePath, pdf), |
718 pageLayout) |
736 pageLayout, |
|
737 ) |
719 elif Globals.isLinuxPlatform(): |
738 elif Globals.isLinuxPlatform(): |
720 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
739 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
721 if Preferences.getPrinter("ColorMode"): |
740 if Preferences.getPrinter("ColorMode"): |
722 printer.setColorMode(QPrinter.ColorMode.Color) |
741 printer.setColorMode(QPrinter.ColorMode.Color) |
723 else: |
742 else: |
727 printer.setPrinterName(printerName) |
746 printer.setPrinterName(printerName) |
728 printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat) |
747 printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat) |
729 if name: |
748 if name: |
730 printer.setOutputFileName(name) |
749 printer.setOutputFileName(name) |
731 printer.setResolution(Preferences.getPrinter("Resolution")) |
750 printer.setResolution(Preferences.getPrinter("Resolution")) |
732 |
751 |
733 printDialog = QPrintDialog(printer, self) |
752 printDialog = QPrintDialog(printer, self) |
734 if printDialog.exec() == QDialog.DialogCode.Accepted: |
753 if printDialog.exec() == QDialog.DialogCode.Accepted: |
735 browser.render(printer) |
754 browser.render(printer) |
736 |
755 |
737 def __pdfGeneratedForSave(self, filePath, pdfData): |
756 def __pdfGeneratedForSave(self, filePath, pdfData): |
738 """ |
757 """ |
739 Private slot to save the generated PDF data to a file. |
758 Private slot to save the generated PDF data to a file. |
740 |
759 |
741 @param filePath path to save the PDF to |
760 @param filePath path to save the PDF to |
742 @type str |
761 @type str |
743 @param pdfData generated PDF document |
762 @param pdfData generated PDF document |
744 @type QByteArray |
763 @type QByteArray |
745 """ |
764 """ |
746 if pdfData.size() == 0: |
765 if pdfData.size() == 0: |
747 return |
766 return |
748 |
767 |
749 try: |
768 try: |
750 with open(filePath, "wb") as f: |
769 with open(filePath, "wb") as f: |
751 f.write(pdfData) |
770 f.write(pdfData) |
752 except OSError as err: |
771 except OSError as err: |
753 EricMessageBox.critical( |
772 EricMessageBox.critical( |
754 self, |
773 self, |
755 self.tr("Print to PDF"), |
774 self.tr("Print to PDF"), |
756 self.tr("""<p>The PDF could not be written to file <b>{0}""" |
775 self.tr( |
757 """</b>.</p><p><b>Error:</b> {1}</p>""").format( |
776 """<p>The PDF could not be written to file <b>{0}""" |
758 filePath, str(err)), |
777 """</b>.</p><p><b>Error:</b> {1}</p>""" |
759 EricMessageBox.Ok) |
778 ).format(filePath, str(err)), |
760 |
779 EricMessageBox.Ok, |
|
780 ) |
|
781 |
761 @pyqtSlot() |
782 @pyqtSlot() |
762 def printPreviewBrowser(self, browser=None): |
783 def printPreviewBrowser(self, browser=None): |
763 """ |
784 """ |
764 Public slot called to show a print preview of the displayed file. |
785 Public slot called to show a print preview of the displayed file. |
765 |
786 |
766 @param browser reference to the browser to be printed (WebBrowserView) |
787 @param browser reference to the browser to be printed (WebBrowserView) |
767 """ |
788 """ |
768 from PyQt6.QtPrintSupport import QPrintPreviewDialog |
789 from PyQt6.QtPrintSupport import QPrintPreviewDialog |
769 |
790 |
770 if browser is None: |
791 if browser is None: |
771 browser = self.currentBrowser() |
792 browser = self.currentBrowser() |
772 |
793 |
773 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
794 printer = QPrinter(mode=QPrinter.PrinterMode.HighResolution) |
774 if Preferences.getPrinter("ColorMode"): |
795 if Preferences.getPrinter("ColorMode"): |
775 printer.setColorMode(QPrinter.ColorMode.Color) |
796 printer.setColorMode(QPrinter.ColorMode.Color) |
776 else: |
797 else: |
777 printer.setColorMode(QPrinter.ColorMode.GrayScale) |
798 printer.setColorMode(QPrinter.ColorMode.GrayScale) |
778 if Preferences.getPrinter("FirstPageFirst"): |
799 if Preferences.getPrinter("FirstPageFirst"): |
779 printer.setPageOrder(QPrinter.PageOrder.FirstPageFirst) |
800 printer.setPageOrder(QPrinter.PageOrder.FirstPageFirst) |
780 else: |
801 else: |
781 printer.setPageOrder(QPrinter.PageOrder.LastPageFirst) |
802 printer.setPageOrder(QPrinter.PageOrder.LastPageFirst) |
782 printer.setPageMargins(QMarginsF( |
803 printer.setPageMargins( |
783 Preferences.getPrinter("LeftMargin") * 10, |
804 QMarginsF( |
784 Preferences.getPrinter("TopMargin") * 10, |
805 Preferences.getPrinter("LeftMargin") * 10, |
785 Preferences.getPrinter("RightMargin") * 10, |
806 Preferences.getPrinter("TopMargin") * 10, |
786 Preferences.getPrinter("BottomMargin") * 10), |
807 Preferences.getPrinter("RightMargin") * 10, |
787 QPageLayout.Unit.Millimeter |
808 Preferences.getPrinter("BottomMargin") * 10, |
|
809 ), |
|
810 QPageLayout.Unit.Millimeter, |
788 ) |
811 ) |
789 printerName = Preferences.getPrinter("PrinterName") |
812 printerName = Preferences.getPrinter("PrinterName") |
790 if printerName: |
813 if printerName: |
791 printer.setPrinterName(printerName) |
814 printer.setPrinterName(printerName) |
792 printer.setResolution(Preferences.getPrinter("Resolution")) |
815 printer.setResolution(Preferences.getPrinter("Resolution")) |
793 |
816 |
794 preview = QPrintPreviewDialog(printer, self) |
817 preview = QPrintPreviewDialog(printer, self) |
795 preview.resize(800, 750) |
818 preview.resize(800, 750) |
796 preview.paintRequested.connect( |
819 preview.paintRequested.connect( |
797 lambda p: self.__printPreviewRequested(p, browser)) |
820 lambda p: self.__printPreviewRequested(p, browser) |
|
821 ) |
798 preview.exec() |
822 preview.exec() |
799 |
823 |
800 def __printPreviewRequested(self, printer, browser): |
824 def __printPreviewRequested(self, printer, browser): |
801 """ |
825 """ |
802 Private slot to generate the print preview. |
826 Private slot to generate the print preview. |
803 |
827 |
804 @param printer reference to the printer object |
828 @param printer reference to the printer object |
805 @type QPrinter |
829 @type QPrinter |
806 @param browser reference to the browser to be printed |
830 @param browser reference to the browser to be printed |
807 @type WebBrowserView |
831 @type WebBrowserView |
808 """ |
832 """ |
809 with EricOverrideCursor(): |
833 with EricOverrideCursor(): |
810 browser.page().execPrintPage(printer, 10 * 1000) |
834 browser.page().execPrintPage(printer, 10 * 1000) |
811 |
835 |
812 def __sourceChanged(self, url, browser): |
836 def __sourceChanged(self, url, browser): |
813 """ |
837 """ |
814 Private slot to handle a change of a browsers source. |
838 Private slot to handle a change of a browsers source. |
815 |
839 |
816 @param url URL of the new site |
840 @param url URL of the new site |
817 @type QUrl |
841 @type QUrl |
818 @param browser reference to the web browser |
842 @param browser reference to the web browser |
819 @type WebBrowserView |
843 @type WebBrowserView |
820 """ |
844 """ |
821 self.sourceChanged.emit(browser, url) |
845 self.sourceChanged.emit(browser, url) |
822 |
846 |
823 if browser == self.currentBrowser(): |
847 if browser == self.currentBrowser(): |
824 self.currentUrlChanged.emit(url) |
848 self.currentUrlChanged.emit(url) |
825 |
849 |
826 def __titleChanged(self, title, browser): |
850 def __titleChanged(self, title, browser): |
827 """ |
851 """ |
828 Private slot to handle a change of a browsers title. |
852 Private slot to handle a change of a browsers title. |
829 |
853 |
830 @param title new title |
854 @param title new title |
831 @type str |
855 @type str |
832 @param browser reference to the web browser |
856 @param browser reference to the web browser |
833 @type WebBrowserView |
857 @type WebBrowserView |
834 """ |
858 """ |
835 index = self.indexOf(browser) |
859 index = self.indexOf(browser) |
836 if title == "": |
860 if title == "": |
837 title = browser.url().toString() |
861 title = browser.url().toString() |
838 |
862 |
839 self.setTabText(index, self.__elide(title.replace("&", "&&"))) |
863 self.setTabText(index, self.__elide(title.replace("&", "&&"))) |
840 self.setTabToolTip(index, title) |
864 self.setTabToolTip(index, title) |
841 |
865 |
842 self.titleChanged.emit(browser, title) |
866 self.titleChanged.emit(browser, title) |
843 |
867 |
844 def __elide(self, txt, mode=Qt.TextElideMode.ElideRight, length=40): |
868 def __elide(self, txt, mode=Qt.TextElideMode.ElideRight, length=40): |
845 """ |
869 """ |
846 Private method to elide some text. |
870 Private method to elide some text. |
847 |
871 |
848 @param txt text to be elided (string) |
872 @param txt text to be elided (string) |
849 @param mode elide mode (Qt.TextElideMode) |
873 @param mode elide mode (Qt.TextElideMode) |
850 @param length amount of characters to be used (integer) |
874 @param length amount of characters to be used (integer) |
851 @return the elided text (string) |
875 @return the elided text (string) |
852 """ |
876 """ |
853 if mode == Qt.TextElideMode.ElideNone or len(txt) < length: |
877 if mode == Qt.TextElideMode.ElideNone or len(txt) < length: |
854 return txt |
878 return txt |
855 elif mode == Qt.TextElideMode.ElideLeft: |
879 elif mode == Qt.TextElideMode.ElideLeft: |
856 return "...{0}".format(txt[-length:]) |
880 return "...{0}".format(txt[-length:]) |
857 elif mode == Qt.TextElideMode.ElideMiddle: |
881 elif mode == Qt.TextElideMode.ElideMiddle: |
858 return "{0}...{1}".format(txt[:length // 2], txt[-(length // 2):]) |
882 return "{0}...{1}".format(txt[: length // 2], txt[-(length // 2) :]) |
859 elif mode == Qt.TextElideMode.ElideRight: |
883 elif mode == Qt.TextElideMode.ElideRight: |
860 return "{0}...".format(txt[:length]) |
884 return "{0}...".format(txt[:length]) |
861 else: |
885 else: |
862 # just in case |
886 # just in case |
863 return txt |
887 return txt |
864 |
888 |
865 def preferencesChanged(self): |
889 def preferencesChanged(self): |
866 """ |
890 """ |
867 Public slot to handle a change of preferences. |
891 Public slot to handle a change of preferences. |
868 """ |
892 """ |
869 for browser in self.browsers(): |
893 for browser in self.browsers(): |
870 browser.preferencesChanged() |
894 browser.preferencesChanged() |
871 |
895 |
872 for urlbar in self.__stackedUrlBar.urlBars(): |
896 for urlbar in self.__stackedUrlBar.urlBars(): |
873 urlbar.preferencesChanged() |
897 urlbar.preferencesChanged() |
874 |
898 |
875 def __loadFinished(self, ok, browser): |
899 def __loadFinished(self, ok, browser): |
876 """ |
900 """ |
877 Private method to handle the loadFinished signal. |
901 Private method to handle the loadFinished signal. |
878 |
902 |
879 @param ok flag indicating the result |
903 @param ok flag indicating the result |
880 @type bool |
904 @type bool |
881 @param browser reference to the web browser |
905 @param browser reference to the web browser |
882 @type WebBrowserView |
906 @type WebBrowserView |
883 """ |
907 """ |
884 if ok: |
908 if ok: |
885 self.showMessage.emit(self.tr("Finished loading")) |
909 self.showMessage.emit(self.tr("Finished loading")) |
886 else: |
910 else: |
887 self.showMessage.emit(self.tr("Failed to load")) |
911 self.showMessage.emit(self.tr("Failed to load")) |
888 |
912 |
889 def __loadProgress(self, progress, browser): |
913 def __loadProgress(self, progress, browser): |
890 """ |
914 """ |
891 Private method to handle the loadProgress signal. |
915 Private method to handle the loadProgress signal. |
892 |
916 |
893 Note: This works around wegengine not sending a loadFinished |
917 Note: This works around wegengine not sending a loadFinished |
894 signal for navigation on the same page. |
918 signal for navigation on the same page. |
895 |
919 |
896 @param progress load progress in percent |
920 @param progress load progress in percent |
897 @type int |
921 @type int |
898 @param browser reference to the web browser |
922 @param browser reference to the web browser |
899 @type WebBrowserView |
923 @type WebBrowserView |
900 """ |
924 """ |
907 else: |
931 else: |
908 self.setTabIcon(index, QIcon()) |
932 self.setTabIcon(index, QIcon()) |
909 self.setTabText(index, self.tr("Loading...")) |
933 self.setTabText(index, self.tr("Loading...")) |
910 self.setTabToolTip(index, self.tr("Loading...")) |
934 self.setTabToolTip(index, self.tr("Loading...")) |
911 self.showMessage.emit(self.tr("Loading...")) |
935 self.showMessage.emit(self.tr("Loading...")) |
912 |
936 |
913 self.__mainWindow.setLoadingActions(True) |
937 self.__mainWindow.setLoadingActions(True) |
914 elif progress == 100: |
938 elif progress == 100: |
915 import WebBrowser.WebBrowserWindow |
939 import WebBrowser.WebBrowserWindow |
|
940 |
916 self.resetAnimation(index) |
941 self.resetAnimation(index) |
917 self.setTabIcon( |
942 self.setTabIcon( |
918 index, WebBrowser.WebBrowserWindow.WebBrowserWindow.icon( |
943 index, WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(browser.url()) |
919 browser.url())) |
944 ) |
920 self.showMessage.emit(self.tr("Finished loading")) |
945 self.showMessage.emit(self.tr("Finished loading")) |
921 |
946 |
922 self.__mainWindow.setLoadingActions(False) |
947 self.__mainWindow.setLoadingActions(False) |
923 |
948 |
924 def __iconChanged(self, browser): |
949 def __iconChanged(self, browser): |
925 """ |
950 """ |
926 Private slot to handle a change of the web site icon. |
951 Private slot to handle a change of the web site icon. |
927 |
952 |
928 @param browser reference to the web browser |
953 @param browser reference to the web browser |
929 @type WebBrowserView |
954 @type WebBrowserView |
930 """ |
955 """ |
931 self.setTabIcon( |
956 self.setTabIcon(self.indexOf(browser), browser.icon()) |
932 self.indexOf(browser), |
|
933 browser.icon()) |
|
934 self.__mainWindow.bookmarksManager().faviconChanged(browser.url()) |
957 self.__mainWindow.bookmarksManager().faviconChanged(browser.url()) |
935 |
958 |
936 def getSourceFileList(self): |
959 def getSourceFileList(self): |
937 """ |
960 """ |
938 Public method to get a list of all opened Qt help files. |
961 Public method to get a list of all opened Qt help files. |
939 |
962 |
940 @return dictionary with tab id as key and host/namespace as value |
963 @return dictionary with tab id as key and host/namespace as value |
941 """ |
964 """ |
942 sourceList = {} |
965 sourceList = {} |
943 for i in range(self.count()): |
966 for i in range(self.count()): |
944 browser = self.widget(i) |
967 browser = self.widget(i) |
945 if ( |
968 if browser is not None and browser.source().isValid(): |
946 browser is not None and |
|
947 browser.source().isValid() |
|
948 ): |
|
949 sourceList[i] = browser.source().host() |
969 sourceList[i] = browser.source().host() |
950 |
970 |
951 return sourceList |
971 return sourceList |
952 |
972 |
953 def shallShutDown(self): |
973 def shallShutDown(self): |
954 """ |
974 """ |
955 Public method to check, if the application should be shut down. |
975 Public method to check, if the application should be shut down. |
956 |
976 |
957 @return flag indicating a shut down (boolean) |
977 @return flag indicating a shut down (boolean) |
958 """ |
978 """ |
959 if self.count() > 1 and Preferences.getWebBrowser( |
979 if self.count() > 1 and Preferences.getWebBrowser("WarnOnMultipleClose"): |
960 "WarnOnMultipleClose"): |
|
961 mb = EricMessageBox.EricMessageBox( |
980 mb = EricMessageBox.EricMessageBox( |
962 EricMessageBox.Information, |
981 EricMessageBox.Information, |
963 self.tr("Are you sure you want to close the window?"), |
982 self.tr("Are you sure you want to close the window?"), |
964 self.tr("""Are you sure you want to close the window?\n""" |
983 self.tr( |
965 """You have %n tab(s) open.""", "", self.count()), |
984 """Are you sure you want to close the window?\n""" |
|
985 """You have %n tab(s) open.""", |
|
986 "", |
|
987 self.count(), |
|
988 ), |
966 modal=True, |
989 modal=True, |
967 parent=self) |
990 parent=self, |
968 quitButton = mb.addButton( |
991 ) |
969 self.tr("&Quit"), EricMessageBox.AcceptRole) |
992 quitButton = mb.addButton(self.tr("&Quit"), EricMessageBox.AcceptRole) |
970 quitButton.setIcon(UI.PixmapCache.getIcon("exit")) |
993 quitButton.setIcon(UI.PixmapCache.getIcon("exit")) |
971 closeTabButton = mb.addButton( |
994 closeTabButton = mb.addButton( |
972 self.tr("C&lose Current Tab"), EricMessageBox.AcceptRole) |
995 self.tr("C&lose Current Tab"), EricMessageBox.AcceptRole |
|
996 ) |
973 closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose")) |
997 closeTabButton.setIcon(UI.PixmapCache.getIcon("tabClose")) |
974 mb.addButton(EricMessageBox.Cancel) |
998 mb.addButton(EricMessageBox.Cancel) |
975 mb.exec() |
999 mb.exec() |
976 if mb.clickedButton() == quitButton: |
1000 if mb.clickedButton() == quitButton: |
977 return True |
1001 return True |
978 else: |
1002 else: |
979 if mb.clickedButton() == closeTabButton: |
1003 if mb.clickedButton() == closeTabButton: |
980 self.closeBrowser() |
1004 self.closeBrowser() |
981 return False |
1005 return False |
982 |
1006 |
983 return True |
1007 return True |
984 |
1008 |
985 def stackedUrlBar(self): |
1009 def stackedUrlBar(self): |
986 """ |
1010 """ |
987 Public method to get a reference to the stacked url bar. |
1011 Public method to get a reference to the stacked url bar. |
988 |
1012 |
989 @return reference to the stacked url bar (StackedUrlBar) |
1013 @return reference to the stacked url bar (StackedUrlBar) |
990 """ |
1014 """ |
991 return self.__stackedUrlBar |
1015 return self.__stackedUrlBar |
992 |
1016 |
993 def currentUrlBar(self): |
1017 def currentUrlBar(self): |
994 """ |
1018 """ |
995 Public method to get a reference to the current url bar. |
1019 Public method to get a reference to the current url bar. |
996 |
1020 |
997 @return reference to the current url bar (UrlBar) |
1021 @return reference to the current url bar (UrlBar) |
998 """ |
1022 """ |
999 return self.__stackedUrlBar.currentWidget() |
1023 return self.__stackedUrlBar.currentWidget() |
1000 |
1024 |
1001 def urlBarForView(self, view): |
1025 def urlBarForView(self, view): |
1002 """ |
1026 """ |
1003 Public method to get a reference to the UrlBar associated with the |
1027 Public method to get a reference to the UrlBar associated with the |
1004 given view. |
1028 given view. |
1005 |
1029 |
1006 @param view reference to the view to get the urlbar for |
1030 @param view reference to the view to get the urlbar for |
1007 @type WebBrowserView |
1031 @type WebBrowserView |
1008 @return reference to the associated urlbar |
1032 @return reference to the associated urlbar |
1009 @rtype UrlBar |
1033 @rtype UrlBar |
1010 """ |
1034 """ |
1011 for urlbar in self.__stackedUrlBar.urlBars(): |
1035 for urlbar in self.__stackedUrlBar.urlBars(): |
1012 if urlbar.browser() is view: |
1036 if urlbar.browser() is view: |
1013 return urlbar |
1037 return urlbar |
1014 |
1038 |
1015 return None |
1039 return None |
1016 |
1040 |
1017 def __lineEditReturnPressed(self, edit): |
1041 def __lineEditReturnPressed(self, edit): |
1018 """ |
1042 """ |
1019 Private slot to handle the entering of an URL. |
1043 Private slot to handle the entering of an URL. |
1020 |
1044 |
1021 @param edit reference to the line edit |
1045 @param edit reference to the line edit |
1022 @type UrlBar |
1046 @type UrlBar |
1023 """ |
1047 """ |
1024 url = self.__guessUrlFromPath(edit.text()) |
1048 url = self.__guessUrlFromPath(edit.text()) |
1025 if ericApp().keyboardModifiers() == Qt.KeyboardModifier.AltModifier: |
1049 if ericApp().keyboardModifiers() == Qt.KeyboardModifier.AltModifier: |
1026 self.newBrowser(url) |
1050 self.newBrowser(url) |
1027 else: |
1051 else: |
1028 self.currentBrowser().setSource(url) |
1052 self.currentBrowser().setSource(url) |
1029 self.currentBrowser().setFocus() |
1053 self.currentBrowser().setFocus() |
1030 |
1054 |
1031 def __pathSelected(self, path): |
1055 def __pathSelected(self, path): |
1032 """ |
1056 """ |
1033 Private slot called when a URL is selected from the completer. |
1057 Private slot called when a URL is selected from the completer. |
1034 |
1058 |
1035 @param path path to be shown (string) |
1059 @param path path to be shown (string) |
1036 """ |
1060 """ |
1037 url = self.__guessUrlFromPath(path) |
1061 url = self.__guessUrlFromPath(path) |
1038 self.currentBrowser().setSource(url) |
1062 self.currentBrowser().setSource(url) |
1039 |
1063 |
1040 def __guessUrlFromPath(self, path): |
1064 def __guessUrlFromPath(self, path): |
1041 """ |
1065 """ |
1042 Private method to guess an URL given a path string. |
1066 Private method to guess an URL given a path string. |
1043 |
1067 |
1044 @param path path string to guess an URL for (string) |
1068 @param path path string to guess an URL for (string) |
1045 @return guessed URL (QUrl) |
1069 @return guessed URL (QUrl) |
1046 """ |
1070 """ |
1047 manager = self.__mainWindow.openSearchManager() |
1071 manager = self.__mainWindow.openSearchManager() |
1048 path = Utilities.fromNativeSeparators(path) |
1072 path = Utilities.fromNativeSeparators(path) |
1049 url = manager.convertKeywordSearchToUrl(path) |
1073 url = manager.convertKeywordSearchToUrl(path) |
1050 if url.isValid(): |
1074 if url.isValid(): |
1051 return url |
1075 return url |
1052 |
1076 |
1053 try: |
1077 try: |
1054 url = QUrl.fromUserInput(path) |
1078 url = QUrl.fromUserInput(path) |
1055 except AttributeError: |
1079 except AttributeError: |
1056 url = QUrl(path) |
1080 url = QUrl(path) |
1057 |
1081 |
1058 if ( |
1082 if url.scheme() == "about" and url.path() == "home": |
1059 url.scheme() == "about" and |
|
1060 url.path() == "home" |
|
1061 ): |
|
1062 url = QUrl("eric:home") |
1083 url = QUrl("eric:home") |
1063 |
1084 |
1064 if url.scheme() in ["s", "search"]: |
1085 if url.scheme() in ["s", "search"]: |
1065 url = manager.currentEngine().searchUrl(url.path().strip()) |
1086 url = manager.currentEngine().searchUrl(url.path().strip()) |
1066 |
1087 |
1067 if ( |
1088 if url.scheme() != "" and (url.host() != "" or url.path() != ""): |
1068 url.scheme() != "" and |
|
1069 (url.host() != "" or url.path() != "") |
|
1070 ): |
|
1071 return url |
1089 return url |
1072 |
1090 |
1073 urlString = Preferences.getWebBrowser("DefaultScheme") + path.strip() |
1091 urlString = Preferences.getWebBrowser("DefaultScheme") + path.strip() |
1074 url = QUrl.fromEncoded(urlString.encode("utf-8"), |
1092 url = QUrl.fromEncoded(urlString.encode("utf-8"), QUrl.ParsingMode.TolerantMode) |
1075 QUrl.ParsingMode.TolerantMode) |
1093 |
1076 |
|
1077 return url |
1094 return url |
1078 |
1095 |
1079 def __currentChanged(self, index): |
1096 def __currentChanged(self, index): |
1080 """ |
1097 """ |
1081 Private slot to handle an index change. |
1098 Private slot to handle an index change. |
1082 |
1099 |
1083 @param index new index (integer) |
1100 @param index new index (integer) |
1084 """ |
1101 """ |
1085 self.__stackedUrlBar.setCurrentIndex(index) |
1102 self.__stackedUrlBar.setCurrentIndex(index) |
1086 |
1103 |
1087 browser = self.browserAt(index) |
1104 browser = self.browserAt(index) |
1088 if browser is not None: |
1105 if browser is not None: |
1089 if browser.url() == "" and browser.hasFocus(): |
1106 if browser.url() == "" and browser.hasFocus(): |
1090 self.__stackedUrlBar.currentWidget.setFocus() |
1107 self.__stackedUrlBar.currentWidget.setFocus() |
1091 elif browser.url() != "": |
1108 elif browser.url() != "": |
1092 browser.setFocus() |
1109 browser.setFocus() |
1093 |
1110 |
1094 def restoreClosedTab(self, act): |
1111 def restoreClosedTab(self, act): |
1095 """ |
1112 """ |
1096 Public slot to restore the most recently closed tab. |
1113 Public slot to restore the most recently closed tab. |
1097 |
1114 |
1098 @param act reference to the action that triggered |
1115 @param act reference to the action that triggered |
1099 @type QAction |
1116 @type QAction |
1100 """ |
1117 """ |
1101 if not self.canRestoreClosedTab(): |
1118 if not self.canRestoreClosedTab(): |
1102 return |
1119 return |
1103 |
1120 |
1104 tab = self.__closedTabsManager.getClosedTabAt(act.data()) |
1121 tab = self.__closedTabsManager.getClosedTabAt(act.data()) |
1105 |
1122 |
1106 self.newBrowser(tab.url.toString(), position=tab.position) |
1123 self.newBrowser(tab.url.toString(), position=tab.position) |
1107 |
1124 |
1108 def canRestoreClosedTab(self): |
1125 def canRestoreClosedTab(self): |
1109 """ |
1126 """ |
1110 Public method to check, if closed tabs can be restored. |
1127 Public method to check, if closed tabs can be restored. |
1111 |
1128 |
1112 @return flag indicating that closed tabs can be restored (boolean) |
1129 @return flag indicating that closed tabs can be restored (boolean) |
1113 """ |
1130 """ |
1114 return self.__closedTabsManager.isClosedTabAvailable() |
1131 return self.__closedTabsManager.isClosedTabAvailable() |
1115 |
1132 |
1116 def restoreAllClosedTabs(self): |
1133 def restoreAllClosedTabs(self): |
1117 """ |
1134 """ |
1118 Public slot to restore all closed tabs. |
1135 Public slot to restore all closed tabs. |
1119 """ |
1136 """ |
1120 if not self.canRestoreClosedTab(): |
1137 if not self.canRestoreClosedTab(): |
1121 return |
1138 return |
1122 |
1139 |
1123 for tab in self.__closedTabsManager.allClosedTabs(): |
1140 for tab in self.__closedTabsManager.allClosedTabs(): |
1124 self.newBrowser(tab.url.toString(), position=tab.position) |
1141 self.newBrowser(tab.url.toString(), position=tab.position) |
1125 self.__closedTabsManager.clearList() |
1142 self.__closedTabsManager.clearList() |
1126 |
1143 |
1127 def clearClosedTabsList(self): |
1144 def clearClosedTabsList(self): |
1128 """ |
1145 """ |
1129 Public slot to clear the list of closed tabs. |
1146 Public slot to clear the list of closed tabs. |
1130 """ |
1147 """ |
1131 self.__closedTabsManager.clearList() |
1148 self.__closedTabsManager.clearList() |
1132 |
1149 |
1133 def __aboutToShowClosedTabsMenu(self): |
1150 def __aboutToShowClosedTabsMenu(self): |
1134 """ |
1151 """ |
1135 Private slot to populate the closed tabs menu. |
1152 Private slot to populate the closed tabs menu. |
1136 """ |
1153 """ |
1137 fm = self.__closedTabsMenu.fontMetrics() |
1154 fm = self.__closedTabsMenu.fontMetrics() |
1138 try: |
1155 try: |
1139 maxWidth = fm.horizontalAdvance('m') * 40 |
1156 maxWidth = fm.horizontalAdvance("m") * 40 |
1140 except AttributeError: |
1157 except AttributeError: |
1141 maxWidth = fm.width('m') * 40 |
1158 maxWidth = fm.width("m") * 40 |
1142 |
1159 |
1143 self.__closedTabsMenu.clear() |
1160 self.__closedTabsMenu.clear() |
1144 for index, tab in enumerate(self.__closedTabsManager.allClosedTabs()): |
1161 for index, tab in enumerate(self.__closedTabsManager.allClosedTabs()): |
1145 title = fm.elidedText(tab.title, Qt.TextElideMode.ElideRight, |
1162 title = fm.elidedText(tab.title, Qt.TextElideMode.ElideRight, maxWidth) |
1146 maxWidth) |
|
1147 act = self.__closedTabsMenu.addAction( |
1163 act = self.__closedTabsMenu.addAction( |
1148 self.__mainWindow.icon(tab.url), title) |
1164 self.__mainWindow.icon(tab.url), title |
|
1165 ) |
1149 act.setData(index) |
1166 act.setData(index) |
1150 act.triggered.connect(lambda: self.restoreClosedTab(act)) |
1167 act.triggered.connect(lambda: self.restoreClosedTab(act)) |
1151 self.__closedTabsMenu.addSeparator() |
1168 self.__closedTabsMenu.addSeparator() |
1152 self.__closedTabsMenu.addAction( |
1169 self.__closedTabsMenu.addAction( |
1153 self.tr("Restore All Closed Tabs"), self.restoreAllClosedTabs) |
1170 self.tr("Restore All Closed Tabs"), self.restoreAllClosedTabs |
1154 self.__closedTabsMenu.addAction( |
1171 ) |
1155 self.tr("Clear List"), self.clearClosedTabsList) |
1172 self.__closedTabsMenu.addAction(self.tr("Clear List"), self.clearClosedTabsList) |
1156 |
1173 |
1157 def closedTabsManager(self): |
1174 def closedTabsManager(self): |
1158 """ |
1175 """ |
1159 Public slot to get a reference to the closed tabs manager. |
1176 Public slot to get a reference to the closed tabs manager. |
1160 |
1177 |
1161 @return reference to the closed tabs manager (ClosedTabsManager) |
1178 @return reference to the closed tabs manager (ClosedTabsManager) |
1162 """ |
1179 """ |
1163 return self.__closedTabsManager |
1180 return self.__closedTabsManager |
1164 |
1181 |
1165 def __closedTabAvailable(self, avail): |
1182 def __closedTabAvailable(self, avail): |
1166 """ |
1183 """ |
1167 Private slot to handle changes of the availability of closed tabs. |
1184 Private slot to handle changes of the availability of closed tabs. |
1168 |
1185 |
1169 @param avail flag indicating the availability of closed tabs (boolean) |
1186 @param avail flag indicating the availability of closed tabs (boolean) |
1170 """ |
1187 """ |
1171 self.__closedTabsButton.setEnabled(avail) |
1188 self.__closedTabsButton.setEnabled(avail) |
1172 self.__restoreClosedTabAct.setEnabled(avail) |
1189 self.__restoreClosedTabAct.setEnabled(avail) |
1173 |
1190 |
1174 #################################################### |
1191 #################################################### |
1175 ## Methods below implement session related functions |
1192 ## Methods below implement session related functions |
1176 #################################################### |
1193 #################################################### |
1177 |
1194 |
1178 def getSessionData(self): |
1195 def getSessionData(self): |
1179 """ |
1196 """ |
1180 Public method to populate the session data. |
1197 Public method to populate the session data. |
1181 |
1198 |
1182 @return dictionary containing the session data |
1199 @return dictionary containing the session data |
1183 @rtype dict |
1200 @rtype dict |
1184 """ |
1201 """ |
1185 sessionData = {} |
1202 sessionData = {} |
1186 |
1203 |
1187 # 1. current index |
1204 # 1. current index |
1188 sessionData["CurrentTabIndex"] = self.currentIndex() |
1205 sessionData["CurrentTabIndex"] = self.currentIndex() |
1189 |
1206 |
1190 # 2. tab data |
1207 # 2. tab data |
1191 sessionData["Tabs"] = [] |
1208 sessionData["Tabs"] = [] |
1192 for index in range(self.count()): |
1209 for index in range(self.count()): |
1193 browser = self.widget(index) |
1210 browser = self.widget(index) |
1194 data = browser.getSessionData() |
1211 data = browser.getSessionData() |
1195 sessionData["Tabs"].append(data) |
1212 sessionData["Tabs"].append(data) |
1196 |
1213 |
1197 return sessionData |
1214 return sessionData |
1198 |
1215 |
1199 def loadFromSessionData(self, sessionData): |
1216 def loadFromSessionData(self, sessionData): |
1200 """ |
1217 """ |
1201 Public method to load the session data. |
1218 Public method to load the session data. |
1202 |
1219 |
1203 @param sessionData dictionary containing the session data as |
1220 @param sessionData dictionary containing the session data as |
1204 generated by getSessionData() |
1221 generated by getSessionData() |
1205 @type dict |
1222 @type dict |
1206 """ |
1223 """ |
1207 tabCount = self.count() |
1224 tabCount = self.count() |
1208 |
1225 |
1209 # 1. load tab data |
1226 # 1. load tab data |
1210 if "Tabs" in sessionData: |
1227 if "Tabs" in sessionData: |
1211 loadTabOnActivate = Preferences.getWebBrowser( |
1228 loadTabOnActivate = Preferences.getWebBrowser("LoadTabOnActivation") |
1212 "LoadTabOnActivation") |
|
1213 for data in sessionData["Tabs"]: |
1229 for data in sessionData["Tabs"]: |
1214 browser = self.newBrowser(restoreSession=True) |
1230 browser = self.newBrowser(restoreSession=True) |
1215 if loadTabOnActivate: |
1231 if loadTabOnActivate: |
1216 browser.storeSessionData(data) |
1232 browser.storeSessionData(data) |
1217 title, urlStr, icon = browser.extractSessionMetaData(data) |
1233 title, urlStr, icon = browser.extractSessionMetaData(data) |
1218 index = self.indexOf(browser) |
1234 index = self.indexOf(browser) |
1219 self.setTabText(index, title) |
1235 self.setTabText(index, title) |
1220 self.setTabIcon(index, icon) |
1236 self.setTabIcon(index, icon) |
1221 else: |
1237 else: |
1222 browser.loadFromSessionData(data) |
1238 browser.loadFromSessionData(data) |
1223 |
1239 |
1224 # 2. set tab index |
1240 # 2. set tab index |
1225 if ( |
1241 if "CurrentTabIndex" in sessionData and sessionData["CurrentTabIndex"] >= 0: |
1226 "CurrentTabIndex" in sessionData and |
|
1227 sessionData["CurrentTabIndex"] >= 0 |
|
1228 ): |
|
1229 index = tabCount + sessionData["CurrentTabIndex"] |
1242 index = tabCount + sessionData["CurrentTabIndex"] |
1230 self.setCurrentIndex(index) |
1243 self.setCurrentIndex(index) |
1231 self.browserAt(index).activateSession() |
1244 self.browserAt(index).activateSession() |