Skip to content
Snippets Groups Projects
Commit 5d5b68f3 authored by Mayr, Hannes's avatar Mayr, Hannes
Browse files

Add rudimentary qrcode support.

parent 89a25a23
No related branches found
No related tags found
1 merge request!24QR Codes now work with mpl and image engine.
Pipeline #803534 waiting for manual action
......@@ -33,6 +33,8 @@ class PlotOptions:
id_method for creating the ID. Create an ID by Unix time is referenced
as 'time', create a random ID with id_method='random'.
The default is 'time'.
qrcode : bool, optional
Experimental status. Print qrcode on exported plot. Default: False.
"""
def __init__(self, figs, rotation, position, **kwargs):
......@@ -43,6 +45,7 @@ class PlotOptions:
self.position = position
self.prefix = kwargs.get('prefix', '')
self.id_method = kwargs.get('id_method', 'time')
self.qrcode = kwargs.get('qrcode', False)
def __str__(self):
"""Representation if an object of this class is printed."""
......
......@@ -55,6 +55,7 @@ def tagplot_image(plotid_object):
(int(img.width*plotid_object.position[0]),
int(img.height*(1-plotid_object.position[1]))), txt)
if plotid_object.qrcode:
qrcode = create_qrcode(img_id)
qrcode.thumbnail((100, 100), Image.ANTIALIAS)
img.paste(qrcode, box=(img.width-100, img.height-100))
......
......@@ -52,7 +52,9 @@ def tagplot_matplotlib(plotid_object):
s=fig_id, ha='left', wrap=True,
rotation=plotid_object.rotation,
fontsize=fontsize, color=color)
qrcode = create_qrcode(figure_id)
if plotid_object.qrcode:
qrcode = create_qrcode(fig_id)
qrcode.thumbnail((100, 100), Image.ANTIALIAS)
fig.figimage(qrcode, fig.bbox.xmax - 100, 0, cmap='bone')
fig.tight_layout()
......
......@@ -5,7 +5,9 @@ Unittests for create_id
"""
import unittest
import qrcode
import plotid.create_id as cid
from plotid.create_id import create_qrcode
class TestCreateID(unittest.TestCase):
......@@ -30,6 +32,11 @@ class TestCreateID(unittest.TestCase):
self.assertEqual(len(cid.create_id('time')), 10)
self.assertEqual(len(cid.create_id('random')), 8)
def test_qrcode(self):
"""Test if qrcode returns a image."""
self.assertIsInstance(create_qrcode('test_ID'),
qrcode.image.pil.PilImage)
if __name__ == '__main__':
unittest.main()
......@@ -44,7 +44,7 @@ class TestTagplot(unittest.TestCase):
"<class 'plotid.plotoptions.PlotOptions'>: {'figs': "
"'FIG', 'figure_ids': [], 'rotation': 270, 'position'"
": (100, 200), 'prefix': 'xyz', 'id_method': "
"'random'}")
"'random', 'qrcode': False}")
def test_str_plotidtransfer(self):
"""
......
......@@ -40,7 +40,7 @@ class TestTagplotImage(unittest.TestCase):
respectively.
"""
options = PlotOptions(IMGS_AS_LIST, ROTATION, POSITION,
prefix=PROJECT_ID, id_method=METHOD)
prefix=PROJECT_ID, id_method=METHOD, qrcode=True)
options.validate_input()
figs_and_ids = tagplot_image(options)
self.assertIsInstance(figs_and_ids.figs[0],
......
......@@ -30,7 +30,7 @@ class TestTagplotMatplotlib(unittest.TestCase):
def test_mplfigures(self):
""" Test of returned objects. Check if they are matplotlib figures. """
options = PlotOptions(FIGS_AS_LIST, ROTATION, POSITION,
prefix=PROJECT_ID, id_method=METHOD)
prefix=PROJECT_ID, id_method=METHOD, qrcode=True)
options.validate_input()
figs_and_ids = tagplot_matplotlib(options)
self.assertIsInstance(figs_and_ids.figs[0], Figure)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment