WebBrowser/WebBrowserWindow.py

branch
QtWebEngine
changeset 4805
8ef007140046
parent 4801
71bdc520f640
child 4806
5c0745cb26ea
equal deleted inserted replaced
4804:f794ff054d8f 4805:8ef007140046
70 70
71 @signal webBrowserClosed() emitted after the window was requested to close 71 @signal webBrowserClosed() emitted after the window was requested to close
72 @signal zoomTextOnlyChanged(bool) emitted after the zoom text only setting 72 @signal zoomTextOnlyChanged(bool) emitted after the zoom text only setting
73 was changed 73 was changed
74 """ 74 """
75 ## zoomTextOnlyChanged = pyqtSignal(bool)
76 webBrowserClosed = pyqtSignal() 75 webBrowserClosed = pyqtSignal()
77 76
78 BrowserWindows = [] 77 BrowserWindows = []
79 78
80 ## maxMenuFilePathLen = 75 79 ## maxMenuFilePathLen = 75
377 376
378 def __initWebEngineSettings(self): 377 def __initWebEngineSettings(self):
379 """ 378 """
380 Private method to set the global web settings. 379 Private method to set the global web settings.
381 """ 380 """
382 standardFont = Preferences.getWebBrowser("StandardFont")
383 fixedFont = Preferences.getWebBrowser("FixedFont")
384 # TODO: Fonts: add support for other font types
385
386 settings = QWebEngineSettings.globalSettings() 381 settings = QWebEngineSettings.globalSettings()
387 ## settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) 382
388 383 settings.setFontFamily(
389 settings.setFontFamily(QWebEngineSettings.StandardFont, 384 QWebEngineSettings.StandardFont,
390 standardFont.family()) 385 Preferences.getWebBrowser("StandardFontFamily"))
391 settings.setFontSize(QWebEngineSettings.DefaultFontSize, 386 settings.setFontFamily(
392 standardFont.pointSize()) 387 QWebEngineSettings.FixedFont,
393 settings.setFontFamily(QWebEngineSettings.FixedFont, 388 Preferences.getWebBrowser("FixedFontFamily"))
394 fixedFont.family()) 389 settings.setFontFamily(
395 settings.setFontSize(QWebEngineSettings.DefaultFixedFontSize, 390 QWebEngineSettings.SerifFont,
396 fixedFont.pointSize()) 391 Preferences.getWebBrowser("SerifFontFamily"))
392 settings.setFontFamily(
393 QWebEngineSettings.SansSerifFont,
394 Preferences.getWebBrowser("SansSerifFontFamily"))
395 settings.setFontFamily(
396 QWebEngineSettings.CursiveFont,
397 Preferences.getWebBrowser("CursiveFontFamily"))
398 settings.setFontFamily(
399 QWebEngineSettings.FantasyFont,
400 Preferences.getWebBrowser("FantasyFontFamily"))
401
402 settings.setFontSize(
403 QWebEngineSettings.DefaultFontSize,
404 Preferences.getWebBrowser("DefaultFontSize"))
405 settings.setFontSize(
406 QWebEngineSettings.DefaultFixedFontSize,
407 Preferences.getWebBrowser("DefaultFixedFontSize"))
397 settings.setFontSize( 408 settings.setFontSize(
398 QWebEngineSettings.MinimumFontSize, 409 QWebEngineSettings.MinimumFontSize,
399 Preferences.getWebBrowser("MinimumFontSize")) 410 Preferences.getWebBrowser("MinimumFontSize"))
400 settings.setFontSize( 411 settings.setFontSize(
401 QWebEngineSettings.MinimumLogicalFontSize, 412 QWebEngineSettings.MinimumLogicalFontSize,
405 self.__setUserStyleSheet(styleSheet) 416 self.__setUserStyleSheet(styleSheet)
406 417
407 settings.setAttribute( 418 settings.setAttribute(
408 QWebEngineSettings.AutoLoadImages, 419 QWebEngineSettings.AutoLoadImages,
409 Preferences.getWebBrowser("AutoLoadImages")) 420 Preferences.getWebBrowser("AutoLoadImages"))
421 # TODO: Qt 5.6
410 ## settings.setAttribute( 422 ## settings.setAttribute(
411 ## QWebSettings.JavaEnabled, 423 ## QWebSettings.JavaEnabled,
412 ## Preferences.getWebBrowser("JavaEnabled")) 424 ## Preferences.getWebBrowser("JavaEnabled"))
413 settings.setAttribute( 425 settings.setAttribute(
414 QWebEngineSettings.JavascriptEnabled, 426 QWebEngineSettings.JavascriptEnabled,
417 QWebEngineSettings.JavascriptCanOpenWindows, 429 QWebEngineSettings.JavascriptCanOpenWindows,
418 Preferences.getWebBrowser("JavaScriptCanOpenWindows")) 430 Preferences.getWebBrowser("JavaScriptCanOpenWindows"))
419 settings.setAttribute( 431 settings.setAttribute(
420 QWebEngineSettings.JavascriptCanAccessClipboard, 432 QWebEngineSettings.JavascriptCanAccessClipboard,
421 Preferences.getWebBrowser("JavaScriptCanAccessClipboard")) 433 Preferences.getWebBrowser("JavaScriptCanAccessClipboard"))
434 # TODO: Qt 5.6
422 ## settings.setAttribute( 435 ## settings.setAttribute(
423 ## QWebSettings.PluginsEnabled, 436 ## QWebSettings.PluginsEnabled,
424 ## Preferences.getWebBrowser("PluginsEnabled")) 437 ## Preferences.getWebBrowser("PluginsEnabled"))
425 438
426 ## if hasattr(QWebSettings, "PrintElementBackgrounds"): 439 ## if hasattr(QWebSettings, "PrintElementBackgrounds"):
488 QWebEngineSettings.LocalContentCanAccessFileUrls, 501 QWebEngineSettings.LocalContentCanAccessFileUrls,
489 Preferences.getWebBrowser("LocalContentCanAccessFileUrls")) 502 Preferences.getWebBrowser("LocalContentCanAccessFileUrls"))
490 settings.setAttribute( 503 settings.setAttribute(
491 QWebEngineSettings.XSSAuditingEnabled, 504 QWebEngineSettings.XSSAuditingEnabled,
492 Preferences.getWebBrowser("XSSAuditingEnabled")) 505 Preferences.getWebBrowser("XSSAuditingEnabled"))
493 ## if hasattr(QWebSettings, "SiteSpecificQuirksEnabled"):
494 ## settings.setAttribute(
495 ## QWebSettings.SiteSpecificQuirksEnabled,
496 ## Preferences.getWebBrowser("SiteSpecificQuirksEnabled"))
497 ## 506 ##
498 ## QWebSecurityOrigin.addLocalScheme("eric") 507 ## QWebSecurityOrigin.addLocalScheme("eric")
499 settings.setAttribute( 508 settings.setAttribute(
500 QWebEngineSettings.ScrollAnimatorEnabled, 509 QWebEngineSettings.ScrollAnimatorEnabled,
501 Preferences.getWebBrowser("ScrollAnimatorEnabled")) 510 Preferences.getWebBrowser("ScrollAnimatorEnabled"))
1151 """This sets the zoom factor to 100%.</p>""" 1160 """This sets the zoom factor to 100%.</p>"""
1152 )) 1161 ))
1153 if not self.__initShortcutsOnly: 1162 if not self.__initShortcutsOnly:
1154 self.zoomResetAct.triggered.connect(self.__zoomReset) 1163 self.zoomResetAct.triggered.connect(self.__zoomReset)
1155 self.__actions.append(self.zoomResetAct) 1164 self.__actions.append(self.zoomResetAct)
1156
1157 ## if hasattr(QWebSettings, 'ZoomTextOnly'):
1158 ## self.zoomTextOnlyAct = E5Action(
1159 ## self.tr('Zoom text only'),
1160 ## self.tr('Zoom &text only'),
1161 ## 0, 0, self, 'webbrowser_view_zoom_text_only')
1162 ## self.zoomTextOnlyAct.setCheckable(True)
1163 ## self.zoomTextOnlyAct.setStatusTip(self.tr(
1164 ## 'Zoom text only; pictures remain constant'))
1165 ## self.zoomTextOnlyAct.setWhatsThis(self.tr(
1166 ## """<b>Zoom text only</b>"""
1167 ## """<p>Zoom text only; pictures remain constant.</p>"""
1168 ## ))
1169 ## if not self.__initShortcutsOnly:
1170 ## self.zoomTextOnlyAct.triggered[bool].connect(
1171 ## self.__zoomTextOnly)
1172 ## self.__actions.append(self.zoomTextOnlyAct)
1173 ## else:
1174 ## self.zoomTextOnlyAct = None
1175 1165
1176 self.pageSourceAct = E5Action( 1166 self.pageSourceAct = E5Action(
1177 self.tr('Show page source'), 1167 self.tr('Show page source'),
1178 self.tr('Show page source'), 1168 self.tr('Show page source'),
1179 QKeySequence(self.tr('Ctrl+U')), 0, 1169 QKeySequence(self.tr('Ctrl+U')), 0,
1790 menu = mb.addMenu(self.tr('&View')) 1780 menu = mb.addMenu(self.tr('&View'))
1791 menu.setTearOffEnabled(True) 1781 menu.setTearOffEnabled(True)
1792 menu.addAction(self.zoomInAct) 1782 menu.addAction(self.zoomInAct)
1793 menu.addAction(self.zoomResetAct) 1783 menu.addAction(self.zoomResetAct)
1794 menu.addAction(self.zoomOutAct) 1784 menu.addAction(self.zoomOutAct)
1795 ## if self.zoomTextOnlyAct is not None:
1796 ## menu.addAction(self.zoomTextOnlyAct)
1797 menu.addSeparator() 1785 menu.addSeparator()
1798 menu.addAction(self.pageSourceAct) 1786 menu.addAction(self.pageSourceAct)
1799 menu.addAction(self.fullScreenAct) 1787 menu.addAction(self.fullScreenAct)
1800 self.__textEncodingMenu = menu.addMenu( 1788 self.__textEncodingMenu = menu.addMenu(
1801 self.tr("Text Encoding")) 1789 self.tr("Text Encoding"))
1891 menu.setTearOffEnabled(True) 1879 menu.setTearOffEnabled(True)
1892 menu.addAction(self.feedsManagerAct) 1880 menu.addAction(self.feedsManagerAct)
1893 menu.addAction(self.siteInfoAct) 1881 menu.addAction(self.siteInfoAct)
1894 menu.addSeparator() 1882 menu.addSeparator()
1895 menu.addAction(self.synchronizationAct) 1883 menu.addAction(self.synchronizationAct)
1884 # TODO: Network Monitor
1896 ## menu.addSeparator() 1885 ## menu.addSeparator()
1897 ## menu.addAction(self.toolsMonitorAct) 1886 ## menu.addAction(self.toolsMonitorAct)
1898 1887
1899 menu = mb.addMenu(self.tr("&Window")) 1888 menu = mb.addMenu(self.tr("&Window"))
1900 menu.setTearOffEnabled(True) 1889 menu.setTearOffEnabled(True)
2481 if not self.downloadManager().allowQuit(): 2470 if not self.downloadManager().allowQuit():
2482 return False 2471 return False
2483 2472
2484 self.downloadManager().shutdown() 2473 self.downloadManager().shutdown()
2485 2474
2475 # TODO: Network Monitor
2486 ## self.__closeNetworkMonitor() 2476 ## self.__closeNetworkMonitor()
2487 ## 2477 ##
2478 # TODO: Cookies
2488 ## self.cookieJar().close() 2479 ## self.cookieJar().close()
2489 ## 2480 ##
2490 self.bookmarksToolBar.setModel(None) 2481 self.bookmarksToolBar.setModel(None)
2491 self.bookmarksManager().close() 2482 self.bookmarksManager().close()
2492 2483
2493 self.historyManager().close() 2484 self.historyManager().close()
2494 2485
2495 self.passwordManager().close() 2486 self.passwordManager().close()
2496 2487
2488 # TODO: AdBlock
2497 ## self.adBlockManager().close() 2489 ## self.adBlockManager().close()
2498 ## 2490 ##
2491 # TODO: UserAgents
2499 ## self.userAgentsManager().close() 2492 ## self.userAgentsManager().close()
2500 ## 2493 ##
2494 # TODO: SpeedDial
2501 ## self.speedDial().close() 2495 ## self.speedDial().close()
2502 2496
2503 self.syncManager().close() 2497 self.syncManager().close()
2504 2498
2505 ZoomManager.instance().close() 2499 ZoomManager.instance().close()
2567 2561
2568 def __reload(self): 2562 def __reload(self):
2569 """ 2563 """
2570 Private slot called to handle the reload action. 2564 Private slot called to handle the reload action.
2571 """ 2565 """
2572 ## self.currentBrowser().reload()
2573 self.currentBrowser().reloadBypassingCache() 2566 self.currentBrowser().reloadBypassingCache()
2574 2567
2575 def __stopLoading(self): 2568 def __stopLoading(self):
2576 """ 2569 """
2577 Private slot called to handle loading of the current page. 2570 Private slot called to handle loading of the current page.
2605 Private slot called to handle the zoom reset action. 2598 Private slot called to handle the zoom reset action.
2606 """ 2599 """
2607 self.currentBrowser().zoomReset() 2600 self.currentBrowser().zoomReset()
2608 self.__zoomWidget.setValue(self.currentBrowser().zoomValue()) 2601 self.__zoomWidget.setValue(self.currentBrowser().zoomValue())
2609 2602
2610 ## def __zoomTextOnly(self, textOnly):
2611 ## """
2612 ## Private slot called to handle the zoom text only action.
2613 ##
2614 ## @param textOnly flag indicating to zoom text only (boolean)
2615 ## """
2616 ## QWebSettings.globalSettings().setAttribute(
2617 ## QWebSettings.ZoomTextOnly, textOnly)
2618 ## self.zoomTextOnlyChanged.emit(textOnly)
2619 ##
2620 def __viewFullScreen(self): 2603 def __viewFullScreen(self):
2621 """ 2604 """
2622 Private slot called to toggle fullscreen mode. 2605 Private slot called to toggle fullscreen mode.
2623 """ 2606 """
2624 if self.__isFullScreen(): 2607 if self.__isFullScreen():
2769 2752
2770 self.__tabWidget.preferencesChanged() 2753 self.__tabWidget.preferencesChanged()
2771 2754
2772 self.searchEdit.preferencesChanged() 2755 self.searchEdit.preferencesChanged()
2773 2756
2757 if not self.isPrivate():
2758 # TODO: Cache settings
2759 pass
2760
2774 self.__virusTotal.preferencesChanged() 2761 self.__virusTotal.preferencesChanged()
2775 if not Preferences.getWebBrowser("VirusTotalEnabled") or \ 2762 if not Preferences.getWebBrowser("VirusTotalEnabled") or \
2776 Preferences.getWebBrowser("VirusTotalServiceKey") == "": 2763 Preferences.getWebBrowser("VirusTotalServiceKey") == "":
2777 self.virustotalScanCurrentAct.setEnabled(False) 2764 self.virustotalScanCurrentAct.setEnabled(False)
2778 self.virustotalIpReportAct.setEnabled(False) 2765 self.virustotalIpReportAct.setEnabled(False)
2803 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog 2790 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
2804 dlg = WebBrowserLanguagesDialog(self) 2791 dlg = WebBrowserLanguagesDialog(self)
2805 dlg.exec_() 2792 dlg.exec_()
2806 self.networkManager().languagesChanged() 2793 self.networkManager().languagesChanged()
2807 2794
2795 # TODO: Cookies
2808 ## def __showCookiesConfiguration(self): 2796 ## def __showCookiesConfiguration(self):
2809 ## """ 2797 ## """
2810 ## Private slot to configure the cookies handling. 2798 ## Private slot to configure the cookies handling.
2811 ## """ 2799 ## """
2812 ## from .CookieJar.CookiesConfigurationDialog import \ 2800 ## from .CookieJar.CookiesConfigurationDialog import \
2870 if cls._networkManager is None: 2858 if cls._networkManager is None:
2871 from .Network.NetworkManager import NetworkManager 2859 from .Network.NetworkManager import NetworkManager
2872 cls._networkManager = NetworkManager() 2860 cls._networkManager = NetworkManager()
2873 2861
2874 return cls._networkManager 2862 return cls._networkManager
2875 2863
2864 # TODO: Cookies
2876 ## @classmethod 2865 ## @classmethod
2877 ## def cookieJar(cls): 2866 ## def cookieJar(cls):
2878 ## """ 2867 ## """
2879 ## Class method to get a reference to the cookie jar. 2868 ## Class method to get a reference to the cookie jar.
2880 ## 2869 ##
2897 2886
2898 @param url URL to be shown (QUrl) 2887 @param url URL to be shown (QUrl)
2899 """ 2888 """
2900 if not self.__activating: 2889 if not self.__activating:
2901 self.__activating = True 2890 self.__activating = True
2902 ## req = QNetworkRequest(url)
2903 ## req.setRawHeader(b"X-Eric6-UserLoadAction", b"1")
2904 ## self.currentBrowser().setSource(
2905 ## None, (req, QNetworkAccessManager.GetOperation, b""))
2906 self.currentBrowser().setUrl(url) 2891 self.currentBrowser().setUrl(url)
2907 self.__activating = False 2892 self.__activating = False
2908 2893
2909 # TODO: QtHelp 2894 # TODO: QtHelp
2910 ## def __linksActivated(self, links, keyword): 2895 ## def __linksActivated(self, links, keyword):
3037 Public method to get a list of all opened source files. 3022 Public method to get a list of all opened source files.
3038 3023
3039 @return dictionary with tab id as key and host/namespace as value 3024 @return dictionary with tab id as key and host/namespace as value
3040 """ 3025 """
3041 return self.__tabWidget.getSourceFileList() 3026 return self.__tabWidget.getSourceFileList()
3042 3027
3028 # TODO: QtHelp
3043 ## def __manageQtHelpFilters(self): 3029 ## def __manageQtHelpFilters(self):
3044 ## """ 3030 ## """
3045 ## Private slot to manage the QtHelp filters. 3031 ## Private slot to manage the QtHelp filters.
3046 ## """ 3032 ## """
3047 ## if WebBrowserWindow.UseQtHelp: 3033 ## if WebBrowserWindow.UseQtHelp:
3317 """ 3303 """
3318 from .Passwords.PasswordsDialog import PasswordsDialog 3304 from .Passwords.PasswordsDialog import PasswordsDialog
3319 3305
3320 dlg = PasswordsDialog(self) 3306 dlg = PasswordsDialog(self)
3321 dlg.exec_() 3307 dlg.exec_()
3322 3308
3309 # TODO: Certificates
3323 ## def __showCertificatesDialog(self): 3310 ## def __showCertificatesDialog(self):
3324 ## """ 3311 ## """
3325 ## Private slot to show the certificates management dialog. 3312 ## Private slot to show the certificates management dialog.
3326 ## """ 3313 ## """
3327 ## from E5Network.E5SslCertificatesDialog import E5SslCertificatesDialog 3314 ## from E5Network.E5SslCertificatesDialog import E5SslCertificatesDialog
3328 ## 3315 ##
3329 ## dlg = E5SslCertificatesDialog(self) 3316 ## dlg = E5SslCertificatesDialog(self)
3330 ## dlg.exec_() 3317 ## dlg.exec_()
3331 ## 3318 ##
3319 # TODO: AdBlock
3332 ## def __showAdBlockDialog(self): 3320 ## def __showAdBlockDialog(self):
3333 ## """ 3321 ## """
3334 ## Private slot to show the AdBlock configuration dialog. 3322 ## Private slot to show the AdBlock configuration dialog.
3335 ## """ 3323 ## """
3336 ## self.adBlockManager().showDialog() 3324 ## self.adBlockManager().showDialog()
3337 ## 3325 ##
3326 # TODO: Click2Flash
3338 ## def __showClickToFlashDialog(self): 3327 ## def __showClickToFlashDialog(self):
3339 ## """ 3328 ## """
3340 ## Private slot to open the ClickToFlash whitelist configuration dialog. 3329 ## Private slot to open the ClickToFlash whitelist configuration dialog.
3341 ## """ 3330 ## """
3342 ## from .HelpBrowserWV import HelpWebPage 3331 ## from .HelpBrowserWV import HelpWebPage
3366 """ 3355 """
3367 from .ZoomManager.ZoomValuesDialog import ZoomValuesDialog 3356 from .ZoomManager.ZoomValuesDialog import ZoomValuesDialog
3368 3357
3369 dlg = ZoomValuesDialog(self) 3358 dlg = ZoomValuesDialog(self)
3370 dlg.exec_() 3359 dlg.exec_()
3371 3360
3361 # TODO: Network Monitor
3372 ## def __showNetworkMonitor(self): 3362 ## def __showNetworkMonitor(self):
3373 ## """ 3363 ## """
3374 ## Private slot to show the network monitor dialog. 3364 ## Private slot to show the network monitor dialog.
3375 ## """ 3365 ## """
3376 ## from E5Network.E5NetworkMonitor import E5NetworkMonitor 3366 ## from E5Network.E5NetworkMonitor import E5NetworkMonitor
3381 """ 3371 """
3382 Private slot to show the downloads dialog. 3372 Private slot to show the downloads dialog.
3383 """ 3373 """
3384 self.downloadManager().show() 3374 self.downloadManager().show()
3385 3375
3376 # TODO: Network Monitor
3386 ## def __closeNetworkMonitor(self): 3377 ## def __closeNetworkMonitor(self):
3387 ## """ 3378 ## """
3388 ## Private slot to close the network monitor dialog. 3379 ## Private slot to close the network monitor dialog.
3389 ## """ 3380 ## """
3390 ## from E5Network.E5NetworkMonitor import E5NetworkMonitor 3381 ## from E5Network.E5NetworkMonitor import E5NetworkMonitor
3446 Public slot to load a URL in a new tab. 3437 Public slot to load a URL in a new tab.
3447 3438
3448 @param url URL to be opened (QUrl) 3439 @param url URL to be opened (QUrl)
3449 @param title title of the bookmark (string) 3440 @param title title of the bookmark (string)
3450 """ 3441 """
3451 ## req = QNetworkRequest(url)
3452 ## req.setRawHeader(b"X-Eric6-UserLoadAction", b"1")
3453 ## self.newTab(None, (req, QNetworkAccessManager.GetOperation, b""))
3454 self.newTab(url) 3442 self.newTab(url)
3455 3443
3456 @classmethod 3444 @classmethod
3457 def historyManager(cls): 3445 def historyManager(cls):
3458 """ 3446 """
3476 if cls._passwordManager is None: 3464 if cls._passwordManager is None:
3477 from .Passwords.PasswordManager import PasswordManager 3465 from .Passwords.PasswordManager import PasswordManager
3478 cls._passwordManager = PasswordManager() 3466 cls._passwordManager = PasswordManager()
3479 3467
3480 return cls._passwordManager 3468 return cls._passwordManager
3481 3469
3470 # TODO: AdBlock
3482 ## @classmethod 3471 ## @classmethod
3483 ## def adBlockManager(cls): 3472 ## def adBlockManager(cls):
3484 ## """ 3473 ## """
3485 ## Class method to get a reference to the AdBlock manager. 3474 ## Class method to get a reference to the AdBlock manager.
3486 ## 3475 ##
4078 else: 4067 else:
4079 cls._webProfile = QWebEngineProfile.defaultProfile() 4068 cls._webProfile = QWebEngineProfile.defaultProfile()
4080 cls._webProfile.downloadRequested.connect( 4069 cls._webProfile.downloadRequested.connect(
4081 cls.downloadRequested) 4070 cls.downloadRequested)
4082 4071
4072 # TODO: Cache settings
4073
4083 # Setup QWebChannel user script 4074 # Setup QWebChannel user script
4084 script = QWebEngineScript() 4075 script = QWebEngineScript()
4085 script.setName("_eric_webchannel") 4076 script.setName("_eric_webchannel")
4086 script.setInjectionPoint(QWebEngineScript.DocumentCreation) 4077 script.setInjectionPoint(QWebEngineScript.DocumentCreation)
4087 script.setWorldId(QWebEngineScript.MainWorld) 4078 script.setWorldId(QWebEngineScript.MainWorld)

eric ide

mercurial