WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4885
362360f9a979
parent 4884
6983af705a7f
child 4886
b56735d36159
equal deleted inserted replaced
4884:6983af705a7f 4885:362360f9a979
539 hitTest = self.page().hitTestContent(evt.pos()) 539 hitTest = self.page().hitTestContent(evt.pos())
540 540
541 self.__createContextMenu(self.__menu, hitTest) 541 self.__createContextMenu(self.__menu, hitTest)
542 542
543 if not hitTest.isContentEditable() and not hitTest.isContentSelected(): 543 if not hitTest.isContentEditable() and not hitTest.isContentSelected():
544 self.__menu.addSeparator()
544 self.__menu.addAction(self.__mw.adBlockIcon().menuAction()) 545 self.__menu.addAction(self.__mw.adBlockIcon().menuAction())
545 546
546 if Preferences.getWebBrowser("WebInspectorEnabled"): 547 if Preferences.getWebBrowser("WebInspectorEnabled"):
547 self.__menu.addSeparator() 548 self.__menu.addSeparator()
548 self.__menu.addAction( 549 self.__menu.addAction(
618 menu.addAction( 619 menu.addAction(
619 UI.PixmapCache.getIcon("privateMode.png"), 620 UI.PixmapCache.getIcon("privateMode.png"),
620 self.tr("Open Link in New Private Window"), 621 self.tr("Open Link in New Private Window"),
621 self.__openLinkInNewPrivateWindow).setData(hitTest.linkUrl()) 622 self.__openLinkInNewPrivateWindow).setData(hitTest.linkUrl())
622 menu.addSeparator() 623 menu.addSeparator()
623 # TODO: Qt 5.6 624 menu.addAction(
624 ## menu.addAction( 625 UI.PixmapCache.getIcon("download.png"),
625 ## UI.PixmapCache.getIcon("download.png"), 626 self.tr("Save Lin&k"), self.__downloadLink)
626 ## self.tr("Save Lin&k"), self.__downloadLink)
627 menu.addAction( 627 menu.addAction(
628 UI.PixmapCache.getIcon("bookmark22.png"), 628 UI.PixmapCache.getIcon("bookmark22.png"),
629 self.tr("Bookmark this Link"), self.__bookmarkLink)\ 629 self.tr("Bookmark this Link"), self.__bookmarkLink)\
630 .setData(hitTest.linkUrl()) 630 .setData(hitTest.linkUrl())
631 menu.addSeparator() 631 menu.addSeparator()
659 menu.addAction( 659 menu.addAction(
660 UI.PixmapCache.getIcon("openNewTab.png"), 660 UI.PixmapCache.getIcon("openNewTab.png"),
661 self.tr("Open Image in New Tab"), 661 self.tr("Open Image in New Tab"),
662 self.__openLinkInNewTab).setData(hitTest.imageUrl()) 662 self.__openLinkInNewTab).setData(hitTest.imageUrl())
663 menu.addSeparator() 663 menu.addSeparator()
664 # TODO: Save Image 664 menu.addAction(
665 ## menu.addAction( 665 UI.PixmapCache.getIcon("download.png"),
666 ## UI.PixmapCache.getIcon("download.png"), 666 self.tr("Save Image"), self.__downloadImage)
667 ## self.tr("Save Image"), self.__downloadImage) 667 menu.addAction(
668 # TODO: Copy Image 668 self.tr("Copy Image to Clipboard"), self.__copyImage)
669 ## menu.addAction(
670 ## self.tr("Copy Image to Clipboard"), self.__copyImage)
671 menu.addAction( 669 menu.addAction(
672 UI.PixmapCache.getIcon("editCopy.png"), 670 UI.PixmapCache.getIcon("editCopy.png"),
673 self.tr("Copy Image Location to Clipboard"), 671 self.tr("Copy Image Location to Clipboard"),
674 self.__copyLink).setData(hitTest.imageUrl()) 672 self.__copyLink).setData(hitTest.imageUrl())
675 menu.addAction( 673 menu.addAction(
725 self.__copyLink).setData(hitTest.mediaUrl()) 723 self.__copyLink).setData(hitTest.mediaUrl())
726 menu.addAction( 724 menu.addAction(
727 UI.PixmapCache.getIcon("mailSend.png"), 725 UI.PixmapCache.getIcon("mailSend.png"),
728 self.tr("Send Media Address"), self.__sendLink)\ 726 self.tr("Send Media Address"), self.__sendLink)\
729 .setData(hitTest.mediaUrl()) 727 .setData(hitTest.mediaUrl())
730 # TODO: Qt 5.6 728 menu.addAction(
731 ## menu.addAction( 729 UI.PixmapCache.getIcon("download.png"),
732 ## UI.PixmapCache.getIcon("download.png"), 730 self.tr("Save Media"), self.__downloadMedia)
733 ## self.tr("Save Media"), self.__downloadMedia)
734 731
735 def __createSelectedTextContextMenu(self, menu, hitTest): 732 def __createSelectedTextContextMenu(self, menu, hitTest):
736 """ 733 """
737 Private method to populate the context menu for selected text. 734 Private method to populate the context menu for selected text.
738 735
812 menu.addAction(self.__mw.newAct) 809 menu.addAction(self.__mw.newAct)
813 menu.addSeparator() 810 menu.addSeparator()
814 # TODO: Save 811 # TODO: Save
815 ## menu.addAction(self.__mw.saveAsAct) 812 ## menu.addAction(self.__mw.saveAsAct)
816 ## menu.addSeparator() 813 ## menu.addSeparator()
814
815 # TODO: Speed Dial
816 if self.url().toString() == "eric:speeddial":
817 # special menu for the spedd dial page
818 menu.addAction(self.__mw.backAct)
819 menu.addAction(self.__mw.forwardAct)
820 menu.addSeparator()
821 menu.addAction(
822 UI.PixmapCache.getIcon("plus.png"),
823 self.tr("Add New Page"), self.__addSpeedDial)
824 menu.addAction(
825 UI.PixmapCache.getIcon("preferences-general.png"),
826 self.tr("Configure Speed Dial"), self.__configureSpeedDial)
827 menu.addSeparator()
828 menu.addAction(
829 UI.PixmapCache.getIcon("reload.png"),
830 self.tr("Reload All Dials"), self.__reloadAllSpeedDials)
831 return
817 832
818 menu.addAction( 833 menu.addAction(
819 UI.PixmapCache.getIcon("bookmark22.png"), 834 UI.PixmapCache.getIcon("bookmark22.png"),
820 self.tr("Bookmark this Page"), self.addBookmark) 835 self.tr("Bookmark this Page"), self.addBookmark)
821 menu.addAction( 836 menu.addAction(
1004 1019
1005 if isinstance(data, QUrl): 1020 if isinstance(data, QUrl):
1006 data = data.toString() 1021 data = data.toString()
1007 QApplication.clipboard().setText(data) 1022 QApplication.clipboard().setText(data)
1008 1023
1009 # TODO: Qt 5.6 1024 def __downloadLink(self):
1010 ## def __downloadLink(self): 1025 """
1011 ## """ 1026 Private slot to download a link and save it to disk.
1012 ## Private slot to download a link and save it to disk. 1027 """
1013 ## """ 1028 self.triggerPageAction(QWebEnginePage.DownloadLinkToDisk)
1014 ## self.triggerPageAction(QWebEnginePage.DownloadLinkToDisk) 1029
1015 ## 1030 def __downloadImage(self):
1016 ## def __downloadImage(self): 1031 """
1017 ## """ 1032 Private slot to download an image and save it to disk.
1018 ## Private slot to download an image and save it to disk. 1033 """
1019 ## """ 1034 self.triggerPageAction(QWebEnginePage.DownloadImageToDisk)
1020 ## self.triggerPageAction(QWebEnginePage.DownloadImageToDisk) 1035
1021 ## 1036 def __copyImage(self):
1022 ## def __copyImage(self): 1037 """
1023 ## """ 1038 Private slot to copy an image to the clipboard.
1024 ## Private slot to copy an image to the clipboard. 1039 """
1025 ## """ 1040 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
1026 ## self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
1027 1041
1028 def __blockImage(self): 1042 def __blockImage(self):
1029 """ 1043 """
1030 Private slot to add a block rule for an image URL. 1044 Private slot to add a block rule for an image URL.
1031 """ 1045 """
1033 act = self.sender() 1047 act = self.sender()
1034 url = act.data() 1048 url = act.data()
1035 dlg = WebBrowserWindow.adBlockManager().showDialog() 1049 dlg = WebBrowserWindow.adBlockManager().showDialog()
1036 dlg.addCustomRule(url) 1050 dlg.addCustomRule(url)
1037 1051
1038 # TODO: Qt 5.6 1052 def __downloadMedia(self):
1039 ## def __downloadMedia(self): 1053 """
1040 ## """ 1054 Private slot to download a media and save it to disk.
1041 ## Private slot to download a media and save it to disk. 1055 """
1042 ## """ 1056 self.triggerPageAction(QWebEnginePage.DownloadMediaToDisk)
1043 ## self.triggerPageAction(QWebEnginePage.DownloadMediaToDisk)
1044 1057
1045 # TODO: Qt 5.6: do this with triggerPageAction() 1058 # TODO: Qt 5.6: do this with triggerPageAction()
1046 def __pauseMedia(self): 1059 def __pauseMedia(self):
1047 """ 1060 """
1048 Private slot to pause or play the selected media. 1061 Private slot to pause or play the selected media.
1049 """ 1062 """
1050 from .Tools import Scripts 1063 self.triggerPageAction(QWebEnginePage.ToggleMediaPlayPause)
1051 script = Scripts.toggleMediaPause(self.__clickedPos) 1064 ## from .Tools import Scripts
1052 self.page().runJavaScript(script) 1065 ## script = Scripts.toggleMediaPause(self.__clickedPos)
1066 ## self.page().runJavaScript(script)
1053 1067
1054 # TODO: Qt 5.6: do this with triggerPageAction() 1068 # TODO: Qt 5.6: do this with triggerPageAction()
1055 def __muteMedia(self): 1069 def __muteMedia(self):
1056 """ 1070 """
1057 Private slot to (un)mute the selected media. 1071 Private slot to (un)mute the selected media.
1058 """ 1072 """
1059 from .Tools import Scripts 1073 self.triggerPageAction(QWebEnginePage.ToggleMediaMute)
1060 script = Scripts.toggleMediaMute(self.__clickedPos) 1074 ## from .Tools import Scripts
1061 self.page().runJavaScript(script) 1075 ## script = Scripts.toggleMediaMute(self.__clickedPos)
1076 ## self.page().runJavaScript(script)
1062 1077
1063 def __virusTotal(self): 1078 def __virusTotal(self):
1064 """ 1079 """
1065 Private slot to scan the selected URL with VirusTotal. 1080 Private slot to scan the selected URL with VirusTotal.
1066 """ 1081 """
1954 self.__mw.enterHtmlFullScreen() 1969 self.__mw.enterHtmlFullScreen()
1955 else: 1970 else:
1956 self.__mw.showNormal() 1971 self.__mw.showNormal()
1957 1972
1958 ########################################################################### 1973 ###########################################################################
1959 ## Clicked Frame slots 1974 ## Speed Dial slots below
1960 ########################################################################### 1975 ###########################################################################
1961 1976
1962 ## def __loadClickedFrame(self): 1977 def __addSpeedDial(self):
1963 ## """ 1978 """
1964 ## Private slot to load the selected frame only. 1979 Private slot to add a new speed dial.
1965 ## """ 1980 """
1966 ## self.setSource(self.__clickedFrame.url()) 1981 self.__page.runJavaScript("addSpeedDial();")
1967 ## 1982
1968 ## def __printClickedFrame(self): 1983 def __configureSpeedDial(self):
1969 ## """ 1984 """
1970 ## Private slot to print the selected frame. 1985 Private slot to configure the speed dial.
1971 ## """ 1986 """
1972 ## printer = QPrinter(mode=QPrinter.HighResolution) 1987 self.page().runJavaScript("configureSpeedDial();")
1973 ## if Preferences.getPrinter("ColorMode"): 1988
1974 ## printer.setColorMode(QPrinter.Color) 1989 def __reloadAllSpeedDials(self):
1975 ## else: 1990 """
1976 ## printer.setColorMode(QPrinter.GrayScale) 1991 Private slot to reload all speed dials.
1977 ## if Preferences.getPrinter("FirstPageFirst"): 1992 """
1978 ## printer.setPageOrder(QPrinter.FirstPageFirst) 1993 self.page().runJavaScript("reloadAll();")
1979 ## else:
1980 ## printer.setPageOrder(QPrinter.LastPageFirst)
1981 ## printer.setPageMargins(
1982 ## Preferences.getPrinter("LeftMargin") * 10,
1983 ## Preferences.getPrinter("TopMargin") * 10,
1984 ## Preferences.getPrinter("RightMargin") * 10,
1985 ## Preferences.getPrinter("BottomMargin") * 10,
1986 ## QPrinter.Millimeter
1987 ## )
1988 ## printerName = Preferences.getPrinter("PrinterName")
1989 ## if printerName:
1990 ## printer.setPrinterName(printerName)
1991 ##
1992 ## printDialog = QPrintDialog(printer, self)
1993 ## if printDialog.exec_() == QDialog.Accepted:
1994 ## try:
1995 ## self.__clickedFrame.print_(printer)
1996 ## except AttributeError:
1997 ## E5MessageBox.critical(
1998 ## self,
1999 ## self.tr("eric6 Web Browser"),
2000 ## self.tr(
2001 ## """<p>Printing is not available due to a bug in"""
2002 ## """ PyQt5. Please upgrade.</p>"""))
2003 ##
2004 ## def __printPreviewClickedFrame(self):
2005 ## """
2006 ## Private slot to show a print preview of the clicked frame.
2007 ## """
2008 ## from PyQt5.QtPrintSupport import QPrintPreviewDialog
2009 ##
2010 ## printer = QPrinter(mode=QPrinter.HighResolution)
2011 ## if Preferences.getPrinter("ColorMode"):
2012 ## printer.setColorMode(QPrinter.Color)
2013 ## else:
2014 ## printer.setColorMode(QPrinter.GrayScale)
2015 ## if Preferences.getPrinter("FirstPageFirst"):
2016 ## printer.setPageOrder(QPrinter.FirstPageFirst)
2017 ## else:
2018 ## printer.setPageOrder(QPrinter.LastPageFirst)
2019 ## printer.setPageMargins(
2020 ## Preferences.getPrinter("LeftMargin") * 10,
2021 ## Preferences.getPrinter("TopMargin") * 10,
2022 ## Preferences.getPrinter("RightMargin") * 10,
2023 ## Preferences.getPrinter("BottomMargin") * 10,
2024 ## QPrinter.Millimeter
2025 ## )
2026 ## printerName = Preferences.getPrinter("PrinterName")
2027 ## if printerName:
2028 ## printer.setPrinterName(printerName)
2029 ##
2030 ## preview = QPrintPreviewDialog(printer, self)
2031 ## preview.paintRequested.connect(self.__generatePrintPreviewClickedFrame)
2032 ## preview.exec_()
2033 ##
2034 ## def __generatePrintPreviewClickedFrame(self, printer):
2035 ## """
2036 ## Private slot to generate a print preview of the clicked frame.
2037 ##
2038 ## @param printer reference to the printer object (QPrinter)
2039 ## """
2040 ## try:
2041 ## self.__clickedFrame.print_(printer)
2042 ## except AttributeError:
2043 ## E5MessageBox.critical(
2044 ## self,
2045 ## self.tr("eric6 Web Browser"),
2046 ## self.tr(
2047 ## """<p>Printing is not available due to a bug in PyQt5."""
2048 ## """Please upgrade.</p>"""))
2049 ## return
2050 ##
2051 ## def __printPdfClickedFrame(self):
2052 ## """
2053 ## Private slot to print the selected frame to PDF.
2054 ## """
2055 ## printer = QPrinter(mode=QPrinter.HighResolution)
2056 ## if Preferences.getPrinter("ColorMode"):
2057 ## printer.setColorMode(QPrinter.Color)
2058 ## else:
2059 ## printer.setColorMode(QPrinter.GrayScale)
2060 ## printerName = Preferences.getPrinter("PrinterName")
2061 ## if printerName:
2062 ## printer.setPrinterName(printerName)
2063 ## printer.setOutputFormat(QPrinter.PdfFormat)
2064 ## name = self.__clickedFrame.url().path().rsplit('/', 1)[-1]
2065 ## if name:
2066 ## name = name.rsplit('.', 1)[0]
2067 ## name += '.pdf'
2068 ## printer.setOutputFileName(name)
2069 ##
2070 ## printDialog = QPrintDialog(printer, self)
2071 ## if printDialog.exec_() == QDialog.Accepted:
2072 ## try:
2073 ## self.__clickedFrame.print_(printer)
2074 ## except AttributeError:
2075 ## E5MessageBox.critical(
2076 ## self,
2077 ## self.tr("eric6 Web Browser"),
2078 ## self.tr(
2079 ## """<p>Printing is not available due to a bug in"""
2080 ## """ PyQt5. Please upgrade.</p>"""))
2081 ## return
2082 ##
2083 ## def __zoomInClickedFrame(self):
2084 ## """
2085 ## Private slot to zoom into the clicked frame.
2086 ## """
2087 ## index = self.__levelForZoom(
2088 ## int(self.__clickedFrame.zoomFactor() * 100))
2089 ## if index < len(self.__zoomLevels) - 1:
2090 ## self.__clickedFrame.setZoomFactor(
2091 ## self.__zoomLevels[index + 1] / 100)
2092 ##
2093 ## def __zoomResetClickedFrame(self):
2094 ## """
2095 ## Private slot to reset the zoom factor of the clicked frame.
2096 ## """
2097 ## self.__clickedFrame.setZoomFactor(self.__currentZoom / 100)
2098 ##
2099 ## def __zoomOutClickedFrame(self):
2100 ## """
2101 ## Private slot to zoom out of the clicked frame.
2102 ## """
2103 ## index = self.__levelForZoom(
2104 ## int(self.__clickedFrame.zoomFactor() * 100))
2105 ## if index > 0:
2106 ## self.__clickedFrame.setZoomFactor(
2107 ## self.__zoomLevels[index - 1] / 100)
2108 ##
2109 ## def __showClickedFrameSource(self):
2110 ## """
2111 ## Private slot to show the source of the clicked frame.
2112 ## """
2113 ## from QScintilla.MiniEditor import MiniEditor
2114 ## src = self.__clickedFrame.toHtml()
2115 ## editor = MiniEditor(parent=self)
2116 ## editor.setText(src, "Html")
2117 ## editor.setLanguage("dummy.html")
2118 ## editor.show()
2119
2120 1994
2121 ##def contentSniff(data): 1995 ##def contentSniff(data):
2122 ## """ 1996 ## """
2123 ## Module function to do some content sniffing to check, if the data is HTML. 1997 ## Module function to do some content sniffing to check, if the data is HTML.
2124 ## 1998 ##

eric ide

mercurial