WebBrowser/WebBrowserView.py

branch
maintenance
changeset 6166
bace7fb85a01
parent 6097
bf18415da0c7
parent 6155
ae44225e7e7c
child 6273
0daf79d65080
equal deleted inserted replaced
6114:0c976706e8c1 6166:bace7fb85a01
14 except NameError: 14 except NameError:
15 pass 15 pass
16 16
17 import os 17 import os
18 18
19 from PyQt5.QtCore import pyqtSignal, PYQT_VERSION, Qt, QUrl, QFileInfo, \ 19 from PyQt5.QtCore import pyqtSignal, pyqtSlot, PYQT_VERSION, Qt, QUrl, \
20 QTimer, QEvent, QPoint, QPointF, QDateTime, QStandardPaths, QByteArray, \ 20 QFileInfo, QTimer, QEvent, QPoint, QPointF, QDateTime, QStandardPaths, \
21 QIODevice, QDataStream 21 QByteArray, QIODevice, QDataStream
22 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ 22 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \
23 QContextMenuEvent, QPixmap 23 QContextMenuEvent, QPixmap
24 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication 24 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication
25 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ 25 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \
26 QWebEngineDownloadItem 26 QWebEngineDownloadItem
150 self.__page = WebBrowserPage(self) 150 self.__page = WebBrowserPage(self)
151 self.setPage(self.__page) 151 self.setPage(self.__page)
152 152
153 self.__page.safeBrowsingAbort.connect(self.safeBrowsingAbort) 153 self.__page.safeBrowsingAbort.connect(self.safeBrowsingAbort)
154 self.__page.safeBrowsingBad.connect(self.safeBrowsingBad) 154 self.__page.safeBrowsingBad.connect(self.safeBrowsingBad)
155 self.__page.printRequested.connect(self.__printPage)
155 156
156 def __setRwhvqt(self): 157 def __setRwhvqt(self):
157 """ 158 """
158 Private slot to set widget that receives input events. 159 Private slot to set widget that receives input events.
159 """ 160 """
186 Public method to load a web site. 187 Public method to load a web site.
187 188
188 @param url URL to be loaded 189 @param url URL to be loaded
189 @type QUrl 190 @type QUrl
190 """ 191 """
192 if self.__page is not None and \
193 not self.__page.acceptNavigationRequest(
194 url, QWebEnginePage.NavigationTypeTyped, True):
195 return
196
191 super(WebBrowserView, self).load(url) 197 super(WebBrowserView, self).load(url)
192 198
193 if not self.__firstLoad: 199 if not self.__firstLoad:
194 self.__firstLoad = True 200 self.__firstLoad = True
195 WebInspector.pushView(self) 201 WebInspector.pushView(self)
554 bool(contextMenuData.misspelledWord()): 560 bool(contextMenuData.misspelledWord()):
555 boldFont = menu.font() 561 boldFont = menu.font()
556 boldFont.setBold(True) 562 boldFont.setBold(True)
557 563
558 for suggestion in contextMenuData.spellCheckerSuggestions(): 564 for suggestion in contextMenuData.spellCheckerSuggestions():
559 act = menu.addAction( 565 act = menu.addAction(suggestion)
560 suggestion,
561 self.__replaceMisspelledWord)
562 act.setFont(boldFont) 566 act.setFont(boldFont)
567 act.triggered.connect(
568 lambda: self.__replaceMisspelledWord)(act)
563 569
564 if not bool(menu.actions()): 570 if not bool(menu.actions()):
565 menu.addAction(self.tr("No suggestions")).setEnabled(False) 571 menu.addAction(self.tr("No suggestions")).setEnabled(False)
566 572
567 menu.addSeparator() 573 menu.addSeparator()
612 @type WebHitTestResult 618 @type WebHitTestResult
613 """ 619 """
614 if not menu.isEmpty(): 620 if not menu.isEmpty():
615 menu.addSeparator() 621 menu.addSeparator()
616 622
617 menu.addAction( 623 act = menu.addAction(
618 UI.PixmapCache.getIcon("openNewTab.png"), 624 UI.PixmapCache.getIcon("openNewTab.png"),
619 self.tr("Open Link in New Tab\tCtrl+LMB"), 625 self.tr("Open Link in New Tab\tCtrl+LMB"))
620 self.__openLinkInNewTab).setData(hitTest.linkUrl()) 626 act.setData(hitTest.linkUrl())
621 menu.addAction( 627 act.triggered.connect(
628 lambda: self.__openLinkInNewTab(act))
629 act = menu.addAction(
622 UI.PixmapCache.getIcon("newWindow.png"), 630 UI.PixmapCache.getIcon("newWindow.png"),
623 self.tr("Open Link in New Window"), 631 self.tr("Open Link in New Window"))
624 self.__openLinkInNewWindow).setData(hitTest.linkUrl()) 632 act.setData(hitTest.linkUrl())
625 menu.addAction( 633 act.triggered.connect(
634 lambda: self.__openLinkInNewWindow(act))
635 act = menu.addAction(
626 UI.PixmapCache.getIcon("privateMode.png"), 636 UI.PixmapCache.getIcon("privateMode.png"),
627 self.tr("Open Link in New Private Window"), 637 self.tr("Open Link in New Private Window"))
628 self.__openLinkInNewPrivateWindow).setData(hitTest.linkUrl()) 638 act.setData(hitTest.linkUrl())
639 act.triggered.connect(
640 lambda: self.__openLinkInNewPrivateWindow(act))
629 menu.addSeparator() 641 menu.addSeparator()
630 menu.addAction( 642 menu.addAction(
631 UI.PixmapCache.getIcon("download.png"), 643 UI.PixmapCache.getIcon("download.png"),
632 self.tr("Save Lin&k"), self.__downloadLink) 644 self.tr("Save Lin&k"), self.__downloadLink)
633 menu.addAction( 645 act = menu.addAction(
634 UI.PixmapCache.getIcon("bookmark22.png"), 646 UI.PixmapCache.getIcon("bookmark22.png"),
635 self.tr("Bookmark this Link"), self.__bookmarkLink)\ 647 self.tr("Bookmark this Link"))
636 .setData(hitTest.linkUrl()) 648 act.setData(hitTest.linkUrl())
649 act.triggered.connect(
650 lambda: self.__bookmarkLink(act))
637 menu.addSeparator() 651 menu.addSeparator()
638 menu.addAction( 652 act = menu.addAction(
639 UI.PixmapCache.getIcon("editCopy.png"), 653 UI.PixmapCache.getIcon("editCopy.png"),
640 self.tr("Copy Link to Clipboard"), self.__copyLink)\ 654 self.tr("Copy Link to Clipboard"))
641 .setData(hitTest.linkUrl()) 655 act.setData(hitTest.linkUrl())
642 menu.addAction( 656 act.triggered.connect(
657 lambda: self.__copyLink(act))
658 act = menu.addAction(
643 UI.PixmapCache.getIcon("mailSend.png"), 659 UI.PixmapCache.getIcon("mailSend.png"),
644 self.tr("Send Link"), 660 self.tr("Send Link"))
645 self.__sendLink).setData(hitTest.linkUrl()) 661 act.setData(hitTest.linkUrl())
662 act.triggered.connect(
663 lambda: self.__sendLink(act))
646 if Preferences.getWebBrowser("VirusTotalEnabled") and \ 664 if Preferences.getWebBrowser("VirusTotalEnabled") and \
647 Preferences.getWebBrowser("VirusTotalServiceKey") != "": 665 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
648 menu.addAction( 666 act = menu.addAction(
649 UI.PixmapCache.getIcon("virustotal.png"), 667 UI.PixmapCache.getIcon("virustotal.png"),
650 self.tr("Scan Link with VirusTotal"), 668 self.tr("Scan Link with VirusTotal"))
651 self.__virusTotal).setData(hitTest.linkUrl()) 669 act.setData(hitTest.linkUrl())
670 act.triggered.connect(
671 lambda: self.__virusTotal(act))
652 672
653 def __createImageContextMenu(self, menu, hitTest): 673 def __createImageContextMenu(self, menu, hitTest):
654 """ 674 """
655 Private method to populate the context menu for images. 675 Private method to populate the context menu for images.
656 676
660 @type WebHitTestResult 680 @type WebHitTestResult
661 """ 681 """
662 if not menu.isEmpty(): 682 if not menu.isEmpty():
663 menu.addSeparator() 683 menu.addSeparator()
664 684
665 menu.addAction( 685 act = menu.addAction(
666 UI.PixmapCache.getIcon("openNewTab.png"), 686 UI.PixmapCache.getIcon("openNewTab.png"),
667 self.tr("Open Image in New Tab"), 687 self.tr("Open Image in New Tab"))
668 self.__openLinkInNewTab).setData(hitTest.imageUrl()) 688 act.setData(hitTest.imageUrl())
689 act.triggered.connect(
690 lambda: self.__openLinkInNewTab(act))
669 menu.addSeparator() 691 menu.addSeparator()
670 menu.addAction( 692 menu.addAction(
671 UI.PixmapCache.getIcon("download.png"), 693 UI.PixmapCache.getIcon("download.png"),
672 self.tr("Save Image"), self.__downloadImage) 694 self.tr("Save Image"), self.__downloadImage)
673 menu.addAction( 695 menu.addAction(
674 self.tr("Copy Image to Clipboard"), self.__copyImage) 696 self.tr("Copy Image to Clipboard"), self.__copyImage)
675 menu.addAction( 697 act = menu.addAction(
676 UI.PixmapCache.getIcon("editCopy.png"), 698 UI.PixmapCache.getIcon("editCopy.png"),
677 self.tr("Copy Image Location to Clipboard"), 699 self.tr("Copy Image Location to Clipboard"))
678 self.__copyLink).setData(hitTest.imageUrl()) 700 act.setData(hitTest.imageUrl())
679 menu.addAction( 701 act.triggered.connect(
702 lambda: self.__copyLink(act))
703 act = menu.addAction(
680 UI.PixmapCache.getIcon("mailSend.png"), 704 UI.PixmapCache.getIcon("mailSend.png"),
681 self.tr("Send Image Link"), 705 self.tr("Send Image Link"))
682 self.__sendLink).setData(hitTest.imageUrl()) 706 act.setData(hitTest.imageUrl())
707 act.triggered.connect(
708 lambda: self.__sendLink(act))
683 709
684 if hitTest.imageUrl().scheme() in ["http", "https"]: 710 if hitTest.imageUrl().scheme() in ["http", "https"]:
685 menu.addSeparator() 711 menu.addSeparator()
686 engine = WebBrowserWindow.imageSearchEngine() 712 engine = WebBrowserWindow.imageSearchEngine()
687 searchEngineName = engine.searchEngine() 713 searchEngineName = engine.searchEngine()
688 menu.addAction( 714 act = menu.addAction(
689 UI.PixmapCache.getIcon("{0}.png".format( 715 UI.PixmapCache.getIcon("{0}.png".format(
690 searchEngineName.lower())), 716 searchEngineName.lower())),
691 self.tr("Search image in {0}").format(searchEngineName), 717 self.tr("Search image in {0}").format(searchEngineName))
692 self.__searchImage).setData( 718 act.setData(engine.getSearchQuery(hitTest.imageUrl()))
693 engine.getSearchQuery(hitTest.imageUrl())) 719 act.triggered.connect(
720 lambda: self.__searchImage(act))
694 self.__imageSearchMenu = menu.addMenu( 721 self.__imageSearchMenu = menu.addMenu(
695 self.tr("Search image with...")) 722 self.tr("Search image with..."))
696 for searchEngineName in engine.searchEngineNames(): 723 for searchEngineName in engine.searchEngineNames():
697 self.__imageSearchMenu.addAction( 724 act = self.__imageSearchMenu.addAction(
698 UI.PixmapCache.getIcon("{0}.png".format( 725 UI.PixmapCache.getIcon("{0}.png".format(
699 searchEngineName.lower())), 726 searchEngineName.lower())),
700 self.tr("Search image in {0}").format(searchEngineName), 727 self.tr("Search image in {0}").format(searchEngineName))
701 self.__searchImage).setData( 728 act.setData(engine.getSearchQuery(
702 engine.getSearchQuery( 729 hitTest.imageUrl(), searchEngineName))
703 hitTest.imageUrl(), searchEngineName)) 730 act.triggered.connect(
731 lambda: self.__searchImage(act))
704 732
705 menu.addSeparator() 733 menu.addSeparator()
706 menu.addAction( 734 act = menu.addAction(
707 UI.PixmapCache.getIcon("adBlockPlus.png"), 735 UI.PixmapCache.getIcon("adBlockPlus.png"),
708 self.tr("Block Image"), self.__blockImage)\ 736 self.tr("Block Image"))
709 .setData(hitTest.imageUrl().toString()) 737 act.setData(hitTest.imageUrl().toString())
738 act.triggered.connect(
739 lambda: self.__blockImage(act))
710 if Preferences.getWebBrowser("VirusTotalEnabled") and \ 740 if Preferences.getWebBrowser("VirusTotalEnabled") and \
711 Preferences.getWebBrowser("VirusTotalServiceKey") != "": 741 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
712 menu.addAction( 742 act = menu.addAction(
713 UI.PixmapCache.getIcon("virustotal.png"), 743 UI.PixmapCache.getIcon("virustotal.png"),
714 self.tr("Scan Image with VirusTotal"), 744 self.tr("Scan Image with VirusTotal"))
715 self.__virusTotal).setData(hitTest.imageUrl()) 745 act.setData(hitTest.imageUrl())
746 act.triggered.connect(
747 lambda: self.__virusTotal(act))
716 748
717 def __createMediaContextMenu(self, menu, hitTest): 749 def __createMediaContextMenu(self, menu, hitTest):
718 """ 750 """
719 Private method to populate the context menu for media elements. 751 Private method to populate the context menu for media elements.
720 752
741 else: 773 else:
742 menu.addAction( 774 menu.addAction(
743 UI.PixmapCache.getIcon("audioVolumeMuted.png"), 775 UI.PixmapCache.getIcon("audioVolumeMuted.png"),
744 self.tr("Mute"), self.__muteMedia) 776 self.tr("Mute"), self.__muteMedia)
745 menu.addSeparator() 777 menu.addSeparator()
746 menu.addAction( 778 act = menu.addAction(
747 UI.PixmapCache.getIcon("editCopy.png"), 779 UI.PixmapCache.getIcon("editCopy.png"),
748 self.tr("Copy Media Address to Clipboard"), 780 self.tr("Copy Media Address to Clipboard"))
749 self.__copyLink).setData(hitTest.mediaUrl()) 781 act.setData(hitTest.mediaUrl())
750 menu.addAction( 782 act.triggered.connect(
783 lambda: self.__copyLink(act))
784 act = menu.addAction(
751 UI.PixmapCache.getIcon("mailSend.png"), 785 UI.PixmapCache.getIcon("mailSend.png"),
752 self.tr("Send Media Address"), self.__sendLink)\ 786 self.tr("Send Media Address"))
753 .setData(hitTest.mediaUrl()) 787 act.setData(hitTest.mediaUrl())
788 act.triggered.connect(
789 lambda: self.__sendLink(act))
754 menu.addAction( 790 menu.addAction(
755 UI.PixmapCache.getIcon("download.png"), 791 UI.PixmapCache.getIcon("download.png"),
756 self.tr("Save Media"), self.__downloadMedia) 792 self.tr("Save Media"), self.__downloadMedia)
757 793
758 def __createSelectedTextContextMenu(self, menu, hitTest): 794 def __createSelectedTextContextMenu(self, menu, hitTest):
767 if not menu.isEmpty(): 803 if not menu.isEmpty():
768 menu.addSeparator() 804 menu.addSeparator()
769 805
770 menu.addAction(self.__mw.copyAct) 806 menu.addAction(self.__mw.copyAct)
771 menu.addSeparator() 807 menu.addSeparator()
772 menu.addAction( 808 act = menu.addAction(
773 UI.PixmapCache.getIcon("mailSend.png"), 809 UI.PixmapCache.getIcon("mailSend.png"),
774 self.tr("Send Text"), 810 self.tr("Send Text"))
775 self.__sendLink).setData(self.selectedText()) 811 act.setData(self.selectedText())
812 act.triggered.connect(
813 lambda: self.__sendLink(act))
776 814
777 engineName = self.__mw.openSearchManager().currentEngineName() 815 engineName = self.__mw.openSearchManager().currentEngineName()
778 if engineName: 816 if engineName:
779 menu.addAction(self.tr("Search with '{0}'").format(engineName), 817 menu.addAction(self.tr("Search with '{0}'").format(engineName),
780 self.__searchDefaultRequested) 818 self.__searchDefaultRequested)
802 language = languages[0] 840 language = languages[0]
803 langCode = language.split("[")[1][:2] 841 langCode = language.split("[")[1][:2]
804 googleTranslatorUrl = QUrl( 842 googleTranslatorUrl = QUrl(
805 "http://translate.google.com/#auto/{0}/{1}".format( 843 "http://translate.google.com/#auto/{0}/{1}".format(
806 langCode, self.selectedText())) 844 langCode, self.selectedText()))
807 menu.addAction( 845 act = menu.addAction(
808 UI.PixmapCache.getIcon("translate.png"), 846 UI.PixmapCache.getIcon("translate.png"),
809 self.tr("Google Translate"), self.__openLinkInNewTab)\ 847 self.tr("Google Translate"))
810 .setData(googleTranslatorUrl) 848 act.setData(googleTranslatorUrl)
849 act.triggered.connect(
850 lambda: self.__openLinkInNewTab(act))
811 wiktionaryUrl = QUrl( 851 wiktionaryUrl = QUrl(
812 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" 852 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
813 .format(langCode, self.selectedText())) 853 .format(langCode, self.selectedText()))
814 menu.addAction( 854 act = menu.addAction(
815 UI.PixmapCache.getIcon("wikipedia.png"), 855 UI.PixmapCache.getIcon("wikipedia.png"),
816 self.tr("Dictionary"), self.__openLinkInNewTab)\ 856 self.tr("Dictionary"))
817 .setData(wiktionaryUrl) 857 act.setData(wiktionaryUrl)
858 act.triggered.connect(
859 lambda: self.__openLinkInNewTab(act))
818 menu.addSeparator() 860 menu.addSeparator()
819 861
820 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) 862 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
821 if self.__isUrlValid(guessedUrl): 863 if self.__isUrlValid(guessedUrl):
822 menu.addAction( 864 act = menu.addAction(self.tr("Go to web address"))
823 self.tr("Go to web address"), 865 act.setData(guessedUrl)
824 self.__openLinkInNewTab).setData(guessedUrl) 866 act.triggered.connect(
867 lambda: self.__openLinkInNewTab(act))
825 868
826 def __createPageContextMenu(self, menu): 869 def __createPageContextMenu(self, menu):
827 """ 870 """
828 Private method to populate the basic context menu. 871 Private method to populate the basic context menu.
829 872
833 menu.addAction(self.__mw.newTabAct) 876 menu.addAction(self.__mw.newTabAct)
834 menu.addAction(self.__mw.newAct) 877 menu.addAction(self.__mw.newAct)
835 menu.addSeparator() 878 menu.addSeparator()
836 if self.__mw.saveAsAct is not None: 879 if self.__mw.saveAsAct is not None:
837 menu.addAction(self.__mw.saveAsAct) 880 menu.addAction(self.__mw.saveAsAct)
838 menu.addSeparator() 881 menu.addAction(self.__mw.saveVisiblePageScreenAct)
882 menu.addSeparator()
839 883
840 if self.url().toString() == "eric:speeddial": 884 if self.url().toString() == "eric:speeddial":
841 # special menu for the spedd dial page 885 # special menu for the spedd dial page
842 menu.addAction(self.__mw.backAct) 886 menu.addAction(self.__mw.backAct)
843 menu.addAction(self.__mw.forwardAct) 887 menu.addAction(self.__mw.forwardAct)
858 return 902 return
859 903
860 menu.addAction( 904 menu.addAction(
861 UI.PixmapCache.getIcon("bookmark22.png"), 905 UI.PixmapCache.getIcon("bookmark22.png"),
862 self.tr("Bookmark this Page"), self.addBookmark) 906 self.tr("Bookmark this Page"), self.addBookmark)
863 menu.addAction( 907 act = menu.addAction(
864 UI.PixmapCache.getIcon("editCopy.png"), 908 UI.PixmapCache.getIcon("editCopy.png"),
865 self.tr("Copy Page Link"), self.__copyLink).setData(self.url()) 909 self.tr("Copy Page Link"))
866 menu.addAction( 910 act.setData(self.url())
911 act.triggered.connect(
912 lambda: self.__copyLink(act))
913 act = menu.addAction(
867 UI.PixmapCache.getIcon("mailSend.png"), 914 UI.PixmapCache.getIcon("mailSend.png"),
868 self.tr("Send Page Link"), self.__sendLink).setData(self.url()) 915 self.tr("Send Page Link"))
916 act.setData(self.url())
917 act.triggered.connect(
918 lambda: self.__sendLink(act))
869 menu.addSeparator() 919 menu.addSeparator()
870 920
871 from .UserAgent.UserAgentMenu import UserAgentMenu 921 from .UserAgent.UserAgentMenu import UserAgentMenu
872 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"), 922 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
873 url=self.url()) 923 url=self.url())
894 menu.addSeparator() 944 menu.addSeparator()
895 945
896 w3url = QUrl.fromEncoded( 946 w3url = QUrl.fromEncoded(
897 b"http://validator.w3.org/check?uri=" + 947 b"http://validator.w3.org/check?uri=" +
898 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode())) 948 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode()))
899 menu.addAction( 949 act = menu.addAction(
900 UI.PixmapCache.getIcon("w3.png"), 950 UI.PixmapCache.getIcon("w3.png"),
901 self.tr("Validate Page"), self.__openLinkInNewTab)\ 951 self.tr("Validate Page"))
902 .setData(w3url) 952 act.setData(w3url)
953 act.triggered.connect(
954 lambda: self.__openLinkInNewTab(act))
903 955
904 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog 956 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
905 languages = Preferences.toList( 957 languages = Preferences.toList(
906 Preferences.Prefs.settings.value( 958 Preferences.Prefs.settings.value(
907 "WebBrowser/AcceptLanguages", 959 "WebBrowser/AcceptLanguages",
913 b"http://translate.google.com/translate?sl=auto&tl=" + 965 b"http://translate.google.com/translate?sl=auto&tl=" +
914 langCode.encode() + 966 langCode.encode() +
915 b"&u=" + 967 b"&u=" +
916 QUrl.toPercentEncoding( 968 QUrl.toPercentEncoding(
917 bytes(self.url().toEncoded()).decode())) 969 bytes(self.url().toEncoded()).decode()))
918 menu.addAction( 970 act = menu.addAction(
919 UI.PixmapCache.getIcon("translate.png"), 971 UI.PixmapCache.getIcon("translate.png"),
920 self.tr("Google Translate"), self.__openLinkInNewTab)\ 972 self.tr("Google Translate"))
921 .setData(googleTranslatorUrl) 973 act.setData(googleTranslatorUrl)
922 974 act.triggered.connect(
975 lambda: self.__openLinkInNewTab(act))
976
923 def __checkForForm(self, act, pos): 977 def __checkForForm(self, act, pos):
924 """ 978 """
925 Private method to check the given position for an open search form. 979 Private method to check the given position for an open search form.
926 980
927 @param act reference to the action to be populated upon success 981 @param act reference to the action to be populated upon success
968 return url.isValid() and \ 1022 return url.isValid() and \
969 bool(url.host()) and \ 1023 bool(url.host()) and \
970 bool(url.scheme()) and \ 1024 bool(url.scheme()) and \
971 "." in url.host() 1025 "." in url.host()
972 1026
973 def __replaceMisspelledWord(self): 1027 def __replaceMisspelledWord(self, act):
974 """ 1028 """
975 Private slot to replace a misspelled word under the context menu. 1029 Private slot to replace a misspelled word under the context menu.
976 """ 1030
977 act = self.sender() 1031 @param act reference to the action that triggered
1032 @type QAction
1033 """
978 suggestion = act.text() 1034 suggestion = act.text()
979 self.page().replaceMisspelledWord(suggestion) 1035 self.page().replaceMisspelledWord(suggestion)
980 1036
981 def __openLinkInNewTab(self): 1037 def __openLinkInNewTab(self, act):
982 """ 1038 """
983 Private method called by the context menu to open a link in a new 1039 Private method called by the context menu to open a link in a new
984 tab. 1040 tab.
985 """ 1041
986 act = self.sender() 1042 @param act reference to the action that triggered
1043 @type QAction
1044 """
987 url = act.data() 1045 url = act.data()
988 if url.isEmpty(): 1046 if url.isEmpty():
989 return 1047 return
990 1048
991 self.setSource(url, newTab=True) 1049 self.setSource(url, newTab=True)
992 1050
993 def __openLinkInNewWindow(self): 1051 def __openLinkInNewWindow(self, act):
994 """ 1052 """
995 Private slot called by the context menu to open a link in a new 1053 Private slot called by the context menu to open a link in a new
996 window. 1054 window.
997 """ 1055
998 act = self.sender() 1056 @param act reference to the action that triggered
1057 @type QAction
1058 """
999 url = act.data() 1059 url = act.data()
1000 if url.isEmpty(): 1060 if url.isEmpty():
1001 return 1061 return
1002 1062
1003 self.__mw.newWindow(url) 1063 self.__mw.newWindow(url)
1004 1064
1005 def __openLinkInNewPrivateWindow(self): 1065 def __openLinkInNewPrivateWindow(self, act):
1006 """ 1066 """
1007 Private slot called by the context menu to open a link in a new 1067 Private slot called by the context menu to open a link in a new
1008 private window. 1068 private window.
1009 """ 1069
1010 act = self.sender() 1070 @param act reference to the action that triggered
1071 @type QAction
1072 """
1011 url = act.data() 1073 url = act.data()
1012 if url.isEmpty(): 1074 if url.isEmpty():
1013 return 1075 return
1014 1076
1015 self.__mw.newPrivateWindow(url) 1077 self.__mw.newPrivateWindow(url)
1016 1078
1017 def __bookmarkLink(self): 1079 def __bookmarkLink(self, act):
1018 """ 1080 """
1019 Private slot to bookmark a link via the context menu. 1081 Private slot to bookmark a link via the context menu.
1020 """ 1082
1021 act = self.sender() 1083 @param act reference to the action that triggered
1084 @type QAction
1085 """
1022 url = act.data() 1086 url = act.data()
1023 if url.isEmpty(): 1087 if url.isEmpty():
1024 return 1088 return
1025 1089
1026 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 1090 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
1027 dlg = AddBookmarkDialog() 1091 dlg = AddBookmarkDialog()
1028 dlg.setUrl(bytes(url.toEncoded()).decode()) 1092 dlg.setUrl(bytes(url.toEncoded()).decode())
1029 dlg.exec_() 1093 dlg.exec_()
1030 1094
1031 def __sendLink(self): 1095 def __sendLink(self, act):
1032 """ 1096 """
1033 Private slot to send a link via email. 1097 Private slot to send a link via email.
1034 """ 1098
1035 act = self.sender() 1099 @param act reference to the action that triggered
1100 @type QAction
1101 """
1036 data = act.data() 1102 data = act.data()
1037 if isinstance(data, QUrl) and data.isEmpty(): 1103 if isinstance(data, QUrl) and data.isEmpty():
1038 return 1104 return
1039 1105
1040 if isinstance(data, QUrl): 1106 if isinstance(data, QUrl):
1041 data = data.toString() 1107 data = data.toString()
1042 QDesktopServices.openUrl(QUrl("mailto:?body=" + data)) 1108 QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
1043 1109
1044 def __copyLink(self): 1110 def __copyLink(self, act):
1045 """ 1111 """
1046 Private slot to copy a link to the clipboard. 1112 Private slot to copy a link to the clipboard.
1047 """ 1113
1048 act = self.sender() 1114 @param act reference to the action that triggered
1115 @type QAction
1116 """
1049 data = act.data() 1117 data = act.data()
1050 if isinstance(data, QUrl) and data.isEmpty(): 1118 if isinstance(data, QUrl) and data.isEmpty():
1051 return 1119 return
1052 1120
1053 if isinstance(data, QUrl): 1121 if isinstance(data, QUrl):
1070 """ 1138 """
1071 Private slot to copy an image to the clipboard. 1139 Private slot to copy an image to the clipboard.
1072 """ 1140 """
1073 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard) 1141 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
1074 1142
1075 def __blockImage(self): 1143 def __blockImage(self, act):
1076 """ 1144 """
1077 Private slot to add a block rule for an image URL. 1145 Private slot to add a block rule for an image URL.
1078 """ 1146
1079 act = self.sender() 1147 @param act reference to the action that triggered
1148 @type QAction
1149 """
1080 url = act.data() 1150 url = act.data()
1081 dlg = WebBrowserWindow.adBlockManager().showDialog() 1151 dlg = WebBrowserWindow.adBlockManager().showDialog()
1082 dlg.addCustomRule(url) 1152 dlg.addCustomRule(url)
1083 1153
1084 def __searchImage(self): 1154 def __searchImage(self, act):
1085 """ 1155 """
1086 Private slot to search for an image URL. 1156 Private slot to search for an image URL.
1087 """ 1157
1088 act = self.sender() 1158 @param act reference to the action that triggered
1159 @type QAction
1160 """
1089 url = act.data() 1161 url = act.data()
1090 self.setSource(url, newTab=True) 1162 self.setSource(url, newTab=True)
1091 1163
1092 def __downloadMedia(self): 1164 def __downloadMedia(self):
1093 """ 1165 """
1105 """ 1177 """
1106 Private slot to (un)mute the selected media. 1178 Private slot to (un)mute the selected media.
1107 """ 1179 """
1108 self.triggerPageAction(QWebEnginePage.ToggleMediaMute) 1180 self.triggerPageAction(QWebEnginePage.ToggleMediaMute)
1109 1181
1110 def __virusTotal(self): 1182 def __virusTotal(self, act):
1111 """ 1183 """
1112 Private slot to scan the selected URL with VirusTotal. 1184 Private slot to scan the selected URL with VirusTotal.
1113 """ 1185
1114 act = self.sender() 1186 @param act reference to the action that triggered
1187 @type QAction
1188 """
1115 url = act.data() 1189 url = act.data()
1116 self.__mw.requestVirusTotalScan(url) 1190 self.__mw.requestVirusTotalScan(url)
1117 1191
1118 def __searchDefaultRequested(self): 1192 def __searchDefaultRequested(self):
1119 """ 1193 """
1161 1235
1162 def __webInspector(self): 1236 def __webInspector(self):
1163 """ 1237 """
1164 Private slot to show the web inspector window. 1238 Private slot to show the web inspector window.
1165 """ 1239 """
1166 if self.__inspector is None: 1240 from .WebInspector import WebInspector
1167 from .WebInspector import WebInspector 1241 if WebInspector.isEnabled():
1168 self.__inspector = WebInspector() 1242 if self.__inspector is None:
1169 self.__inspector.setView(self, True) 1243 self.__inspector = WebInspector()
1170 self.__inspector.show() 1244 self.__inspector.setView(self, True)
1171 else: 1245 self.__inspector.inspectorClosed.connect(
1172 self.closeWebInspector() 1246 self.closeWebInspector)
1247 self.__inspector.show()
1248 else:
1249 self.closeWebInspector()
1173 1250
1174 def closeWebInspector(self): 1251 def closeWebInspector(self):
1175 """ 1252 """
1176 Public slot to close the web inspector. 1253 Public slot to close the web inspector.
1177 """ 1254 """
1559 if not self.__siteIcon.isNull(): 1636 if not self.__siteIcon.isNull():
1560 return QIcon(self.__siteIcon) 1637 return QIcon(self.__siteIcon)
1561 1638
1562 from .Tools import WebIconProvider 1639 from .Tools import WebIconProvider
1563 return WebIconProvider.instance().iconForUrl(self.url()) 1640 return WebIconProvider.instance().iconForUrl(self.url())
1641
1642 def title(self):
1643 """
1644 Public method to get the view title.
1645
1646 @return view title
1647 @rtype str
1648 """
1649 titleStr = super(WebBrowserView, self).title()
1650 if not titleStr:
1651 if self.url().isEmpty():
1652 url = self.__page.requestedUrl()
1653 else:
1654 url = self.url()
1655
1656 titleStr = url.host()
1657 if not titleStr:
1658 titleStr = url.toString(QUrl.RemoveFragment)
1659
1660 if not titleStr or titleStr == "about:blank":
1661 titleStr = self.tr("Empty Page")
1662
1663 return titleStr
1564 1664
1565 def __linkHovered(self, link): 1665 def __linkHovered(self, link):
1566 """ 1666 """
1567 Private slot to handle the linkHovered signal. 1667 Private slot to handle the linkHovered signal.
1568 1668
2079 """ 2179 """
2080 if self.__page: 2180 if self.__page:
2081 return self.__page.getSafeBrowsingStatus() 2181 return self.__page.getSafeBrowsingStatus()
2082 else: 2182 else:
2083 return True 2183 return True
2184
2185 ###########################################################################
2186 ## Methods below implement print support from the page
2187 ###########################################################################
2188
2189 @pyqtSlot()
2190 def __printPage(self):
2191 """
2192 Private slot to support printing from the web page.
2193 """
2194 self.__mw.tabWidget.printBrowser(browser=self)

eric ide

mercurial