Skip to content

Commit

Permalink
Device title (#24)
Browse files Browse the repository at this point in the history
* make it possible to add a title to device annotator

* Fix: add default title to device annotator
  • Loading branch information
jenshnielsen committed Aug 16, 2017
1 parent 29e3982 commit acc3168
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 19 additions & 3 deletions qcodes/utils/qcodes_device_annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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():

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion qcodes/utils/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand All @@ -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):
Expand Down

0 comments on commit acc3168

Please sign in to comment.