From 7412c82770c0344dd720d9a12c88a068e71c18d8 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Wed, 5 Apr 2017 14:28:00 +0200 Subject: [PATCH] Device title (#24) * make it possible to add a title to device annotator * Fix: add default title to device annotator --- qcodes/utils/qcodes_device_annotator.py | 22 +++++++++++++++++++--- qcodes/utils/wrappers.py | 3 ++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/qcodes/utils/qcodes_device_annotator.py b/qcodes/utils/qcodes_device_annotator.py index 8e04754b361..997652e652b 100644 --- a/qcodes/utils/qcodes_device_annotator.py +++ b/qcodes/utils/qcodes_device_annotator.py @@ -141,7 +141,7 @@ def saveAndClose(self): self.close() @staticmethod - def _renderImage(data, canvas, filename): + def _renderImage(data, canvas, filename, title=None): """ Render an image """ @@ -154,6 +154,21 @@ def _renderImage(data, canvas, filename): spacing = int(label_size * 0.2) painter = gui.QPainter(pixmap) + if title: + painter.setBrush(gui.QColor(255, 255, 255, 100)) + textfont = gui.QFont('Decorative', label_size) + textwidth = gui.QFontMetrics(textfont).width(title) + rectangle_width = textwidth + 2 * spacing + rectangle_height = label_size + 2 * spacing + painter.drawRect(0, + 0, + rectangle_width, + rectangle_height) + painter.drawText(core.QRectF(spacing, spacing, + rectangle_width, rectangle_height), + core.Qt.AlignTop + core.Qt.AlignLeft, + title) + for instrument, parameters in data.items(): for parameter, positions in parameters.items(): @@ -273,7 +288,7 @@ def updateValues(self, station): valuestr = str(value) self._data[instrument][parameter]['value'] = valuestr - def makePNG(self, counter, path=None): + def makePNG(self, counter, path=None, title=None): """ Render the image with new voltage values and save it to disk @@ -293,7 +308,8 @@ def makePNG(self, counter, path=None): grid.addWidget(win.imageCanvas) win.imageCanvas, pixmap = MakeDeviceImage._renderImage(self._data, win.imageCanvas, - self.filename) + self.filename, + title) filename = '{:03d}_deviceimage.png'.format(counter) if path: filename = os.path.join(path, filename) diff --git a/qcodes/utils/wrappers.py b/qcodes/utils/wrappers.py index 20ad3c27486..767ff178e72 100644 --- a/qcodes/utils/wrappers.py +++ b/qcodes/utils/wrappers.py @@ -181,6 +181,7 @@ def _save_individual_plots(data, inst_meas): def save_device_image(): counter = CURRENT_EXPERIMENT['provider'].counter + title = "{} #{:03d}".format(CURRENT_EXPERIMENT["sample_name"], counter) di = CURRENT_EXPERIMENT['device_image'] di.updateValues(CURRENT_EXPERIMENT['station']) @@ -189,7 +190,7 @@ def save_device_image(): di.makePNG(CURRENT_EXPERIMENT["provider"].counter, os.path.join(CURRENT_EXPERIMENT["exp_folder"], - '{:03d}'.format(counter))) + '{:03d}'.format(counter)), title) def do1d(inst_set, start, stop, num_points, delay, *inst_meas):