WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4728
0367675d783d
parent 4727
62b50a24fb59
child 4729
fc8d00860717
equal deleted inserted replaced
4727:62b50a24fb59 4728:0367675d783d
16 16
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \ 17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \
18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \ 18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \
19 QRect, QFile, QPoint, QByteArray, qVersion 19 QRect, QFile, QPoint, QByteArray, qVersion
20 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \ 20 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \
21 QPalette, QIcon 21 QPalette, QIcon, QContextMenuEvent
22 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \ 22 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \
23 QLineEdit, QLabel, QToolTip, QFrame, QDialog 23 QLineEdit, QLabel, QToolTip, QFrame, QDialog
24 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog 24 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
25 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest 25 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
26 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage 26 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
554 ## """ 554 ## """
555 ## return element.tagName().lower() in ["video", "audio"] 555 ## return element.tagName().lower() in ["video", "audio"]
556 556
557 def contextMenuEvent(self, evt): 557 def contextMenuEvent(self, evt):
558 """ 558 """
559 Protected method called to create a context menu. 559 Public method called to create a context menu.
560 560
561 This method is overridden from QWebEngineView. 561 This method is overridden from QWebEngineView.
562 562
563 @param evt reference to the context menu event object 563 @param evt reference to the context menu event object
564 (QContextMenuEvent) 564 (QContextMenuEvent)
565 """ 565 """
566 pos = evt.pos()
567 reason = evt.reason()
568 QTimer.singleShot(
569 0,
570 lambda: self._contextMenuEvent(QContextMenuEvent(reason, pos)))
571 # needs to be done this way because contextMenuEvent is blocking
572 # the main loop
573
574 # TODO: re-arrange the menu creation stuff to better adjust to the current situation
575 ##void TabbedWebView::_contextMenuEvent(QContextMenuEvent *event)
576 ##{
577 ## m_menu->clear();
578 ##
579 ## const WebHitTestResult hitTest = page()->hitTestContent(event->pos());
580 ##
581 ## createContextMenu(m_menu, hitTest);
582 ##
583 ## if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {
584 ## m_menu->addAction(m_window->adBlockIcon()->menuAction());
585 ## }
586 ##
587 ## m_menu->addSeparator();
588 ## m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));
589 ##
590 ## if (!m_menu->isEmpty()) {
591 ## // Prevent choosing first option with double rightclick
592 ## const QPoint pos = event->globalPos();
593 ## QPoint p(pos.x(), pos.y() + 1);
594 ##
595 ## m_menu->popup(p);
596 ## return;
597 ## }
598 ##
599 ## WebView::_contextMenuEvent(event);
600 ##}
601 def _contextMenuEvent(self, evt):
602 """
603 Protected method called to create a context menu.
604
605 This method is overridden from QWebEngineView.
606
607 @param evt reference to the context menu event object
608 (QContextMenuEvent)
609 """
610 hitTest = self.page().hitTestContent(evt.pos())
611
566 # TODO: User Agent 612 # TODO: User Agent
567 ## from .UserAgent.UserAgentMenu import UserAgentMenu 613 ## from .UserAgent.UserAgentMenu import UserAgentMenu
568 menu = QMenu(self) 614 menu = QMenu(self)
569 615
570 ## frameAtPos = self.page().frameAt(evt.pos()) 616 ## frameAtPos = self.page().frameAt(evt.pos())

eric ide

mercurial