# HG changeset patch # User David Douard # Date 1219785758 -7200 # Node ID baab64c18885210dcf270b9640fff69aafa5321e # Parent 069666c7bf6c13ef0d3f59119db3891870f5982d add ability to print a plot in qgpibplotter diff -r 069666c7bf6c -r baab64c18885 pygpibtoolkit/plotter/qgpib_plotter.py --- a/pygpibtoolkit/plotter/qgpib_plotter.py Tue Aug 26 21:13:12 2008 +0200 +++ b/pygpibtoolkit/plotter/qgpib_plotter.py Tue Aug 26 23:22:38 2008 +0200 @@ -30,8 +30,11 @@ ldir = os.path.abspath(os.path.dirname(__file__)) sys.path.append(os.path.join(ldir, "..", "qt4")) print "ldir=",ldir -form_class, base_class = uic.loadUiType(os.path.join(ldir, "qhpgl_plotter.ui")) - +try: + form_class, base_class = uic.loadUiType(os.path.join(ldir, "qhpgl_plotter.ui")) +except: + from qhpgl_plotter_ui import Ui_MainWindow as form_class + from pygpibtoolkit.qt4.qpreferences import BaseItem, IntItem, UnicodeItem, ColorItem from pygpibtoolkit.qt4.qpreferences import PointItem, SizeItem, ByteArrayItem from pygpibtoolkit.qt4.qpreferences import AbstractPreferences @@ -125,6 +128,10 @@ self.connect(self.actionSaveAs, SIGNAL('triggered(bool)'), self.saveAsTriggered) + self.actionPrint.setShortcut(QtGui.QKeySequence(u'Ctrl+P')) + self.connect(self.actionPrint, SIGNAL('triggered(bool)'), + self.printTriggered) + self.plotterWidget = QHPGLPlotterWidget(self) self.setCentralWidget(self.plotterWidget) @@ -203,7 +210,26 @@ def plotStarted(self): self._receiving = True self.setReceivingLed() - + + def printTriggered(self, checked=False): + cindex = self.plotsView.currentIndex() + if cindex and cindex.isValid(): + plotname = unicode(self.plotsView.model().data(cindex, Qt.DisplayRole).toString()) + printer = QtGui.QPrinter() + printer.setOutputFormat(printer.PdfFormat) + # isn't there a simpler way of doing this? + printer.setOutputFileName('%s.pdf'%plotname) + prdialog = QtGui.QPrintDialog(printer) + prdialog.setEnabledOptions(prdialog.PrintToFile) + if prdialog.exec_() == QtGui.QDialog.Accepted: + painter = QtGui.QPainter(printer) + painter.setRenderHint(painter.Antialiasing) + self.plotterWidget.qview.render(painter) + painter.end() + else: + QtGui.QMessageBox.warning(self, "Nothing to print", + "Unable to print:
No plot is currently selected.") + def saveTriggered(self, checked=False): print "save" diff -r 069666c7bf6c -r baab64c18885 pygpibtoolkit/plotter/qhpgl_plotter.ui --- a/pygpibtoolkit/plotter/qhpgl_plotter.ui Tue Aug 26 21:13:12 2008 +0200 +++ b/pygpibtoolkit/plotter/qhpgl_plotter.ui Tue Aug 26 23:22:38 2008 +0200 @@ -12,14 +12,23 @@ MainWindow - + + + + 264 + 30 + 243 + 439 + + + 0 0 507 - 25 + 30 @@ -30,6 +39,7 @@ + @@ -41,12 +51,37 @@ - + + + + 0 + 469 + 507 + 23 + + + + + + 0 + 30 + 258 + 439 + + 1 + + + 0 + 21 + 258 + 418 + + 4 @@ -77,7 +112,8 @@ on line - + + :/icons/led_green_off.svg:/icons/led_green_off.svg @@ -98,7 +134,7 @@ Qt::Horizontal - + 40 20 @@ -112,7 +148,8 @@ - + + :/icons/led_red_off.svg:/icons/led_red_off.svg @@ -158,6 +195,11 @@ Preferences + + + &Print... + +