3 from PyQt4
import QtCore, QtGui
9 QtCore.QObject.__init__(self, parent)
10 self.
_imageFormats = [
"pdf",
"ps"] + [str(f)
for f
in QtGui.QImageWriter.supportedImageFormats()]
17 return ext.upper() +
" File (*."+ ext.lower() +
")"
20 """ This function recursively does the painting for exportPdf().
22 picture = QtGui.QPicture()
23 QtGui.QPainter.setRedirected(widget, picture)
24 QtGui.QApplication.instance().sendEvent(widget, QtGui.QPaintEvent(widget.rect()))
25 QtGui.QPainter.restoreRedirected(widget)
26 painter.drawPicture(offset, picture)
28 for child
in widget.children():
29 if isinstance(child, QtGui.QWidget)
and child.isVisible():
32 def exportPdf(self, widget, filename, format=QtGui.QPrinter.PdfFormat):
33 """ This function draws itself into a pdf file with given filename.
35 format is any format type supported by QtGui.QPrinter.
37 logging.debug(self.__class__.__name__ +
": exportPdf()")
39 printer = QtGui.QPrinter(QtGui.QPrinter.ScreenResolution)
40 printer.setOutputFileName(filename)
41 printer.setOutputFormat(format)
42 printer.setFullPage(
True)
43 printer.setPaperSize(QtCore.QSizeF(widget.size()), QtGui.QPrinter.DevicePixel)
44 painter = QtGui.QPainter()
45 painter.begin(printer)
54 defaultname = QtCore.QCoreApplication.instance().getLastOpenLocation()
57 filename = str(QtGui.QFileDialog.getSaveFileName(self.parent(),
"Save image...",defaultname, self.
_fileFiltersString, filter))
58 ext = str(filter).
split(
" ")[0].lower()
66 name=os.path.splitext(filename)[0]
67 ext=os.path.splitext(filename)[1].lower().
strip(
".")
71 self.
exportPdf(widget, name +
"."+ ext, QtGui.QPrinter.PdfFormat)
73 self.
exportPdf(widget, name +
"."+ ext, QtGui.QPrinter.PostScriptFormat)
75 childrenRect = widget.childrenRect()
77 picture = QtGui.QPixmap.grabWidget(widget, childrenRect.left() - margin, childrenRect.top() - margin, childrenRect.width() + 2*margin, childrenRect.height() + 2*margin)
81 picture.save(name+
"."+ext,ext)
static std::string join(char **cmd)