diff options
author | David Lamparter <equinox@diac24.net> | 2013-12-23 19:43:55 +0100 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2013-12-23 19:43:55 +0100 |
commit | e78a4f633cd33d79c8acf23183432f2052756a14 (patch) | |
tree | eb1f4fcea6f8a34d8a4c299e92b1abcc9c3d9ed5 /ptbulk.py | |
parent | 62b8d81ca3169d9fb0367f6ae2aa25bc2c9f59e3 (diff) |
Diffstat (limited to 'ptbulk.py')
-rw-r--r-- | ptbulk.py | 52 |
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)) + |