WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4900
32f940762654
parent 4886
b56735d36159
child 4903
10910764454a
equal deleted inserted replaced
4895:3baaf8303a7f 4900:32f940762654
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, QContextMenuEvent 21 QPalette, QIcon, QContextMenuEvent, QPixmap
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, QHostInfo 25 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest, QHostInfo
26 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage 26 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
37 37
38 from . import WebInspector 38 from . import WebInspector
39 39
40 import Preferences 40 import Preferences
41 import UI.PixmapCache 41 import UI.PixmapCache
42 import Globals 42 ##import Globals
43 43
44 try: 44 ##try:
45 from PyQt5.QtNetwork import QSslCertificate 45 ## from PyQt5.QtNetwork import QSslCertificate
46 SSL_AVAILABLE = True 46 ## SSL_AVAILABLE = True
47 except ImportError: 47 ##except ImportError:
48 SSL_AVAILABLE = False 48 ## SSL_AVAILABLE = False
49 49
50 50
51 class WebBrowserView(QWebEngineView): 51 class WebBrowserView(QWebEngineView):
52 """ 52 """
53 Class implementing the web browser view widget. 53 Class implementing the web browser view widget.
102 self.__siteIconLoader = None 102 self.__siteIconLoader = None
103 self.__siteIcon = QIcon() 103 self.__siteIcon = QIcon()
104 self.__menu = QMenu(self) 104 self.__menu = QMenu(self)
105 self.__clickedPos = QPoint() 105 self.__clickedPos = QPoint()
106 self.__firstLoad = False 106 self.__firstLoad = False
107 self.__preview = QPixmap()
107 108
108 self.__currentZoom = 100 109 self.__currentZoom = 100
109 self.__zoomLevels = WebBrowserView.ZoomLevels[:] 110 self.__zoomLevels = WebBrowserView.ZoomLevels[:]
110 111
111 ## self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) 112 ## self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
117 self.page().linkHovered.connect(self.__linkHovered) 118 self.page().linkHovered.connect(self.__linkHovered)
118 119
119 self.loadStarted.connect(self.__loadStarted) 120 self.loadStarted.connect(self.__loadStarted)
120 self.loadProgress.connect(self.__loadProgress) 121 self.loadProgress.connect(self.__loadProgress)
121 self.loadFinished.connect(self.__loadFinished) 122 self.loadFinished.connect(self.__loadFinished)
123 # TODO: renderProcessTerminated
124 ## self.page().renderProcessTerminated.connect(self.__renderProcessTerminated)
122 125
123 ## self.page().setForwardUnsupportedContent(True) 126 ## self.page().setForwardUnsupportedContent(True)
124 ## self.page().unsupportedContent.connect(self.__unsupportedContent) 127 ## self.page().unsupportedContent.connect(self.__unsupportedContent)
125 128
126 ## self.page().databaseQuotaExceeded.connect(self.__databaseQuotaExceeded) 129 ## self.page().databaseQuotaExceeded.connect(self.__databaseQuotaExceeded)
1495 1498
1496 ########################################################################### 1499 ###########################################################################
1497 ## Signal handlers below 1500 ## Signal handlers below
1498 ########################################################################### 1501 ###########################################################################
1499 1502
1503 # TODO: renderProcessTerminated
1504 ## def __renderProcessTerminated(self, status, exitCode):
1505 ## print(status, exitCode)
1506 ##
1500 def __loadStarted(self): 1507 def __loadStarted(self):
1501 """ 1508 """
1502 Private method to handle the loadStarted signal. 1509 Private method to handle the loadStarted signal.
1503 """ 1510 """
1504 self.__isLoading = True 1511 self.__isLoading = True
1518 1525
1519 @param ok flag indicating the result (boolean) 1526 @param ok flag indicating the result (boolean)
1520 """ 1527 """
1521 self.__isLoading = False 1528 self.__isLoading = False
1522 self.__progress = 0 1529 self.__progress = 0
1530
1531 QTimer.singleShot(200, self.__renderPreview)
1523 1532
1524 # TODO: ClickToFlash (?) 1533 # TODO: ClickToFlash (?)
1525 ## if Preferences.getWebBrowser("ClickToFlashEnabled"): 1534 ## if Preferences.getWebBrowser("ClickToFlashEnabled"):
1526 ## # this is a hack to make the ClickToFlash button appear 1535 ## # this is a hack to make the ClickToFlash button appear
1527 ## self.zoomIn() 1536 ## self.zoomIn()
1550 Public method to get the load progress. 1559 Public method to get the load progress.
1551 1560
1552 @return load progress (integer) 1561 @return load progress (integer)
1553 """ 1562 """
1554 return self.__progress 1563 return self.__progress
1564
1565 def __renderPreview(self):
1566 """
1567 Private slot to render a preview pixmap after the page was loaded.
1568 """
1569 from .WebBrowserSnap import renderTabPreview
1570 w = 600 # some default width, the preview gets scaled when shown
1571 h = int(w * self.height() / self.width())
1572 self.__preview = renderTabPreview(self, w, h)
1573
1574 def getPreview(self):
1575 """
1576 Public method to get the preview pixmap.
1577
1578 @return preview pixmap
1579 @rtype QPixmap
1580 """
1581 return self.__preview
1555 1582
1556 ## def saveAs(self): 1583 ## def saveAs(self):
1557 ## """ 1584 ## """
1558 ## Public method to save the current page to a file. 1585 ## Public method to save the current page to a file.
1559 ## """ 1586 ## """

eric ide

mercurial