Helpviewer/HelpBrowserWV.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3190
a9a94491c4fd
child 3539
0c2dc1446ebf
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
8 Module implementing the helpbrowser using QWebView. 8 Module implementing the helpbrowser using QWebView.
9 """ 9 """
10 10
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 try: 12 try:
13 str = unicode # __IGNORE_WARNING__ 13 str = unicode
14 except (NameError): 14 except NameError:
15 pass 15 pass
16 16
17 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \ 17 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \
18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, QRect, QFile, \ 18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, QRect, QFile, \
19 QPoint, QByteArray, qVersion 19 QPoint, QByteArray, qVersion
122 if qApp.isLeftToRight(): 122 if qApp.isLeftToRight():
123 return "LTR" 123 return "LTR"
124 else: 124 else:
125 return "RTL" 125 return "RTL"
126 126
127 return self.trUtf8(trans) 127 return self.tr(trans)
128 128
129 @pyqtSlot(result=str) 129 @pyqtSlot(result=str)
130 def providerString(self): 130 def providerString(self):
131 """ 131 """
132 Public method to get a string for the search provider. 132 Public method to get a string for the search provider.
133 133
134 @return string for the search provider (string) 134 @return string for the search provider (string)
135 """ 135 """
136 return self.trUtf8("Search results provided by {0}")\ 136 return self.tr("Search results provided by {0}")\
137 .format(self.__mw.openSearchManager().currentEngineName()) 137 .format(self.__mw.openSearchManager().currentEngineName())
138 138
139 @pyqtSlot(str, result=str) 139 @pyqtSlot(str, result=str)
140 def searchUrl(self, searchStr): 140 def searchUrl(self, searchStr):
141 """ 141 """
205 return False 205 return False
206 206
207 if type_ == QWebPage.NavigationTypeFormResubmitted: 207 if type_ == QWebPage.NavigationTypeFormResubmitted:
208 res = E5MessageBox.yesNo( 208 res = E5MessageBox.yesNo(
209 self.view(), 209 self.view(),
210 self.trUtf8("Resending POST request"), 210 self.tr("Resending POST request"),
211 self.trUtf8( 211 self.tr(
212 """In order to display the site, the request along with""" 212 """In order to display the site, the request along with"""
213 """ all the data must be sent once again, which may lead""" 213 """ all the data must be sent once again, which may lead"""
214 """ to some unexpected behaviour of the site e.g. the""" 214 """ to some unexpected behaviour of the site e.g. the"""
215 """ same action might be performed once again. Do you""" 215 """ same action might be performed once again. Do you"""
216 """ want to continue anyway?"""), 216 """ want to continue anyway?"""),
286 if info.suggestedFileNames: 286 if info.suggestedFileNames:
287 suggestedFileName = info.suggestedFileNames[0] 287 suggestedFileName = info.suggestedFileNames[0]
288 288
289 files.fileNames = E5FileDialog.getOpenFileNames( 289 files.fileNames = E5FileDialog.getOpenFileNames(
290 None, 290 None,
291 self.trUtf8("Select files to upload..."), 291 self.tr("Select files to upload..."),
292 suggestedFileName) 292 suggestedFileName)
293 return True 293 return True
294 294
295 if extension == QWebPage.ErrorPageExtension: 295 if extension == QWebPage.ErrorPageExtension:
296 info = sip.cast(option, QWebPage.ErrorPageExtensionOption) 296 info = sip.cast(option, QWebPage.ErrorPageExtensionOption)
315 element.setAttribute("style", "display:none;") 315 element.setAttribute("style", "display:none;")
316 return False 316 return False
317 else: 317 else:
318 # the whole page is blocked 318 # the whole page is blocked
319 rule = info.errorString.replace("AdBlockRule:", "") 319 rule = info.errorString.replace("AdBlockRule:", "")
320 title = self.trUtf8("Content blocked by AdBlock Plus") 320 title = self.tr("Content blocked by AdBlock Plus")
321 message = self.trUtf8( 321 message = self.tr(
322 "Blocked by rule: <i>{0}</i>").format(rule) 322 "Blocked by rule: <i>{0}</i>").format(rule)
323 323
324 htmlFile = QFile(":/html/adblockPage.html") 324 htmlFile = QFile(":/html/adblockPage.html")
325 htmlFile.open(QFile.ReadOnly) 325 htmlFile.open(QFile.ReadOnly)
326 html = htmlFile.readAll() 326 html = htmlFile.readAll()
336 if info.domain == QWebPage.QtNetwork and \ 336 if info.domain == QWebPage.QtNetwork and \
337 info.error == QNetworkReply.OperationCanceledError and \ 337 info.error == QNetworkReply.OperationCanceledError and \
338 info.errorString == "eric5:No Error": 338 info.errorString == "eric5:No Error":
339 return False 339 return False
340 340
341 title = self.trUtf8("Error loading page: {0}").format(urlString) 341 title = self.tr("Error loading page: {0}").format(urlString)
342 htmlFile = QFile(":/html/notFoundPage.html") 342 htmlFile = QFile(":/html/notFoundPage.html")
343 htmlFile.open(QFile.ReadOnly) 343 htmlFile.open(QFile.ReadOnly)
344 html = htmlFile.readAll() 344 html = htmlFile.readAll()
345 pixmap = qApp.style()\ 345 pixmap = qApp.style()\
346 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48) 346 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
356 html = html.replace( 356 html = html.replace(
357 "@FAVICON@", imageBuffer.buffer().toBase64()) 357 "@FAVICON@", imageBuffer.buffer().toBase64())
358 html = html.replace("@TITLE@", title.encode("utf8")) 358 html = html.replace("@TITLE@", title.encode("utf8"))
359 html = html.replace("@H1@", info.errorString.encode("utf8")) 359 html = html.replace("@H1@", info.errorString.encode("utf8"))
360 html = html.replace( 360 html = html.replace(
361 "@H2@", self.trUtf8("When connecting to: {0}.") 361 "@H2@", self.tr("When connecting to: {0}.")
362 .format(urlString).encode("utf8")) 362 .format(urlString).encode("utf8"))
363 html = html.replace( 363 html = html.replace(
364 "@LI-1@", 364 "@LI-1@",
365 self.trUtf8("Check the address for errors such as " 365 self.tr("Check the address for errors such as "
366 "<b>ww</b>.example.org instead of " 366 "<b>ww</b>.example.org instead of "
367 "<b>www</b>.example.org").encode("utf8")) 367 "<b>www</b>.example.org").encode("utf8"))
368 html = html.replace( 368 html = html.replace(
369 "@LI-2@", 369 "@LI-2@",
370 self.trUtf8( 370 self.tr(
371 "If the address is correct, try checking the network " 371 "If the address is correct, try checking the network "
372 "connection.").encode("utf8")) 372 "connection.").encode("utf8"))
373 html = html.replace( 373 html = html.replace(
374 "@LI-3@", 374 "@LI-3@",
375 self.trUtf8( 375 self.tr(
376 "If your computer or network is protected by a firewall " 376 "If your computer or network is protected by a firewall "
377 "or proxy, make sure that the browser is permitted to " 377 "or proxy, make sure that the browser is permitted to "
378 "access the network.").encode("utf8")) 378 "access the network.").encode("utf8"))
379 html = html.replace( 379 html = html.replace(
380 "@LI-4@", 380 "@LI-4@",
381 self.trUtf8("If your cache policy is set to offline browsing," 381 self.tr("If your cache policy is set to offline browsing,"
382 "only pages in the local cache are available.") 382 "only pages in the local cache are available.")
383 .encode("utf8")) 383 .encode("utf8"))
384 html = html.replace( 384 html = html.replace(
385 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) 385 "@BUTTON@", self.tr("Try Again").encode("utf8"))
386 errorPage.content = html 386 errorPage.content = html
387 return True 387 return True
388 388
389 return QWebPage.extension(self, extension, option, output) 389 return QWebPage.extension(self, extension, option, output)
390 390
546 self.mainFrame().url(), self.__sslConfiguration, self.view()) 546 self.mainFrame().url(), self.__sslConfiguration, self.view())
547 widget.showAt(pos) 547 widget.showAt(pos)
548 else: 548 else:
549 E5MessageBox.warning( 549 E5MessageBox.warning(
550 self.view(), 550 self.view(),
551 self.trUtf8("SSL Info"), 551 self.tr("SSL Info"),
552 self.trUtf8("""This site does not contain SSL information.""")) 552 self.tr("""This site does not contain SSL information."""))
553 553
554 def hasValidSslInfo(self): 554 def hasValidSslInfo(self):
555 """ 555 """
556 Public method to check, if the page has a valid SSL certificate. 556 Public method to check, if the page has a valid SSL certificate.
557 557
652 @param parent parent widget of this window (QWidget) 652 @param parent parent widget of this window (QWidget)
653 @param name name of this window (string) 653 @param name name of this window (string)
654 """ 654 """
655 super(HelpBrowser, self).__init__(parent) 655 super(HelpBrowser, self).__init__(parent)
656 self.setObjectName(name) 656 self.setObjectName(name)
657 self.setWhatsThis(self.trUtf8( 657 self.setWhatsThis(self.tr(
658 """<b>Help Window</b>""" 658 """<b>Help Window</b>"""
659 """<p>This window displays the selected help information.</p>""" 659 """<p>This window displays the selected help information.</p>"""
660 )) 660 ))
661 661
662 import Helpviewer.HelpWindow 662 import Helpviewer.HelpWindow
826 name = QUrl.fromLocalFile(name.toString()) 826 name = QUrl.fromLocalFile(name.toString())
827 827
828 if not QFileInfo(name.toLocalFile()).exists(): 828 if not QFileInfo(name.toLocalFile()).exists():
829 E5MessageBox.critical( 829 E5MessageBox.critical(
830 self, 830 self,
831 self.trUtf8("eric5 Web Browser"), 831 self.tr("eric5 Web Browser"),
832 self.trUtf8( 832 self.tr(
833 """<p>The file <b>{0}</b> does not exist.</p>""") 833 """<p>The file <b>{0}</b> does not exist.</p>""")
834 .format(name.toLocalFile())) 834 .format(name.toLocalFile()))
835 return 835 return
836 836
837 if name.toLocalFile().endswith(".pdf") or \ 837 if name.toLocalFile().endswith(".pdf") or \
840 name.toLocalFile().endswith(".CHM"): 840 name.toLocalFile().endswith(".CHM"):
841 started = QDesktopServices.openUrl(name) 841 started = QDesktopServices.openUrl(name)
842 if not started: 842 if not started:
843 E5MessageBox.critical( 843 E5MessageBox.critical(
844 self, 844 self,
845 self.trUtf8("eric5 Web Browser"), 845 self.tr("eric5 Web Browser"),
846 self.trUtf8( 846 self.tr(
847 """<p>Could not start a viewer""" 847 """<p>Could not start a viewer"""
848 """ for file <b>{0}</b>.</p>""") 848 """ for file <b>{0}</b>.</p>""")
849 .format(name.path())) 849 .format(name.path()))
850 return 850 return
851 elif name.scheme() in ["mailto"]: 851 elif name.scheme() in ["mailto"]:
852 started = QDesktopServices.openUrl(name) 852 started = QDesktopServices.openUrl(name)
853 if not started: 853 if not started:
854 E5MessageBox.critical( 854 E5MessageBox.critical(
855 self, 855 self,
856 self.trUtf8("eric5 Web Browser"), 856 self.tr("eric5 Web Browser"),
857 self.trUtf8( 857 self.tr(
858 """<p>Could not start an application""" 858 """<p>Could not start an application"""
859 """ for URL <b>{0}</b>.</p>""") 859 """ for URL <b>{0}</b>.</p>""")
860 .format(name.toString())) 860 .format(name.toString()))
861 return 861 return
862 elif name.scheme() == "javascript": 862 elif name.scheme() == "javascript":
871 name.toString().endswith(".CHM"): 871 name.toString().endswith(".CHM"):
872 started = QDesktopServices.openUrl(name) 872 started = QDesktopServices.openUrl(name)
873 if not started: 873 if not started:
874 E5MessageBox.critical( 874 E5MessageBox.critical(
875 self, 875 self,
876 self.trUtf8("eric5 Web Browser"), 876 self.tr("eric5 Web Browser"),
877 self.trUtf8( 877 self.tr(
878 """<p>Could not start a viewer""" 878 """<p>Could not start a viewer"""
879 """ for file <b>{0}</b>.</p>""") 879 """ for file <b>{0}</b>.</p>""")
880 .format(name.path())) 880 .format(name.path()))
881 return 881 return
882 882
1081 frameAtPos = self.page().frameAt(evt.pos()) 1081 frameAtPos = self.page().frameAt(evt.pos())
1082 hit = self.page().mainFrame().hitTestContent(evt.pos()) 1082 hit = self.page().mainFrame().hitTestContent(evt.pos())
1083 if not hit.linkUrl().isEmpty(): 1083 if not hit.linkUrl().isEmpty():
1084 menu.addAction( 1084 menu.addAction(
1085 UI.PixmapCache.getIcon("openNewTab.png"), 1085 UI.PixmapCache.getIcon("openNewTab.png"),
1086 self.trUtf8("Open Link in New Tab\tCtrl+LMB"), 1086 self.tr("Open Link in New Tab\tCtrl+LMB"),
1087 self.__openLinkInNewTab).setData(hit.linkUrl()) 1087 self.__openLinkInNewTab).setData(hit.linkUrl())
1088 menu.addSeparator() 1088 menu.addSeparator()
1089 menu.addAction( 1089 menu.addAction(
1090 UI.PixmapCache.getIcon("download.png"), 1090 UI.PixmapCache.getIcon("download.png"),
1091 self.trUtf8("Save Lin&k"), self.__downloadLink) 1091 self.tr("Save Lin&k"), self.__downloadLink)
1092 menu.addAction( 1092 menu.addAction(
1093 UI.PixmapCache.getIcon("bookmark22.png"), 1093 UI.PixmapCache.getIcon("bookmark22.png"),
1094 self.trUtf8("Bookmark this Link"), self.__bookmarkLink)\ 1094 self.tr("Bookmark this Link"), self.__bookmarkLink)\
1095 .setData(hit.linkUrl()) 1095 .setData(hit.linkUrl())
1096 menu.addSeparator() 1096 menu.addSeparator()
1097 menu.addAction( 1097 menu.addAction(
1098 UI.PixmapCache.getIcon("editCopy.png"), 1098 UI.PixmapCache.getIcon("editCopy.png"),
1099 self.trUtf8("Copy Link to Clipboard"), self.__copyLink) 1099 self.tr("Copy Link to Clipboard"), self.__copyLink)
1100 menu.addAction( 1100 menu.addAction(
1101 UI.PixmapCache.getIcon("mailSend.png"), 1101 UI.PixmapCache.getIcon("mailSend.png"),
1102 self.trUtf8("Send Link"), 1102 self.tr("Send Link"),
1103 self.__sendLink).setData(hit.linkUrl()) 1103 self.__sendLink).setData(hit.linkUrl())
1104 if Preferences.getHelp("VirusTotalEnabled") and \ 1104 if Preferences.getHelp("VirusTotalEnabled") and \
1105 Preferences.getHelp("VirusTotalServiceKey") != "": 1105 Preferences.getHelp("VirusTotalServiceKey") != "":
1106 menu.addAction( 1106 menu.addAction(
1107 UI.PixmapCache.getIcon("virustotal.png"), 1107 UI.PixmapCache.getIcon("virustotal.png"),
1108 self.trUtf8("Scan Link with VirusTotal"), 1108 self.tr("Scan Link with VirusTotal"),
1109 self.__virusTotal).setData(hit.linkUrl()) 1109 self.__virusTotal).setData(hit.linkUrl())
1110 1110
1111 if not hit.imageUrl().isEmpty(): 1111 if not hit.imageUrl().isEmpty():
1112 if not menu.isEmpty(): 1112 if not menu.isEmpty():
1113 menu.addSeparator() 1113 menu.addSeparator()
1114 menu.addAction( 1114 menu.addAction(
1115 UI.PixmapCache.getIcon("openNewTab.png"), 1115 UI.PixmapCache.getIcon("openNewTab.png"),
1116 self.trUtf8("Open Image in New Tab"), 1116 self.tr("Open Image in New Tab"),
1117 self.__openLinkInNewTab).setData(hit.imageUrl()) 1117 self.__openLinkInNewTab).setData(hit.imageUrl())
1118 menu.addSeparator() 1118 menu.addSeparator()
1119 menu.addAction( 1119 menu.addAction(
1120 UI.PixmapCache.getIcon("download.png"), 1120 UI.PixmapCache.getIcon("download.png"),
1121 self.trUtf8("Save Image"), self.__downloadImage) 1121 self.tr("Save Image"), self.__downloadImage)
1122 menu.addAction( 1122 menu.addAction(
1123 self.trUtf8("Copy Image to Clipboard"), self.__copyImage) 1123 self.tr("Copy Image to Clipboard"), self.__copyImage)
1124 menu.addAction( 1124 menu.addAction(
1125 UI.PixmapCache.getIcon("editCopy.png"), 1125 UI.PixmapCache.getIcon("editCopy.png"),
1126 self.trUtf8("Copy Image Location to Clipboard"), 1126 self.tr("Copy Image Location to Clipboard"),
1127 self.__copyLocation).setData(hit.imageUrl().toString()) 1127 self.__copyLocation).setData(hit.imageUrl().toString())
1128 menu.addAction( 1128 menu.addAction(
1129 UI.PixmapCache.getIcon("mailSend.png"), 1129 UI.PixmapCache.getIcon("mailSend.png"),
1130 self.trUtf8("Send Image Link"), 1130 self.tr("Send Image Link"),
1131 self.__sendLink).setData(hit.imageUrl()) 1131 self.__sendLink).setData(hit.imageUrl())
1132 menu.addSeparator() 1132 menu.addSeparator()
1133 menu.addAction( 1133 menu.addAction(
1134 UI.PixmapCache.getIcon("adBlockPlus.png"), 1134 UI.PixmapCache.getIcon("adBlockPlus.png"),
1135 self.trUtf8("Block Image"), self.__blockImage)\ 1135 self.tr("Block Image"), self.__blockImage)\
1136 .setData(hit.imageUrl().toString()) 1136 .setData(hit.imageUrl().toString())
1137 if Preferences.getHelp("VirusTotalEnabled") and \ 1137 if Preferences.getHelp("VirusTotalEnabled") and \
1138 Preferences.getHelp("VirusTotalServiceKey") != "": 1138 Preferences.getHelp("VirusTotalServiceKey") != "":
1139 menu.addAction( 1139 menu.addAction(
1140 UI.PixmapCache.getIcon("virustotal.png"), 1140 UI.PixmapCache.getIcon("virustotal.png"),
1141 self.trUtf8("Scan Image with VirusTotal"), 1141 self.tr("Scan Image with VirusTotal"),
1142 self.__virusTotal).setData(hit.imageUrl()) 1142 self.__virusTotal).setData(hit.imageUrl())
1143 1143
1144 element = hit.element() 1144 element = hit.element()
1145 if not element.isNull(): 1145 if not element.isNull():
1146 if self.__isMediaElement(element): 1146 if self.__isMediaElement(element):
1154 videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc")) 1154 videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc"))
1155 1155
1156 if paused: 1156 if paused:
1157 menu.addAction( 1157 menu.addAction(
1158 UI.PixmapCache.getIcon("mediaPlaybackStart.png"), 1158 UI.PixmapCache.getIcon("mediaPlaybackStart.png"),
1159 self.trUtf8("Play"), self.__pauseMedia) 1159 self.tr("Play"), self.__pauseMedia)
1160 else: 1160 else:
1161 menu.addAction( 1161 menu.addAction(
1162 UI.PixmapCache.getIcon("mediaPlaybackPause.png"), 1162 UI.PixmapCache.getIcon("mediaPlaybackPause.png"),
1163 self.trUtf8("Pause"), self.__pauseMedia) 1163 self.tr("Pause"), self.__pauseMedia)
1164 if muted: 1164 if muted:
1165 menu.addAction( 1165 menu.addAction(
1166 UI.PixmapCache.getIcon("audioVolumeHigh.png"), 1166 UI.PixmapCache.getIcon("audioVolumeHigh.png"),
1167 self.trUtf8("Unmute"), self.__muteMedia) 1167 self.tr("Unmute"), self.__muteMedia)
1168 else: 1168 else:
1169 menu.addAction( 1169 menu.addAction(
1170 UI.PixmapCache.getIcon("audioVolumeMuted.png"), 1170 UI.PixmapCache.getIcon("audioVolumeMuted.png"),
1171 self.trUtf8("Mute"), self.__muteMedia) 1171 self.tr("Mute"), self.__muteMedia)
1172 menu.addSeparator() 1172 menu.addSeparator()
1173 menu.addAction( 1173 menu.addAction(
1174 UI.PixmapCache.getIcon("editCopy.png"), 1174 UI.PixmapCache.getIcon("editCopy.png"),
1175 self.trUtf8("Copy Media Address to Clipboard"), 1175 self.tr("Copy Media Address to Clipboard"),
1176 self.__copyLocation).setData(videoUrl.toString()) 1176 self.__copyLocation).setData(videoUrl.toString())
1177 menu.addAction( 1177 menu.addAction(
1178 UI.PixmapCache.getIcon("mailSend.png"), 1178 UI.PixmapCache.getIcon("mailSend.png"),
1179 self.trUtf8("Send Media Address"), self.__sendLink)\ 1179 self.tr("Send Media Address"), self.__sendLink)\
1180 .setData(videoUrl) 1180 .setData(videoUrl)
1181 menu.addAction( 1181 menu.addAction(
1182 UI.PixmapCache.getIcon("download.png"), 1182 UI.PixmapCache.getIcon("download.png"),
1183 self.trUtf8("Save Media"), self.__downloadMedia)\ 1183 self.tr("Save Media"), self.__downloadMedia)\
1184 .setData(videoUrl) 1184 .setData(videoUrl)
1185 1185
1186 if element.tagName().lower() in ["input", "textarea"]: 1186 if element.tagName().lower() in ["input", "textarea"]:
1187 if menu.isEmpty(): 1187 if menu.isEmpty():
1188 pageMenu = self.page().createStandardContextMenu() 1188 pageMenu = self.page().createStandardContextMenu()
1219 menu.addAction(self.mw.saveAsAct) 1219 menu.addAction(self.mw.saveAsAct)
1220 menu.addSeparator() 1220 menu.addSeparator()
1221 1221
1222 if frameAtPos and self.page().mainFrame() != frameAtPos: 1222 if frameAtPos and self.page().mainFrame() != frameAtPos:
1223 self.__clickedFrame = frameAtPos 1223 self.__clickedFrame = frameAtPos
1224 fmenu = QMenu(self.trUtf8("This Frame")) 1224 fmenu = QMenu(self.tr("This Frame"))
1225 frameUrl = self.__clickedFrame.url() 1225 frameUrl = self.__clickedFrame.url()
1226 if frameUrl.isValid(): 1226 if frameUrl.isValid():
1227 fmenu.addAction( 1227 fmenu.addAction(
1228 self.trUtf8("Show &only this frame"), 1228 self.tr("Show &only this frame"),
1229 self.__loadClickedFrame) 1229 self.__loadClickedFrame)
1230 fmenu.addAction( 1230 fmenu.addAction(
1231 UI.PixmapCache.getIcon("openNewTab.png"), 1231 UI.PixmapCache.getIcon("openNewTab.png"),
1232 self.trUtf8("Show in new &tab"), 1232 self.tr("Show in new &tab"),
1233 self.__openLinkInNewTab).setData(self.__clickedFrame.url()) 1233 self.__openLinkInNewTab).setData(self.__clickedFrame.url())
1234 fmenu.addSeparator() 1234 fmenu.addSeparator()
1235 fmenu.addAction( 1235 fmenu.addAction(
1236 UI.PixmapCache.getIcon("print.png"), 1236 UI.PixmapCache.getIcon("print.png"),
1237 self.trUtf8("&Print"), self.__printClickedFrame) 1237 self.tr("&Print"), self.__printClickedFrame)
1238 fmenu.addAction( 1238 fmenu.addAction(
1239 UI.PixmapCache.getIcon("printPreview.png"), 1239 UI.PixmapCache.getIcon("printPreview.png"),
1240 self.trUtf8("Print Preview"), self.__printPreviewClickedFrame) 1240 self.tr("Print Preview"), self.__printPreviewClickedFrame)
1241 fmenu.addAction( 1241 fmenu.addAction(
1242 UI.PixmapCache.getIcon("printPdf.png"), 1242 UI.PixmapCache.getIcon("printPdf.png"),
1243 self.trUtf8("Print as PDF"), self.__printPdfClickedFrame) 1243 self.tr("Print as PDF"), self.__printPdfClickedFrame)
1244 fmenu.addSeparator() 1244 fmenu.addSeparator()
1245 fmenu.addAction( 1245 fmenu.addAction(
1246 UI.PixmapCache.getIcon("zoomIn.png"), 1246 UI.PixmapCache.getIcon("zoomIn.png"),
1247 self.trUtf8("Zoom &in"), self.__zoomInClickedFrame) 1247 self.tr("Zoom &in"), self.__zoomInClickedFrame)
1248 fmenu.addAction( 1248 fmenu.addAction(
1249 UI.PixmapCache.getIcon("zoomReset.png"), 1249 UI.PixmapCache.getIcon("zoomReset.png"),
1250 self.trUtf8("Zoom &reset"), self.__zoomResetClickedFrame) 1250 self.tr("Zoom &reset"), self.__zoomResetClickedFrame)
1251 fmenu.addAction( 1251 fmenu.addAction(
1252 UI.PixmapCache.getIcon("zoomOut.png"), 1252 UI.PixmapCache.getIcon("zoomOut.png"),
1253 self.trUtf8("Zoom &out"), self.__zoomOutClickedFrame) 1253 self.tr("Zoom &out"), self.__zoomOutClickedFrame)
1254 fmenu.addSeparator() 1254 fmenu.addSeparator()
1255 fmenu.addAction( 1255 fmenu.addAction(
1256 self.trUtf8("Show frame so&urce"), 1256 self.tr("Show frame so&urce"),
1257 self.__showClickedFrameSource) 1257 self.__showClickedFrameSource)
1258 1258
1259 menu.addMenu(fmenu) 1259 menu.addMenu(fmenu)
1260 menu.addSeparator() 1260 menu.addSeparator()
1261 1261
1262 menu.addAction( 1262 menu.addAction(
1263 UI.PixmapCache.getIcon("bookmark22.png"), 1263 UI.PixmapCache.getIcon("bookmark22.png"),
1264 self.trUtf8("Bookmark this Page"), self.addBookmark) 1264 self.tr("Bookmark this Page"), self.addBookmark)
1265 menu.addAction( 1265 menu.addAction(
1266 UI.PixmapCache.getIcon("mailSend.png"), 1266 UI.PixmapCache.getIcon("mailSend.png"),
1267 self.trUtf8("Send Page Link"), self.__sendLink).setData(self.url()) 1267 self.tr("Send Page Link"), self.__sendLink).setData(self.url())
1268 menu.addSeparator() 1268 menu.addSeparator()
1269 self.__userAgentMenu = UserAgentMenu(self.trUtf8("User Agent"), 1269 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
1270 url=self.url()) 1270 url=self.url())
1271 menu.addMenu(self.__userAgentMenu) 1271 menu.addMenu(self.__userAgentMenu)
1272 menu.addSeparator() 1272 menu.addSeparator()
1273 menu.addAction(self.mw.backAct) 1273 menu.addAction(self.mw.backAct)
1274 menu.addAction(self.mw.forwardAct) 1274 menu.addAction(self.mw.forwardAct)
1280 menu.addSeparator() 1280 menu.addSeparator()
1281 if self.selectedText(): 1281 if self.selectedText():
1282 menu.addAction(self.mw.copyAct) 1282 menu.addAction(self.mw.copyAct)
1283 menu.addAction( 1283 menu.addAction(
1284 UI.PixmapCache.getIcon("mailSend.png"), 1284 UI.PixmapCache.getIcon("mailSend.png"),
1285 self.trUtf8("Send Text"), 1285 self.tr("Send Text"),
1286 self.__sendLink).setData(self.selectedText()) 1286 self.__sendLink).setData(self.selectedText())
1287 menu.addAction(self.mw.findAct) 1287 menu.addAction(self.mw.findAct)
1288 menu.addSeparator() 1288 menu.addSeparator()
1289 if self.selectedText(): 1289 if self.selectedText():
1290 self.__searchMenu = menu.addMenu(self.trUtf8("Search with...")) 1290 self.__searchMenu = menu.addMenu(self.tr("Search with..."))
1291 1291
1292 from .OpenSearch.OpenSearchEngineAction import \ 1292 from .OpenSearch.OpenSearchEngineAction import \
1293 OpenSearchEngineAction 1293 OpenSearchEngineAction
1294 engineNames = self.mw.openSearchManager().allEnginesNames() 1294 engineNames = self.mw.openSearchManager().allEnginesNames()
1295 for engineName in engineNames: 1295 for engineName in engineNames:
1312 googleTranslatorUrl = QUrl( 1312 googleTranslatorUrl = QUrl(
1313 "http://translate.google.com/#auto|{0}|{1}".format( 1313 "http://translate.google.com/#auto|{0}|{1}".format(
1314 langCode, self.selectedText())) 1314 langCode, self.selectedText()))
1315 menu.addAction( 1315 menu.addAction(
1316 UI.PixmapCache.getIcon("translate.png"), 1316 UI.PixmapCache.getIcon("translate.png"),
1317 self.trUtf8("Google Translate"), self.__openLinkInNewTab)\ 1317 self.tr("Google Translate"), self.__openLinkInNewTab)\
1318 .setData(googleTranslatorUrl) 1318 .setData(googleTranslatorUrl)
1319 wiktionaryUrl = QUrl( 1319 wiktionaryUrl = QUrl(
1320 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" 1320 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
1321 .format(langCode, self.selectedText())) 1321 .format(langCode, self.selectedText()))
1322 menu.addAction( 1322 menu.addAction(
1323 UI.PixmapCache.getIcon("wikipedia.png"), 1323 UI.PixmapCache.getIcon("wikipedia.png"),
1324 self.trUtf8("Dictionary"), self.__openLinkInNewTab)\ 1324 self.tr("Dictionary"), self.__openLinkInNewTab)\
1325 .setData(wiktionaryUrl) 1325 .setData(wiktionaryUrl)
1326 menu.addSeparator() 1326 menu.addSeparator()
1327 1327
1328 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) 1328 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
1329 if self.__isUrlValid(guessedUrl): 1329 if self.__isUrlValid(guessedUrl):
1330 menu.addAction( 1330 menu.addAction(
1331 self.trUtf8("Go to web address"), 1331 self.tr("Go to web address"),
1332 self.__openLinkInNewTab).setData(guessedUrl) 1332 self.__openLinkInNewTab).setData(guessedUrl)
1333 menu.addSeparator() 1333 menu.addSeparator()
1334 1334
1335 element = hit.element() 1335 element = hit.element()
1336 if not element.isNull() and \ 1336 if not element.isNull() and \
1337 element.tagName().lower() == "input" and \ 1337 element.tagName().lower() == "input" and \
1338 element.attribute("type", "text") == "text": 1338 element.attribute("type", "text") == "text":
1339 menu.addAction(self.trUtf8("Add to web search toolbar"), 1339 menu.addAction(self.tr("Add to web search toolbar"),
1340 self.__addSearchEngine).setData(element) 1340 self.__addSearchEngine).setData(element)
1341 menu.addSeparator() 1341 menu.addSeparator()
1342 1342
1343 menu.addAction( 1343 menu.addAction(
1344 UI.PixmapCache.getIcon("webInspector.png"), 1344 UI.PixmapCache.getIcon("webInspector.png"),
1345 self.trUtf8("Web Inspector..."), self.__webInspector) 1345 self.tr("Web Inspector..."), self.__webInspector)
1346 1346
1347 menu.exec_(evt.globalPos()) 1347 menu.exec_(evt.globalPos())
1348 1348
1349 def __isUrlValid(self, url): 1349 def __isUrlValid(self, url):
1350 """ 1350 """
1515 1515
1516 method = formElement.attribute("method", "get").lower() 1516 method = formElement.attribute("method", "get").lower()
1517 if method != "get": 1517 if method != "get":
1518 E5MessageBox.warning( 1518 E5MessageBox.warning(
1519 self, 1519 self,
1520 self.trUtf8("Method not supported"), 1520 self.tr("Method not supported"),
1521 self.trUtf8( 1521 self.tr(
1522 """{0} method is not supported.""").format(method.upper())) 1522 """{0} method is not supported.""").format(method.upper()))
1523 return 1523 return
1524 1524
1525 searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved( 1525 searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved(
1526 QUrl(formElement.attribute("action")))) 1526 QUrl(formElement.attribute("action"))))
1560 1560
1561 ok = True 1561 ok = True
1562 if len(searchEngines) > 1: 1562 if len(searchEngines) > 1:
1563 searchEngine, ok = QInputDialog.getItem( 1563 searchEngine, ok = QInputDialog.getItem(
1564 self, 1564 self,
1565 self.trUtf8("Search engine"), 1565 self.tr("Search engine"),
1566 self.trUtf8("Choose the desired search engine"), 1566 self.tr("Choose the desired search engine"),
1567 sorted(searchEngines.keys()), 0, False) 1567 sorted(searchEngines.keys()), 0, False)
1568 1568
1569 if not ok: 1569 if not ok:
1570 return 1570 return
1571 1571
1578 if labels.count() > 0: 1578 if labels.count() > 0:
1579 engineName = labels.at(0).toPlainText() 1579 engineName = labels.at(0).toPlainText()
1580 1580
1581 engineName, ok = QInputDialog.getText( 1581 engineName, ok = QInputDialog.getText(
1582 self, 1582 self,
1583 self.trUtf8("Engine name"), 1583 self.tr("Engine name"),
1584 self.trUtf8("Enter a name for the engine"), 1584 self.tr("Enter a name for the engine"),
1585 QLineEdit.Normal, 1585 QLineEdit.Normal,
1586 engineName) 1586 engineName)
1587 if not ok: 1587 if not ok:
1588 return 1588 return
1589 1589
1938 if contentSniff(data): 1938 if contentSniff(data):
1939 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl) 1939 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl)
1940 return 1940 return
1941 1941
1942 urlString = bytes(replyUrl.toEncoded()).decode() 1942 urlString = bytes(replyUrl.toEncoded()).decode()
1943 title = self.trUtf8("Error loading page: {0}").format(urlString) 1943 title = self.tr("Error loading page: {0}").format(urlString)
1944 htmlFile = QFile(":/html/notFoundPage.html") 1944 htmlFile = QFile(":/html/notFoundPage.html")
1945 htmlFile.open(QFile.ReadOnly) 1945 htmlFile.open(QFile.ReadOnly)
1946 html = htmlFile.readAll() 1946 html = htmlFile.readAll()
1947 pixmap = qApp.style()\ 1947 pixmap = qApp.style()\
1948 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48) 1948 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
1957 if pixmap.save(imageBuffer, "PNG"): 1957 if pixmap.save(imageBuffer, "PNG"):
1958 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) 1958 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64())
1959 html = html.replace("@TITLE@", title.encode("utf8")) 1959 html = html.replace("@TITLE@", title.encode("utf8"))
1960 html = html.replace("@H1@", reply.errorString().encode("utf8")) 1960 html = html.replace("@H1@", reply.errorString().encode("utf8"))
1961 html = html.replace( 1961 html = html.replace(
1962 "@H2@", self.trUtf8("When connecting to: {0}.") 1962 "@H2@", self.tr("When connecting to: {0}.")
1963 .format(urlString).encode("utf8")) 1963 .format(urlString).encode("utf8"))
1964 html = html.replace( 1964 html = html.replace(
1965 "@LI-1@", 1965 "@LI-1@",
1966 self.trUtf8("Check the address for errors such as " 1966 self.tr("Check the address for errors such as "
1967 "<b>ww</b>.example.org instead of " 1967 "<b>ww</b>.example.org instead of "
1968 "<b>www</b>.example.org").encode("utf8")) 1968 "<b>www</b>.example.org").encode("utf8"))
1969 html = html.replace( 1969 html = html.replace(
1970 "@LI-2@", 1970 "@LI-2@",
1971 self.trUtf8("If the address is correct, try checking the network " 1971 self.tr("If the address is correct, try checking the network "
1972 "connection.").encode("utf8")) 1972 "connection.").encode("utf8"))
1973 html = html.replace( 1973 html = html.replace(
1974 "@LI-3@", 1974 "@LI-3@",
1975 self.trUtf8( 1975 self.tr(
1976 "If your computer or network is protected by a firewall " 1976 "If your computer or network is protected by a firewall "
1977 "or proxy, make sure that the browser is permitted to " 1977 "or proxy, make sure that the browser is permitted to "
1978 "access the network.").encode("utf8")) 1978 "access the network.").encode("utf8"))
1979 html = html.replace( 1979 html = html.replace(
1980 "@LI-4@", 1980 "@LI-4@",
1981 self.trUtf8("If your cache policy is set to offline browsing," 1981 self.tr("If your cache policy is set to offline browsing,"
1982 "only pages in the local cache are available.") 1982 "only pages in the local cache are available.")
1983 .encode("utf8")) 1983 .encode("utf8"))
1984 html = html.replace( 1984 html = html.replace(
1985 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) 1985 "@BUTTON@", self.tr("Try Again").encode("utf8"))
1986 notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl) 1986 notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl)
1987 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title()) 1987 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title())
1988 self.loadFinished.emit(False) 1988 self.loadFinished.emit(False)
1989 1989
1990 def __downloadRequested(self, request): 1990 def __downloadRequested(self, request):
2009 # accessed for the first time 2009 # accessed for the first time
2010 return 2010 return
2011 2011
2012 res = E5MessageBox.yesNo( 2012 res = E5MessageBox.yesNo(
2013 self, 2013 self,
2014 self.trUtf8("Web Database Quota"), 2014 self.tr("Web Database Quota"),
2015 self.trUtf8( 2015 self.tr(
2016 """<p>The database quota of <strong>{0}</strong> has""" 2016 """<p>The database quota of <strong>{0}</strong> has"""
2017 """ been exceeded while accessing database <strong>{1}""" 2017 """ been exceeded while accessing database <strong>{1}"""
2018 """</strong>.</p><p>Shall it be changed?</p>""") 2018 """</strong>.</p><p>Shall it be changed?</p>""")
2019 .format(self.__dataString(securityOrigin.databaseQuota()), 2019 .format(self.__dataString(securityOrigin.databaseQuota()),
2020 databaseName), 2020 databaseName),
2021 yesDefault=True) 2021 yesDefault=True)
2022 if res: 2022 if res:
2023 newQuota, ok = QInputDialog.getInt( 2023 newQuota, ok = QInputDialog.getInt(
2024 self, 2024 self,
2025 self.trUtf8("New Web Database Quota"), 2025 self.tr("New Web Database Quota"),
2026 self.trUtf8( 2026 self.tr(
2027 "Enter the new quota in MB (current = {0}, used = {1}; " 2027 "Enter the new quota in MB (current = {0}, used = {1}; "
2028 "step size = 5 MB):" 2028 "step size = 5 MB):"
2029 .format( 2029 .format(
2030 self.__dataString(securityOrigin.databaseQuota()), 2030 self.__dataString(securityOrigin.databaseQuota()),
2031 self.__dataString(securityOrigin.databaseUsage()))), 2031 self.__dataString(securityOrigin.databaseUsage()))),
2041 @param size size to be formatted (integer) 2041 @param size size to be formatted (integer)
2042 @return formatted data string (string) 2042 @return formatted data string (string)
2043 """ 2043 """
2044 unit = "" 2044 unit = ""
2045 if size < 1024: 2045 if size < 1024:
2046 unit = self.trUtf8("bytes") 2046 unit = self.tr("bytes")
2047 elif size < 1024 * 1024: 2047 elif size < 1024 * 1024:
2048 size /= 1024 2048 size /= 1024
2049 unit = self.trUtf8("kB") 2049 unit = self.tr("kB")
2050 else: 2050 else:
2051 size /= 1024 * 1024 2051 size /= 1024 * 1024
2052 unit = self.trUtf8("MB") 2052 unit = self.tr("MB")
2053 return "{0:.1f} {1}".format(size, unit) 2053 return "{0:.1f} {1}".format(size, unit)
2054 2054
2055 ########################################################################### 2055 ###########################################################################
2056 ## Access key related methods below 2056 ## Access key related methods below
2057 ########################################################################### 2057 ###########################################################################
2324 try: 2324 try:
2325 self.__clickedFrame.print_(printer) 2325 self.__clickedFrame.print_(printer)
2326 except AttributeError: 2326 except AttributeError:
2327 E5MessageBox.critical( 2327 E5MessageBox.critical(
2328 self, 2328 self,
2329 self.trUtf8("eric5 Web Browser"), 2329 self.tr("eric5 Web Browser"),
2330 self.trUtf8( 2330 self.tr(
2331 """<p>Printing is not available due to a bug in""" 2331 """<p>Printing is not available due to a bug in"""
2332 """ PyQt4. Please upgrade.</p>""")) 2332 """ PyQt4. Please upgrade.</p>"""))
2333 2333
2334 def __printPreviewClickedFrame(self): 2334 def __printPreviewClickedFrame(self):
2335 """ 2335 """
2370 try: 2370 try:
2371 self.__clickedFrame.print_(printer) 2371 self.__clickedFrame.print_(printer)
2372 except AttributeError: 2372 except AttributeError:
2373 E5MessageBox.critical( 2373 E5MessageBox.critical(
2374 self, 2374 self,
2375 self.trUtf8("eric5 Web Browser"), 2375 self.tr("eric5 Web Browser"),
2376 self.trUtf8( 2376 self.tr(
2377 """<p>Printing is not available due to a bug in PyQt4.""" 2377 """<p>Printing is not available due to a bug in PyQt4."""
2378 """Please upgrade.</p>""")) 2378 """Please upgrade.</p>"""))
2379 return 2379 return
2380 2380
2381 def __printPdfClickedFrame(self): 2381 def __printPdfClickedFrame(self):
2402 try: 2402 try:
2403 self.__clickedFrame.print_(printer) 2403 self.__clickedFrame.print_(printer)
2404 except AttributeError: 2404 except AttributeError:
2405 E5MessageBox.critical( 2405 E5MessageBox.critical(
2406 self, 2406 self,
2407 self.trUtf8("eric5 Web Browser"), 2407 self.tr("eric5 Web Browser"),
2408 self.trUtf8( 2408 self.tr(
2409 """<p>Printing is not available due to a bug in""" 2409 """<p>Printing is not available due to a bug in"""
2410 """ PyQt4. Please upgrade.</p>""")) 2410 """ PyQt4. Please upgrade.</p>"""))
2411 return 2411 return
2412 2412
2413 def __zoomInClickedFrame(self): 2413 def __zoomInClickedFrame(self):

eric ide

mercurial