Add example printing from CSV

This commit is contained in:
Mario Hüttel 2021-12-27 20:52:01 +01:00
parent 08c09cc696
commit 7f88dcaab5
4 changed files with 45 additions and 1 deletions

12
.vscode/launch.json vendored
View File

@ -4,13 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"name": "Python: Example Print",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/generate_label_example.py",
"console": "integratedTerminal",
"args": []
},
{
"name": "Python: Print CSV",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/print_labels_from_csv.py",
"console": "integratedTerminal",
"args": []
}
]
}

View File

@ -1,3 +1,6 @@
# Prerequisites
- This project requires the brother_ql binary from the ``brother_ql`` project to be in the PATH.
# License
This project is licensed under the GPLv2 license.

10
labels.csv Normal file
View File

@ -0,0 +1,10 @@
Heading,Line1,Line2,Cut
100n 10%,0603 X7R 10V,AVX,
100n 10%,0603 X7R 10V,Kemet,
100n 10%,0603 X7R 10V,AVX,
100n 10%,0805 X7R 10V,Taiyo Yuden,
100n 10%,0805 X7R 10V,TKK,
100n 20%,1206 X7R 25V,Murata,
220n 20%,0805 X5R 100V,Murata,
120n 10%,1206 X7R 10V,Samsung,1
1 Heading Line1 Line2 Cut
2 100n 10% 0603 X7R 10V AVX
3 100n 10% 0603 X7R 10V Kemet
4 100n 10% 0603 X7R 10V AVX
5 100n 10% 0805 X7R 10V Taiyo Yuden
6 100n 10% 0805 X7R 10V TKK
7 100n 20% 1206 X7R 25V Murata
8 220n 20% 0805 X5R 100V Murata
9 120n 10% 1206 X7R 10V Samsung 1

21
print_labels_from_csv.py Normal file
View File

@ -0,0 +1,21 @@
import pandas as pd
import shimatta_label.label_image as li
import shimatta_label.brother_ql_wrapper as ql_wrapper
import os
medir = os.path.dirname(__file__)
example_data_path = os.path.join(medir, 'labels.csv')
df = pd.read_csv(example_data_path)
printer = ql_wrapper.BrotherQlPrinter(model='QL-800', printer_connection='usb://0x04f9:0x209b')
for _, row in df.iterrows():
label = li.MiceToiletLabel()
label.put_text(row['Heading'], row['Line1'], row['Line2'])
file_path = label.save()
cut = False
if row['Cut'] == 1:
cut = True
printer.print_image(file_path, cut = cut, rotation=270)
os.remove(file_path)