From e78a4f633cd33d79c8acf23183432f2052756a14 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 23 Dec 2013 19:43:55 +0100 Subject: add bulk cmdline version --- ptbulk.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ptbulk.py 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)) + -- cgit v1.2.1