src/eric7/WebBrowser/WebBrowserView.py

branch
eric7
changeset 10436
f6881d10e995
parent 10339
446d22fa1aea
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
136 136
137 def __init__(self, mainWindow, parent=None, name=""): 137 def __init__(self, mainWindow, parent=None, name=""):
138 """ 138 """
139 Constructor 139 Constructor
140 140
141 @param mainWindow reference to the main window (WebBrowserWindow) 141 @param mainWindow reference to the main window
142 @param parent parent widget of this window (QWidget) 142 @type WebBrowserWindow
143 @param name name of this window (string) 143 @param parent parent widget of this window
144 @type QWidget
145 @param name name of this window
146 @type str
144 """ 147 """
145 super().__init__(parent) 148 super().__init__(parent)
146 self.setObjectName(name) 149 self.setObjectName(name)
147 150
148 self.__rwhvqt = None 151 self.__rwhvqt = None
287 290
288 def setSource(self, name, newTab=False): 291 def setSource(self, name, newTab=False):
289 """ 292 """
290 Public method used to set the source to be displayed. 293 Public method used to set the source to be displayed.
291 294
292 @param name filename to be shown (QUrl) 295 @param name filename to be shown
293 @param newTab flag indicating to open the URL in a new tab (bool) 296 @type QUrl
297 @param newTab flag indicating to open the URL in a new tab
298 @type bool
294 """ 299 """
295 if name is None or not name.isValid(): 300 if name is None or not name.isValid():
296 return 301 return
297 302
298 if newTab: 303 if newTab:
370 375
371 def source(self): 376 def source(self):
372 """ 377 """
373 Public method to return the URL of the loaded page. 378 Public method to return the URL of the loaded page.
374 379
375 @return URL loaded in the help browser (QUrl) 380 @return URL loaded in the help browser
381 @rtype QUrl
376 """ 382 """
377 return self.url() 383 return self.url()
378 384
379 def documentTitle(self): 385 def documentTitle(self):
380 """ 386 """
381 Public method to return the title of the loaded page. 387 Public method to return the title of the loaded page.
382 388
383 @return title (string) 389 @return title
390 @rtype str
384 """ 391 """
385 return self.title() 392 return self.title()
386 393
387 def backward(self): 394 def backward(self):
388 """ 395 """
462 469
463 def isForwardAvailable(self): 470 def isForwardAvailable(self):
464 """ 471 """
465 Public method to determine, if a forward move in history is possible. 472 Public method to determine, if a forward move in history is possible.
466 473
467 @return flag indicating move forward is possible (boolean) 474 @return flag indicating move forward is possible
475 @rtype bool
468 """ 476 """
469 return self.history().canGoForward() 477 return self.history().canGoForward()
470 478
471 def isBackwardAvailable(self): 479 def isBackwardAvailable(self):
472 """ 480 """
473 Public method to determine, if a backwards move in history is possible. 481 Public method to determine, if a backwards move in history is possible.
474 482
475 @return flag indicating move backwards is possible (boolean) 483 @return flag indicating move backwards is possible
484 @rtype bool
476 """ 485 """
477 return self.history().canGoBack() 486 return self.history().canGoBack()
478 487
479 def __levelForZoom(self, zoom): 488 def __levelForZoom(self, zoom):
480 """ 489 """
481 Private method determining the zoom level index given a zoom factor. 490 Private method determining the zoom level index given a zoom factor.
482 491
483 @param zoom zoom factor (integer) 492 @param zoom zoom factor
484 @return index of zoom factor (integer) 493 @type int
494 @return index of zoom factor
495 @rtype int
485 """ 496 """
486 try: 497 try:
487 index = self.__zoomLevels.index(zoom) 498 index = self.__zoomLevels.index(zoom)
488 except ValueError: 499 except ValueError:
489 for index in range(len(self.__zoomLevels)): 500 for index in range(len(self.__zoomLevels)):
493 504
494 def setZoomValue(self, value, saveValue=True): 505 def setZoomValue(self, value, saveValue=True):
495 """ 506 """
496 Public method to set the zoom value. 507 Public method to set the zoom value.
497 508
498 @param value zoom value (integer) 509 @param value zoom value
510 @type int
499 @param saveValue flag indicating to save the zoom value with the 511 @param saveValue flag indicating to save the zoom value with the
500 zoom manager 512 zoom manager
501 @type bool 513 @type bool
502 """ 514 """
503 if value != self.__currentZoom: 515 if value != self.__currentZoom:
509 521
510 def zoomValue(self): 522 def zoomValue(self):
511 """ 523 """
512 Public method to get the current zoom value. 524 Public method to get the current zoom value.
513 525
514 @return zoom value (integer) 526 @return zoom value
527 @rtype int
515 """ 528 """
516 val = self.zoomFactor() * 100 529 val = self.zoomFactor() * 100
517 return int(val) 530 return int(val)
518 531
519 def zoomIn(self): 532 def zoomIn(self):
552 565
553 def hasSelection(self): 566 def hasSelection(self):
554 """ 567 """
555 Public method to determine, if there is some text selected. 568 Public method to determine, if there is some text selected.
556 569
557 @return flag indicating text has been selected (boolean) 570 @return flag indicating text has been selected
571 @rtype bool
558 """ 572 """
559 return self.selectedText() != "" 573 return self.selectedText() != ""
560 574
561 def findNextPrev(self, txt, case, backwards, callback): 575 def findNextPrev(self, txt, case, backwards, callback):
562 """ 576 """
563 Public slot to find the next occurrence of a text. 577 Public slot to find the next occurrence of a text.
564 578
565 @param txt text to search for (string) 579 @param txt text to search for
566 @param case flag indicating a case sensitive search (boolean) 580 @type str
567 @param backwards flag indicating a backwards search (boolean) 581 @param case flag indicating a case sensitive search
582 @type bool
583 @param backwards flag indicating a backwards search
584 @type bool
568 @param callback reference to a function with a bool parameter 585 @param callback reference to a function with a bool parameter
569 @type function(bool) or None 586 @type function(bool) or None
570 """ 587 """
571 findFlags = QWebEnginePage.FindFlag(0) 588 findFlags = QWebEnginePage.FindFlag(0)
572 if case: 589 if case:
1105 1122
1106 def __isUrlValid(self, url): 1123 def __isUrlValid(self, url):
1107 """ 1124 """
1108 Private method to check a URL for validity. 1125 Private method to check a URL for validity.
1109 1126
1110 @param url URL to be checked (QUrl) 1127 @param url URL to be checked
1111 @return flag indicating a valid URL (boolean) 1128 @type QUrl
1129 @return flag indicating a valid URL
1130 @rtype bool
1112 """ 1131 """
1113 return ( 1132 return (
1114 url.isValid() 1133 url.isValid()
1115 and bool(url.host()) 1134 and bool(url.host())
1116 and bool(url.scheme()) 1135 and bool(url.scheme())
1301 1320
1302 def __searchRequested(self, act): 1321 def __searchRequested(self, act):
1303 """ 1322 """
1304 Private slot to search for some text with a selected search engine. 1323 Private slot to search for some text with a selected search engine.
1305 1324
1306 @param act reference to the action that triggered this slot (QAction) 1325 @param act reference to the action that triggered this slot
1326 @type QAction
1307 """ 1327 """
1308 searchText = self.selectedText() 1328 searchText = self.selectedText()
1309 1329
1310 if not searchText: 1330 if not searchText:
1311 return 1331 return
1392 1412
1393 def dragEnterEvent(self, evt): 1413 def dragEnterEvent(self, evt):
1394 """ 1414 """
1395 Protected method called by a drag enter event. 1415 Protected method called by a drag enter event.
1396 1416
1397 @param evt reference to the drag enter event (QDragEnterEvent) 1417 @param evt reference to the drag enter event
1418 @type QDragEnterEvent
1398 """ 1419 """
1399 evt.acceptProposedAction() 1420 evt.acceptProposedAction()
1400 1421
1401 def dragMoveEvent(self, evt): 1422 def dragMoveEvent(self, evt):
1402 """ 1423 """
1403 Protected method called by a drag move event. 1424 Protected method called by a drag move event.
1404 1425
1405 @param evt reference to the drag move event (QDragMoveEvent) 1426 @param evt reference to the drag move event
1427 @type QDragMoveEvent
1406 """ 1428 """
1407 evt.ignore() 1429 evt.ignore()
1408 if evt.source() != self: 1430 if evt.source() != self:
1409 if len(evt.mimeData().urls()) > 0: 1431 if len(evt.mimeData().urls()) > 0:
1410 evt.acceptProposedAction() 1432 evt.acceptProposedAction()
1418 1440
1419 def dropEvent(self, evt): 1441 def dropEvent(self, evt):
1420 """ 1442 """
1421 Protected method called by a drop event. 1443 Protected method called by a drop event.
1422 1444
1423 @param evt reference to the drop event (QDropEvent) 1445 @param evt reference to the drop event
1446 @type QDropEvent
1424 """ 1447 """
1425 super().dropEvent(evt) 1448 super().dropEvent(evt)
1426 if ( 1449 if (
1427 not evt.isAccepted() 1450 not evt.isAccepted()
1428 and evt.source() != self 1451 and evt.source() != self
1439 1462
1440 def _mousePressEvent(self, evt): 1463 def _mousePressEvent(self, evt):
1441 """ 1464 """
1442 Protected method called by a mouse press event. 1465 Protected method called by a mouse press event.
1443 1466
1444 @param evt reference to the mouse event (QMouseEvent) 1467 @param evt reference to the mouse event
1468 @type QMouseEvent
1445 """ 1469 """
1446 if WebBrowserWindow.autoScroller().mousePress(self, evt): 1470 if WebBrowserWindow.autoScroller().mousePress(self, evt):
1447 evt.accept() 1471 evt.accept()
1448 return 1472 return
1449 1473
1450 def _mouseReleaseEvent(self, evt): 1474 def _mouseReleaseEvent(self, evt):
1451 """ 1475 """
1452 Protected method called by a mouse release event. 1476 Protected method called by a mouse release event.
1453 1477
1454 @param evt reference to the mouse event (QMouseEvent) 1478 @param evt reference to the mouse event
1479 @type QMouseEvent
1455 """ 1480 """
1456 if WebBrowserWindow.autoScroller().mouseRelease(evt): 1481 if WebBrowserWindow.autoScroller().mouseRelease(evt):
1457 evt.accept() 1482 evt.accept()
1458 return 1483 return
1459 1484
1467 1492
1468 def _mouseMoveEvent(self, evt): 1493 def _mouseMoveEvent(self, evt):
1469 """ 1494 """
1470 Protected method to handle mouse move events. 1495 Protected method to handle mouse move events.
1471 1496
1472 @param evt reference to the mouse event (QMouseEvent) 1497 @param evt reference to the mouse event
1498 @type QMouseEvent
1473 """ 1499 """
1474 if self.__mw and self.__mw.isFullScreen(): 1500 if self.__mw and self.__mw.isFullScreen():
1475 if self.__mw.isFullScreenNavigationVisible(): 1501 if self.__mw.isFullScreenNavigationVisible():
1476 self.__mw.hideFullScreenNavigation() 1502 self.__mw.hideFullScreenNavigation()
1477 elif evt.y() < 10: 1503 elif evt.y() < 10:
1483 1509
1484 def _wheelEvent(self, evt): 1510 def _wheelEvent(self, evt):
1485 """ 1511 """
1486 Protected method to handle wheel events. 1512 Protected method to handle wheel events.
1487 1513
1488 @param evt reference to the wheel event (QWheelEvent) 1514 @param evt reference to the wheel event
1515 @type QWheelEvent
1489 """ 1516 """
1490 if WebBrowserWindow.autoScroller().wheel(): 1517 if WebBrowserWindow.autoScroller().wheel():
1491 evt.accept() 1518 evt.accept()
1492 return 1519 return
1493 1520
1508 1535
1509 def _keyPressEvent(self, evt): 1536 def _keyPressEvent(self, evt):
1510 """ 1537 """
1511 Protected method called by a key press. 1538 Protected method called by a key press.
1512 1539
1513 @param evt reference to the key event (QKeyEvent) 1540 @param evt reference to the key event
1541 @type QKeyEvent
1514 """ 1542 """
1515 if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt): 1543 if self.__mw.personalInformationManager().viewKeyPressEvent(self, evt):
1516 evt.accept() 1544 evt.accept()
1517 return 1545 return
1518 1546
1548 1576
1549 def _keyReleaseEvent(self, evt): 1577 def _keyReleaseEvent(self, evt):
1550 """ 1578 """
1551 Protected method called by a key release. 1579 Protected method called by a key release.
1552 1580
1553 @param evt reference to the key event (QKeyEvent) 1581 @param evt reference to the key event
1582 @type QKeyEvent
1554 """ 1583 """
1555 if evt.key() == Qt.Key.Key_Escape and self.isFullScreen(): 1584 if evt.key() == Qt.Key.Key_Escape and self.isFullScreen():
1556 self.triggerPageAction(QWebEnginePage.WebAction.ExitFullScreen) 1585 self.triggerPageAction(QWebEnginePage.WebAction.ExitFullScreen)
1557 evt.accept() 1586 evt.accept()
1558 self.requestFullScreen(False) 1587 self.requestFullScreen(False)
1659 1688
1660 def event(self, evt): 1689 def event(self, evt):
1661 """ 1690 """
1662 Public method handling events. 1691 Public method handling events.
1663 1692
1664 @param evt reference to the event (QEvent) 1693 @param evt reference to the event
1665 @return flag indicating, if the event was handled (boolean) 1694 @type QEvent
1695 @return flag indicating, if the event was handled
1696 @rtype bool
1666 """ 1697 """
1667 if evt.type() == QEvent.Type.Gesture: 1698 if evt.type() == QEvent.Type.Gesture:
1668 self._gestureEvent(evt) 1699 self._gestureEvent(evt)
1669 return True 1700 return True
1670 1701
1692 1723
1693 def __urlChanged(self, url): 1724 def __urlChanged(self, url):
1694 """ 1725 """
1695 Private slot to handle the urlChanged signal. 1726 Private slot to handle the urlChanged signal.
1696 1727
1697 @param url the new url (QUrl) 1728 @param url the new url
1729 @type QUrl
1698 """ 1730 """
1699 self.sourceChanged.emit(url) 1731 self.sourceChanged.emit(url)
1700 1732
1701 self.forwardAvailable.emit(self.isForwardAvailable()) 1733 self.forwardAvailable.emit(self.isForwardAvailable())
1702 self.backwardAvailable.emit(self.isBackwardAvailable()) 1734 self.backwardAvailable.emit(self.isBackwardAvailable())
1775 1807
1776 def __linkHovered(self, link): 1808 def __linkHovered(self, link):
1777 """ 1809 """
1778 Private slot to handle the linkHovered signal. 1810 Private slot to handle the linkHovered signal.
1779 1811
1780 @param link the URL of the link (string) 1812 @param link the URL of the link
1813 @type str
1781 """ 1814 """
1782 self.highlighted.emit(link) 1815 self.highlighted.emit(link)
1783 1816
1784 ########################################################################### 1817 ###########################################################################
1785 ## Signal handlers below 1818 ## Signal handlers below
1866 1899
1867 def __loadProgress(self, progress): 1900 def __loadProgress(self, progress):
1868 """ 1901 """
1869 Private method to handle the loadProgress signal. 1902 Private method to handle the loadProgress signal.
1870 1903
1871 @param progress progress value (integer) 1904 @param progress progress value
1905 @type int
1872 """ 1906 """
1873 self.__progress = progress 1907 self.__progress = progress
1874 1908
1875 def __loadFinished(self, ok): 1909 def __loadFinished(self, ok):
1876 """ 1910 """
1877 Private method to handle the loadFinished signal. 1911 Private method to handle the loadFinished signal.
1878 1912
1879 @param ok flag indicating the result (boolean) 1913 @param ok flag indicating the result
1914 @type bool
1880 """ 1915 """
1881 self.__isLoading = False 1916 self.__isLoading = False
1882 self.__progress = 0 1917 self.__progress = 0
1883 1918
1884 QApplication.processEvents() 1919 QApplication.processEvents()
1915 1950
1916 def isLoading(self): 1951 def isLoading(self):
1917 """ 1952 """
1918 Public method to get the loading state. 1953 Public method to get the loading state.
1919 1954
1920 @return flag indicating the loading state (boolean) 1955 @return flag indicating the loading state
1956 @rtype bool
1921 """ 1957 """
1922 return self.__isLoading 1958 return self.__isLoading
1923 1959
1924 def progress(self): 1960 def progress(self):
1925 """ 1961 """
1926 Public method to get the load progress. 1962 Public method to get the load progress.
1927 1963
1928 @return load progress (integer) 1964 @return load progress
1965 @rtype int
1929 """ 1966 """
1930 return self.__progress 1967 return self.__progress
1931 1968
1932 def __renderPreview(self): 1969 def __renderPreview(self):
1933 """ 1970 """
2059 def createWindow(self, windowType): 2096 def createWindow(self, windowType):
2060 """ 2097 """
2061 Public method called, when a new window should be created. 2098 Public method called, when a new window should be created.
2062 2099
2063 @param windowType type of the requested window 2100 @param windowType type of the requested window
2064 (QWebEnginePage.WebWindowType) 2101 @type QWebEnginePage.WebWindowType
2065 @return reference to the created browser window (WebBrowserView) 2102 @return reference to the created browser window
2103 @rtype WebBrowserView
2066 """ 2104 """
2067 if windowType in [ 2105 if windowType in [
2068 QWebEnginePage.WebWindowType.WebBrowserTab, 2106 QWebEnginePage.WebWindowType.WebBrowserTab,
2069 QWebEnginePage.WebWindowType.WebDialog, 2107 QWebEnginePage.WebWindowType.WebDialog,
2070 ]: 2108 ]:
2089 2127
2090 def checkRSS(self): 2128 def checkRSS(self):
2091 """ 2129 """
2092 Public method to check, if the loaded page contains feed links. 2130 Public method to check, if the loaded page contains feed links.
2093 2131
2094 @return flag indicating the existence of feed links (boolean) 2132 @return flag indicating the existence of feed links
2133 @rtype bool
2095 """ 2134 """
2096 self.__rss = [] 2135 self.__rss = []
2097 2136
2098 script = Scripts.getFeedLinks() 2137 script = Scripts.getFeedLinks()
2099 feeds = self.page().execJavaScript(script) 2138 feeds = self.page().execJavaScript(script)
2107 2146
2108 def getRSS(self): 2147 def getRSS(self):
2109 """ 2148 """
2110 Public method to get the extracted RSS feeds. 2149 Public method to get the extracted RSS feeds.
2111 2150
2112 @return list of RSS feeds (list of tuples of two strings) 2151 @return list of RSS feeds
2152 @rtype list of [(str, str)]
2113 """ 2153 """
2114 return self.__rss 2154 return self.__rss
2115 2155
2116 def hasRSS(self): 2156 def hasRSS(self):
2117 """ 2157 """
2118 Public method to check, if the loaded page has RSS links. 2158 Public method to check, if the loaded page has RSS links.
2119 2159
2120 @return flag indicating the presence of RSS links (boolean) 2160 @return flag indicating the presence of RSS links
2161 @rtype bool
2121 """ 2162 """
2122 return len(self.__rss) > 0 2163 return len(self.__rss) > 0
2123 2164
2124 ########################################################################### 2165 ###########################################################################
2125 ## Full Screen handling below 2166 ## Full Screen handling below

eric ide

mercurial