eric6/WebBrowser/WebBrowserWindow.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7939
0fc1df79965d
parent 7960
e8fc383322f7
child 8142
43248bafe9b2
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
36 from E5Gui.E5MainWindow import E5MainWindow 36 from E5Gui.E5MainWindow import E5MainWindow
37 from E5Gui.E5Application import e5App 37 from E5Gui.E5Application import e5App
38 from E5Gui.E5ZoomWidget import E5ZoomWidget 38 from E5Gui.E5ZoomWidget import E5ZoomWidget
39 from E5Gui.E5OverrideCursor import E5OverrideCursor 39 from E5Gui.E5OverrideCursor import E5OverrideCursor
40 40
41 from E5Network.E5NetworkIcon import E5NetworkIcon
42
43 import Preferences 41 import Preferences
44 from Preferences import Shortcuts 42 from Preferences import Shortcuts
45 43
46 import Utilities 44 import Utilities
47 import Globals 45 import Globals
48 from Globals import qVersionTuple
49 46
50 import UI.PixmapCache 47 import UI.PixmapCache
51 import UI.Config 48 import UI.Config
52 from UI.Info import Version 49 from UI.Info import Version
50 from UI.NotificationWidget import NotificationTypes
53 51
54 from .Tools import Scripts, WebBrowserTools, WebIconProvider 52 from .Tools import Scripts, WebBrowserTools, WebIconProvider
55 53
56 from .ZoomManager import ZoomManager 54 from .ZoomManager import ZoomManager
57 55
144 self.__hideNavigationTimer = None 142 self.__hideNavigationTimer = None
145 143
146 super(WebBrowserWindow, self).__init__(parent) 144 super(WebBrowserWindow, self).__init__(parent)
147 self.setObjectName(name) 145 self.setObjectName(name)
148 if private: 146 if private:
149 self.setWindowTitle(self.tr("eric6 Web Browser (Private Mode)")) 147 self.setWindowTitle(self.tr("eric Web Browser (Private Mode)"))
150 else: 148 else:
151 self.setWindowTitle(self.tr("eric6 Web Browser")) 149 self.setWindowTitle(self.tr("eric Web Browser"))
152 150
153 self.__settingsDir = settingsDir 151 self.__settingsDir = settingsDir
154 self.setWindowIcon(UI.PixmapCache.getIcon("ericWeb")) 152 self.setWindowIcon(UI.PixmapCache.getIcon("ericWeb"))
155 153
156 self.__mHistory = [] 154 self.__mHistory = []
160 158
161 self.__shortcutsDialog = None 159 self.__shortcutsDialog = None
162 160
163 self.__eventMouseButtons = Qt.NoButton 161 self.__eventMouseButtons = Qt.NoButton
164 self.__eventKeyboardModifiers = Qt.NoModifier 162 self.__eventKeyboardModifiers = Qt.NoModifier
165
166 if (
167 qVersionTuple() < (5, 11, 0) and
168 Preferences.getWebBrowser("WebInspectorEnabled")
169 ):
170 os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = str(
171 Preferences.getWebBrowser("WebInspectorPort"))
172 163
173 WebBrowserWindow.setUseQtHelp(qthelp or bool(searchWord)) 164 WebBrowserWindow.setUseQtHelp(qthelp or bool(searchWord))
174 165
175 self.webProfile(private) 166 self.webProfile(private)
176 self.networkManager() 167 self.networkManager()
394 self.__adBlockIcon.sourceChanged) 385 self.__adBlockIcon.sourceChanged)
395 386
396 self.__tabManagerIcon = self.tabManager().createStatusBarIcon() 387 self.__tabManagerIcon = self.tabManager().createStatusBarIcon()
397 self.statusBar().addPermanentWidget(self.__tabManagerIcon) 388 self.statusBar().addPermanentWidget(self.__tabManagerIcon)
398 389
399 self.networkIcon = E5NetworkIcon(self)
400 self.statusBar().addPermanentWidget(self.networkIcon)
401
402 if not Preferences.getWebBrowser("StatusBarVisible"): 390 if not Preferences.getWebBrowser("StatusBarVisible"):
403 self.statusBar().hide() 391 self.statusBar().hide()
404 392
405 if len(WebBrowserWindow.BrowserWindows): 393 if len(WebBrowserWindow.BrowserWindows):
406 QDesktopServices.setUrlHandler( 394 QDesktopServices.setUrlHandler(
612 QWebEngineSettings.ErrorPageEnabled, 600 QWebEngineSettings.ErrorPageEnabled,
613 Preferences.getWebBrowser("ErrorPageEnabled")) 601 Preferences.getWebBrowser("ErrorPageEnabled"))
614 settings.setAttribute( 602 settings.setAttribute(
615 QWebEngineSettings.FullScreenSupportEnabled, 603 QWebEngineSettings.FullScreenSupportEnabled,
616 Preferences.getWebBrowser("FullScreenSupportEnabled")) 604 Preferences.getWebBrowser("FullScreenSupportEnabled"))
617 605 settings.setAttribute(
618 try: 606 QWebEngineSettings.ScreenCaptureEnabled,
619 # Qt 5.7 607 Preferences.getWebBrowser("ScreenCaptureEnabled"))
620 settings.setAttribute( 608 settings.setAttribute(
621 QWebEngineSettings.ScreenCaptureEnabled, 609 QWebEngineSettings.WebGLEnabled,
622 Preferences.getWebBrowser("ScreenCaptureEnabled")) 610 Preferences.getWebBrowser("WebGLEnabled"))
623 settings.setAttribute( 611 settings.setAttribute(
624 QWebEngineSettings.WebGLEnabled, 612 QWebEngineSettings.FocusOnNavigationEnabled,
625 Preferences.getWebBrowser("WebGLEnabled")) 613 Preferences.getWebBrowser("FocusOnNavigationEnabled"))
626 except (AttributeError, KeyError): 614 settings.setAttribute(
627 pass 615 QWebEngineSettings.PrintElementBackgrounds,
628 616 Preferences.getWebBrowser("PrintElementBackgrounds"))
629 try: 617 settings.setAttribute(
630 # Qt 5.8 618 QWebEngineSettings.AllowRunningInsecureContent,
631 settings.setAttribute( 619 Preferences.getWebBrowser("AllowRunningInsecureContent"))
632 QWebEngineSettings.FocusOnNavigationEnabled, 620 settings.setAttribute(
633 Preferences.getWebBrowser("FocusOnNavigationEnabled")) 621 QWebEngineSettings.AllowGeolocationOnInsecureOrigins,
634 settings.setAttribute( 622 Preferences.getWebBrowser("AllowGeolocationOnInsecureOrigins"))
635 QWebEngineSettings.PrintElementBackgrounds, 623 settings.setAttribute(
636 Preferences.getWebBrowser("PrintElementBackgrounds")) 624 QWebEngineSettings.AllowWindowActivationFromJavaScript,
637 settings.setAttribute( 625 Preferences.getWebBrowser(
638 QWebEngineSettings.AllowRunningInsecureContent, 626 "AllowWindowActivationFromJavaScript"))
639 Preferences.getWebBrowser("AllowRunningInsecureContent")) 627 settings.setAttribute(
640 except (AttributeError, KeyError): 628 QWebEngineSettings.ShowScrollBars,
641 pass 629 Preferences.getWebBrowser("ShowScrollBars"))
642 630 settings.setAttribute(
643 try: 631 QWebEngineSettings.PlaybackRequiresUserGesture,
644 # Qt 5.9 632 Preferences.getWebBrowser(
645 settings.setAttribute( 633 "PlaybackRequiresUserGesture"))
646 QWebEngineSettings.AllowGeolocationOnInsecureOrigins, 634 settings.setAttribute(
647 Preferences.getWebBrowser("AllowGeolocationOnInsecureOrigins")) 635 QWebEngineSettings.JavascriptCanPaste,
648 except (AttributeError, KeyError): 636 Preferences.getWebBrowser(
649 pass 637 "JavaScriptCanPaste"))
650 638 settings.setAttribute(
651 try: 639 QWebEngineSettings.WebRTCPublicInterfacesOnly,
652 # Qt 5.10 640 Preferences.getWebBrowser(
653 settings.setAttribute( 641 "WebRTCPublicInterfacesOnly"))
654 QWebEngineSettings.AllowWindowActivationFromJavaScript, 642 settings.setAttribute(
655 Preferences.getWebBrowser( 643 QWebEngineSettings.DnsPrefetchEnabled,
656 "AllowWindowActivationFromJavaScript")) 644 Preferences.getWebBrowser(
657 settings.setAttribute( 645 "DnsPrefetchEnabled"))
658 QWebEngineSettings.ShowScrollBars,
659 Preferences.getWebBrowser("ShowScrollBars"))
660 except (AttributeError, KeyError):
661 pass
662
663 try:
664 # Qt 5.11
665 settings.setAttribute(
666 QWebEngineSettings.PlaybackRequiresUserGesture,
667 Preferences.getWebBrowser(
668 "PlaybackRequiresUserGesture"))
669 settings.setAttribute(
670 QWebEngineSettings.JavascriptCanPaste,
671 Preferences.getWebBrowser(
672 "JavaScriptCanPaste"))
673 settings.setAttribute(
674 QWebEngineSettings.WebRTCPublicInterfacesOnly,
675 Preferences.getWebBrowser(
676 "WebRTCPublicInterfacesOnly"))
677 except (AttributeError, KeyError):
678 pass
679
680 try:
681 # Qt 5.12
682 settings.setAttribute(
683 QWebEngineSettings.DnsPrefetchEnabled,
684 Preferences.getWebBrowser(
685 "DnsPrefetchEnabled"))
686 except (AttributeError, KeyError):
687 pass
688 646
689 try: 647 try:
690 # Qt 5.13 648 # Qt 5.13
691 settings.setAttribute( 649 settings.setAttribute(
692 QWebEngineSettings.PdfViewerEnabled, 650 QWebEngineSettings.PdfViewerEnabled,
932 self.tr('Quit'), 890 self.tr('Quit'),
933 UI.PixmapCache.getIcon("exit"), 891 UI.PixmapCache.getIcon("exit"),
934 self.tr('&Quit'), 892 self.tr('&Quit'),
935 QKeySequence(self.tr("Ctrl+Q", "File|Quit")), 893 QKeySequence(self.tr("Ctrl+Q", "File|Quit")),
936 0, self, 'webbrowser_file_quit') 894 0, self, 'webbrowser_file_quit')
937 self.exitAct.setStatusTip(self.tr('Quit the eric6 Web Browser')) 895 self.exitAct.setStatusTip(self.tr('Quit the eric Web Browser'))
938 self.exitAct.setWhatsThis(self.tr( 896 self.exitAct.setWhatsThis(self.tr(
939 """<b>Quit</b>""" 897 """<b>Quit</b>"""
940 """<p>Quit the eric6 Web Browser.</p>""" 898 """<p>Quit the eric Web Browser.</p>"""
941 )) 899 ))
942 self.exitAct.triggered.connect(self.shutdown) 900 self.exitAct.triggered.connect(self.shutdown)
943 self.__actions.append(self.exitAct) 901 self.__actions.append(self.exitAct)
944 902
945 self.backAct = E5Action( 903 self.backAct = E5Action(
2132 menu.addAction(self.showDownloadManagerAct) 2090 menu.addAction(self.showDownloadManagerAct)
2133 menu.addAction(self.showJavaScriptConsoleAct) 2091 menu.addAction(self.showJavaScriptConsoleAct)
2134 menu.addAction(self.showTabManagerAct) 2092 menu.addAction(self.showTabManagerAct)
2135 menu.addAction(self.showProtocolHandlerManagerAct) 2093 menu.addAction(self.showProtocolHandlerManagerAct)
2136 if WebBrowserWindow._useQtHelp: 2094 if WebBrowserWindow._useQtHelp:
2137 menu.addSeparator() 2095 menu.addSection(self.tr("QtHelp"))
2138 menu.addAction(self.showTocAct) 2096 menu.addAction(self.showTocAct)
2139 menu.addAction(self.showIndexAct) 2097 menu.addAction(self.showIndexAct)
2140 menu.addAction(self.showSearchAct) 2098 menu.addAction(self.showSearchAct)
2141 menu.addSeparator() 2099 menu.addSeparator()
2142 self.__toolbarsMenu = menu.addMenu(self.tr("&Toolbars")) 2100 self.__toolbarsMenu = menu.addMenu(self.tr("&Toolbars"))
2246 windowsMenu.addAction(self.showDownloadManagerAct) 2204 windowsMenu.addAction(self.showDownloadManagerAct)
2247 windowsMenu.addAction(self.showJavaScriptConsoleAct) 2205 windowsMenu.addAction(self.showJavaScriptConsoleAct)
2248 windowsMenu.addAction(self.showTabManagerAct) 2206 windowsMenu.addAction(self.showTabManagerAct)
2249 windowsMenu.addAction(self.showProtocolHandlerManagerAct) 2207 windowsMenu.addAction(self.showProtocolHandlerManagerAct)
2250 if WebBrowserWindow._useQtHelp: 2208 if WebBrowserWindow._useQtHelp:
2251 windowsMenu.addSeparator() 2209 windowsMenu.addSection(self.tr("QtHelp"))
2252 windowsMenu.addAction(self.showTocAct) 2210 windowsMenu.addAction(self.showTocAct)
2253 windowsMenu.addAction(self.showIndexAct) 2211 windowsMenu.addAction(self.showIndexAct)
2254 windowsMenu.addAction(self.showSearchAct) 2212 windowsMenu.addAction(self.showSearchAct)
2255 menu.addSeparator() 2213 menu.addSeparator()
2256 menu.addAction(self.stopAct) 2214 menu.addAction(self.stopAct)
2461 Public slot called to open a new web browser tab. 2419 Public slot called to open a new web browser tab.
2462 2420
2463 @param link file to be displayed in the new window (string or QUrl) 2421 @param link file to be displayed in the new window (string or QUrl)
2464 @param addNextTo reference to the browser to open the tab after 2422 @param addNextTo reference to the browser to open the tab after
2465 (WebBrowserView) 2423 (WebBrowserView)
2466 @keyparam background flag indicating to open the tab in the 2424 @param background flag indicating to open the tab in the
2467 background (bool) 2425 background (bool)
2468 @return reference to the new browser 2426 @return reference to the new browser
2469 @rtype WebBrowserView 2427 @rtype WebBrowserView
2470 """ 2428 """
2471 if addNextTo: 2429 if addNextTo:
2604 chromeVersion, webengineVersion = ( 2562 chromeVersion, webengineVersion = (
2605 WebBrowserTools.getWebEngineVersions() 2563 WebBrowserTools.getWebEngineVersions()
2606 ) 2564 )
2607 E5MessageBox.about( 2565 E5MessageBox.about(
2608 self, 2566 self,
2609 self.tr("eric6 Web Browser"), 2567 self.tr("eric Web Browser"),
2610 self.tr( 2568 self.tr(
2611 """<b>eric6 Web Browser - {0}</b>""" 2569 """<b>eric Web Browser - {0}</b>"""
2612 """<p>The eric6 Web Browser is a combined help file and HTML""" 2570 """<p>The eric Web Browser is a combined help file and HTML"""
2613 """ browser. It is part of the eric6 development""" 2571 """ browser. It is part of the eric development"""
2614 """ toolset.</p>""" 2572 """ toolset.</p>"""
2615 """<p>It is based on QtWebEngine {1} and Chrome {2}.</p>""" 2573 """<p>It is based on QtWebEngine {1} and Chrome {2}.</p>"""
2616 ).format(Version, webengineVersion, chromeVersion)) 2574 ).format(Version, webengineVersion, chromeVersion))
2617 2575
2618 def __aboutQt(self): 2576 def __aboutQt(self):
2619 """ 2577 """
2620 Private slot to show info about Qt. 2578 Private slot to show info about Qt.
2621 """ 2579 """
2622 E5MessageBox.aboutQt(self, self.tr("eric6 Web Browser")) 2580 E5MessageBox.aboutQt(self, self.tr("eric Web Browser"))
2623 2581
2624 def setBackwardAvailable(self, b): 2582 def setBackwardAvailable(self, b):
2625 """ 2583 """
2626 Public slot called when backward references are available. 2584 Public slot called when backward references are available.
2627 2585
3638 3596
3639 @param message message to be shown (string) 3597 @param message message to be shown (string)
3640 """ 3598 """
3641 E5MessageBox.warning( 3599 E5MessageBox.warning(
3642 self, 3600 self,
3643 self.tr("eric6 Web Browser"), 3601 self.tr("eric Web Browser"),
3644 message) 3602 message)
3645 3603
3646 def __docsInstalled(self, installed): 3604 def __docsInstalled(self, installed):
3647 """ 3605 """
3648 Private slot handling the end of documentation installation. 3606 Private slot handling the end of documentation installation.
4759 ########################################## 4717 ##########################################
4760 ## Support for desktop notifications below 4718 ## Support for desktop notifications below
4761 ########################################## 4719 ##########################################
4762 4720
4763 @classmethod 4721 @classmethod
4764 def showNotification(cls, icon, heading, text, timeout=None): 4722 def showNotification(cls, icon, heading, text,
4723 kind=NotificationTypes.Information, timeout=None):
4765 """ 4724 """
4766 Class method to show a desktop notification. 4725 Class method to show a desktop notification.
4767 4726
4768 @param icon icon to be shown in the notification 4727 @param icon icon to be shown in the notification
4769 @type QPixmap 4728 @type QPixmap
4770 @param heading heading of the notification 4729 @param heading heading of the notification
4771 @type str 4730 @type str
4772 @param text text of the notification 4731 @param text text of the notification
4773 @type str 4732 @type str
4733 @param kind kind of notification to be shown
4734 @type NotificationTypes
4774 @param timeout time in seconds the notification should be shown 4735 @param timeout time in seconds the notification should be shown
4775 (None = use configured timeout, 0 = indefinitely) 4736 (None = use configured timeout, 0 = indefinitely)
4776 @type int 4737 @type int
4777 """ 4738 """
4778 if Preferences.getUI("NotificationsEnabled"): 4739 if cls._notification is None:
4779 if cls._notification is None: 4740 from UI.NotificationWidget import NotificationWidget
4780 from UI.NotificationWidget import NotificationWidget 4741 cls._notification = NotificationWidget()
4781 cls._notification = NotificationWidget() 4742
4782 cls._notification.setPixmap(icon) 4743 if timeout is None:
4783 cls._notification.setHeading(heading) 4744 timeout = Preferences.getUI("NotificationTimeout")
4784 cls._notification.setText(text) 4745 cls._notification.showNotification(
4785 if timeout is None: 4746 icon, heading, text, kind=kind, timeout=timeout)
4786 timeout = Preferences.getUI("NotificationTimeout")
4787 cls._notification.setTimeout(timeout)
4788 cls._notification.move(
4789 Preferences.getUI("NotificationPosition"))
4790 cls._notification.show()
4791
4792 @classmethod
4793 def notificationsEnabled(cls):
4794 """
4795 Class method to check, if notifications are enabled.
4796
4797 @return flag indicating, if notifications are enabled (boolean)
4798 """
4799 return Preferences.getUI("NotificationsEnabled")
4800 4747
4801 ###################################### 4748 ######################################
4802 ## Support for global status bar below 4749 ## Support for global status bar below
4803 ###################################### 4750 ######################################
4804 4751

eric ide

mercurial