Skip to content

Commit

Permalink
Reviewed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Sep 3, 2020
1 parent da6d0ad commit c502520
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 46 deletions.
5 changes: 2 additions & 3 deletions examples/barcode_and_dynamic_picture/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Barcode and dynamic picture

In this example we will print an indenticon and a barcode for each label.
In this example we will print an identicon and a barcode for each label.

<p align='center'><img src="./screenshot.png" alt="screenshot"></p>

This example shows:

- How to use ``label_tools.barcode``
- How to transform a picture generated on-the-fly into base64 data so it can be intergrated into a ``<img/>`` tag.
- How to transform a picture generated on-the-fly into base64 data so it can be integrated into a ``<img/>`` tag.
- How to define extra variables or functions and use them from inside the template (here, ``generate_identicon``).

This example requires [pydenticon](https://github.com/azaghal/pydenticon) installed:

```
pip install pydenticon
```

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
import pydenticon
import base64


def generate_identicon(sample_id):
identicon_generator = pydenticon.Generator(
6, 6, foreground=['red', 'blue', 'green', 'purple'])
6, 6, foreground=["red", "blue", "green", "purple"]
)
img = identicon_generator.generate(sample_id, 60, 60)
return 'data:image/png;base64,%s' % (base64.b64encode(img).decode())
return "data:image/png;base64,%s" % (base64.b64encode(img).decode())


label_writer = LabelWriter("item_template.html",
default_stylesheets=("style.css",),
generate_identicon=generate_identicon)
records= [
label_writer = LabelWriter(
"item_template.html",
default_stylesheets=("style.css",),
generate_identicon=generate_identicon,
)
records = [
dict(sample_id="s01", sample_name="Sample 1"),
dict(sample_id="s02", sample_name="Sample 2"),
dict(sample_id="s03", sample_name="Sample 3")
dict(sample_id="s03", sample_name="Sample 3"),
]

label_writer.write_labels(records, target='barcode_and_dynamic_picture.pdf')
label_writer.write_labels(records, target="barcode_and_dynamic_picture.pdf")
3 changes: 0 additions & 3 deletions examples/labels_from_spreadsheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ Install Pandas with:
```
pip install pandas
```



Binary file modified examples/labels_from_spreadsheet/labels_from_spreadsheet.pdf
Binary file not shown.
9 changes: 4 additions & 5 deletions examples/labels_from_spreadsheet/labels_from_spreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from blabel import LabelWriter
import pandas

dataframe = pandas.read_csv('records.csv')
records = dataframe.to_dict(orient='record')
dataframe = pandas.read_csv("records.csv")
records = dataframe.to_dict(orient="record")

label_writer = LabelWriter("item_template.html",
default_stylesheets=("style.css",))
label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css",))

label_writer.write_labels(records, target='labels_from_spreadsheet.pdf')
label_writer.write_labels(records, target="labels_from_spreadsheet.pdf")
2 changes: 0 additions & 2 deletions examples/logo_and_datamatrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ This example shows:

- How to use local pictures (notice that it requires to set the ``base_url`` in ``write_pdf``).
- How to use ``label_tools.datamatrix()``


Binary file modified examples/logo_and_datamatrix/logo_and_datamatrix.pdf
Binary file not shown.
10 changes: 4 additions & 6 deletions examples/logo_and_datamatrix/logo_and_datamatrix.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from blabel import LabelWriter

label_writer = LabelWriter("item_template.html",
default_stylesheets=("style.css",))
records= [
label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css",))
records = [
dict(sample_id="s01", sample_name="Sample 1"),
dict(sample_id="s02", sample_name="Sample 2")
dict(sample_id="s02", sample_name="Sample 2"),
]

label_writer.write_labels(records, target='logo_and_datamatrix.pdf',
base_url='.')
label_writer.write_labels(records, target="logo_and_datamatrix.pdf", base_url=".")
2 changes: 0 additions & 2 deletions examples/qrcode_and_date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ This example shows:

- How to use ``label_tools.qr_code()``.
- How to use ``label_tools.now()`` to print a date (you can also provide a date formatting string to ``now()``).


8 changes: 4 additions & 4 deletions examples/qrcode_and_date/item_template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="{{label_tools.qr_code(sample_id)}}"/>
<img src="{{label_tools.qr_code(sample_id)}}" />
<span class='label'>
{{ sample_name }} <br/>
Made with ❤ @ EGF <br/>
🗓 {{ label_tools.now() }}
{{ sample_name }} <br />
Made with blabel <br />
{{ label_tools.now() }}
</span>
Binary file modified examples/qrcode_and_date/qrcode_and_date.pdf
Binary file not shown.
9 changes: 4 additions & 5 deletions examples/qrcode_and_date/qrcode_and_date.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from blabel import LabelWriter

label_writer = LabelWriter("item_template.html",
default_stylesheets=("style.css",))
records= [
label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css",))
records = [
dict(sample_id="s01", sample_name="Sample 1"),
dict(sample_id="s02", sample_name="Sample 2")
dict(sample_id="s02", sample_name="Sample 2"),
]

label_writer.write_labels(records, target='qrcode_and_date.pdf')
label_writer.write_labels(records, target="qrcode_and_date.pdf")
2 changes: 0 additions & 2 deletions examples/several_items_per_page/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ In this example we will print 3 items per sticker.
This example shows:

- How to set several items per sticker with ``items_per_page=3``.


Binary file modified examples/several_items_per_page/several_items_per_page.pdf
Binary file not shown.
12 changes: 6 additions & 6 deletions examples/several_items_per_page/several_items_per_page.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from blabel import LabelWriter

label_writer = LabelWriter("item_template.html", items_per_page=3,
default_stylesheets=("style.css",))
records= [
label_writer = LabelWriter(
"item_template.html", items_per_page=3, default_stylesheets=("style.css",)
)
records = [
dict(name="Scott", sex="M"),
dict(name="Laura", sex="F"),
dict(name="Jane", sex="F"),
dict(name="Valentin", sex="M"),
dict(name="Hille", sex="F")
dict(name="Hille", sex="F"),
]

label_writer.write_labels(records, target='several_items_per_page.pdf',
base_url='.')
label_writer.write_labels(records, target="several_items_per_page.pdf", base_url=".")

0 comments on commit c502520

Please sign in to comment.