summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ptbulk.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/ptbulk.py b/ptbulk.py
new file mode 100644
index 0000000..583bb03
--- /dev/null
+++ b/ptbulk.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# vim: set expandtab ts=4:
+
+import cairo, pango, pangocairo
+import pttarget, ptlayout
+from ptlayout import PTLText
+import time, sys
+import usb.core
+
+layout = ptlayout.PTLHSeq()
+layout.spacing = 0
+layout.add(ptlayout.PTLHSpace()).spacing = 5
+text = layout.add(ptlayout.PTLText())
+layout.add(ptlayout.PTLHSpace()).spacing = 5
+
+pttarget.PTUSB.scan()
+print 'device list:'
+for dev in pttarget.PTUSB.printers:
+ print str(dev)
+if len(pttarget.PTUSB.printers) != 1:
+ print 'no idea which printer to use!'
+ sys.exit(1)
+dev = pttarget.PTUSB.printers[0]
+dev.setup()
+dev.refresh_status()
+mtype = pttarget.media_types.get(dev.media_type, 'unknown (%02x)' % (dev.media_type))
+msize = '%dx%dmm' % (dev.media_width, dev.media_length) if dev.media_length != 0 else \
+ '%dmm continuous tape' % (dev.media_width)
+print 'Status: %s, %s %s' % (dev.get_errstr(), mtype, msize)
+
+tape = dev.find_tape()
+
+for line in sys.stdin.readlines():
+ line = line.strip()
+
+ # insert code here
+
+ text.text = line
+
+ w, h = layout.prep_size(tape.pixels)
+ if w < 32:
+ w = 32
+ label_surface = cairo.ImageSurface(cairo.FORMAT_A1, w, tape.pixels)
+ ctx = cairo.Context(label_surface)
+ ctx.set_operator(cairo.OPERATOR_SOURCE)
+ final_w = layout.render(ctx, tape.pixels)
+ print 'text: "%s" label width: %d' % (line, final_w)
+
+ data = pttarget.PTLabelData()
+ data.addcairo(label_surface, offset = tape.offset)
+ dev.send(data.get(True))
+