WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4713
8dca047daf4b
parent 4711
0a9162801b8d
child 4715
79009bc4acd5
equal deleted inserted replaced
4711:0a9162801b8d 4713:8dca047daf4b
329 ## Private slot to track a change of the current search engine. 329 ## Private slot to track a change of the current search engine.
330 ## """ 330 ## """
331 ## if self.url().toString() == "eric:home": 331 ## if self.url().toString() == "eric:home":
332 ## self.reload() 332 ## self.reload()
333 333
334 # TODO: eliminate requestData 334 # TODO: eliminate requestData, add param to get rid of __ctrlPressed
335 def setSource(self, name, requestData=None): 335 def setSource(self, name, requestData=None):
336 """ 336 """
337 Public method used to set the source to be displayed. 337 Public method used to set the source to be displayed.
338 338
339 @param name filename to be shown (QUrl) 339 @param name filename to be shown (QUrl)
571 571
572 @return flag indicating text has been selected (boolean) 572 @return flag indicating text has been selected (boolean)
573 """ 573 """
574 return self.selectedText() != "" 574 return self.selectedText() != ""
575 575
576 # FIXME: do this first 576 # TODO: adjust this to what Qt 5.6 is offering
577 def findNextPrev(self, txt, case, backwards, wrap, highlightAll): 577 def findNextPrev(self, txt, case, backwards, wrap, highlightAll, callback):
578 """ 578 """
579 Public slot to find the next occurrence of a text. 579 Public slot to find the next occurrence of a text.
580 580
581 @param txt text to search for (string) 581 @param txt text to search for (string)
582 @param case flag indicating a case sensitive search (boolean) 582 @param case flag indicating a case sensitive search (boolean)
583 @param backwards flag indicating a backwards search (boolean) 583 @param backwards flag indicating a backwards search (boolean)
584 @param wrap flag indicating to wrap around (boolean) 584 @param wrap flag indicating to wrap around (boolean)
585 @param highlightAll flag indicating to highlight all occurrences 585 @param highlightAll flag indicating to highlight all occurrences
586 (boolean) 586 (boolean)
587 @return flag indicating that a match was found (boolean) 587 @param callback reference to a function with a bool parameter
588 """ 588 @type function(bool) or None
589 findFlags = QWebPage.FindFlags() 589 """
590
591 findFlags = QWebEnginePage.FindFlags()
590 if case: 592 if case:
591 findFlags |= QWebPage.FindCaseSensitively 593 findFlags |= QWebEnginePage.FindCaseSensitively
592 if backwards: 594 if backwards:
593 findFlags |= QWebPage.FindBackward 595 findFlags |= QWebEnginePage.FindBackward
594 if wrap: 596 ## if wrap:
595 findFlags |= QWebPage.FindWrapsAroundDocument 597 ## findFlags |= QWebPage.FindWrapsAroundDocument
596 try: 598 ## try:
597 if highlightAll: 599 ## if highlightAll:
598 findFlags |= QWebPage.HighlightAllOccurrences 600 ## findFlags |= QWebPage.HighlightAllOccurrences
599 except AttributeError: 601 ## except AttributeError:
600 pass 602 ## pass
601 603
602 return self.findText(txt, findFlags) 604 if callback is None:
603 605 self.findText(txt, findFlags)
604 def __isMediaElement(self, element): 606 else:
605 """ 607 self.findText(txt, findFlags, callback)
606 Private method to check, if the given element is a media element. 608
607 609 # TODO: re-enable once WebBrowserWebElement is done
608 @param element element to be checked (QWebElement) 610 ## def __isMediaElement(self, element):
609 @return flag indicating a media element (boolean) 611 ## """
610 """ 612 ## Private method to check, if the given element is a media element.
611 return element.tagName().lower() in ["video", "audio"] 613 ##
614 ## @param element element to be checked (QWebElement)
615 ## @return flag indicating a media element (boolean)
616 ## """
617 ## return element.tagName().lower() in ["video", "audio"]
612 618
613 def contextMenuEvent(self, evt): 619 def contextMenuEvent(self, evt):
614 """ 620 """
615 Protected method called to create a context menu. 621 Protected method called to create a context menu.
616 622
617 This method is overridden from QWebView. 623 This method is overridden from QWebEngineView.
618 624
619 @param evt reference to the context menu event object 625 @param evt reference to the context menu event object
620 (QContextMenuEvent) 626 (QContextMenuEvent)
621 """ 627 """
622 from .UserAgent.UserAgentMenu import UserAgentMenu 628 # TODO: re-enable once User Agent is done
629 ## from .UserAgent.UserAgentMenu import UserAgentMenu
623 menu = QMenu(self) 630 menu = QMenu(self)
624 631
625 frameAtPos = self.page().frameAt(evt.pos()) 632 ## frameAtPos = self.page().frameAt(evt.pos())
626 hit = self.page().mainFrame().hitTestContent(evt.pos()) 633 # TODO: re-enable once WebHitTestResult is done
627 if not hit.linkUrl().isEmpty(): 634 ## hit = self.page().hitTestContent(evt.pos())
628 menu.addAction( 635 ## if not hit.linkUrl().isEmpty():
629 UI.PixmapCache.getIcon("openNewTab.png"), 636 ## menu.addAction(
630 self.tr("Open Link in New Tab\tCtrl+LMB"), 637 ## UI.PixmapCache.getIcon("openNewTab.png"),
631 self.__openLinkInNewTab).setData(hit.linkUrl()) 638 ## self.tr("Open Link in New Tab\tCtrl+LMB"),
632 menu.addSeparator() 639 ## self.__openLinkInNewTab).setData(hit.linkUrl())
633 menu.addAction( 640 ## menu.addSeparator()
634 UI.PixmapCache.getIcon("download.png"), 641 ## menu.addAction(
635 self.tr("Save Lin&k"), self.__downloadLink) 642 ## UI.PixmapCache.getIcon("download.png"),
636 menu.addAction( 643 ## self.tr("Save Lin&k"), self.__downloadLink)
637 UI.PixmapCache.getIcon("bookmark22.png"), 644 ## menu.addAction(
638 self.tr("Bookmark this Link"), self.__bookmarkLink)\ 645 ## UI.PixmapCache.getIcon("bookmark22.png"),
639 .setData(hit.linkUrl()) 646 ## self.tr("Bookmark this Link"), self.__bookmarkLink)\
640 menu.addSeparator() 647 ## .setData(hit.linkUrl())
641 menu.addAction( 648 ## menu.addSeparator()
642 UI.PixmapCache.getIcon("editCopy.png"), 649 ## menu.addAction(
643 self.tr("Copy Link to Clipboard"), self.__copyLink) 650 ## UI.PixmapCache.getIcon("editCopy.png"),
644 menu.addAction( 651 ## self.tr("Copy Link to Clipboard"), self.__copyLink)
645 UI.PixmapCache.getIcon("mailSend.png"), 652 ## menu.addAction(
646 self.tr("Send Link"), 653 ## UI.PixmapCache.getIcon("mailSend.png"),
647 self.__sendLink).setData(hit.linkUrl()) 654 ## self.tr("Send Link"),
648 if Preferences.getHelp("VirusTotalEnabled") and \ 655 ## self.__sendLink).setData(hit.linkUrl())
649 Preferences.getHelp("VirusTotalServiceKey") != "": 656 ## if Preferences.getHelp("VirusTotalEnabled") and \
650 menu.addAction( 657 ## Preferences.getHelp("VirusTotalServiceKey") != "":
651 UI.PixmapCache.getIcon("virustotal.png"), 658 ## menu.addAction(
652 self.tr("Scan Link with VirusTotal"), 659 ## UI.PixmapCache.getIcon("virustotal.png"),
653 self.__virusTotal).setData(hit.linkUrl()) 660 ## self.tr("Scan Link with VirusTotal"),
654 661 ## self.__virusTotal).setData(hit.linkUrl())
655 if not hit.imageUrl().isEmpty(): 662
656 if not menu.isEmpty(): 663 ## if not hit.imageUrl().isEmpty():
657 menu.addSeparator() 664 ## if not menu.isEmpty():
658 menu.addAction( 665 ## menu.addSeparator()
659 UI.PixmapCache.getIcon("openNewTab.png"), 666 ## menu.addAction(
660 self.tr("Open Image in New Tab"), 667 ## UI.PixmapCache.getIcon("openNewTab.png"),
661 self.__openLinkInNewTab).setData(hit.imageUrl()) 668 ## self.tr("Open Image in New Tab"),
662 menu.addSeparator() 669 ## self.__openLinkInNewTab).setData(hit.imageUrl())
663 menu.addAction( 670 ## menu.addSeparator()
664 UI.PixmapCache.getIcon("download.png"), 671 ## menu.addAction(
665 self.tr("Save Image"), self.__downloadImage) 672 ## UI.PixmapCache.getIcon("download.png"),
666 menu.addAction( 673 ## self.tr("Save Image"), self.__downloadImage)
667 self.tr("Copy Image to Clipboard"), self.__copyImage) 674 ## menu.addAction(
668 menu.addAction( 675 ## self.tr("Copy Image to Clipboard"), self.__copyImage)
669 UI.PixmapCache.getIcon("editCopy.png"), 676 ## menu.addAction(
670 self.tr("Copy Image Location to Clipboard"), 677 ## UI.PixmapCache.getIcon("editCopy.png"),
671 self.__copyLocation).setData(hit.imageUrl().toString()) 678 ## self.tr("Copy Image Location to Clipboard"),
672 menu.addAction( 679 ## self.__copyLocation).setData(hit.imageUrl().toString())
673 UI.PixmapCache.getIcon("mailSend.png"), 680 ## menu.addAction(
674 self.tr("Send Image Link"), 681 ## UI.PixmapCache.getIcon("mailSend.png"),
675 self.__sendLink).setData(hit.imageUrl()) 682 ## self.tr("Send Image Link"),
676 menu.addSeparator() 683 ## self.__sendLink).setData(hit.imageUrl())
677 menu.addAction( 684 ## menu.addSeparator()
678 UI.PixmapCache.getIcon("adBlockPlus.png"), 685 ## menu.addAction(
679 self.tr("Block Image"), self.__blockImage)\ 686 ## UI.PixmapCache.getIcon("adBlockPlus.png"),
680 .setData(hit.imageUrl().toString()) 687 ## self.tr("Block Image"), self.__blockImage)\
681 if Preferences.getHelp("VirusTotalEnabled") and \ 688 ## .setData(hit.imageUrl().toString())
682 Preferences.getHelp("VirusTotalServiceKey") != "": 689 ## if Preferences.getHelp("VirusTotalEnabled") and \
683 menu.addAction( 690 ## Preferences.getHelp("VirusTotalServiceKey") != "":
684 UI.PixmapCache.getIcon("virustotal.png"), 691 ## menu.addAction(
685 self.tr("Scan Image with VirusTotal"), 692 ## UI.PixmapCache.getIcon("virustotal.png"),
686 self.__virusTotal).setData(hit.imageUrl()) 693 ## self.tr("Scan Image with VirusTotal"),
687 694 ## self.__virusTotal).setData(hit.imageUrl())
688 element = hit.element() 695
689 if not element.isNull(): 696 ## element = hit.element()
690 if self.__isMediaElement(element): 697 ## if not element.isNull():
691 if not menu.isEmpty(): 698 ## if self.__isMediaElement(element):
692 menu.addSeparator() 699 ## if not menu.isEmpty():
693 700 ## menu.addSeparator()
694 self.__clickedMediaElement = element 701 ##
695 702 ## self.__clickedMediaElement = element
696 paused = element.evaluateJavaScript("this.paused") 703 ##
697 muted = element.evaluateJavaScript("this.muted") 704 ## paused = element.evaluateJavaScript("this.paused")
698 videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc")) 705 ## muted = element.evaluateJavaScript("this.muted")
699 706 ## videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc"))
700 if paused: 707 ##
701 menu.addAction( 708 ## if paused:
702 UI.PixmapCache.getIcon("mediaPlaybackStart.png"), 709 ## menu.addAction(
703 self.tr("Play"), self.__pauseMedia) 710 ## UI.PixmapCache.getIcon("mediaPlaybackStart.png"),
704 else: 711 ## self.tr("Play"), self.__pauseMedia)
705 menu.addAction( 712 ## else:
706 UI.PixmapCache.getIcon("mediaPlaybackPause.png"), 713 ## menu.addAction(
707 self.tr("Pause"), self.__pauseMedia) 714 ## UI.PixmapCache.getIcon("mediaPlaybackPause.png"),
708 if muted: 715 ## self.tr("Pause"), self.__pauseMedia)
709 menu.addAction( 716 ## if muted:
710 UI.PixmapCache.getIcon("audioVolumeHigh.png"), 717 ## menu.addAction(
711 self.tr("Unmute"), self.__muteMedia) 718 ## UI.PixmapCache.getIcon("audioVolumeHigh.png"),
712 else: 719 ## self.tr("Unmute"), self.__muteMedia)
713 menu.addAction( 720 ## else:
714 UI.PixmapCache.getIcon("audioVolumeMuted.png"), 721 ## menu.addAction(
715 self.tr("Mute"), self.__muteMedia) 722 ## UI.PixmapCache.getIcon("audioVolumeMuted.png"),
716 menu.addSeparator() 723 ## self.tr("Mute"), self.__muteMedia)
717 menu.addAction( 724 ## menu.addSeparator()
718 UI.PixmapCache.getIcon("editCopy.png"), 725 ## menu.addAction(
719 self.tr("Copy Media Address to Clipboard"), 726 ## UI.PixmapCache.getIcon("editCopy.png"),
720 self.__copyLocation).setData(videoUrl.toString()) 727 ## self.tr("Copy Media Address to Clipboard"),
721 menu.addAction( 728 ## self.__copyLocation).setData(videoUrl.toString())
722 UI.PixmapCache.getIcon("mailSend.png"), 729 ## menu.addAction(
723 self.tr("Send Media Address"), self.__sendLink)\ 730 ## UI.PixmapCache.getIcon("mailSend.png"),
724 .setData(videoUrl) 731 ## self.tr("Send Media Address"), self.__sendLink)\
725 menu.addAction( 732 ## .setData(videoUrl)
726 UI.PixmapCache.getIcon("download.png"), 733 ## menu.addAction(
727 self.tr("Save Media"), self.__downloadMedia)\ 734 ## UI.PixmapCache.getIcon("download.png"),
728 .setData(videoUrl) 735 ## self.tr("Save Media"), self.__downloadMedia)\
729 736 ## .setData(videoUrl)
730 if element.tagName().lower() in ["input", "textarea"]: 737 ##
731 if menu.isEmpty(): 738 ## if element.tagName().lower() in ["input", "textarea"]:
732 pageMenu = self.page().createStandardContextMenu() 739 ## if menu.isEmpty():
733 directionFound = False 740 ## pageMenu = self.page().createStandardContextMenu()
734 # used to detect double direction entry 741 ## directionFound = False
735 for act in pageMenu.actions(): 742 ## # used to detect double direction entry
736 if act.isSeparator(): 743 ## for act in pageMenu.actions():
737 menu.addSeparator() 744 ## if act.isSeparator():
738 continue 745 ## menu.addSeparator()
739 if act.menu(): 746 ## continue
740 if self.pageAction( 747 ## if act.menu():
741 QWebPage.SetTextDirectionDefault) in \ 748 ## if self.pageAction(
742 act.menu().actions(): 749 ## QWebPage.SetTextDirectionDefault) in \
743 if directionFound: 750 ## act.menu().actions():
744 act.setVisible(False) 751 ## if directionFound:
745 directionFound = True 752 ## act.setVisible(False)
746 elif self.pageAction(QWebPage.ToggleBold) in \ 753 ## directionFound = True
747 act.menu().actions(): 754 ## elif self.pageAction(QWebPage.ToggleBold) in \
748 act.setVisible(False) 755 ## act.menu().actions():
749 elif act == self.pageAction(QWebPage.InspectElement): 756 ## act.setVisible(False)
750 # we have our own inspect entry 757 ## elif act == self.pageAction(QWebPage.InspectElement):
751 act.setVisible(False) 758 ## # we have our own inspect entry
752 menu.addAction(act) 759 ## act.setVisible(False)
753 pageMenu = None 760 ## menu.addAction(act)
761 ## pageMenu = None
754 762
755 if not menu.isEmpty(): 763 if not menu.isEmpty():
756 menu.addSeparator() 764 menu.addSeparator()
757 765
758 self.__mw.personalInformationManager().createSubMenu(menu, self, hit) 766 # TODO: re-enable once PIM is done
767 ## self.__mw.personalInformationManager().createSubMenu(menu, self, hit)
759 768
760 menu.addAction(self.__mw.newTabAct) 769 menu.addAction(self.__mw.newTabAct)
761 menu.addAction(self.__mw.newAct) 770 menu.addAction(self.__mw.newAct)
762 menu.addSeparator() 771 menu.addSeparator()
763 menu.addAction(self.__mw.saveAsAct) 772 ## menu.addAction(self.__mw.saveAsAct)
764 menu.addSeparator() 773 ## menu.addSeparator()
765 774
766 if frameAtPos and self.page().mainFrame() != frameAtPos: 775 ## if frameAtPos and self.page().mainFrame() != frameAtPos:
767 self.__clickedFrame = frameAtPos 776 ## self.__clickedFrame = frameAtPos
768 fmenu = QMenu(self.tr("This Frame")) 777 ## fmenu = QMenu(self.tr("This Frame"))
769 frameUrl = self.__clickedFrame.url() 778 ## frameUrl = self.__clickedFrame.url()
770 if frameUrl.isValid(): 779 ## if frameUrl.isValid():
771 fmenu.addAction( 780 ## fmenu.addAction(
772 self.tr("Show &only this frame"), 781 ## self.tr("Show &only this frame"),
773 self.__loadClickedFrame) 782 ## self.__loadClickedFrame)
774 fmenu.addAction( 783 ## fmenu.addAction(
775 UI.PixmapCache.getIcon("openNewTab.png"), 784 ## UI.PixmapCache.getIcon("openNewTab.png"),
776 self.tr("Show in new &tab"), 785 ## self.tr("Show in new &tab"),
777 self.__openLinkInNewTab).setData(self.__clickedFrame.url()) 786 ## self.__openLinkInNewTab).setData(self.__clickedFrame.url())
778 fmenu.addSeparator() 787 ## fmenu.addSeparator()
779 fmenu.addAction( 788 ## fmenu.addAction(
780 UI.PixmapCache.getIcon("print.png"), 789 ## UI.PixmapCache.getIcon("print.png"),
781 self.tr("&Print"), self.__printClickedFrame) 790 ## self.tr("&Print"), self.__printClickedFrame)
782 fmenu.addAction( 791 ## fmenu.addAction(
783 UI.PixmapCache.getIcon("printPreview.png"), 792 ## UI.PixmapCache.getIcon("printPreview.png"),
784 self.tr("Print Preview"), self.__printPreviewClickedFrame) 793 ## self.tr("Print Preview"), self.__printPreviewClickedFrame)
785 fmenu.addAction( 794 ## fmenu.addAction(
786 UI.PixmapCache.getIcon("printPdf.png"), 795 ## UI.PixmapCache.getIcon("printPdf.png"),
787 self.tr("Print as PDF"), self.__printPdfClickedFrame) 796 ## self.tr("Print as PDF"), self.__printPdfClickedFrame)
788 fmenu.addSeparator() 797 ## fmenu.addSeparator()
789 fmenu.addAction( 798 ## fmenu.addAction(
790 UI.PixmapCache.getIcon("zoomIn.png"), 799 ## UI.PixmapCache.getIcon("zoomIn.png"),
791 self.tr("Zoom &in"), self.__zoomInClickedFrame) 800 ## self.tr("Zoom &in"), self.__zoomInClickedFrame)
792 fmenu.addAction( 801 ## fmenu.addAction(
793 UI.PixmapCache.getIcon("zoomReset.png"), 802 ## UI.PixmapCache.getIcon("zoomReset.png"),
794 self.tr("Zoom &reset"), self.__zoomResetClickedFrame) 803 ## self.tr("Zoom &reset"), self.__zoomResetClickedFrame)
795 fmenu.addAction( 804 ## fmenu.addAction(
796 UI.PixmapCache.getIcon("zoomOut.png"), 805 ## UI.PixmapCache.getIcon("zoomOut.png"),
797 self.tr("Zoom &out"), self.__zoomOutClickedFrame) 806 ## self.tr("Zoom &out"), self.__zoomOutClickedFrame)
798 fmenu.addSeparator() 807 ## fmenu.addSeparator()
799 fmenu.addAction( 808 ## fmenu.addAction(
800 self.tr("Show frame so&urce"), 809 ## self.tr("Show frame so&urce"),
801 self.__showClickedFrameSource) 810 ## self.__showClickedFrameSource)
802 811 ##
803 menu.addMenu(fmenu) 812 ## menu.addMenu(fmenu)
804 menu.addSeparator() 813 ## menu.addSeparator()
805 814
806 menu.addAction( 815 menu.addAction(
807 UI.PixmapCache.getIcon("bookmark22.png"), 816 UI.PixmapCache.getIcon("bookmark22.png"),
808 self.tr("Bookmark this Page"), self.addBookmark) 817 self.tr("Bookmark this Page"), self.addBookmark)
809 menu.addAction( 818 menu.addAction(
810 UI.PixmapCache.getIcon("mailSend.png"), 819 UI.PixmapCache.getIcon("mailSend.png"),
811 self.tr("Send Page Link"), self.__sendLink).setData(self.url()) 820 self.tr("Send Page Link"), self.__sendLink).setData(self.url())
812 menu.addSeparator() 821 menu.addSeparator()
813 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"), 822 # TODO: re-enable once User Agent is done
814 url=self.url()) 823 ## self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
815 menu.addMenu(self.__userAgentMenu) 824 ## url=self.url())
816 menu.addSeparator() 825 ## menu.addMenu(self.__userAgentMenu)
826 ## menu.addSeparator()
817 menu.addAction(self.__mw.backAct) 827 menu.addAction(self.__mw.backAct)
818 menu.addAction(self.__mw.forwardAct) 828 menu.addAction(self.__mw.forwardAct)
819 menu.addAction(self.__mw.homeAct) 829 menu.addAction(self.__mw.homeAct)
820 menu.addSeparator() 830 menu.addSeparator()
821 menu.addAction(self.__mw.zoomInAct) 831 menu.addAction(self.__mw.zoomInAct)
829 self.tr("Send Text"), 839 self.tr("Send Text"),
830 self.__sendLink).setData(self.selectedText()) 840 self.__sendLink).setData(self.selectedText())
831 menu.addAction(self.__mw.findAct) 841 menu.addAction(self.__mw.findAct)
832 menu.addSeparator() 842 menu.addSeparator()
833 if self.selectedText(): 843 if self.selectedText():
834 self.__searchMenu = menu.addMenu(self.tr("Search with...")) 844 # TODO: re-enable once Open Search is done
845 ## self.__searchMenu = menu.addMenu(self.tr("Search with..."))
846 ##
847 ## from .OpenSearch.OpenSearchEngineAction import \
848 ## OpenSearchEngineAction
849 ## engineNames = self.__mw.openSearchManager().allEnginesNames()
850 ## for engineName in engineNames:
851 ## engine = self.__mw.openSearchManager().engine(engineName)
852 ## act = OpenSearchEngineAction(engine, self.__searchMenu)
853 ## act.setData(engineName)
854 ## self.__searchMenu.addAction(act)
855 ## self.__searchMenu.triggered.connect(self.__searchRequested)
856 ##
857 ## menu.addSeparator()
835 858
836 from .OpenSearch.OpenSearchEngineAction import \ 859 # TODO: re-enable once Languages Dialog is done
837 OpenSearchEngineAction 860 ## from .HelpLanguagesDialog import HelpLanguagesDialog
838 engineNames = self.__mw.openSearchManager().allEnginesNames() 861 ## languages = Preferences.toList(
839 for engineName in engineNames: 862 ## Preferences.Prefs.settings.value(
840 engine = self.__mw.openSearchManager().engine(engineName) 863 ## "Help/AcceptLanguages",
841 act = OpenSearchEngineAction(engine, self.__searchMenu) 864 ## HelpLanguagesDialog.defaultAcceptLanguages()))
842 act.setData(engineName) 865 ## if languages:
843 self.__searchMenu.addAction(act) 866 ## language = languages[0]
844 self.__searchMenu.triggered.connect(self.__searchRequested) 867 ## langCode = language.split("[")[1][:2]
845 868 ## googleTranslatorUrl = QUrl(
846 menu.addSeparator() 869 ## "http://translate.google.com/#auto|{0}|{1}".format(
847 870 ## langCode, self.selectedText()))
848 from .HelpLanguagesDialog import HelpLanguagesDialog 871 ## menu.addAction(
849 languages = Preferences.toList( 872 ## UI.PixmapCache.getIcon("translate.png"),
850 Preferences.Prefs.settings.value( 873 ## self.tr("Google Translate"), self.__openLinkInNewTab)\
851 "Help/AcceptLanguages", 874 ## .setData(googleTranslatorUrl)
852 HelpLanguagesDialog.defaultAcceptLanguages())) 875 ## wiktionaryUrl = QUrl(
853 if languages: 876 ## "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
854 language = languages[0] 877 ## .format(langCode, self.selectedText()))
855 langCode = language.split("[")[1][:2] 878 ## menu.addAction(
856 googleTranslatorUrl = QUrl( 879 ## UI.PixmapCache.getIcon("wikipedia.png"),
857 "http://translate.google.com/#auto|{0}|{1}".format( 880 ## self.tr("Dictionary"), self.__openLinkInNewTab)\
858 langCode, self.selectedText())) 881 ## .setData(wiktionaryUrl)
859 menu.addAction( 882 ## menu.addSeparator()
860 UI.PixmapCache.getIcon("translate.png"),
861 self.tr("Google Translate"), self.__openLinkInNewTab)\
862 .setData(googleTranslatorUrl)
863 wiktionaryUrl = QUrl(
864 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
865 .format(langCode, self.selectedText()))
866 menu.addAction(
867 UI.PixmapCache.getIcon("wikipedia.png"),
868 self.tr("Dictionary"), self.__openLinkInNewTab)\
869 .setData(wiktionaryUrl)
870 menu.addSeparator()
871 883
872 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) 884 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
873 if self.__isUrlValid(guessedUrl): 885 if self.__isUrlValid(guessedUrl):
874 menu.addAction( 886 menu.addAction(
875 self.tr("Go to web address"), 887 self.tr("Go to web address"),
876 self.__openLinkInNewTab).setData(guessedUrl) 888 self.__openLinkInNewTab).setData(guessedUrl)
877 menu.addSeparator() 889 menu.addSeparator()
878 890 ##
879 element = hit.element() 891 ## element = hit.element()
880 if not element.isNull() and \ 892 ## if not element.isNull() and \
881 element.tagName().lower() == "input" and \ 893 ## element.tagName().lower() == "input" and \
882 element.attribute("type", "text") == "text": 894 ## element.attribute("type", "text") == "text":
883 menu.addAction(self.tr("Add to web search toolbar"), 895 ## menu.addAction(self.tr("Add to web search toolbar"),
884 self.__addSearchEngine).setData(element) 896 ## self.__addSearchEngine).setData(element)
885 menu.addSeparator() 897 ## menu.addSeparator()
886 898
887 menu.addAction( 899 # TODO: re-enable once Web Inspector is done
888 UI.PixmapCache.getIcon("webInspector.png"), 900 ## menu.addAction(
889 self.tr("Web Inspector..."), self.__webInspector) 901 ## UI.PixmapCache.getIcon("webInspector.png"),
902 ## self.tr("Web Inspector..."), self.__webInspector)
890 903
891 menu.exec_(evt.globalPos()) 904 menu.exec_(evt.globalPos())
892 905
893 def __isUrlValid(self, url): 906 def __isUrlValid(self, url):
894 """ 907 """
910 act = self.sender() 923 act = self.sender()
911 url = act.data() 924 url = act.data()
912 if url.isEmpty(): 925 if url.isEmpty():
913 return 926 return
914 927
928 # TODO: check, if this can be done simpler
915 self.__ctrlPressed = True 929 self.__ctrlPressed = True
916 self.setSource(url) 930 self.setSource(url)
917 self.__ctrlPressed = False 931 self.__ctrlPressed = False
918 932
919 def __bookmarkLink(self): 933 # TODO: Bookmarks
920 """ 934 ## def __bookmarkLink(self):
921 Private slot to bookmark a link via the context menu. 935 ## """
922 """ 936 ## Private slot to bookmark a link via the context menu.
923 act = self.sender() 937 ## """
924 url = act.data() 938 ## act = self.sender()
925 if url.isEmpty(): 939 ## url = act.data()
926 return 940 ## if url.isEmpty():
927 941 ## return
928 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 942 ##
929 dlg = AddBookmarkDialog() 943 ## from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
930 dlg.setUrl(bytes(url.toEncoded()).decode()) 944 ## dlg = AddBookmarkDialog()
931 dlg.exec_() 945 ## dlg.setUrl(bytes(url.toEncoded()).decode())
946 ## dlg.exec_()
932 947
933 def __sendLink(self): 948 def __sendLink(self):
934 """ 949 """
935 Private slot to send a link via email. 950 Private slot to send a link via email.
936 """ 951 """
941 956
942 if isinstance(data, QUrl): 957 if isinstance(data, QUrl):
943 data = data.toString() 958 data = data.toString()
944 QDesktopServices.openUrl(QUrl("mailto:?body=" + data)) 959 QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
945 960
946 def __downloadLink(self): 961 ## def __downloadLink(self):
947 """ 962 ## """
948 Private slot to download a link and save it to disk. 963 ## Private slot to download a link and save it to disk.
949 """ 964 ## """
950 self.pageAction(QWebPage.DownloadLinkToDisk).trigger() 965 ## self.pageAction(QWebPage.DownloadLinkToDisk).trigger()
951 966 ##
952 def __copyLink(self): 967 ## def __copyLink(self):
953 """ 968 ## """
954 Private slot to copy a link to the clipboard. 969 ## Private slot to copy a link to the clipboard.
955 """ 970 ## """
956 self.pageAction(QWebPage.CopyLinkToClipboard).trigger() 971 ## self.pageAction(QWebPage.CopyLinkToClipboard).trigger()
957 972 ##
958 def __downloadImage(self): 973 ## def __downloadImage(self):
959 """ 974 ## """
960 Private slot to download an image and save it to disk. 975 ## Private slot to download an image and save it to disk.
961 """ 976 ## """
962 self.pageAction(QWebPage.DownloadImageToDisk).trigger() 977 ## self.pageAction(QWebPage.DownloadImageToDisk).trigger()
963 978 ##
964 def __copyImage(self): 979 ## def __copyImage(self):
965 """ 980 ## """
966 Private slot to copy an image to the clipboard. 981 ## Private slot to copy an image to the clipboard.
967 """ 982 ## """
968 self.pageAction(QWebPage.CopyImageToClipboard).trigger() 983 ## self.pageAction(QWebPage.CopyImageToClipboard).trigger()
969 984
970 def __copyLocation(self): 985 def __copyLocation(self):
971 """ 986 """
972 Private slot to copy an image or media location to the clipboard. 987 Private slot to copy an image or media location to the clipboard.
973 """ 988 """
974 act = self.sender() 989 act = self.sender()
975 url = act.data() 990 url = act.data()
976 QApplication.clipboard().setText(url) 991 QApplication.clipboard().setText(url)
977 992
978 def __blockImage(self): 993 # TODO: AdBlock
979 """ 994 ## def __blockImage(self):
980 Private slot to add a block rule for an image URL. 995 ## """
981 """ 996 ## Private slot to add a block rule for an image URL.
982 import Helpviewer.HelpWindow 997 ## """
983 act = self.sender() 998 ## import Helpviewer.HelpWindow
984 url = act.data() 999 ## act = self.sender()
985 dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager().showDialog() 1000 ## url = act.data()
986 dlg.addCustomRule(url) 1001 ## dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager().showDialog()
987 1002 ## dlg.addCustomRule(url)
1003
1004 # TODO: DownloadManager
988 def __downloadMedia(self): 1005 def __downloadMedia(self):
989 """ 1006 """
990 Private slot to download a media and save it to disk. 1007 Private slot to download a media and save it to disk.
991 """ 1008 """
992 act = self.sender() 1009 act = self.sender()
993 url = act.data() 1010 url = act.data()
994 self.__mw.downloadManager().download(url, True, mainWindow=self.__mw) 1011 self.__mw.downloadManager().download(url, True, mainWindow=self.__mw)
995 1012
996 def __pauseMedia(self): 1013 # TODO: this needs to be changed
997 """ 1014 ## def __pauseMedia(self):
998 Private slot to pause or play the selected media. 1015 ## """
999 """ 1016 ## Private slot to pause or play the selected media.
1000 paused = self.__clickedMediaElement.evaluateJavaScript("this.paused") 1017 ## """
1001 1018 ## paused = self.__clickedMediaElement.evaluateJavaScript("this.paused")
1002 if paused: 1019 ##
1003 self.__clickedMediaElement.evaluateJavaScript("this.play()") 1020 ## if paused:
1004 else: 1021 ## self.__clickedMediaElement.evaluateJavaScript("this.play()")
1005 self.__clickedMediaElement.evaluateJavaScript("this.pause()") 1022 ## else:
1006 1023 ## self.__clickedMediaElement.evaluateJavaScript("this.pause()")
1007 def __muteMedia(self): 1024 ##
1008 """ 1025 ## def __muteMedia(self):
1009 Private slot to (un)mute the selected media. 1026 ## """
1010 """ 1027 ## Private slot to (un)mute the selected media.
1011 muted = self.__clickedMediaElement.evaluateJavaScript("this.muted") 1028 ## """
1012 1029 ## muted = self.__clickedMediaElement.evaluateJavaScript("this.muted")
1013 if muted: 1030 ##
1014 self.__clickedMediaElement.evaluateJavaScript("this.muted = false") 1031 ## if muted:
1015 else: 1032 ## self.__clickedMediaElement.evaluateJavaScript("this.muted = false")
1016 self.__clickedMediaElement.evaluateJavaScript("this.muted = true") 1033 ## else:
1017 1034 ## self.__clickedMediaElement.evaluateJavaScript("this.muted = true")
1018 def __virusTotal(self): 1035
1019 """ 1036 # TODO: VirusTotal
1020 Private slot to scan the selected URL with VirusTotal. 1037 ## def __virusTotal(self):
1021 """ 1038 ## """
1022 act = self.sender() 1039 ## Private slot to scan the selected URL with VirusTotal.
1023 url = act.data() 1040 ## """
1024 self.__mw.requestVirusTotalScan(url) 1041 ## act = self.sender()
1025 1042 ## url = act.data()
1026 def __searchRequested(self, act): 1043 ## self.__mw.requestVirusTotalScan(url)
1027 """ 1044
1028 Private slot to search for some text with a selected search engine. 1045 # TODO OpenSearch
1029 1046 ## def __searchRequested(self, act):
1030 @param act reference to the action that triggered this slot (QAction) 1047 ## """
1031 """ 1048 ## Private slot to search for some text with a selected search engine.
1032 searchText = self.selectedText() 1049 ##
1033 1050 ## @param act reference to the action that triggered this slot (QAction)
1034 if not searchText: 1051 ## """
1035 return 1052 ## searchText = self.selectedText()
1036 1053 ##
1037 engineName = act.data() 1054 ## if not searchText:
1038 if engineName: 1055 ## return
1039 engine = self.__mw.openSearchManager().engine(engineName) 1056 ##
1040 self.search.emit(engine.searchUrl(searchText)) 1057 ## engineName = act.data()
1041 1058 ## if engineName:
1042 def __addSearchEngine(self): 1059 ## engine = self.__mw.openSearchManager().engine(engineName)
1043 """ 1060 ## self.search.emit(engine.searchUrl(searchText))
1044 Private slot to add a new search engine. 1061 ##
1045 """ 1062 ## def __addSearchEngine(self):
1046 act = self.sender() 1063 ## """
1047 if act is None: 1064 ## Private slot to add a new search engine.
1048 return 1065 ## """
1049 1066 ## act = self.sender()
1050 element = act.data() 1067 ## if act is None:
1051 elementName = element.attribute("name") 1068 ## return
1052 formElement = QWebElement(element) 1069 ##
1053 while formElement.tagName().lower() != "form": 1070 ## element = act.data()
1054 formElement = formElement.parent() 1071 ## elementName = element.attribute("name")
1055 1072 ## formElement = QWebElement(element)
1056 if formElement.isNull() or \ 1073 ## while formElement.tagName().lower() != "form":
1057 formElement.attribute("action") == "": 1074 ## formElement = formElement.parent()
1058 return 1075 ##
1059 1076 ## if formElement.isNull() or \
1060 method = formElement.attribute("method", "get").lower() 1077 ## formElement.attribute("action") == "":
1061 if method != "get": 1078 ## return
1062 E5MessageBox.warning( 1079 ##
1063 self, 1080 ## method = formElement.attribute("method", "get").lower()
1064 self.tr("Method not supported"), 1081 ## if method != "get":
1065 self.tr( 1082 ## E5MessageBox.warning(
1066 """{0} method is not supported.""").format(method.upper())) 1083 ## self,
1067 return 1084 ## self.tr("Method not supported"),
1068 1085 ## self.tr(
1069 searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved( 1086 ## """{0} method is not supported.""").format(method.upper()))
1070 QUrl(formElement.attribute("action")))) 1087 ## return
1071 if searchUrl.scheme() != "http": 1088 ##
1072 return 1089 ## searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved(
1073 1090 ## QUrl(formElement.attribute("action"))))
1074 if qVersion() >= "5.0.0": 1091 ## if searchUrl.scheme() != "http":
1075 from PyQt5.QtCore import QUrlQuery 1092 ## return
1076 searchUrlQuery = QUrlQuery(searchUrl) 1093 ##
1077 searchEngines = {} 1094 ## if qVersion() >= "5.0.0":
1078 inputFields = formElement.findAll("input") 1095 ## from PyQt5.QtCore import QUrlQuery
1079 for inputField in inputFields.toList(): 1096 ## searchUrlQuery = QUrlQuery(searchUrl)
1080 type_ = inputField.attribute("type", "text") 1097 ## searchEngines = {}
1081 name = inputField.attribute("name") 1098 ## inputFields = formElement.findAll("input")
1082 value = inputField.evaluateJavaScript("this.value") 1099 ## for inputField in inputFields.toList():
1083 1100 ## type_ = inputField.attribute("type", "text")
1084 if type_ == "submit": 1101 ## name = inputField.attribute("name")
1085 searchEngines[value] = name 1102 ## value = inputField.evaluateJavaScript("this.value")
1086 elif type_ == "text": 1103 ##
1087 if inputField == element: 1104 ## if type_ == "submit":
1088 value = "{searchTerms}" 1105 ## searchEngines[value] = name
1089 if qVersion() >= "5.0.0": 1106 ## elif type_ == "text":
1090 searchUrlQuery.addQueryItem(name, value) 1107 ## if inputField == element:
1091 else: 1108 ## value = "{searchTerms}"
1092 searchUrl.addQueryItem(name, value) 1109 ## if qVersion() >= "5.0.0":
1093 elif type_ == "checkbox" or type_ == "radio": 1110 ## searchUrlQuery.addQueryItem(name, value)
1094 if inputField.evaluateJavaScript("this.checked"): 1111 ## else:
1095 if qVersion() >= "5.0.0": 1112 ## searchUrl.addQueryItem(name, value)
1096 searchUrlQuery.addQueryItem(name, value) 1113 ## elif type_ == "checkbox" or type_ == "radio":
1097 else: 1114 ## if inputField.evaluateJavaScript("this.checked"):
1098 searchUrl.addQueryItem(name, value) 1115 ## if qVersion() >= "5.0.0":
1099 elif type_ == "hidden": 1116 ## searchUrlQuery.addQueryItem(name, value)
1100 if qVersion() >= "5.0.0": 1117 ## else:
1101 searchUrlQuery.addQueryItem(name, value) 1118 ## searchUrl.addQueryItem(name, value)
1102 else: 1119 ## elif type_ == "hidden":
1103 searchUrl.addQueryItem(name, value) 1120 ## if qVersion() >= "5.0.0":
1104 1121 ## searchUrlQuery.addQueryItem(name, value)
1105 selectFields = formElement.findAll("select") 1122 ## else:
1106 for selectField in selectFields.toList(): 1123 ## searchUrl.addQueryItem(name, value)
1107 name = selectField.attribute("name") 1124 ##
1108 selectedIndex = selectField.evaluateJavaScript( 1125 ## selectFields = formElement.findAll("select")
1109 "this.selectedIndex") 1126 ## for selectField in selectFields.toList():
1110 if selectedIndex == -1: 1127 ## name = selectField.attribute("name")
1111 continue 1128 ## selectedIndex = selectField.evaluateJavaScript(
1112 1129 ## "this.selectedIndex")
1113 options = selectField.findAll("option") 1130 ## if selectedIndex == -1:
1114 value = options.at(selectedIndex).toPlainText() 1131 ## continue
1115 if qVersion() >= "5.0.0": 1132 ##
1116 searchUrlQuery.addQueryItem(name, value) 1133 ## options = selectField.findAll("option")
1117 else: 1134 ## value = options.at(selectedIndex).toPlainText()
1118 searchUrl.addQueryItem(name, value) 1135 ## if qVersion() >= "5.0.0":
1119 1136 ## searchUrlQuery.addQueryItem(name, value)
1120 ok = True 1137 ## else:
1121 if len(searchEngines) > 1: 1138 ## searchUrl.addQueryItem(name, value)
1122 searchEngine, ok = QInputDialog.getItem( 1139 ##
1123 self, 1140 ## ok = True
1124 self.tr("Search engine"), 1141 ## if len(searchEngines) > 1:
1125 self.tr("Choose the desired search engine"), 1142 ## searchEngine, ok = QInputDialog.getItem(
1126 sorted(searchEngines.keys()), 0, False) 1143 ## self,
1127 1144 ## self.tr("Search engine"),
1128 if not ok: 1145 ## self.tr("Choose the desired search engine"),
1129 return 1146 ## sorted(searchEngines.keys()), 0, False)
1130 1147 ##
1131 if searchEngines[searchEngine] != "": 1148 ## if not ok:
1132 if qVersion() >= "5.0.0": 1149 ## return
1133 searchUrlQuery.addQueryItem( 1150 ##
1134 searchEngines[searchEngine], searchEngine) 1151 ## if searchEngines[searchEngine] != "":
1135 else: 1152 ## if qVersion() >= "5.0.0":
1136 searchUrl.addQueryItem( 1153 ## searchUrlQuery.addQueryItem(
1137 searchEngines[searchEngine], searchEngine) 1154 ## searchEngines[searchEngine], searchEngine)
1138 engineName = "" 1155 ## else:
1139 labels = formElement.findAll('label[for="{0}"]'.format(elementName)) 1156 ## searchUrl.addQueryItem(
1140 if labels.count() > 0: 1157 ## searchEngines[searchEngine], searchEngine)
1141 engineName = labels.at(0).toPlainText() 1158 ## engineName = ""
1142 1159 ## labels = formElement.findAll('label[for="{0}"]'.format(elementName))
1143 engineName, ok = QInputDialog.getText( 1160 ## if labels.count() > 0:
1144 self, 1161 ## engineName = labels.at(0).toPlainText()
1145 self.tr("Engine name"), 1162 ##
1146 self.tr("Enter a name for the engine"), 1163 ## engineName, ok = QInputDialog.getText(
1147 QLineEdit.Normal, 1164 ## self,
1148 engineName) 1165 ## self.tr("Engine name"),
1149 if not ok: 1166 ## self.tr("Enter a name for the engine"),
1150 return 1167 ## QLineEdit.Normal,
1151 1168 ## engineName)
1152 if qVersion() >= "5.0.0": 1169 ## if not ok:
1153 searchUrl.setQuery(searchUrlQuery) 1170 ## return
1154 1171 ##
1155 from .OpenSearch.OpenSearchEngine import OpenSearchEngine 1172 ## if qVersion() >= "5.0.0":
1156 engine = OpenSearchEngine() 1173 ## searchUrl.setQuery(searchUrlQuery)
1157 engine.setName(engineName) 1174 ##
1158 engine.setDescription(engineName) 1175 ## from .OpenSearch.OpenSearchEngine import OpenSearchEngine
1159 engine.setSearchUrlTemplate(searchUrl.toString()) 1176 ## engine = OpenSearchEngine()
1160 engine.setImage(self.icon().pixmap(16, 16).toImage()) 1177 ## engine.setName(engineName)
1161 1178 ## engine.setDescription(engineName)
1162 self.__mw.openSearchManager().addEngine(engine) 1179 ## engine.setSearchUrlTemplate(searchUrl.toString())
1163 1180 ## engine.setImage(self.icon().pixmap(16, 16).toImage())
1164 def __webInspector(self): 1181 ##
1165 """ 1182 ## self.__mw.openSearchManager().addEngine(engine)
1166 Private slot to show the web inspector window. 1183
1167 """ 1184 # TODO: WebInspector
1168 if self.__inspector is None: 1185 ## def __webInspector(self):
1169 from .HelpInspector import HelpInspector 1186 ## """
1170 self.__inspector = HelpInspector() 1187 ## Private slot to show the web inspector window.
1171 self.__inspector.setPage(self.page()) 1188 ## """
1172 self.__inspector.show() 1189 ## if self.__inspector is None:
1173 elif self.__inspector.isVisible(): 1190 ## from .HelpInspector import HelpInspector
1174 self.__inspector.hide() 1191 ## self.__inspector = HelpInspector()
1175 else: 1192 ## self.__inspector.setPage(self.page())
1176 self.__inspector.show() 1193 ## self.__inspector.show()
1177 1194 ## elif self.__inspector.isVisible():
1178 def closeWebInspector(self): 1195 ## self.__inspector.hide()
1179 """ 1196 ## else:
1180 Public slot to close the web inspector. 1197 ## self.__inspector.show()
1181 """ 1198 ##
1182 if self.__inspector is not None: 1199 ## def closeWebInspector(self):
1183 if self.__inspector.isVisible(): 1200 ## """
1184 self.__inspector.hide() 1201 ## Public slot to close the web inspector.
1185 self.__inspector.deleteLater() 1202 ## """
1186 self.__inspector = None 1203 ## if self.__inspector is not None:
1187 1204 ## if self.__inspector.isVisible():
1188 def addBookmark(self): 1205 ## self.__inspector.hide()
1189 """ 1206 ## self.__inspector.deleteLater()
1190 Public slot to bookmark the current page. 1207 ## self.__inspector = None
1191 """ 1208
1192 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 1209 # TODO: Bookmarks
1193 dlg = AddBookmarkDialog() 1210 ## def addBookmark(self):
1194 dlg.setUrl(bytes(self.url().toEncoded()).decode()) 1211 ## """
1195 dlg.setTitle(self.title()) 1212 ## Public slot to bookmark the current page.
1196 meta = self.page().mainFrame().metaData() 1213 ## """
1197 if "description" in meta: 1214 ## from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
1198 dlg.setDescription(meta["description"][0]) 1215 ## dlg = AddBookmarkDialog()
1199 dlg.exec_() 1216 ## dlg.setUrl(bytes(self.url().toEncoded()).decode())
1217 ## dlg.setTitle(self.title())
1218 ## meta = self.page().mainFrame().metaData()
1219 ## if "description" in meta:
1220 ## dlg.setDescription(meta["description"][0])
1221 ## dlg.exec_()
1200 1222
1201 def dragEnterEvent(self, evt): 1223 def dragEnterEvent(self, evt):
1202 """ 1224 """
1203 Protected method called by a drag enter event. 1225 Protected method called by a drag enter event.
1204 1226
1220 url = QUrl(evt.mimeData().text()) 1242 url = QUrl(evt.mimeData().text())
1221 if url.isValid(): 1243 if url.isValid():
1222 evt.acceptProposedAction() 1244 evt.acceptProposedAction()
1223 1245
1224 if not evt.isAccepted(): 1246 if not evt.isAccepted():
1225 super(HelpBrowser, self).dragMoveEvent(evt) 1247 super(WebBrowserView, self).dragMoveEvent(evt)
1226 1248
1227 def dropEvent(self, evt): 1249 def dropEvent(self, evt):
1228 """ 1250 """
1229 Protected method called by a drop event. 1251 Protected method called by a drop event.
1230 1252
1231 @param evt reference to the drop event (QDropEvent) 1253 @param evt reference to the drop event (QDropEvent)
1232 """ 1254 """
1233 super(HelpBrowser, self).dropEvent(evt) 1255 super(WebBrowserView, self).dropEvent(evt)
1234 if not evt.isAccepted() and \ 1256 if not evt.isAccepted() and \
1235 evt.source() != self and \ 1257 evt.source() != self and \
1236 evt.possibleActions() & Qt.CopyAction: 1258 evt.possibleActions() & Qt.CopyAction:
1237 url = QUrl() 1259 url = QUrl()
1238 if len(evt.mimeData().urls()) > 0: 1260 if len(evt.mimeData().urls()) > 0:
1251 """ 1273 """
1252 self.__mw.setEventMouseButtons(evt.buttons()) 1274 self.__mw.setEventMouseButtons(evt.buttons())
1253 self.__mw.setEventKeyboardModifiers(evt.modifiers()) 1275 self.__mw.setEventKeyboardModifiers(evt.modifiers())
1254 1276
1255 if evt.button() == Qt.XButton1: 1277 if evt.button() == Qt.XButton1:
1256 self.pageAction(QWebPage.Back).trigger() 1278 self.pageAction(QWebEnginePage.Back).trigger()
1257 elif evt.button() == Qt.XButton2: 1279 elif evt.button() == Qt.XButton2:
1258 self.pageAction(QWebPage.Forward).trigger() 1280 self.pageAction(QWebEnginePage.Forward).trigger()
1259 else: 1281 else:
1260 super(HelpBrowser, self).mousePressEvent(evt) 1282 super(WebBrowserView, self).mousePressEvent(evt)
1261 1283
1262 def mouseReleaseEvent(self, evt): 1284 def mouseReleaseEvent(self, evt):
1263 """ 1285 """
1264 Protected method called by a mouse release event. 1286 Protected method called by a mouse release event.
1265 1287
1302 else: 1324 else:
1303 self.forward() 1325 self.forward()
1304 evt.accept() 1326 evt.accept()
1305 return 1327 return
1306 1328
1307 super(HelpBrowser, self).wheelEvent(evt) 1329 super(WebBrowserView, self).wheelEvent(evt)
1308 1330
1309 def keyPressEvent(self, evt): 1331 def keyPressEvent(self, evt):
1310 """ 1332 """
1311 Protected method called by a key press. 1333 Protected method called by a key press.
1312 1334
1313 @param evt reference to the key event (QKeyEvent) 1335 @param evt reference to the key event (QKeyEvent)
1314 """ 1336 """
1315 if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt): 1337 # TODO: PIM
1316 return 1338 ## if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt):
1317 1339 ## return
1318 if self.__enableAccessKeys: 1340
1319 self.__accessKeysPressed = ( 1341 # TODO: Access Keys
1320 evt.modifiers() == Qt.ControlModifier and 1342 ## if self.__enableAccessKeys:
1321 evt.key() == Qt.Key_Control) 1343 ## self.__accessKeysPressed = (
1322 if not self.__accessKeysPressed: 1344 ## evt.modifiers() == Qt.ControlModifier and
1323 if self.__checkForAccessKey(evt): 1345 ## evt.key() == Qt.Key_Control)
1324 self.__hideAccessKeys() 1346 ## if not self.__accessKeysPressed:
1325 evt.accept() 1347 ## if self.__checkForAccessKey(evt):
1326 return 1348 ## self.__hideAccessKeys()
1327 self.__hideAccessKeys() 1349 ## evt.accept()
1328 else: 1350 ## return
1329 QTimer.singleShot(300, self.__accessKeyShortcut) 1351 ## self.__hideAccessKeys()
1352 ## else:
1353 ## QTimer.singleShot(300, self.__accessKeyShortcut)
1330 1354
1331 self.__ctrlPressed = (evt.key() == Qt.Key_Control) 1355 self.__ctrlPressed = (evt.key() == Qt.Key_Control)
1332 super(HelpBrowser, self).keyPressEvent(evt) 1356 super(WebBrowserView, self).keyPressEvent(evt)
1333 1357
1334 def keyReleaseEvent(self, evt): 1358 def keyReleaseEvent(self, evt):
1335 """ 1359 """
1336 Protected method called by a key release. 1360 Protected method called by a key release.
1337 1361
1338 @param evt reference to the key event (QKeyEvent) 1362 @param evt reference to the key event (QKeyEvent)
1339 """ 1363 """
1340 if self.__enableAccessKeys: 1364 # TODO: Access Keys
1341 self.__accessKeysPressed = evt.key() == Qt.Key_Control 1365 ## if self.__enableAccessKeys:
1366 ## self.__accessKeysPressed = evt.key() == Qt.Key_Control
1342 1367
1343 self.__ctrlPressed = False 1368 self.__ctrlPressed = False
1344 super(HelpBrowser, self).keyReleaseEvent(evt) 1369 super(WebBrowserView, self).keyReleaseEvent(evt)
1345 1370
1346 def focusOutEvent(self, evt): 1371 def focusOutEvent(self, evt):
1347 """ 1372 """
1348 Protected method called by a focus out event. 1373 Protected method called by a focus out event.
1349 1374
1350 @param evt reference to the focus event (QFocusEvent) 1375 @param evt reference to the focus event (QFocusEvent)
1351 """ 1376 """
1352 if self.__accessKeysPressed: 1377 # TODO: Access Keys
1353 self.__hideAccessKeys() 1378 ## if self.__accessKeysPressed:
1354 self.__accessKeysPressed = False 1379 ## self.__hideAccessKeys()
1355 1380 ## self.__accessKeysPressed = False
1356 super(HelpBrowser, self).focusOutEvent(evt) 1381
1382 super(WebBrowserView, self).focusOutEvent(evt)
1357 1383
1358 def event(self, evt): 1384 def event(self, evt):
1359 """ 1385 """
1360 Public method handling events. 1386 Public method handling events.
1361 1387
1364 """ 1390 """
1365 if evt.type() == QEvent.Gesture: 1391 if evt.type() == QEvent.Gesture:
1366 self.gestureEvent(evt) 1392 self.gestureEvent(evt)
1367 return True 1393 return True
1368 1394
1369 return super(HelpBrowser, self).event(evt) 1395 return super(WebBrowserView, self).event(evt)
1370 1396
1371 def gestureEvent(self, evt): 1397 def gestureEvent(self, evt):
1372 """ 1398 """
1373 Protected method handling gesture events. 1399 Protected method handling gesture events.
1374 1400
1412 ## 1438 ##
1413 ## @param text text to be shown in the status bar (string) 1439 ## @param text text to be shown in the status bar (string)
1414 ## """ 1440 ## """
1415 ## self.__mw.statusBar().showMessage(text) 1441 ## self.__mw.statusBar().showMessage(text)
1416 ## 1442 ##
1417 def __linkHovered(self, link, title, textContent): 1443 def __linkHovered(self, link):
1418 """ 1444 """
1419 Private slot to handle the linkHovered signal. 1445 Private slot to handle the linkHovered signal.
1420 1446
1421 @param link the URL of the link (string) 1447 @param link the URL of the link (string)
1422 @param title the link title (string)
1423 @param textContent text content of the link (string)
1424 """ 1448 """
1425 self.highlighted.emit(link) 1449 self.highlighted.emit(link)
1426 1450
1427 ########################################################################### 1451 ###########################################################################
1428 ## Signal handlers below 1452 ## Signal handlers below
1455 if Preferences.getHelp("ClickToFlashEnabled"): 1479 if Preferences.getHelp("ClickToFlashEnabled"):
1456 # this is a hack to make the ClickToFlash button appear 1480 # this is a hack to make the ClickToFlash button appear
1457 self.zoomIn() 1481 self.zoomIn()
1458 self.zoomOut() 1482 self.zoomOut()
1459 1483
1460 zoomValue = Helpviewer.HelpWindow.HelpWindow.zoomManager()\ 1484 # TODO: ZoomManager
1461 .zoomValue(self.url()) 1485 ## zoomValue = Helpviewer.HelpWindow.HelpWindow.zoomManager()\
1462 self.setZoomValue(zoomValue) 1486 ## .zoomValue(self.url())
1487 ## self.setZoomValue(zoomValue)
1463 1488
1464 if ok: 1489 if ok:
1465 self.__mw.adBlockManager().page().hideBlockedPageEntries(self.page()) 1490 pass
1466 self.__mw.passwordManager().fill(self.page()) 1491 # TODO: AdBlock
1492 ## self.__mw.adBlockManager().page().hideBlockedPageEntries(self.page())
1493 # TODO: Password Manager
1494 ## self.__mw.passwordManager().fill(self.page())
1467 1495
1468 def isLoading(self): 1496 def isLoading(self):
1469 """ 1497 """
1470 Public method to get the loading state. 1498 Public method to get the loading state.
1471 1499
1479 1507
1480 @return load progress (integer) 1508 @return load progress (integer)
1481 """ 1509 """
1482 return self.__progress 1510 return self.__progress
1483 1511
1484 def saveAs(self): 1512 ## def saveAs(self):
1485 """ 1513 ## """
1486 Public method to save the current page to a file. 1514 ## Public method to save the current page to a file.
1487 """ 1515 ## """
1488 url = self.url() 1516 ## url = self.url()
1489 if url.isEmpty(): 1517 ## if url.isEmpty():
1490 return 1518 ## return
1491 1519 ##
1492 self.__mw.downloadManager().download(url, True, mainWindow=self.__mw) 1520 ## self.__mw.downloadManager().download(url, True, mainWindow=self.__mw)
1493 1521
1494 ## def __unsupportedContent(self, reply, requestFilename=None, 1522 ## def __unsupportedContent(self, reply, requestFilename=None,
1495 ## download=False): 1523 ## download=False):
1496 ## """ 1524 ## """
1497 ## Private slot to handle the unsupportedContent signal. 1525 ## Private slot to handle the unsupportedContent signal.
1577 ## notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl) 1605 ## notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl)
1578 ## self.__mw.historyManager().removeHistoryEntry(replyUrl, self.title()) 1606 ## self.__mw.historyManager().removeHistoryEntry(replyUrl, self.title())
1579 ## self.loadFinished.emit(False) 1607 ## self.loadFinished.emit(False)
1580 ## 1608 ##
1581 1609
1582 def __downloadRequested(self, request): 1610 # TODO: Download Manager
1583 """ 1611 ## def __downloadRequested(self, request):
1584 Private slot to handle a download request. 1612 ## """
1585 1613 ## Private slot to handle a download request.
1586 @param request reference to the request object (QNetworkRequest) 1614 ##
1587 """ 1615 ## @param request reference to the request object (QNetworkRequest)
1588 self.__mw.downloadManager().download(request, mainWindow=self.__mw) 1616 ## """
1589 1617 ## self.__mw.downloadManager().download(request, mainWindow=self.__mw)
1590 def __databaseQuotaExceeded(self, frame, databaseName): 1618
1591 """ 1619 ## def __databaseQuotaExceeded(self, frame, databaseName):
1592 Private slot to handle the case, where the database quota is exceeded. 1620 ## """
1593 1621 ## Private slot to handle the case, where the database quota is exceeded.
1594 @param frame reference to the frame (QWebFrame) 1622 ##
1595 @param databaseName name of the web database (string) 1623 ## @param frame reference to the frame (QWebFrame)
1596 """ 1624 ## @param databaseName name of the web database (string)
1597 securityOrigin = frame.securityOrigin() 1625 ## """
1598 if securityOrigin.databaseQuota() > 0 and \ 1626 ## securityOrigin = frame.securityOrigin()
1599 securityOrigin.databaseUsage() == 0: 1627 ## if securityOrigin.databaseQuota() > 0 and \
1600 # cope with a strange behavior of Qt 4.6, if a database is 1628 ## securityOrigin.databaseUsage() == 0:
1601 # accessed for the first time 1629 ## # cope with a strange behavior of Qt 4.6, if a database is
1602 return 1630 ## # accessed for the first time
1603 1631 ## return
1604 res = E5MessageBox.yesNo( 1632 ##
1605 self, 1633 ## res = E5MessageBox.yesNo(
1606 self.tr("Web Database Quota"), 1634 ## self,
1607 self.tr( 1635 ## self.tr("Web Database Quota"),
1608 """<p>The database quota of <strong>{0}</strong> has""" 1636 ## self.tr(
1609 """ been exceeded while accessing database <strong>{1}""" 1637 ## """<p>The database quota of <strong>{0}</strong> has"""
1610 """</strong>.</p><p>Shall it be changed?</p>""") 1638 ## """ been exceeded while accessing database <strong>{1}"""
1611 .format(self.__dataString(securityOrigin.databaseQuota()), 1639 ## """</strong>.</p><p>Shall it be changed?</p>""")
1612 databaseName), 1640 ## .format(self.__dataString(securityOrigin.databaseQuota()),
1613 yesDefault=True) 1641 ## databaseName),
1614 if res: 1642 ## yesDefault=True)
1615 newQuota, ok = QInputDialog.getInt( 1643 ## if res:
1616 self, 1644 ## newQuota, ok = QInputDialog.getInt(
1617 self.tr("New Web Database Quota"), 1645 ## self,
1618 self.tr( 1646 ## self.tr("New Web Database Quota"),
1619 "Enter the new quota in MB (current = {0}, used = {1}; " 1647 ## self.tr(
1620 "step size = 5 MB):" 1648 ## "Enter the new quota in MB (current = {0}, used = {1}; "
1621 .format( 1649 ## "step size = 5 MB):"
1622 self.__dataString(securityOrigin.databaseQuota()), 1650 ## .format(
1623 self.__dataString(securityOrigin.databaseUsage()))), 1651 ## self.__dataString(securityOrigin.databaseQuota()),
1624 securityOrigin.databaseQuota() // (1024 * 1024), 1652 ## self.__dataString(securityOrigin.databaseUsage()))),
1625 0, 2147483647, 5) 1653 ## securityOrigin.databaseQuota() // (1024 * 1024),
1626 if ok: 1654 ## 0, 2147483647, 5)
1627 securityOrigin.setDatabaseQuota(newQuota * 1024 * 1024) 1655 ## if ok:
1628 1656 ## securityOrigin.setDatabaseQuota(newQuota * 1024 * 1024)
1629 def __dataString(self, size): 1657 ##
1630 """ 1658 ## def __dataString(self, size):
1631 Private method to generate a formatted data string. 1659 ## """
1632 1660 ## Private method to generate a formatted data string.
1633 @param size size to be formatted (integer) 1661 ##
1634 @return formatted data string (string) 1662 ## @param size size to be formatted (integer)
1635 """ 1663 ## @return formatted data string (string)
1636 unit = "" 1664 ## """
1637 if size < 1024: 1665 ## unit = ""
1638 unit = self.tr("bytes") 1666 ## if size < 1024:
1639 elif size < 1024 * 1024: 1667 ## unit = self.tr("bytes")
1640 size /= 1024 1668 ## elif size < 1024 * 1024:
1641 unit = self.tr("kB") 1669 ## size /= 1024
1642 else: 1670 ## unit = self.tr("kB")
1643 size /= 1024 * 1024 1671 ## else:
1644 unit = self.tr("MB") 1672 ## size /= 1024 * 1024
1645 return "{0:.1f} {1}".format(size, unit) 1673 ## unit = self.tr("MB")
1674 ## return "{0:.1f} {1}".format(size, unit)
1646 1675
1647 ########################################################################### 1676 ###########################################################################
1648 ## Access key related methods below 1677 ## Access key related methods below
1649 ########################################################################### 1678 ###########################################################################
1650 1679
1651 def __accessKeyShortcut(self): 1680 # TODO: Access Keys
1652 """ 1681 ## def __accessKeyShortcut(self):
1653 Private slot to switch the display of access keys. 1682 ## """
1654 """ 1683 ## Private slot to switch the display of access keys.
1655 if not self.hasFocus() or \ 1684 ## """
1656 not self.__accessKeysPressed or \ 1685 ## if not self.hasFocus() or \
1657 not self.__enableAccessKeys: 1686 ## not self.__accessKeysPressed or \
1658 return 1687 ## not self.__enableAccessKeys:
1659 1688 ## return
1660 if self.__accessKeyLabels: 1689 ##
1661 self.__hideAccessKeys() 1690 ## if self.__accessKeyLabels:
1662 else: 1691 ## self.__hideAccessKeys()
1663 self.__showAccessKeys() 1692 ## else:
1664 1693 ## self.__showAccessKeys()
1665 self.__accessKeysPressed = False 1694 ##
1666 1695 ## self.__accessKeysPressed = False
1667 def __checkForAccessKey(self, evt): 1696 ##
1668 """ 1697 ## def __checkForAccessKey(self, evt):
1669 Private method to check the existence of an access key and activate the 1698 ## """
1670 corresponding link. 1699 ## Private method to check the existence of an access key and activate the
1671 1700 ## corresponding link.
1672 @param evt reference to the key event (QKeyEvent) 1701 ##
1673 @return flag indicating, if the event was handled (boolean) 1702 ## @param evt reference to the key event (QKeyEvent)
1674 """ 1703 ## @return flag indicating, if the event was handled (boolean)
1675 if not self.__accessKeyLabels: 1704 ## """
1676 return False 1705 ## if not self.__accessKeyLabels:
1677 1706 ## return False
1678 text = evt.text() 1707 ##
1679 if not text: 1708 ## text = evt.text()
1680 return False 1709 ## if not text:
1681 1710 ## return False
1682 key = text[0].upper() 1711 ##
1683 handled = False 1712 ## key = text[0].upper()
1684 if key in self.__accessKeyNodes: 1713 ## handled = False
1685 element = self.__accessKeyNodes[key] 1714 ## if key in self.__accessKeyNodes:
1686 p = element.geometry().center() 1715 ## element = self.__accessKeyNodes[key]
1687 frame = element.webFrame() 1716 ## p = element.geometry().center()
1688 p -= frame.scrollPosition() 1717 ## frame = element.webFrame()
1689 frame = frame.parentFrame() 1718 ## p -= frame.scrollPosition()
1690 while frame and frame != self.page().mainFrame(): 1719 ## frame = frame.parentFrame()
1691 p -= frame.scrollPosition() 1720 ## while frame and frame != self.page().mainFrame():
1692 frame = frame.parentFrame() 1721 ## p -= frame.scrollPosition()
1693 pevent = QMouseEvent( 1722 ## frame = frame.parentFrame()
1694 QEvent.MouseButtonPress, p, Qt.LeftButton, 1723 ## pevent = QMouseEvent(
1695 Qt.MouseButtons(Qt.NoButton), 1724 ## QEvent.MouseButtonPress, p, Qt.LeftButton,
1696 Qt.KeyboardModifiers(Qt.NoModifier)) 1725 ## Qt.MouseButtons(Qt.NoButton),
1697 qApp.sendEvent(self, pevent) 1726 ## Qt.KeyboardModifiers(Qt.NoModifier))
1698 revent = QMouseEvent( 1727 ## qApp.sendEvent(self, pevent)
1699 QEvent.MouseButtonRelease, p, Qt.LeftButton, 1728 ## revent = QMouseEvent(
1700 Qt.MouseButtons(Qt.NoButton), 1729 ## QEvent.MouseButtonRelease, p, Qt.LeftButton,
1701 Qt.KeyboardModifiers(Qt.NoModifier)) 1730 ## Qt.MouseButtons(Qt.NoButton),
1702 qApp.sendEvent(self, revent) 1731 ## Qt.KeyboardModifiers(Qt.NoModifier))
1703 handled = True 1732 ## qApp.sendEvent(self, revent)
1704 1733 ## handled = True
1705 return handled 1734 ##
1706 1735 ## return handled
1707 def __hideAccessKeys(self): 1736 ##
1708 """ 1737 ## def __hideAccessKeys(self):
1709 Private slot to hide the access key labels. 1738 ## """
1710 """ 1739 ## Private slot to hide the access key labels.
1711 if self.__accessKeyLabels: 1740 ## """
1712 for label in self.__accessKeyLabels: 1741 ## if self.__accessKeyLabels:
1713 label.hide() 1742 ## for label in self.__accessKeyLabels:
1714 label.deleteLater() 1743 ## label.hide()
1715 self.__accessKeyLabels = [] 1744 ## label.deleteLater()
1716 self.__accessKeyNodes = {} 1745 ## self.__accessKeyLabels = []
1717 self.update() 1746 ## self.__accessKeyNodes = {}
1718 1747 ## self.update()
1719 def __showAccessKeys(self): 1748 ##
1720 """ 1749 ## def __showAccessKeys(self):
1721 Private method to show the access key labels. 1750 ## """
1722 """ 1751 ## Private method to show the access key labels.
1723 supportedElements = [ 1752 ## """
1724 "input", "a", "area", "button", "label", "legend", "textarea", 1753 ## supportedElements = [
1725 ] 1754 ## "input", "a", "area", "button", "label", "legend", "textarea",
1726 unusedKeys = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" \ 1755 ## ]
1727 " 0 1 2 3 4 5 6 7 8 9".split() 1756 ## unusedKeys = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" \
1728 1757 ## " 0 1 2 3 4 5 6 7 8 9".split()
1729 viewport = QRect(self.__page.mainFrame().scrollPosition(), 1758 ##
1730 self.__page.viewportSize()) 1759 ## viewport = QRect(self.__page.mainFrame().scrollPosition(),
1731 # Priority first goes to elements with accesskey attributes 1760 ## self.__page.viewportSize())
1732 alreadyLabeled = [] 1761 ## # Priority first goes to elements with accesskey attributes
1733 for elementType in supportedElements: 1762 ## alreadyLabeled = []
1734 result = self.page().mainFrame().findAllElements(elementType)\ 1763 ## for elementType in supportedElements:
1735 .toList() 1764 ## result = self.page().mainFrame().findAllElements(elementType)\
1736 for element in result: 1765 ## .toList()
1737 geometry = element.geometry() 1766 ## for element in result:
1738 if geometry.size().isEmpty() or \ 1767 ## geometry = element.geometry()
1739 not viewport.contains(geometry.topLeft()): 1768 ## if geometry.size().isEmpty() or \
1740 continue 1769 ## not viewport.contains(geometry.topLeft()):
1741 1770 ## continue
1742 accessKeyAttribute = element.attribute("accesskey").upper() 1771 ##
1743 if not accessKeyAttribute: 1772 ## accessKeyAttribute = element.attribute("accesskey").upper()
1744 continue 1773 ## if not accessKeyAttribute:
1745 1774 ## continue
1746 accessKey = "" 1775 ##
1747 i = 0 1776 ## accessKey = ""
1748 while i < len(accessKeyAttribute): 1777 ## i = 0
1749 if accessKeyAttribute[i] in unusedKeys: 1778 ## while i < len(accessKeyAttribute):
1750 accessKey = accessKeyAttribute[i] 1779 ## if accessKeyAttribute[i] in unusedKeys:
1751 break 1780 ## accessKey = accessKeyAttribute[i]
1752 i += 2 1781 ## break
1753 if accessKey == "": 1782 ## i += 2
1754 continue 1783 ## if accessKey == "":
1755 unusedKeys.remove(accessKey) 1784 ## continue
1756 self.__makeAccessLabel(accessKey, element) 1785 ## unusedKeys.remove(accessKey)
1757 alreadyLabeled.append(element) 1786 ## self.__makeAccessLabel(accessKey, element)
1758 1787 ## alreadyLabeled.append(element)
1759 # Pick an access key first from the letters in the text and then 1788 ##
1760 # from the list of unused access keys 1789 ## # Pick an access key first from the letters in the text and then
1761 for elementType in supportedElements: 1790 ## # from the list of unused access keys
1762 result = self.page().mainFrame().findAllElements(elementType)\ 1791 ## for elementType in supportedElements:
1763 .toList() 1792 ## result = self.page().mainFrame().findAllElements(elementType)\
1764 for element in result: 1793 ## .toList()
1765 geometry = element.geometry() 1794 ## for element in result:
1766 if not unusedKeys or \ 1795 ## geometry = element.geometry()
1767 element in alreadyLabeled or \ 1796 ## if not unusedKeys or \
1768 geometry.size().isEmpty() or \ 1797 ## element in alreadyLabeled or \
1769 not viewport.contains(geometry.topLeft()): 1798 ## geometry.size().isEmpty() or \
1770 continue 1799 ## not viewport.contains(geometry.topLeft()):
1771 1800 ## continue
1772 accessKey = "" 1801 ##
1773 text = element.toPlainText().upper() 1802 ## accessKey = ""
1774 for c in text: 1803 ## text = element.toPlainText().upper()
1775 if c in unusedKeys: 1804 ## for c in text:
1776 accessKey = c 1805 ## if c in unusedKeys:
1777 break 1806 ## accessKey = c
1778 if accessKey == "": 1807 ## break
1779 accessKey = unusedKeys[0] 1808 ## if accessKey == "":
1780 unusedKeys.remove(accessKey) 1809 ## accessKey = unusedKeys[0]
1781 self.__makeAccessLabel(accessKey, element) 1810 ## unusedKeys.remove(accessKey)
1782 1811 ## self.__makeAccessLabel(accessKey, element)
1783 def __makeAccessLabel(self, accessKey, element): 1812 ##
1784 """ 1813 ## def __makeAccessLabel(self, accessKey, element):
1785 Private method to generate the access label for an element. 1814 ## """
1786 1815 ## Private method to generate the access label for an element.
1787 @param accessKey access key to generate the label for (str) 1816 ##
1788 @param element reference to the web element to create the label for 1817 ## @param accessKey access key to generate the label for (str)
1789 (QWebElement) 1818 ## @param element reference to the web element to create the label for
1790 """ 1819 ## (QWebElement)
1791 label = QLabel(self) 1820 ## """
1792 label.setText("<qt><b>{0}</b></qt>".format(accessKey)) 1821 ## label = QLabel(self)
1793 1822 ## label.setText("<qt><b>{0}</b></qt>".format(accessKey))
1794 p = QToolTip.palette() 1823 ##
1795 color = QColor(Qt.yellow).lighter(150) 1824 ## p = QToolTip.palette()
1796 color.setAlpha(175) 1825 ## color = QColor(Qt.yellow).lighter(150)
1797 p.setColor(QPalette.Window, color) 1826 ## color.setAlpha(175)
1798 label.setPalette(p) 1827 ## p.setColor(QPalette.Window, color)
1799 label.setAutoFillBackground(True) 1828 ## label.setPalette(p)
1800 label.setFrameStyle(QFrame.Box | QFrame.Plain) 1829 ## label.setAutoFillBackground(True)
1801 point = element.geometry().center() 1830 ## label.setFrameStyle(QFrame.Box | QFrame.Plain)
1802 point -= self.__page.mainFrame().scrollPosition() 1831 ## point = element.geometry().center()
1803 label.move(point) 1832 ## point -= self.__page.mainFrame().scrollPosition()
1804 label.show() 1833 ## label.move(point)
1805 point.setX(point.x() - label.width() // 2) 1834 ## label.show()
1806 label.move(point) 1835 ## point.setX(point.x() - label.width() // 2)
1807 self.__accessKeyLabels.append(label) 1836 ## label.move(point)
1808 self.__accessKeyNodes[accessKey] = element 1837 ## self.__accessKeyLabels.append(label)
1838 ## self.__accessKeyNodes[accessKey] = element
1809 1839
1810 ########################################################################### 1840 ###########################################################################
1811 ## Miscellaneous methods below 1841 ## Miscellaneous methods below
1812 ########################################################################### 1842 ###########################################################################
1813 1843
1844 # TODO: check, if this is needed (referenced anywhere) (same for HelpBrowserWV)
1814 def createWindow(self, windowType): 1845 def createWindow(self, windowType):
1815 """ 1846 """
1816 Public method called, when a new window should be created. 1847 Public method called, when a new window should be created.
1817 1848
1818 @param windowType type of the requested window (QWebPage.WebWindowType) 1849 @param windowType type of the requested window (QWebPage.WebWindowType)
1823 1854
1824 def preferencesChanged(self): 1855 def preferencesChanged(self):
1825 """ 1856 """
1826 Public method to indicate a change of the settings. 1857 Public method to indicate a change of the settings.
1827 """ 1858 """
1828 self.__enableAccessKeys = Preferences.getHelp("AccessKeysEnabled") 1859 # TODO: Access Keys
1829 if not self.__enableAccessKeys: 1860 ## self.__enableAccessKeys = Preferences.getHelp("AccessKeysEnabled")
1830 self.__hideAccessKeys() 1861 ## if not self.__enableAccessKeys:
1862 ## self.__hideAccessKeys()
1831 1863
1832 self.reload() 1864 self.reload()
1833 1865
1834 ########################################################################### 1866 ###########################################################################
1835 ## RSS related methods below 1867 ## RSS related methods below
1836 ########################################################################### 1868 ###########################################################################
1837 1869
1838 def checkRSS(self): 1870 # TODO: extract links from page to implement RSS stuff
1839 """ 1871 ## def checkRSS(self):
1840 Public method to check, if the loaded page contains feed links. 1872 ## """
1841 1873 ## Public method to check, if the loaded page contains feed links.
1842 @return flag indicating the existence of feed links (boolean) 1874 ##
1843 """ 1875 ## @return flag indicating the existence of feed links (boolean)
1844 self.__rss = [] 1876 ## """
1845 1877 ## self.__rss = []
1846 frame = self.page().mainFrame() 1878 ##
1847 linkElementsList = frame.findAllElements("link").toList() 1879 ## frame = self.page()
1848 1880 ## linkElementsList = frame.findAllElements("link").toList()
1849 for linkElement in linkElementsList: 1881 ##
1850 # only atom+xml and rss+xml will be processed 1882 ## for linkElement in linkElementsList:
1851 if linkElement.attribute("rel") != "alternate" or \ 1883 ## # only atom+xml and rss+xml will be processed
1852 (linkElement.attribute("type") != "application/rss+xml" and 1884 ## if linkElement.attribute("rel") != "alternate" or \
1853 linkElement.attribute("type") != "application/atom+xml"): 1885 ## (linkElement.attribute("type") != "application/rss+xml" and
1854 continue 1886 ## linkElement.attribute("type") != "application/atom+xml"):
1855 1887 ## continue
1856 title = linkElement.attribute("title") 1888 ##
1857 href = linkElement.attribute("href") 1889 ## title = linkElement.attribute("title")
1858 if href == "" or title == "": 1890 ## href = linkElement.attribute("href")
1859 continue 1891 ## if href == "" or title == "":
1860 self.__rss.append((title, href)) 1892 ## continue
1861 1893 ## self.__rss.append((title, href))
1862 return len(self.__rss) > 0 1894 ##
1895 ## return len(self.__rss) > 0
1863 1896
1864 def getRSS(self): 1897 def getRSS(self):
1865 """ 1898 """
1866 Public method to get the extracted RSS feeds. 1899 Public method to get the extracted RSS feeds.
1867 1900
1879 1912
1880 ########################################################################### 1913 ###########################################################################
1881 ## Clicked Frame slots 1914 ## Clicked Frame slots
1882 ########################################################################### 1915 ###########################################################################
1883 1916
1884 def __loadClickedFrame(self): 1917 ## def __loadClickedFrame(self):
1885 """ 1918 ## """
1886 Private slot to load the selected frame only. 1919 ## Private slot to load the selected frame only.
1887 """ 1920 ## """
1888 self.setSource(self.__clickedFrame.url()) 1921 ## self.setSource(self.__clickedFrame.url())
1889 1922 ##
1890 def __printClickedFrame(self): 1923 ## def __printClickedFrame(self):
1891 """ 1924 ## """
1892 Private slot to print the selected frame. 1925 ## Private slot to print the selected frame.
1893 """ 1926 ## """
1894 printer = QPrinter(mode=QPrinter.HighResolution) 1927 ## printer = QPrinter(mode=QPrinter.HighResolution)
1895 if Preferences.getPrinter("ColorMode"): 1928 ## if Preferences.getPrinter("ColorMode"):
1896 printer.setColorMode(QPrinter.Color) 1929 ## printer.setColorMode(QPrinter.Color)
1897 else: 1930 ## else:
1898 printer.setColorMode(QPrinter.GrayScale) 1931 ## printer.setColorMode(QPrinter.GrayScale)
1899 if Preferences.getPrinter("FirstPageFirst"): 1932 ## if Preferences.getPrinter("FirstPageFirst"):
1900 printer.setPageOrder(QPrinter.FirstPageFirst) 1933 ## printer.setPageOrder(QPrinter.FirstPageFirst)
1901 else: 1934 ## else:
1902 printer.setPageOrder(QPrinter.LastPageFirst) 1935 ## printer.setPageOrder(QPrinter.LastPageFirst)
1903 printer.setPageMargins( 1936 ## printer.setPageMargins(
1904 Preferences.getPrinter("LeftMargin") * 10, 1937 ## Preferences.getPrinter("LeftMargin") * 10,
1905 Preferences.getPrinter("TopMargin") * 10, 1938 ## Preferences.getPrinter("TopMargin") * 10,
1906 Preferences.getPrinter("RightMargin") * 10, 1939 ## Preferences.getPrinter("RightMargin") * 10,
1907 Preferences.getPrinter("BottomMargin") * 10, 1940 ## Preferences.getPrinter("BottomMargin") * 10,
1908 QPrinter.Millimeter 1941 ## QPrinter.Millimeter
1909 ) 1942 ## )
1910 printerName = Preferences.getPrinter("PrinterName") 1943 ## printerName = Preferences.getPrinter("PrinterName")
1911 if printerName: 1944 ## if printerName:
1912 printer.setPrinterName(printerName) 1945 ## printer.setPrinterName(printerName)
1913 1946 ##
1914 printDialog = QPrintDialog(printer, self) 1947 ## printDialog = QPrintDialog(printer, self)
1915 if printDialog.exec_() == QDialog.Accepted: 1948 ## if printDialog.exec_() == QDialog.Accepted:
1916 try: 1949 ## try:
1917 self.__clickedFrame.print_(printer) 1950 ## self.__clickedFrame.print_(printer)
1918 except AttributeError: 1951 ## except AttributeError:
1919 E5MessageBox.critical( 1952 ## E5MessageBox.critical(
1920 self, 1953 ## self,
1921 self.tr("eric6 Web Browser"), 1954 ## self.tr("eric6 Web Browser"),
1922 self.tr( 1955 ## self.tr(
1923 """<p>Printing is not available due to a bug in""" 1956 ## """<p>Printing is not available due to a bug in"""
1924 """ PyQt5. Please upgrade.</p>""")) 1957 ## """ PyQt5. Please upgrade.</p>"""))
1925 1958 ##
1926 def __printPreviewClickedFrame(self): 1959 ## def __printPreviewClickedFrame(self):
1927 """ 1960 ## """
1928 Private slot to show a print preview of the clicked frame. 1961 ## Private slot to show a print preview of the clicked frame.
1929 """ 1962 ## """
1930 from PyQt5.QtPrintSupport import QPrintPreviewDialog 1963 ## from PyQt5.QtPrintSupport import QPrintPreviewDialog
1931 1964 ##
1932 printer = QPrinter(mode=QPrinter.HighResolution) 1965 ## printer = QPrinter(mode=QPrinter.HighResolution)
1933 if Preferences.getPrinter("ColorMode"): 1966 ## if Preferences.getPrinter("ColorMode"):
1934 printer.setColorMode(QPrinter.Color) 1967 ## printer.setColorMode(QPrinter.Color)
1935 else: 1968 ## else:
1936 printer.setColorMode(QPrinter.GrayScale) 1969 ## printer.setColorMode(QPrinter.GrayScale)
1937 if Preferences.getPrinter("FirstPageFirst"): 1970 ## if Preferences.getPrinter("FirstPageFirst"):
1938 printer.setPageOrder(QPrinter.FirstPageFirst) 1971 ## printer.setPageOrder(QPrinter.FirstPageFirst)
1939 else: 1972 ## else:
1940 printer.setPageOrder(QPrinter.LastPageFirst) 1973 ## printer.setPageOrder(QPrinter.LastPageFirst)
1941 printer.setPageMargins( 1974 ## printer.setPageMargins(
1942 Preferences.getPrinter("LeftMargin") * 10, 1975 ## Preferences.getPrinter("LeftMargin") * 10,
1943 Preferences.getPrinter("TopMargin") * 10, 1976 ## Preferences.getPrinter("TopMargin") * 10,
1944 Preferences.getPrinter("RightMargin") * 10, 1977 ## Preferences.getPrinter("RightMargin") * 10,
1945 Preferences.getPrinter("BottomMargin") * 10, 1978 ## Preferences.getPrinter("BottomMargin") * 10,
1946 QPrinter.Millimeter 1979 ## QPrinter.Millimeter
1947 ) 1980 ## )
1948 printerName = Preferences.getPrinter("PrinterName") 1981 ## printerName = Preferences.getPrinter("PrinterName")
1949 if printerName: 1982 ## if printerName:
1950 printer.setPrinterName(printerName) 1983 ## printer.setPrinterName(printerName)
1951 1984 ##
1952 preview = QPrintPreviewDialog(printer, self) 1985 ## preview = QPrintPreviewDialog(printer, self)
1953 preview.paintRequested.connect(self.__generatePrintPreviewClickedFrame) 1986 ## preview.paintRequested.connect(self.__generatePrintPreviewClickedFrame)
1954 preview.exec_() 1987 ## preview.exec_()
1955 1988 ##
1956 def __generatePrintPreviewClickedFrame(self, printer): 1989 ## def __generatePrintPreviewClickedFrame(self, printer):
1957 """ 1990 ## """
1958 Private slot to generate a print preview of the clicked frame. 1991 ## Private slot to generate a print preview of the clicked frame.
1959 1992 ##
1960 @param printer reference to the printer object (QPrinter) 1993 ## @param printer reference to the printer object (QPrinter)
1961 """ 1994 ## """
1962 try: 1995 ## try:
1963 self.__clickedFrame.print_(printer) 1996 ## self.__clickedFrame.print_(printer)
1964 except AttributeError: 1997 ## except AttributeError:
1965 E5MessageBox.critical( 1998 ## E5MessageBox.critical(
1966 self, 1999 ## self,
1967 self.tr("eric6 Web Browser"), 2000 ## self.tr("eric6 Web Browser"),
1968 self.tr( 2001 ## self.tr(
1969 """<p>Printing is not available due to a bug in PyQt5.""" 2002 ## """<p>Printing is not available due to a bug in PyQt5."""
1970 """Please upgrade.</p>""")) 2003 ## """Please upgrade.</p>"""))
1971 return 2004 ## return
1972 2005 ##
1973 def __printPdfClickedFrame(self): 2006 ## def __printPdfClickedFrame(self):
1974 """ 2007 ## """
1975 Private slot to print the selected frame to PDF. 2008 ## Private slot to print the selected frame to PDF.
1976 """ 2009 ## """
1977 printer = QPrinter(mode=QPrinter.HighResolution) 2010 ## printer = QPrinter(mode=QPrinter.HighResolution)
1978 if Preferences.getPrinter("ColorMode"): 2011 ## if Preferences.getPrinter("ColorMode"):
1979 printer.setColorMode(QPrinter.Color) 2012 ## printer.setColorMode(QPrinter.Color)
1980 else: 2013 ## else:
1981 printer.setColorMode(QPrinter.GrayScale) 2014 ## printer.setColorMode(QPrinter.GrayScale)
1982 printerName = Preferences.getPrinter("PrinterName") 2015 ## printerName = Preferences.getPrinter("PrinterName")
1983 if printerName: 2016 ## if printerName:
1984 printer.setPrinterName(printerName) 2017 ## printer.setPrinterName(printerName)
1985 printer.setOutputFormat(QPrinter.PdfFormat) 2018 ## printer.setOutputFormat(QPrinter.PdfFormat)
1986 name = self.__clickedFrame.url().path().rsplit('/', 1)[-1] 2019 ## name = self.__clickedFrame.url().path().rsplit('/', 1)[-1]
1987 if name: 2020 ## if name:
1988 name = name.rsplit('.', 1)[0] 2021 ## name = name.rsplit('.', 1)[0]
1989 name += '.pdf' 2022 ## name += '.pdf'
1990 printer.setOutputFileName(name) 2023 ## printer.setOutputFileName(name)
1991 2024 ##
1992 printDialog = QPrintDialog(printer, self) 2025 ## printDialog = QPrintDialog(printer, self)
1993 if printDialog.exec_() == QDialog.Accepted: 2026 ## if printDialog.exec_() == QDialog.Accepted:
1994 try: 2027 ## try:
1995 self.__clickedFrame.print_(printer) 2028 ## self.__clickedFrame.print_(printer)
1996 except AttributeError: 2029 ## except AttributeError:
1997 E5MessageBox.critical( 2030 ## E5MessageBox.critical(
1998 self, 2031 ## self,
1999 self.tr("eric6 Web Browser"), 2032 ## self.tr("eric6 Web Browser"),
2000 self.tr( 2033 ## self.tr(
2001 """<p>Printing is not available due to a bug in""" 2034 ## """<p>Printing is not available due to a bug in"""
2002 """ PyQt5. Please upgrade.</p>""")) 2035 ## """ PyQt5. Please upgrade.</p>"""))
2003 return 2036 ## return
2004 2037 ##
2005 def __zoomInClickedFrame(self): 2038 ## def __zoomInClickedFrame(self):
2006 """ 2039 ## """
2007 Private slot to zoom into the clicked frame. 2040 ## Private slot to zoom into the clicked frame.
2008 """ 2041 ## """
2009 index = self.__levelForZoom( 2042 ## index = self.__levelForZoom(
2010 int(self.__clickedFrame.zoomFactor() * 100)) 2043 ## int(self.__clickedFrame.zoomFactor() * 100))
2011 if index < len(self.__zoomLevels) - 1: 2044 ## if index < len(self.__zoomLevels) - 1:
2012 self.__clickedFrame.setZoomFactor( 2045 ## self.__clickedFrame.setZoomFactor(
2013 self.__zoomLevels[index + 1] / 100) 2046 ## self.__zoomLevels[index + 1] / 100)
2014 2047 ##
2015 def __zoomResetClickedFrame(self): 2048 ## def __zoomResetClickedFrame(self):
2016 """ 2049 ## """
2017 Private slot to reset the zoom factor of the clicked frame. 2050 ## Private slot to reset the zoom factor of the clicked frame.
2018 """ 2051 ## """
2019 self.__clickedFrame.setZoomFactor(self.__currentZoom / 100) 2052 ## self.__clickedFrame.setZoomFactor(self.__currentZoom / 100)
2020 2053 ##
2021 def __zoomOutClickedFrame(self): 2054 ## def __zoomOutClickedFrame(self):
2022 """ 2055 ## """
2023 Private slot to zoom out of the clicked frame. 2056 ## Private slot to zoom out of the clicked frame.
2024 """ 2057 ## """
2025 index = self.__levelForZoom( 2058 ## index = self.__levelForZoom(
2026 int(self.__clickedFrame.zoomFactor() * 100)) 2059 ## int(self.__clickedFrame.zoomFactor() * 100))
2027 if index > 0: 2060 ## if index > 0:
2028 self.__clickedFrame.setZoomFactor( 2061 ## self.__clickedFrame.setZoomFactor(
2029 self.__zoomLevels[index - 1] / 100) 2062 ## self.__zoomLevels[index - 1] / 100)
2030 2063 ##
2031 def __showClickedFrameSource(self): 2064 ## def __showClickedFrameSource(self):
2032 """ 2065 ## """
2033 Private slot to show the source of the clicked frame. 2066 ## Private slot to show the source of the clicked frame.
2034 """ 2067 ## """
2035 from QScintilla.MiniEditor import MiniEditor 2068 ## from QScintilla.MiniEditor import MiniEditor
2036 src = self.__clickedFrame.toHtml() 2069 ## src = self.__clickedFrame.toHtml()
2037 editor = MiniEditor(parent=self) 2070 ## editor = MiniEditor(parent=self)
2038 editor.setText(src, "Html") 2071 ## editor.setText(src, "Html")
2039 editor.setLanguage("dummy.html") 2072 ## editor.setLanguage("dummy.html")
2040 editor.show() 2073 ## editor.show()
2041 2074
2042 2075
2043 def contentSniff(data): 2076 ##def contentSniff(data):
2044 """ 2077 ## """
2045 Module function to do some content sniffing to check, if the data is HTML. 2078 ## Module function to do some content sniffing to check, if the data is HTML.
2046 2079 ##
2047 @param data data block to sniff at (string) 2080 ## @param data data block to sniff at (string)
2048 @return flag indicating HTML content (boolean) 2081 ## @return flag indicating HTML content (boolean)
2049 """ 2082 ## """
2050 if data.contains("<!doctype") or \ 2083 ## if data.contains("<!doctype") or \
2051 data.contains("<script") or \ 2084 ## data.contains("<script") or \
2052 data.contains("<html") or \ 2085 ## data.contains("<html") or \
2053 data.contains("<!--") or \ 2086 ## data.contains("<!--") or \
2054 data.contains("<head") or \ 2087 ## data.contains("<head") or \
2055 data.contains("<iframe") or \ 2088 ## data.contains("<iframe") or \
2056 data.contains("<h1") or \ 2089 ## data.contains("<h1") or \
2057 data.contains("<div") or \ 2090 ## data.contains("<div") or \
2058 data.contains("<font") or \ 2091 ## data.contains("<font") or \
2059 data.contains("<table") or \ 2092 ## data.contains("<table") or \
2060 data.contains("<a") or \ 2093 ## data.contains("<a") or \
2061 data.contains("<style") or \ 2094 ## data.contains("<style") or \
2062 data.contains("<title") or \ 2095 ## data.contains("<title") or \
2063 data.contains("<b") or \ 2096 ## data.contains("<b") or \
2064 data.contains("<body") or \ 2097 ## data.contains("<body") or \
2065 data.contains("<br") or \ 2098 ## data.contains("<br") or \
2066 data.contains("<p"): 2099 ## data.contains("<p"):
2067 return True 2100 ## return True
2068 2101 ##
2069 return False 2102 ## return False

eric ide

mercurial