Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Styled up label printing. #42
Browse files Browse the repository at this point in the history
  • Loading branch information
miteshashar committed Jul 27, 2013
1 parent 9440be9 commit 777d66f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 20 additions & 13 deletions peopleflow/helpers/printlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from reportlab.lib.units import mm
from reportlab.lib.enums import TA_CENTER
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.platypus.flowables import HRFlowable
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.colors import Color


def printlabel(printer, lines):
Expand All @@ -15,42 +17,47 @@ def printlabel(printer, lines):
fname = f.name
f.close()

heights = [18, 32, 38]

doc = SimpleDocTemplate(fname,
pagesize=(62 * mm, 40 * mm),
pagesize=(62 * mm, heights[len(lines) - 1] * mm),
topMargin=0, leftMargin=0,
rightMargin=0, bottomMargin=0)
story = []

styles = [
ParagraphStyle("s1", fontName="Helvetica", alignment=TA_CENTER, fontSize=18, leading=18),
ParagraphStyle("s2", fontName="Helvetica", alignment=TA_CENTER, fontSize=13, leading=13, spaceBefore=6),
ParagraphStyle("s3", fontName="Helvetica", alignment=TA_CENTER, fontSize=13, leading=13, spaceBefore=6),
ParagraphStyle("s4", fontName="Helvetica", alignment=TA_CENTER, fontSize=13, leading=13, spaceBefore=6)
ParagraphStyle("s1", fontName="Helvetica-Bold", alignment=TA_CENTER, fontSize=15, leading=15),
ParagraphStyle("s2", fontName="Helvetica", alignment=TA_CENTER, fontSize=15, leading=18, spaceBefore=4, textColor=u"#555555"),
ParagraphStyle("s3", fontName="Helvetica", alignment=TA_CENTER, fontSize=12, leading=13, spaceBefore=4, textColor=u"#777777")
]

for i, line in enumerate(lines):
story.append(Paragraph(line, styles[i]))
# story.append(Paragraph(line2, style2))
if i < len(styles):
story.append(Paragraph(line, styles[i]))
if i == 0 and len(lines) > 1:
story.append(HRFlowable(width='95%', color=u"#333333", spaceBefore=5))
doc.build(story)

#os.system("gnome-open " + fname)
os.system("lpr -P %s %s" % (printer, fname))
time.sleep(2)
os.unlink(fname)

def make_label_content(participant):
data = [participant.name]
if participant.company:
data.append(participant.company)
compline = participant.company
if participant.job:
data.append(participant.job)
compline = u"%s, %s" % (participant.job, compline)
data.append(compline)
if(participant.twitter):
data.append('@' + participant.twitter)
return data


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Script to print labels')
parser = argparse.ArgumentParser(description='Script to test printing of labels. Tries to test through fairly large 2-liners for name and job+company.')
parser.add_argument('printer', type=str, help='The name of the printer')
parser.add_argument('--lines', type=int, help='The number of lines to print', default=3)
args = parser.parse_args()
printlabel(args.printer, ["Kiran Jonnalagadda isn't long enough", "@jackerhack"])
data = ["Kiran Jonnalagadda isn't long enough", "CEO, HasGeek Media LLP.", "@jackerhack"]
data = data[:args.lines]
printlabel(args.printer, data)
4 changes: 2 additions & 2 deletions peopleflow/views/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def print_card(participant):
try:
if 'PRINTER_NAME' in app.config:
printlabel(app.config['PRINTER_NAME'], make_label_content(participant))
return jsonify(status=True, msg=u"Card for %s queued for printing" % participant.name)
return jsonify(status=True, msg=u"Label for %s queued for printing" % participant.name)
else:
return jsonify(status=False, msg=u"Printer not configured")
except:
return jsonify(status=False, msg=u"Card for %s queued for printing" % participant.name)
return jsonify(status=False, msg=u"There was an error in printing the label for %s" % participant.name)

@app.route('/<eid>/search', methods=['POST'])
@load_model(Event,{'id':'eid'},'event')
Expand Down

0 comments on commit 777d66f

Please sign in to comment.