WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4727
62b50a24fb59
parent 4726
c26e2a2dc0cb
child 4728
0367675d783d
equal deleted inserted replaced
4726:c26e2a2dc0cb 4727:62b50a24fb59
383 """ 383 """
384 Public slot to copy the selected text. 384 Public slot to copy the selected text.
385 """ 385 """
386 self.triggerPageAction(QWebEnginePage.Copy) 386 self.triggerPageAction(QWebEnginePage.Copy)
387 387
388 def cut(self):
389 """
390 Public slot to cut the selected text.
391 """
392 self.triggerPageAction(QWebEnginePage.Cut)
393
394 def paste(self):
395 """
396 Public slot to paste text from the clipboard.
397 """
398 self.triggerPageAction(QWebEnginePage.Paste)
399
400 def undo(self):
401 """
402 Public slot to undo the last edit action.
403 """
404 self.triggerPageAction(QWebEnginePage.Undo)
405
406 def redo(self):
407 """
408 Public slot to redo the last edit action.
409 """
410 self.triggerPageAction(QWebEnginePage.Redo)
411
412 def selectAll(self):
413 """
414 Public slot to select all text.
415 """
416 self.triggerPageAction(QWebEnginePage.SelectAll)
417
388 def isForwardAvailable(self): 418 def isForwardAvailable(self):
389 """ 419 """
390 Public method to determine, if a forward move in history is possible. 420 Public method to determine, if a forward move in history is possible.
391 421
392 @return flag indicating move forward is possible (boolean) 422 @return flag indicating move forward is possible (boolean)
554 ## self.tr("Bookmark this Link"), self.__bookmarkLink)\ 584 ## self.tr("Bookmark this Link"), self.__bookmarkLink)\
555 ## .setData(hit.linkUrl()) 585 ## .setData(hit.linkUrl())
556 ## menu.addSeparator() 586 ## menu.addSeparator()
557 ## menu.addAction( 587 ## menu.addAction(
558 ## UI.PixmapCache.getIcon("editCopy.png"), 588 ## UI.PixmapCache.getIcon("editCopy.png"),
559 ## self.tr("Copy Link to Clipboard"), self.__copyLink) 589 ## self.tr("Copy Link to Clipboard"), self.__copyLink)\
590 ## .setData(hit.linkUrl())
560 ## menu.addAction( 591 ## menu.addAction(
561 ## UI.PixmapCache.getIcon("mailSend.png"), 592 ## UI.PixmapCache.getIcon("mailSend.png"),
562 ## self.tr("Send Link"), 593 ## self.tr("Send Link"),
563 ## self.__sendLink).setData(hit.linkUrl()) 594 ## self.__sendLink).setData(hit.linkUrl())
564 ## if Preferences.getWebBrowser("VirusTotalEnabled") and \ 595 ## if Preferences.getWebBrowser("VirusTotalEnabled") and \
582 ## menu.addAction( 613 ## menu.addAction(
583 ## self.tr("Copy Image to Clipboard"), self.__copyImage) 614 ## self.tr("Copy Image to Clipboard"), self.__copyImage)
584 ## menu.addAction( 615 ## menu.addAction(
585 ## UI.PixmapCache.getIcon("editCopy.png"), 616 ## UI.PixmapCache.getIcon("editCopy.png"),
586 ## self.tr("Copy Image Location to Clipboard"), 617 ## self.tr("Copy Image Location to Clipboard"),
587 ## self.__copyLocation).setData(hit.imageUrl().toString()) 618 ## self.__copyLink).setData(hit.imageUrl())
588 ## menu.addAction( 619 ## menu.addAction(
589 ## UI.PixmapCache.getIcon("mailSend.png"), 620 ## UI.PixmapCache.getIcon("mailSend.png"),
590 ## self.tr("Send Image Link"), 621 ## self.tr("Send Image Link"),
591 ## self.__sendLink).setData(hit.imageUrl()) 622 ## self.__sendLink).setData(hit.imageUrl())
592 ## menu.addSeparator() 623 ## menu.addSeparator()
631 ## self.tr("Mute"), self.__muteMedia) 662 ## self.tr("Mute"), self.__muteMedia)
632 ## menu.addSeparator() 663 ## menu.addSeparator()
633 ## menu.addAction( 664 ## menu.addAction(
634 ## UI.PixmapCache.getIcon("editCopy.png"), 665 ## UI.PixmapCache.getIcon("editCopy.png"),
635 ## self.tr("Copy Media Address to Clipboard"), 666 ## self.tr("Copy Media Address to Clipboard"),
636 ## self.__copyLocation).setData(videoUrl.toString()) 667 ## self.__copyLink).setData(videoUrl)
637 ## menu.addAction( 668 ## menu.addAction(
638 ## UI.PixmapCache.getIcon("mailSend.png"), 669 ## UI.PixmapCache.getIcon("mailSend.png"),
639 ## self.tr("Send Media Address"), self.__sendLink)\ 670 ## self.tr("Send Media Address"), self.__sendLink)\
640 ## .setData(videoUrl) 671 ## .setData(videoUrl)
641 ## menu.addAction( 672 ## menu.addAction(
723 # TODO: Bookmarks 754 # TODO: Bookmarks
724 ## menu.addAction( 755 ## menu.addAction(
725 ## UI.PixmapCache.getIcon("bookmark22.png"), 756 ## UI.PixmapCache.getIcon("bookmark22.png"),
726 ## self.tr("Bookmark this Page"), self.addBookmark) 757 ## self.tr("Bookmark this Page"), self.addBookmark)
727 menu.addAction( 758 menu.addAction(
759 UI.PixmapCache.getIcon("editCopy.png"),
760 self.tr("Copy Page Link"), self.__copyLink).setData(self.url())
761 menu.addAction(
728 UI.PixmapCache.getIcon("mailSend.png"), 762 UI.PixmapCache.getIcon("mailSend.png"),
729 self.tr("Send Page Link"), self.__sendLink).setData(self.url()) 763 self.tr("Send Page Link"), self.__sendLink).setData(self.url())
730 menu.addSeparator() 764 menu.addSeparator()
731 # TODO: User Agent 765 # TODO: User Agent
732 ## self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"), 766 ## self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
739 menu.addSeparator() 773 menu.addSeparator()
740 menu.addAction(self.__mw.zoomInAct) 774 menu.addAction(self.__mw.zoomInAct)
741 menu.addAction(self.__mw.zoomResetAct) 775 menu.addAction(self.__mw.zoomResetAct)
742 menu.addAction(self.__mw.zoomOutAct) 776 menu.addAction(self.__mw.zoomOutAct)
743 menu.addSeparator() 777 menu.addSeparator()
778 # TODO: edit actions only for forms
779 menu.addAction(self.__mw.undoAct)
780 menu.addAction(self.__mw.redoAct)
781 menu.addSeparator()
744 if self.selectedText(): 782 if self.selectedText():
745 menu.addAction(self.__mw.copyAct) 783 menu.addAction(self.__mw.copyAct)
784 menu.addAction(self.__mw.cutAct)
785 menu.addAction(self.__mw.pasteAct)
786 menu.addAction(self.__mw.selectAllAct)
787 if self.selectedText():
746 menu.addAction( 788 menu.addAction(
747 UI.PixmapCache.getIcon("mailSend.png"), 789 UI.PixmapCache.getIcon("mailSend.png"),
748 self.tr("Send Text"), 790 self.tr("Send Text"),
749 self.__sendLink).setData(self.selectedText()) 791 self.__sendLink).setData(self.selectedText())
750 menu.addAction(self.__mw.findAct) 792 menu.addAction(self.__mw.findAct)
803 ## element.attribute("type", "text") == "text": 845 ## element.attribute("type", "text") == "text":
804 ## menu.addAction(self.tr("Add to web search toolbar"), 846 ## menu.addAction(self.tr("Add to web search toolbar"),
805 ## self.__addSearchEngine).setData(element) 847 ## self.__addSearchEngine).setData(element)
806 ## menu.addSeparator() 848 ## menu.addSeparator()
807 849
808 # TODO: Web Inspector 850 # TODO: WebInspector
809 ## menu.addAction( 851 ## menu.addAction(
810 ## UI.PixmapCache.getIcon("webInspector.png"), 852 ## UI.PixmapCache.getIcon("webInspector.png"),
811 ## self.tr("Web Inspector..."), self.__webInspector) 853 ## self.tr("Web Inspector..."), self.__webInspector)
812 854
813 menu.exec_(evt.globalPos()) 855 menu.exec_(evt.globalPos())
865 907
866 if isinstance(data, QUrl): 908 if isinstance(data, QUrl):
867 data = data.toString() 909 data = data.toString()
868 QDesktopServices.openUrl(QUrl("mailto:?body=" + data)) 910 QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
869 911
912 def __copyLink(self):
913 """
914 Private slot to copy a link to the clipboard.
915 """
916 act = self.sender()
917 data = act.data()
918 if isinstance(data, QUrl) and data.isEmpty():
919 return
920
921 if isinstance(data, QUrl):
922 data = data.toString()
923 QApplication.clipboard().setText(data)
924
870 ## def __downloadLink(self): 925 ## def __downloadLink(self):
871 ## """ 926 ## """
872 ## Private slot to download a link and save it to disk. 927 ## Private slot to download a link and save it to disk.
873 ## """ 928 ## """
874 ## self.pageAction(QWebPage.DownloadLinkToDisk).trigger() 929 ## self.pageAction(QWebPage.DownloadLinkToDisk).trigger()
875 ## 930 ##
876 ## def __copyLink(self):
877 ## """
878 ## Private slot to copy a link to the clipboard.
879 ## """
880 ## self.pageAction(QWebPage.CopyLinkToClipboard).trigger()
881 ##
882 ## def __downloadImage(self): 931 ## def __downloadImage(self):
883 ## """ 932 ## """
884 ## Private slot to download an image and save it to disk. 933 ## Private slot to download an image and save it to disk.
885 ## """ 934 ## """
886 ## self.pageAction(QWebPage.DownloadImageToDisk).trigger() 935 ## self.pageAction(QWebPage.DownloadImageToDisk).trigger()
888 ## def __copyImage(self): 937 ## def __copyImage(self):
889 ## """ 938 ## """
890 ## Private slot to copy an image to the clipboard. 939 ## Private slot to copy an image to the clipboard.
891 ## """ 940 ## """
892 ## self.pageAction(QWebPage.CopyImageToClipboard).trigger() 941 ## self.pageAction(QWebPage.CopyImageToClipboard).trigger()
893
894 def __copyLocation(self):
895 """
896 Private slot to copy an image or media location to the clipboard.
897 """
898 act = self.sender()
899 url = act.data()
900 QApplication.clipboard().setText(url)
901 942
902 # TODO: AdBlock 943 # TODO: AdBlock
903 ## def __blockImage(self): 944 ## def __blockImage(self):
904 ## """ 945 ## """
905 ## Private slot to add a block rule for an image URL. 946 ## Private slot to add a block rule for an image URL.

eric ide

mercurial