Tue, 26 Aug 2008 23:22:38 +0200
add ability to print a plot in qgpibplotter
pygpibtoolkit/plotter/qgpib_plotter.py | file | annotate | diff | comparison | revisions | |
pygpibtoolkit/plotter/qhpgl_plotter.ui | file | annotate | diff | comparison | revisions |
--- 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: <br><b>No plot is currently selected.</b>") + def saveTriggered(self, checked=False): print "save"
--- 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 @@ <property name="windowTitle" > <string>MainWindow</string> </property> - <widget class="QWidget" name="centralwidget" /> + <widget class="QWidget" name="centralwidget" > + <property name="geometry" > + <rect> + <x>264</x> + <y>30</y> + <width>243</width> + <height>439</height> + </rect> + </property> + </widget> <widget class="QMenuBar" name="menubar" > <property name="geometry" > <rect> <x>0</x> <y>0</y> <width>507</width> - <height>25</height> + <height>30</height> </rect> </property> <widget class="QMenu" name="menu_File" > @@ -30,6 +39,7 @@ <addaction name="actionSave" /> <addaction name="actionSaveAs" /> <addaction name="separator" /> + <addaction name="actionPrint" /> <addaction name="actionQuit" /> </widget> <widget class="QMenu" name="menuEdit" > @@ -41,12 +51,37 @@ <addaction name="menu_File" /> <addaction name="menuEdit" /> </widget> - <widget class="QStatusBar" name="statusbar" /> + <widget class="QStatusBar" name="statusbar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>469</y> + <width>507</width> + <height>23</height> + </rect> + </property> + </widget> <widget class="QDockWidget" name="plotsDock" > + <property name="geometry" > + <rect> + <x>0</x> + <y>30</y> + <width>258</width> + <height>439</height> + </rect> + </property> <attribute name="dockWidgetArea" > <number>1</number> </attribute> <widget class="QWidget" name="dockWidgetContents" > + <property name="geometry" > + <rect> + <x>0</x> + <y>21</y> + <width>258</width> + <height>418</height> + </rect> + </property> <layout class="QVBoxLayout" > <property name="spacing" > <number>4</number> @@ -77,7 +112,8 @@ <string>on line</string> </property> <property name="icon" > - <iconset/> + <iconset resource="../qt4/resources.qrc" > + <normaloff>:/icons/led_green_off.svg</normaloff>:/icons/led_green_off.svg</iconset> </property> <property name="iconSize" > <size> @@ -98,7 +134,7 @@ <property name="orientation" > <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" > + <property name="sizeHint" stdset="0" > <size> <width>40</width> <height>20</height> @@ -112,7 +148,8 @@ <string/> </property> <property name="icon" > - <iconset/> + <iconset resource="../qt4/resources.qrc" > + <normaloff>:/icons/led_red_off.svg</normaloff>:/icons/led_red_off.svg</iconset> </property> <property name="iconSize" > <size> @@ -158,6 +195,11 @@ <string>Preferences</string> </property> </action> + <action name="actionPrint" > + <property name="text" > + <string>&Print...</string> + </property> + </action> </widget> <resources> <include location="../qt4/resources.qrc" />