WebBrowser/WebBrowserTabWidget.py

changeset 5181
1948b27d7b21
parent 5113
d394e20f7467
child 5182
e2782c9a43d4
equal deleted inserted replaced
5176:30547e9a19e3 5181:1948b27d7b21
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 13
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QFile 14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QFile, qVersion
15 from PyQt5.QtGui import QIcon, QPixmap, QPainter 15 from PyQt5.QtGui import QIcon, QPixmap, QPainter
16 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QMenu, QToolButton, QDialog 16 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QMenu, QToolButton, QDialog
17 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog 17 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
18 18
19 from E5Gui.E5TabWidget import E5TabWidget 19 from E5Gui.E5TabWidget import E5TabWidget
177 UI.PixmapCache.getIcon("tabCloseOther.png"), 177 UI.PixmapCache.getIcon("tabCloseOther.png"),
178 self.tr("Close Others"), self.__tabContextMenuCloseOthers) 178 self.tr("Close Others"), self.__tabContextMenuCloseOthers)
179 self.__tabContextMenu.addAction( 179 self.__tabContextMenu.addAction(
180 self.tr('Close All'), self.closeAllBrowsers) 180 self.tr('Close All'), self.closeAllBrowsers)
181 self.__tabContextMenu.addSeparator() 181 self.__tabContextMenu.addSeparator()
182 self.__tabContextMenu.addAction( 182 if not Globals.isWindowsPlatform():
183 UI.PixmapCache.getIcon("printPreview.png"), 183 # TODO: implement printing based on printToPdf()
184 self.tr('Print Preview'), self.__tabContextMenuPrintPreview) 184 self.__tabContextMenu.addAction(
185 self.__tabContextMenu.addAction( 185 UI.PixmapCache.getIcon("printPreview.png"),
186 UI.PixmapCache.getIcon("print.png"), 186 self.tr('Print Preview'), self.__tabContextMenuPrintPreview)
187 self.tr('Print'), self.__tabContextMenuPrint) 187 self.__tabContextMenu.addAction(
188 if Globals.isLinuxPlatform(): 188 UI.PixmapCache.getIcon("print.png"),
189 self.tr('Print'), self.__tabContextMenuPrint)
190 if Globals.isLinuxPlatform() or qVersion() >= "5.7.0":
189 self.__tabContextMenu.addAction( 191 self.__tabContextMenu.addAction(
190 UI.PixmapCache.getIcon("printPdf.png"), 192 UI.PixmapCache.getIcon("printPdf.png"),
191 self.tr('Print as PDF'), self.__tabContextMenuPrintPdf) 193 self.tr('Print as PDF'), self.__tabContextMenuPrintPdf)
192 self.__tabContextMenu.addSeparator() 194 self.__tabContextMenu.addSeparator()
193 if hasattr(WebBrowserPage, "isAudioMuted"): 195 if hasattr(WebBrowserPage, "isAudioMuted"):
643 name += '.pdf' 645 name += '.pdf'
644 if hasattr(browser.page(), "printToPdf"): 646 if hasattr(browser.page(), "printToPdf"):
645 from .Tools.PrintToPdfDialog import PrintToPdfDialog 647 from .Tools.PrintToPdfDialog import PrintToPdfDialog
646 if not name: 648 if not name:
647 name = "printout.pdf" 649 name = "printout.pdf"
648 dlg = PrintToPdfDialog(os.path.abspath(name), self) 650 dlg = PrintToPdfDialog(name, self)
649 if dlg.exec_() == QDialog.Accepted: 651 if dlg.exec_() == QDialog.Accepted:
650 filePath, pageLayout = dlg.getData() 652 filePath, pageLayout = dlg.getData()
651 if filePath: 653 if filePath:
654 if os.path.exists(filePath):
655 res = E5MessageBox.warning(
656 self,
657 self.tr("Print to PDF"),
658 self.tr("""<p>The file <b>{0}</b> exists"""
659 """ already. Shall it be"""
660 """ overwritten?</p>""").format(filePath),
661 E5MessageBox.StandardButtons(
662 E5MessageBox.No |
663 E5MessageBox.Yes),
664 E5MessageBox.No)
665 if res == E5MessageBox.No:
666 return
652 browser.page().printToPdf( 667 browser.page().printToPdf(
653 lambda p: self.__pdfGenerated(filePath, p), 668 lambda p: self.__pdfGenerated(filePath, p),
654 pageLayout) 669 pageLayout)
655 else: 670 elif Globals.isLinuxPlatform():
656 printer = QPrinter(mode=QPrinter.HighResolution) 671 printer = QPrinter(mode=QPrinter.HighResolution)
657 if Preferences.getPrinter("ColorMode"): 672 if Preferences.getPrinter("ColorMode"):
658 printer.setColorMode(QPrinter.Color) 673 printer.setColorMode(QPrinter.Color)
659 else: 674 else:
660 printer.setColorMode(QPrinter.GrayScale) 675 printer.setColorMode(QPrinter.GrayScale)

eric ide

mercurial