Browse Source

Add example printing from CSV

Mario Hüttel 3 years ago
parent
commit
7f88dcaab5
4 changed files with 45 additions and 1 deletions
  1. 11 1
      .vscode/launch.json
  2. 3 0
      README.MD
  3. 10 0
      labels.csv
  4. 21 0
      print_labels_from_csv.py

+ 11 - 1
.vscode/launch.json

@@ -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": []
         }
     ]
+    
 }

+ 3 - 0
README.MD

@@ -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 - 0
labels.csv

@@ -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
+

+ 21 - 0
print_labels_from_csv.py

@@ -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)