Helpviewer/HelpBrowserWV.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3484
645c12de6b0c
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
116 if qApp.isLeftToRight(): 116 if qApp.isLeftToRight():
117 return "LTR" 117 return "LTR"
118 else: 118 else:
119 return "RTL" 119 return "RTL"
120 120
121 return self.trUtf8(trans) 121 return self.tr(trans)
122 122
123 @pyqtSlot(result=str) 123 @pyqtSlot(result=str)
124 def providerString(self): 124 def providerString(self):
125 """ 125 """
126 Public method to get a string for the search provider. 126 Public method to get a string for the search provider.
127 127
128 @return string for the search provider (string) 128 @return string for the search provider (string)
129 """ 129 """
130 return self.trUtf8("Search results provided by {0}")\ 130 return self.tr("Search results provided by {0}")\
131 .format(self.__mw.openSearchManager().currentEngineName()) 131 .format(self.__mw.openSearchManager().currentEngineName())
132 132
133 @pyqtSlot(str, result=str) 133 @pyqtSlot(str, result=str)
134 def searchUrl(self, searchStr): 134 def searchUrl(self, searchStr):
135 """ 135 """
199 return False 199 return False
200 200
201 if type_ == QWebPage.NavigationTypeFormResubmitted: 201 if type_ == QWebPage.NavigationTypeFormResubmitted:
202 res = E5MessageBox.yesNo( 202 res = E5MessageBox.yesNo(
203 self.view(), 203 self.view(),
204 self.trUtf8("Resending POST request"), 204 self.tr("Resending POST request"),
205 self.trUtf8( 205 self.tr(
206 """In order to display the site, the request along with""" 206 """In order to display the site, the request along with"""
207 """ all the data must be sent once again, which may lead""" 207 """ all the data must be sent once again, which may lead"""
208 """ to some unexpected behaviour of the site e.g. the""" 208 """ to some unexpected behaviour of the site e.g. the"""
209 """ same action might be performed once again. Do you""" 209 """ same action might be performed once again. Do you"""
210 """ want to continue anyway?"""), 210 """ want to continue anyway?"""),
279 if info.suggestedFileNames: 279 if info.suggestedFileNames:
280 suggestedFileName = info.suggestedFileNames[0] 280 suggestedFileName = info.suggestedFileNames[0]
281 281
282 files.fileNames = E5FileDialog.getOpenFileNames( 282 files.fileNames = E5FileDialog.getOpenFileNames(
283 None, 283 None,
284 self.trUtf8("Select files to upload..."), 284 self.tr("Select files to upload..."),
285 suggestedFileName) 285 suggestedFileName)
286 return True 286 return True
287 287
288 if extension == QWebPage.ErrorPageExtension: 288 if extension == QWebPage.ErrorPageExtension:
289 info = sip.cast(option, QWebPage.ErrorPageExtensionOption) 289 info = sip.cast(option, QWebPage.ErrorPageExtensionOption)
308 element.setAttribute("style", "display:none;") 308 element.setAttribute("style", "display:none;")
309 return False 309 return False
310 else: 310 else:
311 # the whole page is blocked 311 # the whole page is blocked
312 rule = info.errorString.replace("AdBlockRule:", "") 312 rule = info.errorString.replace("AdBlockRule:", "")
313 title = self.trUtf8("Content blocked by AdBlock Plus") 313 title = self.tr("Content blocked by AdBlock Plus")
314 message = self.trUtf8( 314 message = self.tr(
315 "Blocked by rule: <i>{0}</i>").format(rule) 315 "Blocked by rule: <i>{0}</i>").format(rule)
316 316
317 htmlFile = QFile(":/html/adblockPage.html") 317 htmlFile = QFile(":/html/adblockPage.html")
318 htmlFile.open(QFile.ReadOnly) 318 htmlFile.open(QFile.ReadOnly)
319 html = htmlFile.readAll() 319 html = htmlFile.readAll()
329 if info.domain == QWebPage.QtNetwork and \ 329 if info.domain == QWebPage.QtNetwork and \
330 info.error == QNetworkReply.OperationCanceledError and \ 330 info.error == QNetworkReply.OperationCanceledError and \
331 info.errorString == "eric5:No Error": 331 info.errorString == "eric5:No Error":
332 return False 332 return False
333 333
334 title = self.trUtf8("Error loading page: {0}").format(urlString) 334 title = self.tr("Error loading page: {0}").format(urlString)
335 htmlFile = QFile(":/html/notFoundPage.html") 335 htmlFile = QFile(":/html/notFoundPage.html")
336 htmlFile.open(QFile.ReadOnly) 336 htmlFile.open(QFile.ReadOnly)
337 html = htmlFile.readAll() 337 html = htmlFile.readAll()
338 pixmap = qApp.style()\ 338 pixmap = qApp.style()\
339 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48) 339 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
349 html = html.replace( 349 html = html.replace(
350 "@FAVICON@", imageBuffer.buffer().toBase64()) 350 "@FAVICON@", imageBuffer.buffer().toBase64())
351 html = html.replace("@TITLE@", title.encode("utf8")) 351 html = html.replace("@TITLE@", title.encode("utf8"))
352 html = html.replace("@H1@", info.errorString.encode("utf8")) 352 html = html.replace("@H1@", info.errorString.encode("utf8"))
353 html = html.replace( 353 html = html.replace(
354 "@H2@", self.trUtf8("When connecting to: {0}.") 354 "@H2@", self.tr("When connecting to: {0}.")
355 .format(urlString).encode("utf8")) 355 .format(urlString).encode("utf8"))
356 html = html.replace( 356 html = html.replace(
357 "@LI-1@", 357 "@LI-1@",
358 self.trUtf8("Check the address for errors such as " 358 self.tr("Check the address for errors such as "
359 "<b>ww</b>.example.org instead of " 359 "<b>ww</b>.example.org instead of "
360 "<b>www</b>.example.org").encode("utf8")) 360 "<b>www</b>.example.org").encode("utf8"))
361 html = html.replace( 361 html = html.replace(
362 "@LI-2@", 362 "@LI-2@",
363 self.trUtf8( 363 self.tr(
364 "If the address is correct, try checking the network " 364 "If the address is correct, try checking the network "
365 "connection.").encode("utf8")) 365 "connection.").encode("utf8"))
366 html = html.replace( 366 html = html.replace(
367 "@LI-3@", 367 "@LI-3@",
368 self.trUtf8( 368 self.tr(
369 "If your computer or network is protected by a firewall " 369 "If your computer or network is protected by a firewall "
370 "or proxy, make sure that the browser is permitted to " 370 "or proxy, make sure that the browser is permitted to "
371 "access the network.").encode("utf8")) 371 "access the network.").encode("utf8"))
372 html = html.replace( 372 html = html.replace(
373 "@LI-4@", 373 "@LI-4@",
374 self.trUtf8("If your cache policy is set to offline browsing," 374 self.tr("If your cache policy is set to offline browsing,"
375 "only pages in the local cache are available.") 375 "only pages in the local cache are available.")
376 .encode("utf8")) 376 .encode("utf8"))
377 html = html.replace( 377 html = html.replace(
378 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) 378 "@BUTTON@", self.tr("Try Again").encode("utf8"))
379 errorPage.content = html 379 errorPage.content = html
380 return True 380 return True
381 381
382 return QWebPage.extension(self, extension, option, output) 382 return QWebPage.extension(self, extension, option, output)
383 383
539 self.mainFrame().url(), self.__sslConfiguration, self.view()) 539 self.mainFrame().url(), self.__sslConfiguration, self.view())
540 widget.showAt(pos) 540 widget.showAt(pos)
541 else: 541 else:
542 E5MessageBox.warning( 542 E5MessageBox.warning(
543 self.view(), 543 self.view(),
544 self.trUtf8("SSL Info"), 544 self.tr("SSL Info"),
545 self.trUtf8("""This site does not contain SSL information.""")) 545 self.tr("""This site does not contain SSL information."""))
546 546
547 def hasValidSslInfo(self): 547 def hasValidSslInfo(self):
548 """ 548 """
549 Public method to check, if the page has a valid SSL certificate. 549 Public method to check, if the page has a valid SSL certificate.
550 550
645 @param parent parent widget of this window (QWidget) 645 @param parent parent widget of this window (QWidget)
646 @param name name of this window (string) 646 @param name name of this window (string)
647 """ 647 """
648 super().__init__(parent) 648 super().__init__(parent)
649 self.setObjectName(name) 649 self.setObjectName(name)
650 self.setWhatsThis(self.trUtf8( 650 self.setWhatsThis(self.tr(
651 """<b>Help Window</b>""" 651 """<b>Help Window</b>"""
652 """<p>This window displays the selected help information.</p>""" 652 """<p>This window displays the selected help information.</p>"""
653 )) 653 ))
654 654
655 import Helpviewer.HelpWindow 655 import Helpviewer.HelpWindow
819 name = QUrl.fromLocalFile(name.toString()) 819 name = QUrl.fromLocalFile(name.toString())
820 820
821 if not QFileInfo(name.toLocalFile()).exists(): 821 if not QFileInfo(name.toLocalFile()).exists():
822 E5MessageBox.critical( 822 E5MessageBox.critical(
823 self, 823 self,
824 self.trUtf8("eric5 Web Browser"), 824 self.tr("eric5 Web Browser"),
825 self.trUtf8( 825 self.tr(
826 """<p>The file <b>{0}</b> does not exist.</p>""") 826 """<p>The file <b>{0}</b> does not exist.</p>""")
827 .format(name.toLocalFile())) 827 .format(name.toLocalFile()))
828 return 828 return
829 829
830 if name.toLocalFile().endswith(".pdf") or \ 830 if name.toLocalFile().endswith(".pdf") or \
833 name.toLocalFile().endswith(".CHM"): 833 name.toLocalFile().endswith(".CHM"):
834 started = QDesktopServices.openUrl(name) 834 started = QDesktopServices.openUrl(name)
835 if not started: 835 if not started:
836 E5MessageBox.critical( 836 E5MessageBox.critical(
837 self, 837 self,
838 self.trUtf8("eric5 Web Browser"), 838 self.tr("eric5 Web Browser"),
839 self.trUtf8( 839 self.tr(
840 """<p>Could not start a viewer""" 840 """<p>Could not start a viewer"""
841 """ for file <b>{0}</b>.</p>""") 841 """ for file <b>{0}</b>.</p>""")
842 .format(name.path())) 842 .format(name.path()))
843 return 843 return
844 elif name.scheme() in ["mailto"]: 844 elif name.scheme() in ["mailto"]:
845 started = QDesktopServices.openUrl(name) 845 started = QDesktopServices.openUrl(name)
846 if not started: 846 if not started:
847 E5MessageBox.critical( 847 E5MessageBox.critical(
848 self, 848 self,
849 self.trUtf8("eric5 Web Browser"), 849 self.tr("eric5 Web Browser"),
850 self.trUtf8( 850 self.tr(
851 """<p>Could not start an application""" 851 """<p>Could not start an application"""
852 """ for URL <b>{0}</b>.</p>""") 852 """ for URL <b>{0}</b>.</p>""")
853 .format(name.toString())) 853 .format(name.toString()))
854 return 854 return
855 elif name.scheme() == "javascript": 855 elif name.scheme() == "javascript":
864 name.toString().endswith(".CHM"): 864 name.toString().endswith(".CHM"):
865 started = QDesktopServices.openUrl(name) 865 started = QDesktopServices.openUrl(name)
866 if not started: 866 if not started:
867 E5MessageBox.critical( 867 E5MessageBox.critical(
868 self, 868 self,
869 self.trUtf8("eric5 Web Browser"), 869 self.tr("eric5 Web Browser"),
870 self.trUtf8( 870 self.tr(
871 """<p>Could not start a viewer""" 871 """<p>Could not start a viewer"""
872 """ for file <b>{0}</b>.</p>""") 872 """ for file <b>{0}</b>.</p>""")
873 .format(name.path())) 873 .format(name.path()))
874 return 874 return
875 875
1074 frameAtPos = self.page().frameAt(evt.pos()) 1074 frameAtPos = self.page().frameAt(evt.pos())
1075 hit = self.page().mainFrame().hitTestContent(evt.pos()) 1075 hit = self.page().mainFrame().hitTestContent(evt.pos())
1076 if not hit.linkUrl().isEmpty(): 1076 if not hit.linkUrl().isEmpty():
1077 menu.addAction( 1077 menu.addAction(
1078 UI.PixmapCache.getIcon("openNewTab.png"), 1078 UI.PixmapCache.getIcon("openNewTab.png"),
1079 self.trUtf8("Open Link in New Tab\tCtrl+LMB"), 1079 self.tr("Open Link in New Tab\tCtrl+LMB"),
1080 self.__openLinkInNewTab).setData(hit.linkUrl()) 1080 self.__openLinkInNewTab).setData(hit.linkUrl())
1081 menu.addSeparator() 1081 menu.addSeparator()
1082 menu.addAction( 1082 menu.addAction(
1083 UI.PixmapCache.getIcon("download.png"), 1083 UI.PixmapCache.getIcon("download.png"),
1084 self.trUtf8("Save Lin&k"), self.__downloadLink) 1084 self.tr("Save Lin&k"), self.__downloadLink)
1085 menu.addAction( 1085 menu.addAction(
1086 UI.PixmapCache.getIcon("bookmark22.png"), 1086 UI.PixmapCache.getIcon("bookmark22.png"),
1087 self.trUtf8("Bookmark this Link"), self.__bookmarkLink)\ 1087 self.tr("Bookmark this Link"), self.__bookmarkLink)\
1088 .setData(hit.linkUrl()) 1088 .setData(hit.linkUrl())
1089 menu.addSeparator() 1089 menu.addSeparator()
1090 menu.addAction( 1090 menu.addAction(
1091 UI.PixmapCache.getIcon("editCopy.png"), 1091 UI.PixmapCache.getIcon("editCopy.png"),
1092 self.trUtf8("Copy Link to Clipboard"), self.__copyLink) 1092 self.tr("Copy Link to Clipboard"), self.__copyLink)
1093 menu.addAction( 1093 menu.addAction(
1094 UI.PixmapCache.getIcon("mailSend.png"), 1094 UI.PixmapCache.getIcon("mailSend.png"),
1095 self.trUtf8("Send Link"), 1095 self.tr("Send Link"),
1096 self.__sendLink).setData(hit.linkUrl()) 1096 self.__sendLink).setData(hit.linkUrl())
1097 if Preferences.getHelp("VirusTotalEnabled") and \ 1097 if Preferences.getHelp("VirusTotalEnabled") and \
1098 Preferences.getHelp("VirusTotalServiceKey") != "": 1098 Preferences.getHelp("VirusTotalServiceKey") != "":
1099 menu.addAction( 1099 menu.addAction(
1100 UI.PixmapCache.getIcon("virustotal.png"), 1100 UI.PixmapCache.getIcon("virustotal.png"),
1101 self.trUtf8("Scan Link with VirusTotal"), 1101 self.tr("Scan Link with VirusTotal"),
1102 self.__virusTotal).setData(hit.linkUrl()) 1102 self.__virusTotal).setData(hit.linkUrl())
1103 1103
1104 if not hit.imageUrl().isEmpty(): 1104 if not hit.imageUrl().isEmpty():
1105 if not menu.isEmpty(): 1105 if not menu.isEmpty():
1106 menu.addSeparator() 1106 menu.addSeparator()
1107 menu.addAction( 1107 menu.addAction(
1108 UI.PixmapCache.getIcon("openNewTab.png"), 1108 UI.PixmapCache.getIcon("openNewTab.png"),
1109 self.trUtf8("Open Image in New Tab"), 1109 self.tr("Open Image in New Tab"),
1110 self.__openLinkInNewTab).setData(hit.imageUrl()) 1110 self.__openLinkInNewTab).setData(hit.imageUrl())
1111 menu.addSeparator() 1111 menu.addSeparator()
1112 menu.addAction( 1112 menu.addAction(
1113 UI.PixmapCache.getIcon("download.png"), 1113 UI.PixmapCache.getIcon("download.png"),
1114 self.trUtf8("Save Image"), self.__downloadImage) 1114 self.tr("Save Image"), self.__downloadImage)
1115 menu.addAction( 1115 menu.addAction(
1116 self.trUtf8("Copy Image to Clipboard"), self.__copyImage) 1116 self.tr("Copy Image to Clipboard"), self.__copyImage)
1117 menu.addAction( 1117 menu.addAction(
1118 UI.PixmapCache.getIcon("editCopy.png"), 1118 UI.PixmapCache.getIcon("editCopy.png"),
1119 self.trUtf8("Copy Image Location to Clipboard"), 1119 self.tr("Copy Image Location to Clipboard"),
1120 self.__copyLocation).setData(hit.imageUrl().toString()) 1120 self.__copyLocation).setData(hit.imageUrl().toString())
1121 menu.addAction( 1121 menu.addAction(
1122 UI.PixmapCache.getIcon("mailSend.png"), 1122 UI.PixmapCache.getIcon("mailSend.png"),
1123 self.trUtf8("Send Image Link"), 1123 self.tr("Send Image Link"),
1124 self.__sendLink).setData(hit.imageUrl()) 1124 self.__sendLink).setData(hit.imageUrl())
1125 menu.addSeparator() 1125 menu.addSeparator()
1126 menu.addAction( 1126 menu.addAction(
1127 UI.PixmapCache.getIcon("adBlockPlus.png"), 1127 UI.PixmapCache.getIcon("adBlockPlus.png"),
1128 self.trUtf8("Block Image"), self.__blockImage)\ 1128 self.tr("Block Image"), self.__blockImage)\
1129 .setData(hit.imageUrl().toString()) 1129 .setData(hit.imageUrl().toString())
1130 if Preferences.getHelp("VirusTotalEnabled") and \ 1130 if Preferences.getHelp("VirusTotalEnabled") and \
1131 Preferences.getHelp("VirusTotalServiceKey") != "": 1131 Preferences.getHelp("VirusTotalServiceKey") != "":
1132 menu.addAction( 1132 menu.addAction(
1133 UI.PixmapCache.getIcon("virustotal.png"), 1133 UI.PixmapCache.getIcon("virustotal.png"),
1134 self.trUtf8("Scan Image with VirusTotal"), 1134 self.tr("Scan Image with VirusTotal"),
1135 self.__virusTotal).setData(hit.imageUrl()) 1135 self.__virusTotal).setData(hit.imageUrl())
1136 1136
1137 element = hit.element() 1137 element = hit.element()
1138 if not element.isNull(): 1138 if not element.isNull():
1139 if self.__isMediaElement(element): 1139 if self.__isMediaElement(element):
1147 videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc")) 1147 videoUrl = QUrl(element.evaluateJavaScript("this.currentSrc"))
1148 1148
1149 if paused: 1149 if paused:
1150 menu.addAction( 1150 menu.addAction(
1151 UI.PixmapCache.getIcon("mediaPlaybackStart.png"), 1151 UI.PixmapCache.getIcon("mediaPlaybackStart.png"),
1152 self.trUtf8("Play"), self.__pauseMedia) 1152 self.tr("Play"), self.__pauseMedia)
1153 else: 1153 else:
1154 menu.addAction( 1154 menu.addAction(
1155 UI.PixmapCache.getIcon("mediaPlaybackPause.png"), 1155 UI.PixmapCache.getIcon("mediaPlaybackPause.png"),
1156 self.trUtf8("Pause"), self.__pauseMedia) 1156 self.tr("Pause"), self.__pauseMedia)
1157 if muted: 1157 if muted:
1158 menu.addAction( 1158 menu.addAction(
1159 UI.PixmapCache.getIcon("audioVolumeHigh.png"), 1159 UI.PixmapCache.getIcon("audioVolumeHigh.png"),
1160 self.trUtf8("Unmute"), self.__muteMedia) 1160 self.tr("Unmute"), self.__muteMedia)
1161 else: 1161 else:
1162 menu.addAction( 1162 menu.addAction(
1163 UI.PixmapCache.getIcon("audioVolumeMuted.png"), 1163 UI.PixmapCache.getIcon("audioVolumeMuted.png"),
1164 self.trUtf8("Mute"), self.__muteMedia) 1164 self.tr("Mute"), self.__muteMedia)
1165 menu.addSeparator() 1165 menu.addSeparator()
1166 menu.addAction( 1166 menu.addAction(
1167 UI.PixmapCache.getIcon("editCopy.png"), 1167 UI.PixmapCache.getIcon("editCopy.png"),
1168 self.trUtf8("Copy Media Address to Clipboard"), 1168 self.tr("Copy Media Address to Clipboard"),
1169 self.__copyLocation).setData(videoUrl.toString()) 1169 self.__copyLocation).setData(videoUrl.toString())
1170 menu.addAction( 1170 menu.addAction(
1171 UI.PixmapCache.getIcon("mailSend.png"), 1171 UI.PixmapCache.getIcon("mailSend.png"),
1172 self.trUtf8("Send Media Address"), self.__sendLink)\ 1172 self.tr("Send Media Address"), self.__sendLink)\
1173 .setData(videoUrl) 1173 .setData(videoUrl)
1174 menu.addAction( 1174 menu.addAction(
1175 UI.PixmapCache.getIcon("download.png"), 1175 UI.PixmapCache.getIcon("download.png"),
1176 self.trUtf8("Save Media"), self.__downloadMedia)\ 1176 self.tr("Save Media"), self.__downloadMedia)\
1177 .setData(videoUrl) 1177 .setData(videoUrl)
1178 1178
1179 if element.tagName().lower() in ["input", "textarea"]: 1179 if element.tagName().lower() in ["input", "textarea"]:
1180 if menu.isEmpty(): 1180 if menu.isEmpty():
1181 pageMenu = self.page().createStandardContextMenu() 1181 pageMenu = self.page().createStandardContextMenu()
1212 menu.addAction(self.mw.saveAsAct) 1212 menu.addAction(self.mw.saveAsAct)
1213 menu.addSeparator() 1213 menu.addSeparator()
1214 1214
1215 if frameAtPos and self.page().mainFrame() != frameAtPos: 1215 if frameAtPos and self.page().mainFrame() != frameAtPos:
1216 self.__clickedFrame = frameAtPos 1216 self.__clickedFrame = frameAtPos
1217 fmenu = QMenu(self.trUtf8("This Frame")) 1217 fmenu = QMenu(self.tr("This Frame"))
1218 frameUrl = self.__clickedFrame.url() 1218 frameUrl = self.__clickedFrame.url()
1219 if frameUrl.isValid(): 1219 if frameUrl.isValid():
1220 fmenu.addAction( 1220 fmenu.addAction(
1221 self.trUtf8("Show &only this frame"), 1221 self.tr("Show &only this frame"),
1222 self.__loadClickedFrame) 1222 self.__loadClickedFrame)
1223 fmenu.addAction( 1223 fmenu.addAction(
1224 UI.PixmapCache.getIcon("openNewTab.png"), 1224 UI.PixmapCache.getIcon("openNewTab.png"),
1225 self.trUtf8("Show in new &tab"), 1225 self.tr("Show in new &tab"),
1226 self.__openLinkInNewTab).setData(self.__clickedFrame.url()) 1226 self.__openLinkInNewTab).setData(self.__clickedFrame.url())
1227 fmenu.addSeparator() 1227 fmenu.addSeparator()
1228 fmenu.addAction( 1228 fmenu.addAction(
1229 UI.PixmapCache.getIcon("print.png"), 1229 UI.PixmapCache.getIcon("print.png"),
1230 self.trUtf8("&Print"), self.__printClickedFrame) 1230 self.tr("&Print"), self.__printClickedFrame)
1231 fmenu.addAction( 1231 fmenu.addAction(
1232 UI.PixmapCache.getIcon("printPreview.png"), 1232 UI.PixmapCache.getIcon("printPreview.png"),
1233 self.trUtf8("Print Preview"), self.__printPreviewClickedFrame) 1233 self.tr("Print Preview"), self.__printPreviewClickedFrame)
1234 fmenu.addAction( 1234 fmenu.addAction(
1235 UI.PixmapCache.getIcon("printPdf.png"), 1235 UI.PixmapCache.getIcon("printPdf.png"),
1236 self.trUtf8("Print as PDF"), self.__printPdfClickedFrame) 1236 self.tr("Print as PDF"), self.__printPdfClickedFrame)
1237 fmenu.addSeparator() 1237 fmenu.addSeparator()
1238 fmenu.addAction( 1238 fmenu.addAction(
1239 UI.PixmapCache.getIcon("zoomIn.png"), 1239 UI.PixmapCache.getIcon("zoomIn.png"),
1240 self.trUtf8("Zoom &in"), self.__zoomInClickedFrame) 1240 self.tr("Zoom &in"), self.__zoomInClickedFrame)
1241 fmenu.addAction( 1241 fmenu.addAction(
1242 UI.PixmapCache.getIcon("zoomReset.png"), 1242 UI.PixmapCache.getIcon("zoomReset.png"),
1243 self.trUtf8("Zoom &reset"), self.__zoomResetClickedFrame) 1243 self.tr("Zoom &reset"), self.__zoomResetClickedFrame)
1244 fmenu.addAction( 1244 fmenu.addAction(
1245 UI.PixmapCache.getIcon("zoomOut.png"), 1245 UI.PixmapCache.getIcon("zoomOut.png"),
1246 self.trUtf8("Zoom &out"), self.__zoomOutClickedFrame) 1246 self.tr("Zoom &out"), self.__zoomOutClickedFrame)
1247 fmenu.addSeparator() 1247 fmenu.addSeparator()
1248 fmenu.addAction( 1248 fmenu.addAction(
1249 self.trUtf8("Show frame so&urce"), 1249 self.tr("Show frame so&urce"),
1250 self.__showClickedFrameSource) 1250 self.__showClickedFrameSource)
1251 1251
1252 menu.addMenu(fmenu) 1252 menu.addMenu(fmenu)
1253 menu.addSeparator() 1253 menu.addSeparator()
1254 1254
1255 menu.addAction( 1255 menu.addAction(
1256 UI.PixmapCache.getIcon("bookmark22.png"), 1256 UI.PixmapCache.getIcon("bookmark22.png"),
1257 self.trUtf8("Bookmark this Page"), self.addBookmark) 1257 self.tr("Bookmark this Page"), self.addBookmark)
1258 menu.addAction( 1258 menu.addAction(
1259 UI.PixmapCache.getIcon("mailSend.png"), 1259 UI.PixmapCache.getIcon("mailSend.png"),
1260 self.trUtf8("Send Page Link"), self.__sendLink).setData(self.url()) 1260 self.tr("Send Page Link"), self.__sendLink).setData(self.url())
1261 menu.addSeparator() 1261 menu.addSeparator()
1262 self.__userAgentMenu = UserAgentMenu(self.trUtf8("User Agent"), 1262 self.__userAgentMenu = UserAgentMenu(self.tr("User Agent"),
1263 url=self.url()) 1263 url=self.url())
1264 menu.addMenu(self.__userAgentMenu) 1264 menu.addMenu(self.__userAgentMenu)
1265 menu.addSeparator() 1265 menu.addSeparator()
1266 menu.addAction(self.mw.backAct) 1266 menu.addAction(self.mw.backAct)
1267 menu.addAction(self.mw.forwardAct) 1267 menu.addAction(self.mw.forwardAct)
1273 menu.addSeparator() 1273 menu.addSeparator()
1274 if self.selectedText(): 1274 if self.selectedText():
1275 menu.addAction(self.mw.copyAct) 1275 menu.addAction(self.mw.copyAct)
1276 menu.addAction( 1276 menu.addAction(
1277 UI.PixmapCache.getIcon("mailSend.png"), 1277 UI.PixmapCache.getIcon("mailSend.png"),
1278 self.trUtf8("Send Text"), 1278 self.tr("Send Text"),
1279 self.__sendLink).setData(self.selectedText()) 1279 self.__sendLink).setData(self.selectedText())
1280 menu.addAction(self.mw.findAct) 1280 menu.addAction(self.mw.findAct)
1281 menu.addSeparator() 1281 menu.addSeparator()
1282 if self.selectedText(): 1282 if self.selectedText():
1283 self.__searchMenu = menu.addMenu(self.trUtf8("Search with...")) 1283 self.__searchMenu = menu.addMenu(self.tr("Search with..."))
1284 1284
1285 from .OpenSearch.OpenSearchEngineAction import \ 1285 from .OpenSearch.OpenSearchEngineAction import \
1286 OpenSearchEngineAction 1286 OpenSearchEngineAction
1287 engineNames = self.mw.openSearchManager().allEnginesNames() 1287 engineNames = self.mw.openSearchManager().allEnginesNames()
1288 for engineName in engineNames: 1288 for engineName in engineNames:
1305 googleTranslatorUrl = QUrl( 1305 googleTranslatorUrl = QUrl(
1306 "http://translate.google.com/#auto|{0}|{1}".format( 1306 "http://translate.google.com/#auto|{0}|{1}".format(
1307 langCode, self.selectedText())) 1307 langCode, self.selectedText()))
1308 menu.addAction( 1308 menu.addAction(
1309 UI.PixmapCache.getIcon("translate.png"), 1309 UI.PixmapCache.getIcon("translate.png"),
1310 self.trUtf8("Google Translate"), self.__openLinkInNewTab)\ 1310 self.tr("Google Translate"), self.__openLinkInNewTab)\
1311 .setData(googleTranslatorUrl) 1311 .setData(googleTranslatorUrl)
1312 wiktionaryUrl = QUrl( 1312 wiktionaryUrl = QUrl(
1313 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" 1313 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
1314 .format(langCode, self.selectedText())) 1314 .format(langCode, self.selectedText()))
1315 menu.addAction( 1315 menu.addAction(
1316 UI.PixmapCache.getIcon("wikipedia.png"), 1316 UI.PixmapCache.getIcon("wikipedia.png"),
1317 self.trUtf8("Dictionary"), self.__openLinkInNewTab)\ 1317 self.tr("Dictionary"), self.__openLinkInNewTab)\
1318 .setData(wiktionaryUrl) 1318 .setData(wiktionaryUrl)
1319 menu.addSeparator() 1319 menu.addSeparator()
1320 1320
1321 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) 1321 guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
1322 if self.__isUrlValid(guessedUrl): 1322 if self.__isUrlValid(guessedUrl):
1323 menu.addAction( 1323 menu.addAction(
1324 self.trUtf8("Go to web address"), 1324 self.tr("Go to web address"),
1325 self.__openLinkInNewTab).setData(guessedUrl) 1325 self.__openLinkInNewTab).setData(guessedUrl)
1326 menu.addSeparator() 1326 menu.addSeparator()
1327 1327
1328 element = hit.element() 1328 element = hit.element()
1329 if not element.isNull() and \ 1329 if not element.isNull() and \
1330 element.tagName().lower() == "input" and \ 1330 element.tagName().lower() == "input" and \
1331 element.attribute("type", "text") == "text": 1331 element.attribute("type", "text") == "text":
1332 menu.addAction(self.trUtf8("Add to web search toolbar"), 1332 menu.addAction(self.tr("Add to web search toolbar"),
1333 self.__addSearchEngine).setData(element) 1333 self.__addSearchEngine).setData(element)
1334 menu.addSeparator() 1334 menu.addSeparator()
1335 1335
1336 menu.addAction( 1336 menu.addAction(
1337 UI.PixmapCache.getIcon("webInspector.png"), 1337 UI.PixmapCache.getIcon("webInspector.png"),
1338 self.trUtf8("Web Inspector..."), self.__webInspector) 1338 self.tr("Web Inspector..."), self.__webInspector)
1339 1339
1340 menu.exec_(evt.globalPos()) 1340 menu.exec_(evt.globalPos())
1341 1341
1342 def __isUrlValid(self, url): 1342 def __isUrlValid(self, url):
1343 """ 1343 """
1508 1508
1509 method = formElement.attribute("method", "get").lower() 1509 method = formElement.attribute("method", "get").lower()
1510 if method != "get": 1510 if method != "get":
1511 E5MessageBox.warning( 1511 E5MessageBox.warning(
1512 self, 1512 self,
1513 self.trUtf8("Method not supported"), 1513 self.tr("Method not supported"),
1514 self.trUtf8( 1514 self.tr(
1515 """{0} method is not supported.""").format(method.upper())) 1515 """{0} method is not supported.""").format(method.upper()))
1516 return 1516 return
1517 1517
1518 searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved( 1518 searchUrl = QUrl(self.page().mainFrame().baseUrl().resolved(
1519 QUrl(formElement.attribute("action")))) 1519 QUrl(formElement.attribute("action"))))
1553 1553
1554 ok = True 1554 ok = True
1555 if len(searchEngines) > 1: 1555 if len(searchEngines) > 1:
1556 searchEngine, ok = QInputDialog.getItem( 1556 searchEngine, ok = QInputDialog.getItem(
1557 self, 1557 self,
1558 self.trUtf8("Search engine"), 1558 self.tr("Search engine"),
1559 self.trUtf8("Choose the desired search engine"), 1559 self.tr("Choose the desired search engine"),
1560 sorted(searchEngines.keys()), 0, False) 1560 sorted(searchEngines.keys()), 0, False)
1561 1561
1562 if not ok: 1562 if not ok:
1563 return 1563 return
1564 1564
1571 if labels.count() > 0: 1571 if labels.count() > 0:
1572 engineName = labels.at(0).toPlainText() 1572 engineName = labels.at(0).toPlainText()
1573 1573
1574 engineName, ok = QInputDialog.getText( 1574 engineName, ok = QInputDialog.getText(
1575 self, 1575 self,
1576 self.trUtf8("Engine name"), 1576 self.tr("Engine name"),
1577 self.trUtf8("Enter a name for the engine"), 1577 self.tr("Enter a name for the engine"),
1578 QLineEdit.Normal, 1578 QLineEdit.Normal,
1579 engineName) 1579 engineName)
1580 if not ok: 1580 if not ok:
1581 return 1581 return
1582 1582
1931 if contentSniff(data): 1931 if contentSniff(data):
1932 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl) 1932 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl)
1933 return 1933 return
1934 1934
1935 urlString = bytes(replyUrl.toEncoded()).decode() 1935 urlString = bytes(replyUrl.toEncoded()).decode()
1936 title = self.trUtf8("Error loading page: {0}").format(urlString) 1936 title = self.tr("Error loading page: {0}").format(urlString)
1937 htmlFile = QFile(":/html/notFoundPage.html") 1937 htmlFile = QFile(":/html/notFoundPage.html")
1938 htmlFile.open(QFile.ReadOnly) 1938 htmlFile.open(QFile.ReadOnly)
1939 html = htmlFile.readAll() 1939 html = htmlFile.readAll()
1940 pixmap = qApp.style()\ 1940 pixmap = qApp.style()\
1941 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48) 1941 .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
1950 if pixmap.save(imageBuffer, "PNG"): 1950 if pixmap.save(imageBuffer, "PNG"):
1951 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) 1951 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64())
1952 html = html.replace("@TITLE@", title.encode("utf8")) 1952 html = html.replace("@TITLE@", title.encode("utf8"))
1953 html = html.replace("@H1@", reply.errorString().encode("utf8")) 1953 html = html.replace("@H1@", reply.errorString().encode("utf8"))
1954 html = html.replace( 1954 html = html.replace(
1955 "@H2@", self.trUtf8("When connecting to: {0}.") 1955 "@H2@", self.tr("When connecting to: {0}.")
1956 .format(urlString).encode("utf8")) 1956 .format(urlString).encode("utf8"))
1957 html = html.replace( 1957 html = html.replace(
1958 "@LI-1@", 1958 "@LI-1@",
1959 self.trUtf8("Check the address for errors such as " 1959 self.tr("Check the address for errors such as "
1960 "<b>ww</b>.example.org instead of " 1960 "<b>ww</b>.example.org instead of "
1961 "<b>www</b>.example.org").encode("utf8")) 1961 "<b>www</b>.example.org").encode("utf8"))
1962 html = html.replace( 1962 html = html.replace(
1963 "@LI-2@", 1963 "@LI-2@",
1964 self.trUtf8("If the address is correct, try checking the network " 1964 self.tr("If the address is correct, try checking the network "
1965 "connection.").encode("utf8")) 1965 "connection.").encode("utf8"))
1966 html = html.replace( 1966 html = html.replace(
1967 "@LI-3@", 1967 "@LI-3@",
1968 self.trUtf8( 1968 self.tr(
1969 "If your computer or network is protected by a firewall " 1969 "If your computer or network is protected by a firewall "
1970 "or proxy, make sure that the browser is permitted to " 1970 "or proxy, make sure that the browser is permitted to "
1971 "access the network.").encode("utf8")) 1971 "access the network.").encode("utf8"))
1972 html = html.replace( 1972 html = html.replace(
1973 "@LI-4@", 1973 "@LI-4@",
1974 self.trUtf8("If your cache policy is set to offline browsing," 1974 self.tr("If your cache policy is set to offline browsing,"
1975 "only pages in the local cache are available.") 1975 "only pages in the local cache are available.")
1976 .encode("utf8")) 1976 .encode("utf8"))
1977 html = html.replace( 1977 html = html.replace(
1978 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) 1978 "@BUTTON@", self.tr("Try Again").encode("utf8"))
1979 notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl) 1979 notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl)
1980 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title()) 1980 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title())
1981 self.loadFinished.emit(False) 1981 self.loadFinished.emit(False)
1982 1982
1983 def __downloadRequested(self, request): 1983 def __downloadRequested(self, request):
2002 # accessed for the first time 2002 # accessed for the first time
2003 return 2003 return
2004 2004
2005 res = E5MessageBox.yesNo( 2005 res = E5MessageBox.yesNo(
2006 self, 2006 self,
2007 self.trUtf8("Web Database Quota"), 2007 self.tr("Web Database Quota"),
2008 self.trUtf8( 2008 self.tr(
2009 """<p>The database quota of <strong>{0}</strong> has""" 2009 """<p>The database quota of <strong>{0}</strong> has"""
2010 """ been exceeded while accessing database <strong>{1}""" 2010 """ been exceeded while accessing database <strong>{1}"""
2011 """</strong>.</p><p>Shall it be changed?</p>""") 2011 """</strong>.</p><p>Shall it be changed?</p>""")
2012 .format(self.__dataString(securityOrigin.databaseQuota()), 2012 .format(self.__dataString(securityOrigin.databaseQuota()),
2013 databaseName), 2013 databaseName),
2014 yesDefault=True) 2014 yesDefault=True)
2015 if res: 2015 if res:
2016 newQuota, ok = QInputDialog.getInt( 2016 newQuota, ok = QInputDialog.getInt(
2017 self, 2017 self,
2018 self.trUtf8("New Web Database Quota"), 2018 self.tr("New Web Database Quota"),
2019 self.trUtf8( 2019 self.tr(
2020 "Enter the new quota in MB (current = {0}, used = {1}; " 2020 "Enter the new quota in MB (current = {0}, used = {1}; "
2021 "step size = 5 MB):" 2021 "step size = 5 MB):"
2022 .format( 2022 .format(
2023 self.__dataString(securityOrigin.databaseQuota()), 2023 self.__dataString(securityOrigin.databaseQuota()),
2024 self.__dataString(securityOrigin.databaseUsage()))), 2024 self.__dataString(securityOrigin.databaseUsage()))),
2034 @param size size to be formatted (integer) 2034 @param size size to be formatted (integer)
2035 @return formatted data string (string) 2035 @return formatted data string (string)
2036 """ 2036 """
2037 unit = "" 2037 unit = ""
2038 if size < 1024: 2038 if size < 1024:
2039 unit = self.trUtf8("bytes") 2039 unit = self.tr("bytes")
2040 elif size < 1024 * 1024: 2040 elif size < 1024 * 1024:
2041 size /= 1024 2041 size /= 1024
2042 unit = self.trUtf8("kB") 2042 unit = self.tr("kB")
2043 else: 2043 else:
2044 size /= 1024 * 1024 2044 size /= 1024 * 1024
2045 unit = self.trUtf8("MB") 2045 unit = self.tr("MB")
2046 return "{0:.1f} {1}".format(size, unit) 2046 return "{0:.1f} {1}".format(size, unit)
2047 2047
2048 ########################################################################### 2048 ###########################################################################
2049 ## Access key related methods below 2049 ## Access key related methods below
2050 ########################################################################### 2050 ###########################################################################
2317 try: 2317 try:
2318 self.__clickedFrame.print_(printer) 2318 self.__clickedFrame.print_(printer)
2319 except AttributeError: 2319 except AttributeError:
2320 E5MessageBox.critical( 2320 E5MessageBox.critical(
2321 self, 2321 self,
2322 self.trUtf8("eric5 Web Browser"), 2322 self.tr("eric5 Web Browser"),
2323 self.trUtf8( 2323 self.tr(
2324 """<p>Printing is not available due to a bug in""" 2324 """<p>Printing is not available due to a bug in"""
2325 """ PyQt4. Please upgrade.</p>""")) 2325 """ PyQt4. Please upgrade.</p>"""))
2326 2326
2327 def __printPreviewClickedFrame(self): 2327 def __printPreviewClickedFrame(self):
2328 """ 2328 """
2363 try: 2363 try:
2364 self.__clickedFrame.print_(printer) 2364 self.__clickedFrame.print_(printer)
2365 except AttributeError: 2365 except AttributeError:
2366 E5MessageBox.critical( 2366 E5MessageBox.critical(
2367 self, 2367 self,
2368 self.trUtf8("eric5 Web Browser"), 2368 self.tr("eric5 Web Browser"),
2369 self.trUtf8( 2369 self.tr(
2370 """<p>Printing is not available due to a bug in PyQt4.""" 2370 """<p>Printing is not available due to a bug in PyQt4."""
2371 """Please upgrade.</p>""")) 2371 """Please upgrade.</p>"""))
2372 return 2372 return
2373 2373
2374 def __printPdfClickedFrame(self): 2374 def __printPdfClickedFrame(self):
2395 try: 2395 try:
2396 self.__clickedFrame.print_(printer) 2396 self.__clickedFrame.print_(printer)
2397 except AttributeError: 2397 except AttributeError:
2398 E5MessageBox.critical( 2398 E5MessageBox.critical(
2399 self, 2399 self,
2400 self.trUtf8("eric5 Web Browser"), 2400 self.tr("eric5 Web Browser"),
2401 self.trUtf8( 2401 self.tr(
2402 """<p>Printing is not available due to a bug in""" 2402 """<p>Printing is not available due to a bug in"""
2403 """ PyQt4. Please upgrade.</p>""")) 2403 """ PyQt4. Please upgrade.</p>"""))
2404 return 2404 return
2405 2405
2406 def __zoomInClickedFrame(self): 2406 def __zoomInClickedFrame(self):

eric ide

mercurial