WebBrowser/WebBrowserView.py

changeset 6122
e7d98249f393
parent 6081
7ea61bd1aa23
child 6126
6c4509eceea2
equal deleted inserted replaced
6121:d3d64f3128b3 6122:e7d98249f393
554 bool(contextMenuData.misspelledWord()): 554 bool(contextMenuData.misspelledWord()):
555 boldFont = menu.font() 555 boldFont = menu.font()
556 boldFont.setBold(True) 556 boldFont.setBold(True)
557 557
558 for suggestion in contextMenuData.spellCheckerSuggestions(): 558 for suggestion in contextMenuData.spellCheckerSuggestions():
559 act = menu.addAction( 559 act = menu.addAction(suggestion)
560 suggestion,
561 self.__replaceMisspelledWord)
562 act.setFont(boldFont) 560 act.setFont(boldFont)
561 act.triggered.connect(
562 lambda: self.__replaceMisspelledWord)(act)
563 563
564 if not bool(menu.actions()): 564 if not bool(menu.actions()):
565 menu.addAction(self.tr("No suggestions")).setEnabled(False) 565 menu.addAction(self.tr("No suggestions")).setEnabled(False)
566 566
567 menu.addSeparator() 567 menu.addSeparator()
612 @type WebHitTestResult 612 @type WebHitTestResult
613 """ 613 """
614 if not menu.isEmpty(): 614 if not menu.isEmpty():
615 menu.addSeparator() 615 menu.addSeparator()
616 616
617 menu.addAction( 617 act = menu.addAction(
618 UI.PixmapCache.getIcon("openNewTab.png"), 618 UI.PixmapCache.getIcon("openNewTab.png"),
619 self.tr("Open Link in New Tab\tCtrl+LMB"), 619 self.tr("Open Link in New Tab\tCtrl+LMB"))
620 self.__openLinkInNewTab).setData(hitTest.linkUrl()) 620 act.setData(hitTest.linkUrl())
621 menu.addAction( 621 act.triggered.connect(
622 lambda: self.__openLinkInNewTab(act))
623 act = menu.addAction(
622 UI.PixmapCache.getIcon("newWindow.png"), 624 UI.PixmapCache.getIcon("newWindow.png"),
623 self.tr("Open Link in New Window"), 625 self.tr("Open Link in New Window"))
624 self.__openLinkInNewWindow).setData(hitTest.linkUrl()) 626 act.setData(hitTest.linkUrl())
625 menu.addAction( 627 act.triggered.connect(
628 lambda: self.__openLinkInNewWindow(act))
629 act = menu.addAction(
626 UI.PixmapCache.getIcon("privateMode.png"), 630 UI.PixmapCache.getIcon("privateMode.png"),
627 self.tr("Open Link in New Private Window"), 631 self.tr("Open Link in New Private Window"))
628 self.__openLinkInNewPrivateWindow).setData(hitTest.linkUrl()) 632 act.setData(hitTest.linkUrl())
633 act.triggered.connect(
634 lambda: self.__openLinkInNewPrivateWindow(act))
629 menu.addSeparator() 635 menu.addSeparator()
630 menu.addAction( 636 menu.addAction(
631 UI.PixmapCache.getIcon("download.png"), 637 UI.PixmapCache.getIcon("download.png"),
632 self.tr("Save Lin&k"), self.__downloadLink) 638 self.tr("Save Lin&k"), self.__downloadLink)
633 menu.addAction( 639 act = menu.addAction(
634 UI.PixmapCache.getIcon("bookmark22.png"), 640 UI.PixmapCache.getIcon("bookmark22.png"),
635 self.tr("Bookmark this Link"), self.__bookmarkLink)\ 641 self.tr("Bookmark this Link"))
636 .setData(hitTest.linkUrl()) 642 act.setData(hitTest.linkUrl())
643 act.triggered.connect(
644 lambda: self.__bookmarkLink(act))
637 menu.addSeparator() 645 menu.addSeparator()
638 menu.addAction( 646 act = menu.addAction(
639 UI.PixmapCache.getIcon("editCopy.png"), 647 UI.PixmapCache.getIcon("editCopy.png"),
640 self.tr("Copy Link to Clipboard"), self.__copyLink)\ 648 self.tr("Copy Link to Clipboard"))
641 .setData(hitTest.linkUrl()) 649 act.setData(hitTest.linkUrl())
642 menu.addAction( 650 act.triggered.connect(
651 lambda: self.__copyLink(act))
652 act = menu.addAction(
643 UI.PixmapCache.getIcon("mailSend.png"), 653 UI.PixmapCache.getIcon("mailSend.png"),
644 self.tr("Send Link"), 654 self.tr("Send Link"))
645 self.__sendLink).setData(hitTest.linkUrl()) 655 act.setData(hitTest.linkUrl())
656 act.triggered.connect(
657 lambda: self.__sendLink(act))
646 if Preferences.getWebBrowser("VirusTotalEnabled") and \ 658 if Preferences.getWebBrowser("VirusTotalEnabled") and \
647 Preferences.getWebBrowser("VirusTotalServiceKey") != "": 659 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
648 menu.addAction( 660 act = menu.addAction(
649 UI.PixmapCache.getIcon("virustotal.png"), 661 UI.PixmapCache.getIcon("virustotal.png"),
650 self.tr("Scan Link with VirusTotal"), 662 self.tr("Scan Link with VirusTotal"))
651 self.__virusTotal).setData(hitTest.linkUrl()) 663 act.setData(hitTest.linkUrl())
664 act.triggered.connect(
665 lambda: self.__virusTotal(act))
652 666
653 def __createImageContextMenu(self, menu, hitTest): 667 def __createImageContextMenu(self, menu, hitTest):
654 """ 668 """
655 Private method to populate the context menu for images. 669 Private method to populate the context menu for images.
656 670
660 @type WebHitTestResult 674 @type WebHitTestResult
661 """ 675 """
662 if not menu.isEmpty(): 676 if not menu.isEmpty():
663 menu.addSeparator() 677 menu.addSeparator()
664 678
665 menu.addAction( 679 act = menu.addAction(
666 UI.PixmapCache.getIcon("openNewTab.png"), 680 UI.PixmapCache.getIcon("openNewTab.png"),
667 self.tr("Open Image in New Tab"), 681 self.tr("Open Image in New Tab"))
668 self.__openLinkInNewTab).setData(hitTest.imageUrl()) 682 act.setData(hitTest.imageUrl())
683 act.triggered.connect(
684 lambda: self.__openLinkInNewTab(act))
669 menu.addSeparator() 685 menu.addSeparator()
670 menu.addAction( 686 menu.addAction(
671 UI.PixmapCache.getIcon("download.png"), 687 UI.PixmapCache.getIcon("download.png"),
672 self.tr("Save Image"), self.__downloadImage) 688 self.tr("Save Image"), self.__downloadImage)
673 menu.addAction( 689 menu.addAction(
674 self.tr("Copy Image to Clipboard"), self.__copyImage) 690 self.tr("Copy Image to Clipboard"), self.__copyImage)
675 menu.addAction( 691 act = menu.addAction(
676 UI.PixmapCache.getIcon("editCopy.png"), 692 UI.PixmapCache.getIcon("editCopy.png"),
677 self.tr("Copy Image Location to Clipboard"), 693 self.tr("Copy Image Location to Clipboard"))
678 self.__copyLink).setData(hitTest.imageUrl()) 694 act.setData(hitTest.imageUrl())
679 menu.addAction( 695 act.triggered.connect(
696 lambda: self.__copyLink(act))
697 act = menu.addAction(
680 UI.PixmapCache.getIcon("mailSend.png"), 698 UI.PixmapCache.getIcon("mailSend.png"),
681 self.tr("Send Image Link"), 699 self.tr("Send Image Link"))
682 self.__sendLink).setData(hitTest.imageUrl()) 700 act.setData(hitTest.imageUrl())
701 act.triggered.connect(
702 lambda: self.__sendLink(act))
683 703
684 if hitTest.imageUrl().scheme() in ["http", "https"]: 704 if hitTest.imageUrl().scheme() in ["http", "https"]:
685 menu.addSeparator() 705 menu.addSeparator()
686 engine = WebBrowserWindow.imageSearchEngine() 706 engine = WebBrowserWindow.imageSearchEngine()
687 searchEngineName = engine.searchEngine() 707 searchEngineName = engine.searchEngine()
688 menu.addAction( 708 act = menu.addAction(
689 UI.PixmapCache.getIcon("{0}.png".format( 709 UI.PixmapCache.getIcon("{0}.png".format(
690 searchEngineName.lower())), 710 searchEngineName.lower())),
691 self.tr("Search image in {0}").format(searchEngineName), 711 self.tr("Search image in {0}").format(searchEngineName))
692 self.__searchImage).setData( 712 act.setData(engine.getSearchQuery(hitTest.imageUrl()))
693 engine.getSearchQuery(hitTest.imageUrl())) 713 act.triggered.connect(
714 lambda: self.__searchImage(act))
694 self.__imageSearchMenu = menu.addMenu( 715 self.__imageSearchMenu = menu.addMenu(
695 self.tr("Search image with...")) 716 self.tr("Search image with..."))
696 for searchEngineName in engine.searchEngineNames(): 717 for searchEngineName in engine.searchEngineNames():
697 self.__imageSearchMenu.addAction( 718 act = self.__imageSearchMenu.addAction(
698 UI.PixmapCache.getIcon("{0}.png".format( 719 UI.PixmapCache.getIcon("{0}.png".format(
699 searchEngineName.lower())), 720 searchEngineName.lower())),
700 self.tr("Search image in {0}").format(searchEngineName), 721 self.tr("Search image in {0}").format(searchEngineName))
701 self.__searchImage).setData( 722 act.setData(engine.getSearchQuery(
702 engine.getSearchQuery( 723 hitTest.imageUrl(), searchEngineName))
703 hitTest.imageUrl(), searchEngineName)) 724 act.triggered.connect(
725 lambda: self.__searchImage(act))
704 726
705 menu.addSeparator() 727 menu.addSeparator()
706 menu.addAction( 728 act = menu.addAction(
707 UI.PixmapCache.getIcon("adBlockPlus.png"), 729 UI.PixmapCache.getIcon("adBlockPlus.png"),
708 self.tr("Block Image"), self.__blockImage)\ 730 self.tr("Block Image"))
709 .setData(hitTest.imageUrl().toString()) 731 act.setData(hitTest.imageUrl().toString())
732 act.triggered.connect(
733 lambda: self.__blockImage(act))
710 if Preferences.getWebBrowser("VirusTotalEnabled") and \ 734 if Preferences.getWebBrowser("VirusTotalEnabled") and \
711 Preferences.getWebBrowser("VirusTotalServiceKey") != "": 735 Preferences.getWebBrowser("VirusTotalServiceKey") != "":
712 menu.addAction( 736 act = menu.addAction(
713 UI.PixmapCache.getIcon("virustotal.png"), 737 UI.PixmapCache.getIcon("virustotal.png"),
714 self.tr("Scan Image with VirusTotal"), 738 self.tr("Scan Image with VirusTotal"))
715 self.__virusTotal).setData(hitTest.imageUrl()) 739 act.setData(hitTest.imageUrl())
740 act.triggered.connect(
741 lambda: self.__virusTotal(act))
716 742
717 def __createMediaContextMenu(self, menu, hitTest): 743 def __createMediaContextMenu(self, menu, hitTest):
718 """ 744 """
719 Private method to populate the context menu for media elements. 745 Private method to populate the context menu for media elements.
720 746
741 else: 767 else:
742 menu.addAction( 768 menu.addAction(
743 UI.PixmapCache.getIcon("audioVolumeMuted.png"), 769 UI.PixmapCache.getIcon("audioVolumeMuted.png"),
744 self.tr("Mute"), self.__muteMedia) 770 self.tr("Mute"), self.__muteMedia)
745 menu.addSeparator() 771 menu.addSeparator()
746 menu.addAction( 772 act = menu.addAction(
747 UI.PixmapCache.getIcon("editCopy.png"), 773 UI.PixmapCache.getIcon("editCopy.png"),
748 self.tr("Copy Media Address to Clipboard"), 774 self.tr("Copy Media Address to Clipboard"))
749 self.__copyLink).setData(hitTest.mediaUrl()) 775 act.setData(hitTest.mediaUrl())
750 menu.addAction( 776 act.triggered.connect(
777 lambda: self.__copyLink(act))
778 act = menu.addAction(
751 UI.PixmapCache.getIcon("mailSend.png"), 779 UI.PixmapCache.getIcon("mailSend.png"),
752 self.tr("Send Media Address"), self.__sendLink)\ 780 self.tr("Send Media Address"))
753 .setData(hitTest.mediaUrl()) 781 act.setData(hitTest.mediaUrl())
782 act.triggered.connect(
783 lambda: self.__sendLink(act))
754 menu.addAction( 784 menu.addAction(
755 UI.PixmapCache.getIcon("download.png"), 785 UI.PixmapCache.getIcon("download.png"),
756 self.tr("Save Media"), self.__downloadMedia) 786 self.tr("Save Media"), self.__downloadMedia)
757 787
758 def __createSelectedTextContextMenu(self, menu, hitTest): 788 def __createSelectedTextContextMenu(self, menu, hitTest):
767 if not menu.isEmpty(): 797 if not menu.isEmpty():
768 menu.addSeparator() 798 menu.addSeparator()
769 799
770 menu.addAction(self.__mw.copyAct) 800 menu.addAction(self.__mw.copyAct)
771 menu.addSeparator() 801 menu.addSeparator()
772 menu.addAction( 802 act = menu.addAction(
773 UI.PixmapCache.getIcon("mailSend.png"), 803 UI.PixmapCache.getIcon("mailSend.png"),
774 self.tr("Send Text"), 804 self.tr("Send Text"))
775 self.__sendLink).setData(self.selectedText()) 805 act.setData(self.selectedText())
806 act.triggered.connect(
807 lambda: self.__sendLink(act))
776 808
777 engineName = self.__mw.openSearchManager().currentEngineName() 809 engineName = self.__mw.openSearchManager().currentEngineName()
778 if engineName: 810 if engineName:
779 menu.addAction(self.tr("Search with '{0}'").format(engineName), 811 menu.addAction(self.tr("Search with '{0}'").format(engineName),
780 self.__searchDefaultRequested) 812 self.__searchDefaultRequested)
802 language = languages[0] 834 language = languages[0]
803 langCode = language.split("[")[1][:2] 835 langCode = language.split("[")[1][:2]
804 googleTranslatorUrl = QUrl( 836 googleTranslatorUrl = QUrl(
805 "http://translate.google.com/#auto/{0}/{1}".format( 837 "http://translate.google.com/#auto/{0}/{1}".format(
806 langCode, self.selectedText())) 838 langCode, self.selectedText()))
807 menu.addAction( 839 act = menu.addAction(
808 UI.PixmapCache.getIcon("translate.png"), 840 UI.PixmapCache.getIcon("translate.png"),
809 self.tr("Google Translate"), self.__openLinkInNewTab)\ 841 self.tr("Google Translate"))
810 .setData(googleTranslatorUrl) 842 act.setData(googleTranslatorUrl)
843 act.triggered.connect(
844 lambda: self.__openLinkInNewTab(act))
811 wiktionaryUrl = QUrl( 845 wiktionaryUrl = QUrl(
812 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" 846 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
813 .format(langCode, self.selectedText())) 847 .format(langCode, self.selectedText()))
814 menu.addAction( 848 act = menu.addAction(
815 UI.PixmapCache.getIcon("wikipedia.png"), 849 UI.PixmapCache.getIcon("wikipedia.png"),
816 self.tr("Dictionary"), self.__openLinkInNewTab)\ 850 self.tr("Dictionary"))
817 .setData(wiktionaryUrl) 851 act.setData(wiktionaryUrl)
852 act.triggered.connect(
853 lambda: self.__openLinkInNewTab(act))
818 menu.addSeparator() 854 menu.addSeparator()
819 855
820 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) 856 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
821 if self.__isUrlValid(guessedUrl): 857 if self.__isUrlValid(guessedUrl):
822 menu.addAction( 858 act = menu.addAction(self.tr("Go to web address"))
823 self.tr("Go to web address"), 859 act.setData(guessedUrl)
824 self.__openLinkInNewTab).setData(guessedUrl) 860 act.triggered.connect(
861 lambda: self.__openLinkInNewTab(act))
825 862
826 def __createPageContextMenu(self, menu): 863 def __createPageContextMenu(self, menu):
827 """ 864 """
828 Private method to populate the basic context menu. 865 Private method to populate the basic context menu.
829 866
858 return 895 return
859 896
860 menu.addAction( 897 menu.addAction(
861 UI.PixmapCache.getIcon("bookmark22.png"), 898 UI.PixmapCache.getIcon("bookmark22.png"),
862 self.tr("Bookmark this Page"), self.addBookmark) 899 self.tr("Bookmark this Page"), self.addBookmark)
863 menu.addAction( 900 act = menu.addAction(
864 UI.PixmapCache.getIcon("editCopy.png"), 901 UI.PixmapCache.getIcon("editCopy.png"),
865 self.tr("Copy Page Link"), self.__copyLink).setData(self.url()) 902 self.tr("Copy Page Link"))
866 menu.addAction( 903 act.setData(self.url())
904 act.triggered.connect(
905 lambda: self.__copyLink(act))
906 act = menu.addAction(
867 UI.PixmapCache.getIcon("mailSend.png"), 907 UI.PixmapCache.getIcon("mailSend.png"),
868 self.tr("Send Page Link"), self.__sendLink).setData(self.url()) 908 self.tr("Send Page Link"))
909 act.setData(self.url())
910 act.triggered.connect(
911 lambda: self.__sendLink(act))
869 menu.addSeparator() 912 menu.addSeparator()
870 913
871 from .UserAgent.UserAgentMenu import UserAgentMenu 914 from .UserAgent.UserAgentMenu import UserAgentMenu
872 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"), 915 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
873 url=self.url()) 916 url=self.url())
894 menu.addSeparator() 937 menu.addSeparator()
895 938
896 w3url = QUrl.fromEncoded( 939 w3url = QUrl.fromEncoded(
897 b"http://validator.w3.org/check?uri=" + 940 b"http://validator.w3.org/check?uri=" +
898 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode())) 941 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode()))
899 menu.addAction( 942 act = menu.addAction(
900 UI.PixmapCache.getIcon("w3.png"), 943 UI.PixmapCache.getIcon("w3.png"),
901 self.tr("Validate Page"), self.__openLinkInNewTab)\ 944 self.tr("Validate Page"))
902 .setData(w3url) 945 act.setData(w3url)
946 act.triggered.connect(
947 lambda: self.__openLinkInNewTab(act))
903 948
904 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog 949 from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
905 languages = Preferences.toList( 950 languages = Preferences.toList(
906 Preferences.Prefs.settings.value( 951 Preferences.Prefs.settings.value(
907 "WebBrowser/AcceptLanguages", 952 "WebBrowser/AcceptLanguages",
913 b"http://translate.google.com/translate?sl=auto&tl=" + 958 b"http://translate.google.com/translate?sl=auto&tl=" +
914 langCode.encode() + 959 langCode.encode() +
915 b"&u=" + 960 b"&u=" +
916 QUrl.toPercentEncoding( 961 QUrl.toPercentEncoding(
917 bytes(self.url().toEncoded()).decode())) 962 bytes(self.url().toEncoded()).decode()))
918 menu.addAction( 963 act = menu.addAction(
919 UI.PixmapCache.getIcon("translate.png"), 964 UI.PixmapCache.getIcon("translate.png"),
920 self.tr("Google Translate"), self.__openLinkInNewTab)\ 965 self.tr("Google Translate"))
921 .setData(googleTranslatorUrl) 966 act.setData(googleTranslatorUrl)
922 967 act.triggered.connect(
968 lambda: self.__openLinkInNewTab(act))
969
923 def __checkForForm(self, act, pos): 970 def __checkForForm(self, act, pos):
924 """ 971 """
925 Private method to check the given position for an open search form. 972 Private method to check the given position for an open search form.
926 973
927 @param act reference to the action to be populated upon success 974 @param act reference to the action to be populated upon success
968 return url.isValid() and \ 1015 return url.isValid() and \
969 bool(url.host()) and \ 1016 bool(url.host()) and \
970 bool(url.scheme()) and \ 1017 bool(url.scheme()) and \
971 "." in url.host() 1018 "." in url.host()
972 1019
973 def __replaceMisspelledWord(self): 1020 def __replaceMisspelledWord(self, act):
974 """ 1021 """
975 Private slot to replace a misspelled word under the context menu. 1022 Private slot to replace a misspelled word under the context menu.
976 """ 1023
977 act = self.sender() 1024 @param act reference to the action that triggered
1025 @type QAction
1026 """
978 suggestion = act.text() 1027 suggestion = act.text()
979 self.page().replaceMisspelledWord(suggestion) 1028 self.page().replaceMisspelledWord(suggestion)
980 1029
981 def __openLinkInNewTab(self): 1030 def __openLinkInNewTab(self, act):
982 """ 1031 """
983 Private method called by the context menu to open a link in a new 1032 Private method called by the context menu to open a link in a new
984 tab. 1033 tab.
985 """ 1034
986 act = self.sender() 1035 @param act reference to the action that triggered
1036 @type QAction
1037 """
987 url = act.data() 1038 url = act.data()
988 if url.isEmpty(): 1039 if url.isEmpty():
989 return 1040 return
990 1041
991 self.setSource(url, newTab=True) 1042 self.setSource(url, newTab=True)
992 1043
993 def __openLinkInNewWindow(self): 1044 def __openLinkInNewWindow(self, act):
994 """ 1045 """
995 Private slot called by the context menu to open a link in a new 1046 Private slot called by the context menu to open a link in a new
996 window. 1047 window.
997 """ 1048
998 act = self.sender() 1049 @param act reference to the action that triggered
1050 @type QAction
1051 """
999 url = act.data() 1052 url = act.data()
1000 if url.isEmpty(): 1053 if url.isEmpty():
1001 return 1054 return
1002 1055
1003 self.__mw.newWindow(url) 1056 self.__mw.newWindow(url)
1004 1057
1005 def __openLinkInNewPrivateWindow(self): 1058 def __openLinkInNewPrivateWindow(self, act):
1006 """ 1059 """
1007 Private slot called by the context menu to open a link in a new 1060 Private slot called by the context menu to open a link in a new
1008 private window. 1061 private window.
1009 """ 1062
1010 act = self.sender() 1063 @param act reference to the action that triggered
1064 @type QAction
1065 """
1011 url = act.data() 1066 url = act.data()
1012 if url.isEmpty(): 1067 if url.isEmpty():
1013 return 1068 return
1014 1069
1015 self.__mw.newPrivateWindow(url) 1070 self.__mw.newPrivateWindow(url)
1016 1071
1017 def __bookmarkLink(self): 1072 def __bookmarkLink(self, act):
1018 """ 1073 """
1019 Private slot to bookmark a link via the context menu. 1074 Private slot to bookmark a link via the context menu.
1020 """ 1075
1021 act = self.sender() 1076 @param act reference to the action that triggered
1077 @type QAction
1078 """
1022 url = act.data() 1079 url = act.data()
1023 if url.isEmpty(): 1080 if url.isEmpty():
1024 return 1081 return
1025 1082
1026 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 1083 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
1027 dlg = AddBookmarkDialog() 1084 dlg = AddBookmarkDialog()
1028 dlg.setUrl(bytes(url.toEncoded()).decode()) 1085 dlg.setUrl(bytes(url.toEncoded()).decode())
1029 dlg.exec_() 1086 dlg.exec_()
1030 1087
1031 def __sendLink(self): 1088 def __sendLink(self, act):
1032 """ 1089 """
1033 Private slot to send a link via email. 1090 Private slot to send a link via email.
1034 """ 1091
1035 act = self.sender() 1092 @param act reference to the action that triggered
1093 @type QAction
1094 """
1036 data = act.data() 1095 data = act.data()
1037 if isinstance(data, QUrl) and data.isEmpty(): 1096 if isinstance(data, QUrl) and data.isEmpty():
1038 return 1097 return
1039 1098
1040 if isinstance(data, QUrl): 1099 if isinstance(data, QUrl):
1041 data = data.toString() 1100 data = data.toString()
1042 QDesktopServices.openUrl(QUrl("mailto:?body=" + data)) 1101 QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
1043 1102
1044 def __copyLink(self): 1103 def __copyLink(self, act):
1045 """ 1104 """
1046 Private slot to copy a link to the clipboard. 1105 Private slot to copy a link to the clipboard.
1047 """ 1106
1048 act = self.sender() 1107 @param act reference to the action that triggered
1108 @type QAction
1109 """
1049 data = act.data() 1110 data = act.data()
1050 if isinstance(data, QUrl) and data.isEmpty(): 1111 if isinstance(data, QUrl) and data.isEmpty():
1051 return 1112 return
1052 1113
1053 if isinstance(data, QUrl): 1114 if isinstance(data, QUrl):
1070 """ 1131 """
1071 Private slot to copy an image to the clipboard. 1132 Private slot to copy an image to the clipboard.
1072 """ 1133 """
1073 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard) 1134 self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
1074 1135
1075 def __blockImage(self): 1136 def __blockImage(self, act):
1076 """ 1137 """
1077 Private slot to add a block rule for an image URL. 1138 Private slot to add a block rule for an image URL.
1078 """ 1139
1079 act = self.sender() 1140 @param act reference to the action that triggered
1141 @type QAction
1142 """
1080 url = act.data() 1143 url = act.data()
1081 dlg = WebBrowserWindow.adBlockManager().showDialog() 1144 dlg = WebBrowserWindow.adBlockManager().showDialog()
1082 dlg.addCustomRule(url) 1145 dlg.addCustomRule(url)
1083 1146
1084 def __searchImage(self): 1147 def __searchImage(self, act):
1085 """ 1148 """
1086 Private slot to search for an image URL. 1149 Private slot to search for an image URL.
1087 """ 1150
1088 act = self.sender() 1151 @param act reference to the action that triggered
1152 @type QAction
1153 """
1089 url = act.data() 1154 url = act.data()
1090 self.setSource(url, newTab=True) 1155 self.setSource(url, newTab=True)
1091 1156
1092 def __downloadMedia(self): 1157 def __downloadMedia(self):
1093 """ 1158 """
1105 """ 1170 """
1106 Private slot to (un)mute the selected media. 1171 Private slot to (un)mute the selected media.
1107 """ 1172 """
1108 self.triggerPageAction(QWebEnginePage.ToggleMediaMute) 1173 self.triggerPageAction(QWebEnginePage.ToggleMediaMute)
1109 1174
1110 def __virusTotal(self): 1175 def __virusTotal(self, act):
1111 """ 1176 """
1112 Private slot to scan the selected URL with VirusTotal. 1177 Private slot to scan the selected URL with VirusTotal.
1113 """ 1178
1114 act = self.sender() 1179 @param act reference to the action that triggered
1180 @type QAction
1181 """
1115 url = act.data() 1182 url = act.data()
1116 self.__mw.requestVirusTotalScan(url) 1183 self.__mw.requestVirusTotalScan(url)
1117 1184
1118 def __searchDefaultRequested(self): 1185 def __searchDefaultRequested(self):
1119 """ 1186 """

eric ide

mercurial