350 |
350 |
351 def reload(self): |
351 def reload(self): |
352 """ |
352 """ |
353 Public slot to reload the current page. |
353 Public slot to reload the current page. |
354 """ |
354 """ |
355 self.triggerPageAction(QWebEnginePage.Reload) |
355 self.triggerPageAction(QWebEnginePage.WebAction.Reload) |
356 |
356 |
357 def reloadBypassingCache(self): |
357 def reloadBypassingCache(self): |
358 """ |
358 """ |
359 Public slot to reload the current page bypassing the cache. |
359 Public slot to reload the current page bypassing the cache. |
360 """ |
360 """ |
361 self.triggerPageAction(QWebEnginePage.ReloadAndBypassCache) |
361 self.triggerPageAction(QWebEnginePage.WebAction.ReloadAndBypassCache) |
362 |
362 |
363 def copy(self): |
363 def copy(self): |
364 """ |
364 """ |
365 Public slot to copy the selected text. |
365 Public slot to copy the selected text. |
366 """ |
366 """ |
367 self.triggerPageAction(QWebEnginePage.Copy) |
367 self.triggerPageAction(QWebEnginePage.WebAction.Copy) |
368 |
368 |
369 def cut(self): |
369 def cut(self): |
370 """ |
370 """ |
371 Public slot to cut the selected text. |
371 Public slot to cut the selected text. |
372 """ |
372 """ |
373 self.triggerPageAction(QWebEnginePage.Cut) |
373 self.triggerPageAction(QWebEnginePage.WebAction.Cut) |
374 |
374 |
375 def paste(self): |
375 def paste(self): |
376 """ |
376 """ |
377 Public slot to paste text from the clipboard. |
377 Public slot to paste text from the clipboard. |
378 """ |
378 """ |
379 self.triggerPageAction(QWebEnginePage.Paste) |
379 self.triggerPageAction(QWebEnginePage.WebAction.Paste) |
380 |
380 |
381 def undo(self): |
381 def undo(self): |
382 """ |
382 """ |
383 Public slot to undo the last edit action. |
383 Public slot to undo the last edit action. |
384 """ |
384 """ |
385 self.triggerPageAction(QWebEnginePage.Undo) |
385 self.triggerPageAction(QWebEnginePage.WebAction.Undo) |
386 |
386 |
387 def redo(self): |
387 def redo(self): |
388 """ |
388 """ |
389 Public slot to redo the last edit action. |
389 Public slot to redo the last edit action. |
390 """ |
390 """ |
391 self.triggerPageAction(QWebEnginePage.Redo) |
391 self.triggerPageAction(QWebEnginePage.WebAction.Redo) |
392 |
392 |
393 def selectAll(self): |
393 def selectAll(self): |
394 """ |
394 """ |
395 Public slot to select all text. |
395 Public slot to select all text. |
396 """ |
396 """ |
397 self.triggerPageAction(QWebEnginePage.SelectAll) |
397 self.triggerPageAction(QWebEnginePage.WebAction.SelectAll) |
398 |
398 |
399 def unselect(self): |
399 def unselect(self): |
400 """ |
400 """ |
401 Public slot to clear the current selection. |
401 Public slot to clear the current selection. |
402 """ |
402 """ |
403 try: |
403 try: |
404 self.triggerPageAction(QWebEnginePage.Unselect) |
404 self.triggerPageAction(QWebEnginePage.WebAction.Unselect) |
405 except AttributeError: |
405 except AttributeError: |
406 # prior to 5.7.0 |
406 # prior to 5.7.0 |
407 self.page().runJavaScript( |
407 self.page().runJavaScript( |
408 "window.getSelection().empty()", |
408 "window.getSelection().empty()", |
409 WebBrowserPage.SafeJsWorld) |
409 WebBrowserPage.SafeJsWorld) |
1481 """ |
1483 """ |
1482 if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt): |
1484 if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt): |
1483 evt.accept() |
1485 evt.accept() |
1484 return |
1486 return |
1485 |
1487 |
1486 if evt.key() == Qt.Key_ZoomIn: |
1488 if evt.key() == Qt.Key.Key_ZoomIn: |
1487 self.zoomIn() |
1489 self.zoomIn() |
1488 evt.accept() |
1490 evt.accept() |
1489 elif evt.key() == Qt.Key_ZoomOut: |
1491 elif evt.key() == Qt.Key.Key_ZoomOut: |
1490 self.zoomOut() |
1492 self.zoomOut() |
1491 evt.accept() |
1493 evt.accept() |
1492 elif evt.key() == Qt.Key_Plus: |
1494 elif evt.key() == Qt.Key.Key_Plus: |
1493 if evt.modifiers() & Qt.ControlModifier: |
1495 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
1494 self.zoomIn() |
1496 self.zoomIn() |
1495 evt.accept() |
1497 evt.accept() |
1496 elif evt.key() == Qt.Key_Minus: |
1498 elif evt.key() == Qt.Key.Key_Minus: |
1497 if evt.modifiers() & Qt.ControlModifier: |
1499 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
1498 self.zoomOut() |
1500 self.zoomOut() |
1499 evt.accept() |
1501 evt.accept() |
1500 elif evt.key() == Qt.Key_0: |
1502 elif evt.key() == Qt.Key.Key_0: |
1501 if evt.modifiers() & Qt.ControlModifier: |
1503 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
1502 self.zoomReset() |
1504 self.zoomReset() |
1503 evt.accept() |
1505 evt.accept() |
1504 elif evt.key() == Qt.Key_M: |
1506 elif evt.key() == Qt.Key.Key_M: |
1505 if evt.modifiers() & Qt.ControlModifier: |
1507 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
1506 self.__muteMedia() |
1508 self.__muteMedia() |
1507 evt.accept() |
1509 evt.accept() |
1508 elif evt.key() == Qt.Key_Backspace: |
1510 elif evt.key() == Qt.Key.Key_Backspace: |
1509 pos = QCursor.pos() |
1511 pos = QCursor.pos() |
1510 pos = self.mapFromGlobal(pos) |
1512 pos = self.mapFromGlobal(pos) |
1511 hitTest = self.page().hitTestContent(pos) |
1513 hitTest = self.page().hitTestContent(pos) |
1512 if not hitTest.isContentEditable(): |
1514 if not hitTest.isContentEditable(): |
1513 self.pageAction(QWebEnginePage.Back).trigger() |
1515 self.pageAction(QWebEnginePage.WebAction.Back).trigger() |
1514 evt.accept() |
1516 evt.accept() |
1515 |
1517 |
1516 def _keyReleaseEvent(self, evt): |
1518 def _keyReleaseEvent(self, evt): |
1517 """ |
1519 """ |
1518 Protected method called by a key release. |
1520 Protected method called by a key release. |
1519 |
1521 |
1520 @param evt reference to the key event (QKeyEvent) |
1522 @param evt reference to the key event (QKeyEvent) |
1521 """ |
1523 """ |
1522 if evt.key() == Qt.Key_Escape: |
1524 if evt.key() == Qt.Key.Key_Escape: |
1523 if self.isFullScreen(): |
1525 if self.isFullScreen(): |
1524 self.triggerPageAction(QWebEnginePage.ExitFullScreen) |
1526 self.triggerPageAction(QWebEnginePage.WebAction.ExitFullScreen) |
1525 evt.accept() |
1527 evt.accept() |
1526 self.requestFullScreen(False) |
1528 self.requestFullScreen(False) |
1527 |
1529 |
1528 def _gestureEvent(self, evt): |
1530 def _gestureEvent(self, evt): |
1529 """ |
1531 """ |
1530 Protected method handling gesture events. |
1532 Protected method handling gesture events. |
1531 |
1533 |
1532 @param evt reference to the gesture event (QGestureEvent |
1534 @param evt reference to the gesture event (QGestureEvent |
1533 """ |
1535 """ |
1534 pinch = evt.gesture(Qt.PinchGesture) |
1536 pinch = evt.gesture(Qt.GestureType.PinchGesture) |
1535 if pinch: |
1537 if pinch: |
1536 if pinch.state() == Qt.GestureStarted: |
1538 if pinch.state() == Qt.GestureState.GestureStarted: |
1537 pinch.setTotalScaleFactor(self.__currentZoom / 100.0) |
1539 pinch.setTotalScaleFactor(self.__currentZoom / 100.0) |
1538 elif pinch.state() == Qt.GestureUpdated: |
1540 elif pinch.state() == Qt.GestureState.GestureUpdated: |
1539 scaleFactor = pinch.totalScaleFactor() |
1541 scaleFactor = pinch.totalScaleFactor() |
1540 self.setZoomValue(int(scaleFactor * 100)) |
1542 self.setZoomValue(int(scaleFactor * 100)) |
1541 evt.accept() |
1543 evt.accept() |
1542 |
1544 |
1543 def eventFilter(self, obj, evt): |
1545 def eventFilter(self, obj, evt): |
1551 @return flag indicating that the event should be filtered out |
1553 @return flag indicating that the event should be filtered out |
1552 @rtype bool |
1554 @rtype bool |
1553 """ |
1555 """ |
1554 if ( |
1556 if ( |
1555 obj is self and |
1557 obj is self and |
1556 evt.type() == QEvent.ParentChange and |
1558 evt.type() == QEvent.Type.ParentChange and |
1557 self.parentWidget() is not None |
1559 self.parentWidget() is not None |
1558 ): |
1560 ): |
1559 self.parentWidget().installEventFilter(self) |
1561 self.parentWidget().installEventFilter(self) |
1560 |
1562 |
1561 # find the render widget receiving events for the web page |
1563 # find the render widget receiving events for the web page |
1562 if obj is self and evt.type() == QEvent.ChildAdded: |
1564 if obj is self and evt.type() == QEvent.Type.ChildAdded: |
1563 QTimer.singleShot(0, self.__setRwhvqt) |
1565 QTimer.singleShot(0, self.__setRwhvqt) |
1564 |
1566 |
1565 # forward events to WebBrowserView |
1567 # forward events to WebBrowserView |
1566 if ( |
1568 if ( |
1567 obj is self.__rwhvqt and |
1569 obj is self.__rwhvqt and |
1568 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, |
1570 evt.type() in [QEvent.Type.KeyPress, |
1569 QEvent.MouseButtonPress, QEvent.MouseButtonRelease, |
1571 QEvent.Type.KeyRelease, |
1570 QEvent.MouseMove, QEvent.Wheel, QEvent.Gesture] |
1572 QEvent.Type.MouseButtonPress, |
|
1573 QEvent.Type.MouseButtonRelease, |
|
1574 QEvent.Type.MouseMove, |
|
1575 QEvent.Type.Wheel, |
|
1576 QEvent.Type.Gesture] |
1571 ): |
1577 ): |
1572 wasAccepted = evt.isAccepted() |
1578 wasAccepted = evt.isAccepted() |
1573 evt.setAccepted(False) |
1579 evt.setAccepted(False) |
1574 if evt.type() == QEvent.KeyPress: |
1580 if evt.type() == QEvent.Type.KeyPress: |
1575 self._keyPressEvent(evt) |
1581 self._keyPressEvent(evt) |
1576 elif evt.type() == QEvent.KeyRelease: |
1582 elif evt.type() == QEvent.Type.KeyRelease: |
1577 self._keyReleaseEvent(evt) |
1583 self._keyReleaseEvent(evt) |
1578 elif evt.type() == QEvent.MouseButtonPress: |
1584 elif evt.type() == QEvent.Type.MouseButtonPress: |
1579 self._mousePressEvent(evt) |
1585 self._mousePressEvent(evt) |
1580 elif evt.type() == QEvent.MouseButtonRelease: |
1586 elif evt.type() == QEvent.Type.MouseButtonRelease: |
1581 self._mouseReleaseEvent(evt) |
1587 self._mouseReleaseEvent(evt) |
1582 elif evt.type() == QEvent.MouseMove: |
1588 elif evt.type() == QEvent.Type.MouseMove: |
1583 self._mouseMoveEvent(evt) |
1589 self._mouseMoveEvent(evt) |
1584 elif evt.type() == QEvent.Wheel: |
1590 elif evt.type() == QEvent.Type.Wheel: |
1585 self._wheelEvent(evt) |
1591 self._wheelEvent(evt) |
1586 elif evt.type() == QEvent.Gesture: |
1592 elif evt.type() == QEvent.Type.Gesture: |
1587 self._gestureEvent(evt) |
1593 self._gestureEvent(evt) |
1588 ret = evt.isAccepted() |
1594 ret = evt.isAccepted() |
1589 evt.setAccepted(wasAccepted) |
1595 evt.setAccepted(wasAccepted) |
1590 return ret |
1596 return ret |
1591 |
1597 |
1592 if ( |
1598 if ( |
1593 obj is self.parentWidget() and |
1599 obj is self.parentWidget() and |
1594 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease] |
1600 evt.type() in [QEvent.Type.KeyPress, QEvent.Type.KeyRelease] |
1595 ): |
1601 ): |
1596 wasAccepted = evt.isAccepted() |
1602 wasAccepted = evt.isAccepted() |
1597 evt.setAccepted(False) |
1603 evt.setAccepted(False) |
1598 if evt.type() == QEvent.KeyPress: |
1604 if evt.type() == QEvent.Type.KeyPress: |
1599 self._keyPressEvent(evt) |
1605 self._keyPressEvent(evt) |
1600 elif evt.type() == QEvent.KeyRelease: |
1606 elif evt.type() == QEvent.Type.KeyRelease: |
1601 self._keyReleaseEvent(evt) |
1607 self._keyReleaseEvent(evt) |
1602 ret = evt.isAccepted() |
1608 ret = evt.isAccepted() |
1603 evt.setAccepted(wasAccepted) |
1609 evt.setAccepted(wasAccepted) |
1604 return ret |
1610 return ret |
1605 |
1611 |
1606 # block already handled events |
1612 # block already handled events |
1607 if obj is self: |
1613 if obj is self: |
1608 if evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, |
1614 if evt.type() in [QEvent.Type.KeyPress, |
1609 QEvent.MouseButtonPress, |
1615 QEvent.Type.KeyRelease, |
1610 QEvent.MouseButtonRelease, |
1616 QEvent.Type.MouseButtonPress, |
1611 QEvent.MouseMove, QEvent.Wheel, QEvent.Gesture]: |
1617 QEvent.Type.MouseButtonRelease, |
|
1618 QEvent.Type.MouseMove, |
|
1619 QEvent.Type.Wheel, |
|
1620 QEvent.Type.Gesture]: |
1612 return True |
1621 return True |
1613 |
1622 |
1614 elif evt.type() == QEvent.Hide: |
1623 elif evt.type() == QEvent.Type.Hide: |
1615 if self.isFullScreen(): |
1624 if self.isFullScreen(): |
1616 self.triggerPageAction(QWebEnginePage.ExitFullScreen) |
1625 self.triggerPageAction( |
|
1626 QWebEnginePage.WebAction.ExitFullScreen) |
1617 |
1627 |
1618 return super(WebBrowserView, self).eventFilter(obj, evt) |
1628 return super(WebBrowserView, self).eventFilter(obj, evt) |
1619 |
1629 |
1620 def event(self, evt): |
1630 def event(self, evt): |
1621 """ |
1631 """ |
1622 Public method handling events. |
1632 Public method handling events. |
1623 |
1633 |
1624 @param evt reference to the event (QEvent) |
1634 @param evt reference to the event (QEvent) |
1625 @return flag indicating, if the event was handled (boolean) |
1635 @return flag indicating, if the event was handled (boolean) |
1626 """ |
1636 """ |
1627 if evt.type() == QEvent.Gesture: |
1637 if evt.type() == QEvent.Type.Gesture: |
1628 self._gestureEvent(evt) |
1638 self._gestureEvent(evt) |
1629 return True |
1639 return True |
1630 |
1640 |
1631 return super(WebBrowserView, self).event(evt) |
1641 return super(WebBrowserView, self).event(evt) |
1632 |
1642 |
1768 self.page().deleteLater() |
1783 self.page().deleteLater() |
1769 self.__createNewPage() |
1784 self.__createNewPage() |
1770 |
1785 |
1771 html = getHtmlPage("tabCrashPage.html") |
1786 html = getHtmlPage("tabCrashPage.html") |
1772 html = html.replace("@IMAGE@", pixmapToDataUrl( |
1787 html = html.replace("@IMAGE@", pixmapToDataUrl( |
1773 e5App().style().standardIcon(QStyle.SP_MessageBoxWarning).pixmap( |
1788 e5App().style().standardIcon( |
1774 48, 48)).toString()) |
1789 QStyle.StandardPixmap.SP_MessageBoxWarning).pixmap(48, 48) |
|
1790 ).toString()) |
1775 html = html.replace("@FAVICON@", pixmapToDataUrl( |
1791 html = html.replace("@FAVICON@", pixmapToDataUrl( |
1776 e5App().style() .standardIcon(QStyle.SP_MessageBoxWarning).pixmap( |
1792 e5App().style() .standardIcon( |
1777 16, 16)).toString()) |
1793 QStyle.StandardPixmap.SP_MessageBoxWarning).pixmap(16, 16) |
|
1794 ).toString()) |
1778 html = html.replace( |
1795 html = html.replace( |
1779 "@TITLE@", self.tr("Render Process terminated abnormally")) |
1796 "@TITLE@", self.tr("Render Process terminated abnormally")) |
1780 html = html.replace( |
1797 html = html.replace( |
1781 "@H1@", self.tr("Render Process terminated abnormally")) |
1798 "@H1@", self.tr("Render Process terminated abnormally")) |
1782 if status == QWebEnginePage.CrashedTerminationStatus: |
1799 if ( |
|
1800 status == |
|
1801 QWebEnginePage.RenderProcessTerminationStatus |
|
1802 .CrashedTerminationStatus |
|
1803 ): |
1783 msg = self.tr("The render process crashed while" |
1804 msg = self.tr("The render process crashed while" |
1784 " loading this page.") |
1805 " loading this page.") |
1785 elif status == QWebEnginePage.KilledTerminationStatus: |
1806 elif ( |
|
1807 status == |
|
1808 QWebEnginePage.RenderProcessTerminationStatus |
|
1809 .KilledTerminationStatus |
|
1810 ): |
1786 msg = self.tr("The render process was killed.") |
1811 msg = self.tr("The render process was killed.") |
1787 else: |
1812 else: |
1788 msg = self.tr("The render process terminated while" |
1813 msg = self.tr("The render process terminated while" |
1789 " loading this page.") |
1814 " loading this page.") |
1790 html = html.replace("@LI-1@", msg) |
1815 html = html.replace("@LI-1@", msg) |
1932 defaultFileName += ".mht" |
1957 defaultFileName += ".mht" |
1933 else: |
1958 else: |
1934 defaultFileName += ".mhtml" |
1959 defaultFileName += ".mhtml" |
1935 |
1960 |
1936 fileName = "" |
1961 fileName = "" |
1937 saveFormat = QWebEngineDownloadItem.MimeHtmlSaveFormat |
1962 saveFormat = QWebEngineDownloadItem.SavePageFormat.MimeHtmlSaveFormat |
1938 |
1963 |
1939 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
1964 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
1940 None, |
1965 None, |
1941 self.tr("Save Web Page"), |
1966 self.tr("Save Web Page"), |
1942 defaultFileName, |
1967 defaultFileName, |
1943 ";;".join(filterList), |
1968 ";;".join(filterList), |
1944 None) |
1969 None) |
1945 if fileName: |
1970 if fileName: |
1946 index = filterList.index(selectedFilter) |
1971 index = filterList.index(selectedFilter) |
1947 if index == 0: |
1972 if index == 0: |
1948 saveFormat = QWebEngineDownloadItem.MimeHtmlSaveFormat |
1973 saveFormat = ( |
|
1974 QWebEngineDownloadItem.SavePageFormat.MimeHtmlSaveFormat |
|
1975 ) |
1949 elif index == 1: |
1976 elif index == 1: |
1950 saveFormat = QWebEngineDownloadItem.SingleHtmlSaveFormat |
1977 saveFormat = ( |
|
1978 QWebEngineDownloadItem.SavePageFormat.SingleHtmlSaveFormat |
|
1979 ) |
1951 else: |
1980 else: |
1952 saveFormat = QWebEngineDownloadItem.CompleteHtmlSaveFormat |
1981 saveFormat = ( |
|
1982 QWebEngineDownloadItem.SavePageFormat |
|
1983 .CompleteHtmlSaveFormat |
|
1984 ) |
1953 |
1985 |
1954 extension = os.path.splitext(fileName)[1] |
1986 extension = os.path.splitext(fileName)[1] |
1955 if not extension: |
1987 if not extension: |
1956 # add the platform specific default extension |
1988 # add the platform specific default extension |
1957 if Utilities.isWindowsPlatform(): |
1989 if Utilities.isWindowsPlatform(): |
2145 "y": scrollPos.y(), |
2177 "y": scrollPos.y(), |
2146 } |
2178 } |
2147 |
2179 |
2148 # 3. page history |
2180 # 3. page history |
2149 historyArray = QByteArray() |
2181 historyArray = QByteArray() |
2150 stream = QDataStream(historyArray, QIODevice.WriteOnly) |
2182 stream = QDataStream(historyArray, QIODevice.OpenModeFlag.WriteOnly) |
2151 stream << page.history() |
2183 stream << page.history() |
2152 sessionData["History"] = str( |
2184 sessionData["History"] = str( |
2153 historyArray.toBase64(QByteArray.Base64UrlEncoding), |
2185 historyArray.toBase64(QByteArray.Base64Option.Base64UrlEncoding), |
2154 encoding="ascii") |
2186 encoding="ascii") |
2155 sessionData["HistoryIndex"] = page.history().currentItemIndex() |
2187 sessionData["HistoryIndex"] = page.history().currentItemIndex() |
2156 |
2188 |
2157 # 4. current URL and title |
2189 # 4. current URL and title |
2158 sessionData["Url"] = self.url().toString() |
2190 sessionData["Url"] = self.url().toString() |
2159 sessionData["Title"] = self.title() |
2191 sessionData["Title"] = self.title() |
2160 |
2192 |
2161 # 5. web icon |
2193 # 5. web icon |
2162 iconArray = QByteArray() |
2194 iconArray = QByteArray() |
2163 stream = QDataStream(iconArray, QIODevice.WriteOnly) |
2195 stream = QDataStream(iconArray, QIODevice.OpenModeFlag.WriteOnly) |
2164 stream << page.icon() |
2196 stream << page.icon() |
2165 sessionData["Icon"] = str(iconArray.toBase64(), encoding="ascii") |
2197 sessionData["Icon"] = str(iconArray.toBase64(), encoding="ascii") |
2166 |
2198 |
2167 return sessionData |
2199 return sessionData |
2168 |
2200 |