806 |
807 |
807 self.__inspector = None |
808 self.__inspector = None |
808 |
809 |
809 self.grabGesture(Qt.PinchGesture) |
810 self.grabGesture(Qt.PinchGesture) |
810 |
811 |
811 def __addExternalBinding(self, frame=None): |
812 def __addExternalBinding(self, frame, frameCleared): |
812 """ |
813 """ |
813 Private slot to add javascript bindings for adding search providers. |
814 Private slot to add javascript bindings for adding search providers. |
814 |
815 |
815 @param frame reference to the web frame (QWebFrame) |
816 @param frame reference to the web frame |
|
817 @type QWebFrame |
|
818 @param frameCleared flag indicate, that the frame was cleared |
|
819 @type bool |
816 """ |
820 """ |
817 self.page().settings().setAttribute(QWebSettings.JavascriptEnabled, |
821 self.page().settings().setAttribute(QWebSettings.JavascriptEnabled, |
818 True) |
822 True) |
819 if self.__javaScriptBinding is None: |
823 if self.__javaScriptBinding is None: |
820 self.__javaScriptBinding = JavaScriptExternalObject(self.mw, self) |
824 self.__javaScriptBinding = JavaScriptExternalObject(self.mw, self) |
821 |
825 |
822 if frame is None: |
826 if frameCleared: |
823 # called from QWebFrame.javaScriptWindowObjectCleared |
827 # called from QWebFrame.javaScriptWindowObjectCleared |
824 frame = self.sender() |
|
825 if isinstance(frame, HelpWebPage): |
828 if isinstance(frame, HelpWebPage): |
826 frame = frame.mainFrame() |
829 frame = frame.mainFrame() |
827 if frame.url().scheme() == "eric" and frame.url().path() == "home": |
830 if frame.url().scheme() == "eric" and frame.url().path() == "home": |
828 if self.__javaScriptEricObject is None: |
831 if self.__javaScriptEricObject is None: |
829 self.__javaScriptEricObject = JavaScriptEricObject( |
832 self.__javaScriptEricObject = JavaScriptEricObject( |
1208 return |
1211 return |
1209 |
1212 |
1210 frameAtPos = self.page().frameAt(evt.pos()) |
1213 frameAtPos = self.page().frameAt(evt.pos()) |
1211 hit = self.page().mainFrame().hitTestContent(evt.pos()) |
1214 hit = self.page().mainFrame().hitTestContent(evt.pos()) |
1212 if not hit.linkUrl().isEmpty(): |
1215 if not hit.linkUrl().isEmpty(): |
1213 menu.addAction( |
1216 act = menu.addAction( |
1214 UI.PixmapCache.getIcon("openNewTab.png"), |
1217 UI.PixmapCache.getIcon("openNewTab.png"), |
1215 self.tr("Open Link in New Tab\tCtrl+LMB"), |
1218 self.tr("Open Link in New Tab\tCtrl+LMB")) |
1216 self.__openLinkInNewTab).setData(hit.linkUrl()) |
1219 act.setData(hit.linkUrl()) |
|
1220 act.triggered.connect( |
|
1221 lambda: self.__openLinkInNewTab(act)) |
1217 menu.addSeparator() |
1222 menu.addSeparator() |
1218 menu.addAction( |
1223 menu.addAction( |
1219 UI.PixmapCache.getIcon("download.png"), |
1224 UI.PixmapCache.getIcon("download.png"), |
1220 self.tr("Save Lin&k"), self.__downloadLink) |
1225 self.tr("Save Lin&k"), self.__downloadLink) |
1221 menu.addAction( |
1226 act = menu.addAction( |
1222 UI.PixmapCache.getIcon("bookmark22.png"), |
1227 UI.PixmapCache.getIcon("bookmark22.png"), |
1223 self.tr("Bookmark this Link"), self.__bookmarkLink)\ |
1228 self.tr("Bookmark this Link")) |
1224 .setData(hit.linkUrl()) |
1229 act.setData(hit.linkUrl()) |
|
1230 act.triggered.connect( |
|
1231 lambda: self.__bookmarkLink(act)) |
1225 menu.addSeparator() |
1232 menu.addSeparator() |
1226 menu.addAction( |
1233 menu.addAction( |
1227 UI.PixmapCache.getIcon("editCopy.png"), |
1234 UI.PixmapCache.getIcon("editCopy.png"), |
1228 self.tr("Copy Link to Clipboard"), self.__copyLink) |
1235 self.tr("Copy Link to Clipboard"), self.__copyLink) |
1229 menu.addAction( |
1236 act = menu.addAction( |
1230 UI.PixmapCache.getIcon("mailSend.png"), |
1237 UI.PixmapCache.getIcon("mailSend.png"), |
1231 self.tr("Send Link"), |
1238 self.tr("Send Link")) |
1232 self.__sendLink).setData(hit.linkUrl()) |
1239 act.setData(hit.linkUrl()) |
|
1240 act.triggered.connect( |
|
1241 lambda: self.__sendLink(act)) |
1233 if Preferences.getHelp("VirusTotalEnabled") and \ |
1242 if Preferences.getHelp("VirusTotalEnabled") and \ |
1234 Preferences.getHelp("VirusTotalServiceKey") != "": |
1243 Preferences.getHelp("VirusTotalServiceKey") != "": |
1235 menu.addAction( |
1244 act = menu.addAction( |
1236 UI.PixmapCache.getIcon("virustotal.png"), |
1245 UI.PixmapCache.getIcon("virustotal.png"), |
1237 self.tr("Scan Link with VirusTotal"), |
1246 self.tr("Scan Link with VirusTotal")) |
1238 self.__virusTotal).setData(hit.linkUrl()) |
1247 act.setData(hit.linkUrl()) |
|
1248 act.triggered.connect( |
|
1249 lambda: self.__virusTotal(act)) |
1239 |
1250 |
1240 if not hit.imageUrl().isEmpty(): |
1251 if not hit.imageUrl().isEmpty(): |
1241 if not menu.isEmpty(): |
1252 if not menu.isEmpty(): |
1242 menu.addSeparator() |
1253 menu.addSeparator() |
1243 menu.addAction( |
1254 act = menu.addAction( |
1244 UI.PixmapCache.getIcon("openNewTab.png"), |
1255 UI.PixmapCache.getIcon("openNewTab.png"), |
1245 self.tr("Open Image in New Tab"), |
1256 self.tr("Open Image in New Tab")) |
1246 self.__openLinkInNewTab).setData(hit.imageUrl()) |
1257 act.setData(hit.imageUrl()) |
|
1258 act.triggered.connect( |
|
1259 lambda: self.__openLinkInNewTab(act)) |
1247 menu.addSeparator() |
1260 menu.addSeparator() |
1248 menu.addAction( |
1261 menu.addAction( |
1249 UI.PixmapCache.getIcon("download.png"), |
1262 UI.PixmapCache.getIcon("download.png"), |
1250 self.tr("Save Image"), self.__downloadImage) |
1263 self.tr("Save Image"), self.__downloadImage) |
1251 menu.addAction( |
1264 menu.addAction( |
1252 self.tr("Copy Image to Clipboard"), self.__copyImage) |
1265 self.tr("Copy Image to Clipboard"), self.__copyImage) |
1253 menu.addAction( |
1266 act = menu.addAction( |
1254 UI.PixmapCache.getIcon("editCopy.png"), |
1267 UI.PixmapCache.getIcon("editCopy.png"), |
1255 self.tr("Copy Image Location to Clipboard"), |
1268 self.tr("Copy Image Location to Clipboard")) |
1256 self.__copyLocation).setData(hit.imageUrl().toString()) |
1269 act.setData(hit.imageUrl().toString()) |
1257 menu.addAction( |
1270 act.triggered.connect( |
|
1271 lambda: self.__copyLocation(act)) |
|
1272 act = menu.addAction( |
1258 UI.PixmapCache.getIcon("mailSend.png"), |
1273 UI.PixmapCache.getIcon("mailSend.png"), |
1259 self.tr("Send Image Link"), |
1274 self.tr("Send Image Link")) |
1260 self.__sendLink).setData(hit.imageUrl()) |
1275 act.setData(hit.imageUrl()) |
|
1276 act.triggered.connect( |
|
1277 lambda: self.__sendLink(act)) |
1261 menu.addSeparator() |
1278 menu.addSeparator() |
1262 menu.addAction( |
1279 act = menu.addAction( |
1263 UI.PixmapCache.getIcon("adBlockPlus.png"), |
1280 UI.PixmapCache.getIcon("adBlockPlus.png"), |
1264 self.tr("Block Image"), self.__blockImage)\ |
1281 self.tr("Block Image")) |
1265 .setData(hit.imageUrl().toString()) |
1282 act.setData(hit.imageUrl().toString()) |
|
1283 act.triggered.connect( |
|
1284 lambda: self.__blockImage(act)) |
1266 if Preferences.getHelp("VirusTotalEnabled") and \ |
1285 if Preferences.getHelp("VirusTotalEnabled") and \ |
1267 Preferences.getHelp("VirusTotalServiceKey") != "": |
1286 Preferences.getHelp("VirusTotalServiceKey") != "": |
1268 menu.addAction( |
1287 act = menu.addAction( |
1269 UI.PixmapCache.getIcon("virustotal.png"), |
1288 UI.PixmapCache.getIcon("virustotal.png"), |
1270 self.tr("Scan Image with VirusTotal"), |
1289 self.tr("Scan Image with VirusTotal")) |
1271 self.__virusTotal).setData(hit.imageUrl()) |
1290 act.setData(hit.imageUrl()) |
|
1291 act.triggered.connect( |
|
1292 lambda: self.__virusTotal(act)) |
1272 |
1293 |
1273 element = hit.element() |
1294 element = hit.element() |
1274 if not element.isNull(): |
1295 if not element.isNull(): |
1275 if self.__isMediaElement(element): |
1296 if self.__isMediaElement(element): |
1276 if not menu.isEmpty(): |
1297 if not menu.isEmpty(): |
1297 else: |
1318 else: |
1298 menu.addAction( |
1319 menu.addAction( |
1299 UI.PixmapCache.getIcon("audioVolumeMuted.png"), |
1320 UI.PixmapCache.getIcon("audioVolumeMuted.png"), |
1300 self.tr("Mute"), self.__muteMedia) |
1321 self.tr("Mute"), self.__muteMedia) |
1301 menu.addSeparator() |
1322 menu.addSeparator() |
1302 menu.addAction( |
1323 act = menu.addAction( |
1303 UI.PixmapCache.getIcon("editCopy.png"), |
1324 UI.PixmapCache.getIcon("editCopy.png"), |
1304 self.tr("Copy Media Address to Clipboard"), |
1325 self.tr("Copy Media Address to Clipboard")) |
1305 self.__copyLocation).setData(videoUrl.toString()) |
1326 act.setData(videoUrl.toString()) |
1306 menu.addAction( |
1327 act.triggered.connect( |
|
1328 lambda: self.__copyLocation(act)) |
|
1329 act = menu.addAction( |
1307 UI.PixmapCache.getIcon("mailSend.png"), |
1330 UI.PixmapCache.getIcon("mailSend.png"), |
1308 self.tr("Send Media Address"), self.__sendLink)\ |
1331 self.tr("Send Media Address")) |
1309 .setData(videoUrl) |
1332 act.setData(videoUrl) |
1310 menu.addAction( |
1333 act.triggered.connect( |
|
1334 lambda: self.__sendLink(act)) |
|
1335 act = menu.addAction( |
1311 UI.PixmapCache.getIcon("download.png"), |
1336 UI.PixmapCache.getIcon("download.png"), |
1312 self.tr("Save Media"), self.__downloadMedia)\ |
1337 self.tr("Save Media")) |
1313 .setData(videoUrl) |
1338 act.setData(videoUrl) |
|
1339 act.triggered.connect( |
|
1340 lambda: self.__downloadMedia(act)) |
1314 |
1341 |
1315 if element.tagName().lower() in ["input", "textarea"]: |
1342 if element.tagName().lower() in ["input", "textarea"]: |
1316 if menu.isEmpty(): |
1343 if menu.isEmpty(): |
1317 pageMenu = self.page().createStandardContextMenu() |
1344 pageMenu = self.page().createStandardContextMenu() |
1318 directionFound = False |
1345 directionFound = False |
1439 language = languages[0] |
1473 language = languages[0] |
1440 langCode = language.split("[")[1][:2] |
1474 langCode = language.split("[")[1][:2] |
1441 googleTranslatorUrl = QUrl( |
1475 googleTranslatorUrl = QUrl( |
1442 "http://translate.google.com/#auto|{0}|{1}".format( |
1476 "http://translate.google.com/#auto|{0}|{1}".format( |
1443 langCode, self.selectedText())) |
1477 langCode, self.selectedText())) |
1444 menu.addAction( |
1478 act = menu.addAction( |
1445 UI.PixmapCache.getIcon("translate.png"), |
1479 UI.PixmapCache.getIcon("translate.png"), |
1446 self.tr("Google Translate"), self.__openLinkInNewTab)\ |
1480 self.tr("Google Translate")) |
1447 .setData(googleTranslatorUrl) |
1481 act.setData(googleTranslatorUrl) |
|
1482 act.triggered.connect( |
|
1483 lambda: self.__openLinkInNewTab(act)) |
1448 wiktionaryUrl = QUrl( |
1484 wiktionaryUrl = QUrl( |
1449 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" |
1485 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" |
1450 .format(langCode, self.selectedText())) |
1486 .format(langCode, self.selectedText())) |
1451 menu.addAction( |
1487 act = menu.addAction( |
1452 UI.PixmapCache.getIcon("wikipedia.png"), |
1488 UI.PixmapCache.getIcon("wikipedia.png"), |
1453 self.tr("Dictionary"), self.__openLinkInNewTab)\ |
1489 self.tr("Dictionary")) |
1454 .setData(wiktionaryUrl) |
1490 act.setData(wiktionaryUrl) |
|
1491 act.triggered.connect( |
|
1492 lambda: self.__openLinkInNewTab(act)) |
1455 menu.addSeparator() |
1493 menu.addSeparator() |
1456 |
1494 |
1457 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) |
1495 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) |
1458 if self.__isUrlValid(guessedUrl): |
1496 if self.__isUrlValid(guessedUrl): |
1459 menu.addAction( |
1497 act = menu.addAction(self.tr("Go to web address")) |
1460 self.tr("Go to web address"), |
1498 act.setData(guessedUrl) |
1461 self.__openLinkInNewTab).setData(guessedUrl) |
1499 act.triggered.connect( |
|
1500 lambda: self.__openLinkInNewTab(act)) |
1462 menu.addSeparator() |
1501 menu.addSeparator() |
1463 |
1502 |
1464 element = hit.element() |
1503 element = hit.element() |
1465 if not element.isNull() and \ |
1504 if not element.isNull() and \ |
1466 element.tagName().lower() == "input" and \ |
1505 element.tagName().lower() == "input" and \ |
1467 element.attribute("type", "text") == "text": |
1506 element.attribute("type", "text") == "text": |
1468 menu.addAction(self.tr("Add to web search toolbar"), |
1507 act = menu.addAction( |
1469 self.__addSearchEngine).setData(element) |
1508 self.tr("Add to web search toolbar")) |
|
1509 act.setData(element) |
|
1510 act.triggered.connect( |
|
1511 lambda: self.__addSearchEngine(act)) |
1470 menu.addSeparator() |
1512 menu.addSeparator() |
1471 |
1513 |
1472 menu.addAction( |
1514 menu.addAction( |
1473 UI.PixmapCache.getIcon("webInspector.png"), |
1515 UI.PixmapCache.getIcon("webInspector.png"), |
1474 self.tr("Web Inspector..."), self.__webInspector) |
1516 self.tr("Web Inspector..."), self.__webInspector) |
1485 return url.isValid() and \ |
1527 return url.isValid() and \ |
1486 bool(url.host()) and \ |
1528 bool(url.host()) and \ |
1487 bool(url.scheme()) and \ |
1529 bool(url.scheme()) and \ |
1488 "." in url.host() |
1530 "." in url.host() |
1489 |
1531 |
1490 def __openLinkInNewTab(self): |
1532 def __openLinkInNewTab(self, act): |
1491 """ |
1533 """ |
1492 Private method called by the context menu to open a link in a new |
1534 Private method called by the context menu to open a link in a new |
1493 window. |
1535 window. |
1494 """ |
1536 |
1495 act = self.sender() |
1537 @param act reference to the action that triggered |
|
1538 @type QAction |
|
1539 """ |
1496 url = act.data() |
1540 url = act.data() |
1497 if url.isEmpty(): |
1541 if url.isEmpty(): |
1498 return |
1542 return |
1499 |
1543 |
1500 self.ctrlPressed = True |
1544 self.ctrlPressed = True |
1501 self.setSource(url) |
1545 self.setSource(url) |
1502 self.ctrlPressed = False |
1546 self.ctrlPressed = False |
1503 |
1547 |
1504 def __bookmarkLink(self): |
1548 def __bookmarkLink(self, act): |
1505 """ |
1549 """ |
1506 Private slot to bookmark a link via the context menu. |
1550 Private slot to bookmark a link via the context menu. |
1507 """ |
1551 |
1508 act = self.sender() |
1552 @param act reference to the action that triggered |
|
1553 @type QAction |
|
1554 """ |
1509 url = act.data() |
1555 url = act.data() |
1510 if url.isEmpty(): |
1556 if url.isEmpty(): |
1511 return |
1557 return |
1512 |
1558 |
1513 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
1559 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
1514 dlg = AddBookmarkDialog() |
1560 dlg = AddBookmarkDialog() |
1515 dlg.setUrl(bytes(url.toEncoded()).decode()) |
1561 dlg.setUrl(bytes(url.toEncoded()).decode()) |
1516 dlg.exec_() |
1562 dlg.exec_() |
1517 |
1563 |
1518 def __sendLink(self): |
1564 def __sendLink(self, act): |
1519 """ |
1565 """ |
1520 Private slot to send a link via email. |
1566 Private slot to send a link via email. |
1521 """ |
1567 |
1522 act = self.sender() |
1568 @param act reference to the action that triggered |
|
1569 @type QAction |
|
1570 """ |
1523 data = act.data() |
1571 data = act.data() |
1524 if isinstance(data, QUrl) and data.isEmpty(): |
1572 if isinstance(data, QUrl) and data.isEmpty(): |
1525 return |
1573 return |
1526 |
1574 |
1527 if isinstance(data, QUrl): |
1575 if isinstance(data, QUrl): |
1550 """ |
1598 """ |
1551 Private slot to copy an image to the clipboard. |
1599 Private slot to copy an image to the clipboard. |
1552 """ |
1600 """ |
1553 self.pageAction(QWebPage.CopyImageToClipboard).trigger() |
1601 self.pageAction(QWebPage.CopyImageToClipboard).trigger() |
1554 |
1602 |
1555 def __copyLocation(self): |
1603 def __copyLocation(self, act): |
1556 """ |
1604 """ |
1557 Private slot to copy an image or media location to the clipboard. |
1605 Private slot to copy an image or media location to the clipboard. |
1558 """ |
1606 |
1559 act = self.sender() |
1607 @param act reference to the action that triggered |
|
1608 @type QAction |
|
1609 """ |
1560 url = act.data() |
1610 url = act.data() |
1561 QApplication.clipboard().setText(url) |
1611 QApplication.clipboard().setText(url) |
1562 |
1612 |
1563 def __blockImage(self): |
1613 def __blockImage(self, act): |
1564 """ |
1614 """ |
1565 Private slot to add a block rule for an image URL. |
1615 Private slot to add a block rule for an image URL. |
|
1616 |
|
1617 @param act reference to the action that triggered |
|
1618 @type QAction |
1566 """ |
1619 """ |
1567 import Helpviewer.HelpWindow |
1620 import Helpviewer.HelpWindow |
1568 act = self.sender() |
|
1569 url = act.data() |
1621 url = act.data() |
1570 dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager().showDialog() |
1622 dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager().showDialog() |
1571 dlg.addCustomRule(url) |
1623 dlg.addCustomRule(url) |
1572 |
1624 |
1573 def __downloadMedia(self): |
1625 def __downloadMedia(self, act): |
1574 """ |
1626 """ |
1575 Private slot to download a media and save it to disk. |
1627 Private slot to download a media and save it to disk. |
1576 """ |
1628 |
1577 act = self.sender() |
1629 @param act reference to the action that triggered |
|
1630 @type QAction |
|
1631 """ |
1578 url = act.data() |
1632 url = act.data() |
1579 self.mw.downloadManager().download(url, True, mainWindow=self.mw) |
1633 self.mw.downloadManager().download(url, True, mainWindow=self.mw) |
1580 |
1634 |
1581 def __pauseMedia(self): |
1635 def __pauseMedia(self): |
1582 """ |
1636 """ |