Skip to content

Commit

Permalink
Implemented barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
marinho committed Jan 23, 2010
1 parent 90e5abe commit 05711bc
Show file tree
Hide file tree
Showing 64 changed files with 1,408 additions and 220 deletions.
4 changes: 4 additions & 0 deletions CHANGES
@@ -1,3 +1,7 @@
2010-01-23: Version 0.4-alpha-5
-----------------------------
* Implemented barcodes

2010-01-22: Version 0.4-alpha-4
-----------------------------
* Borders now support integer numbers in place of boolean, to set their stroke widths
Expand Down
6 changes: 5 additions & 1 deletion README
Expand Up @@ -25,6 +25,7 @@ Engine API
- Table details
- Support graphics (x)
- Support charts - use graphics.Image to set a rendered char image (x)
- Support with no dependency on charts generators
- Support aggregation fields (x)
- Support expression (x)
- Support calculated fields (x)
Expand All @@ -36,7 +37,10 @@ Engine API
- Support canvas drawing
- Reports merging (many reports at once) (x)
- Multiple columns
- Events (x)
- Events system (x)
- Caching (x)
- Map/Reduce generating
- Drill down reports

Generators
----------
Expand Down
74 changes: 74 additions & 0 deletions docs/source/barcodes.txt
@@ -0,0 +1,74 @@
Barcodes Reference
==================

**New on 0.4**

The BarCode element is just one, and it is used to show barcodes of many types
on the report.

This element is inherited from **geraldo.graphics.Graphic**

BarCode
-------

.. currentmodule:: geraldo.barcodes
.. class:: BarCode

Path: **geraldo.barcodes.BarCode**

This is the once class you can use to show bar codes. It supports the following
bar code types, supplied by **ReportLab** barcodes library:

* Codabar
* Code11
* Code128
* EAN13
* EAN8
* Extended39
* Extended93
* FIM
* I2of5
* MSI
* POSTNET
* Standard39
* Standard93
* USPS_4State

**Attributes**

- **name** - Default: None
- **visible** - Default: True

Set to **False** if you want to make it not visible.

- **height** - Default: 1.5*cm
- **width** - Default: 0.03*cm

This attribute **does not set the barcode width**, but the **bar width**,
what means it is the width of the minimum bar of a barcode. You should set
values like 0.02*cm or something like that (i.e. never 5*cm).

- **attribute_name** - Default: None

As same as **geraldo.widgets.ObjectValue**, this attribute reffers to an
attribute, attribute path or method to get the barcode value.

- **checksum** - Default: 0

Most of barcode types supports you set the number of digits for checksum.

- **routing_attribute** - Default: None

Useful only for **USPS_4State** barcodes. Works like **attribute_name**, but
**routing** attribute of barcode.

**Rendering attributes**

They are read-only attributes you can use at render time.

- **instance** - current object being rendered
- **generator** - generator instance
- **report** - report instance this element is in
- **band** - band this element is in
- **page** - current page

4 changes: 2 additions & 2 deletions docs/source/conf.py
Expand Up @@ -38,7 +38,7 @@

# General information about the project.
project = u'Geraldo Reports Documentation'
copyright = u'2009, Marinho Brandao'
copyright = u'2009-2010, Marinho Brandao'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -47,7 +47,7 @@
# The short X.Y version.
version = '0.4'
# The full version, including alpha/beta/rc tags.
release = '0.4-alpha-4'
release = '0.4-alpha-5'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/additional-fonts.txt
Expand Up @@ -74,4 +74,7 @@ and ReportLab::

report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/additional-fonts.pdf'))

The Result

- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/additional-fonts.pdf

140 changes: 140 additions & 0 deletions docs/source/examples/barcodes.txt
@@ -0,0 +1,140 @@
Showing BarCodes
================

Bar codes are really important on labels, bills, tickets, etc.

This example demonstrates how to show barcodes of all supported types on a report.

There are many different types of bar codes and we will support those ReportLab
already does.

**BarCode element**

**geraldo.barcodes.BarCode** is the graphic class that generates the bar codes of
all supported types. It is an inheritance from Graphic element.

Supported bar code types:

- Codabar
- Code11
- Code128
- EAN13
- EAN8
- Extended39
- Extended93
- FIM
- I2of5
- MSI
- POSTNET
- Standard39
- Standard93
- USPS_4State

The code::

import os
cur_dir = os.path.dirname(os.path.abspath(__file__))

from geraldo.utils import A4, cm, TA_CENTER, TA_RIGHT

from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
FIELD_ACTION_COUNT, BAND_WIDTH
from geraldo.barcodes import BarCode

class SimpleListReport(Report):
title = 'Demonstration of BarCodes'

class band_page_header(ReportBand):
height = 1*cm
elements = [
SystemField(expression='%(report_title)s', top=0.1*cm, left=0, width=BAND_WIDTH,
style={'fontName': 'Helvetica', 'fontSize': 14, 'alignment': TA_CENTER}),
]
borders = {'bottom': True}

class band_page_footer(ReportBand):
height = 0.5*cm
elements = [
Label(text='Created with Geraldo Reports', top=0.1*cm, left=0),
SystemField(expression='Page # %(page_number)d of %(page_count)d', top=0.1*cm,
width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
]
borders = {'top': True}

class band_detail(ReportBand):
height = 15*cm
elements = [
ObjectValue(attribute_name='name', style={'fontSize': 12}),
Label(text='Code:', style={'fontSize': 12}, left=6.5*cm),
ObjectValue(attribute_name='code', style={'fontSize': 12}, left=8*cm),

Label(text='Codabar', top=0.6*cm),
BarCode(type='Codabar', attribute_name='code', top=1.2*cm, height=1.5*cm),

Label(text='Code11', top=0.6*cm, left=6*cm),
BarCode(type='Code11', attribute_name='code', top=1.2*cm, left=6*cm, height=1.5*cm),

Label(text='Code128', top=0.6*cm, left=12*cm),
BarCode(type='Code128', attribute_name='code', top=1.2*cm, left=12*cm, height=1.5*cm),

Label(text='EAN13', top=3.2*cm),
BarCode(type='EAN13', attribute_name='code', top=3.8*cm, height=1.5*cm),

Label(text='EAN8', top=3.2*cm, left=6*cm),
BarCode(type='EAN8', attribute_name='code', top=3.8*cm, left=6*cm, height=1.5*cm),

Label(text='Extended39', top=3.2*cm, left=12*cm),
BarCode(type='Extended39', attribute_name='code', top=3.8*cm, left=12*cm, height=1.5*cm),

Label(text='Extended93', top=5.8*cm),
BarCode(type='Extended93', attribute_name='code', top=6.4*cm, height=1.5*cm),

Label(text='USPS FIM (code: "A")', top=5.8*cm, left=6*cm),
BarCode(type='FIM', attribute_name='code', top=6.4*cm, left=8*cm, height=1.5*cm,
get_value=lambda inst: 'A'),

Label(text='I2of5', top=5.8*cm, left=12*cm),
BarCode(type='I2of5', attribute_name='code', top=6.4*cm, left=12*cm, height=1.5*cm),

Label(text='MSI', top=8.4*cm),
BarCode(type='MSI', attribute_name='code', top=9*cm, height=1.5*cm),

Label(text='POSTNET', top=8.4*cm, left=6*cm),
BarCode(type='POSTNET', attribute_name='code', top=9*cm, left=6*cm, height=1.5*cm),

Label(text='Standard39', top=8.4*cm, left=12*cm),
BarCode(type='Standard39', attribute_name='code', top=9*cm, left=12*cm, height=1.5*cm),

Label(text='Standard93', top=11*cm),
BarCode(type='Standard93', attribute_name='code', top=11.6*cm, height=1.5*cm),

Label(text='USPS_4State / code: 01234567094987654321 / routing:', top=11*cm,
left=6*cm, width=10*cm),
ObjectValue(attribute_name='routing', top=11.5*cm, left=14*cm),
BarCode(type='USPS_4State', attribute_name='code', top=11.6*cm, left=6*cm,
height=1.5*cm, routing_attribute='routing',
get_value=lambda inst: '01234567094987654321'),
]
borders = {'bottom': True}

Creating a list of objects we are going to list on on the report

>>> objects_list = [
... dict(id=1, name='Arduino Duemilanove', code='123456789', routing='01234567891'),
... dict(id=2, name='Arduino Diecimila', code='000000000', routing='01234567891'),
... dict(id=3, name='Robotduino', code='111111111', routing='01234567891'),
... ]

Creating an instance of the report

>>> report = SimpleListReport(queryset=objects_list)

PDF generation

>>> from geraldo.generators import PDFGenerator
>>> report.generate_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/report-with-barcodes.pdf'))

The Result

- http://geraldo.svn.sourceforge.net/viewvc/geraldo/examples/report-with-barcodes.pdf

1 change: 1 addition & 0 deletions docs/source/examples/index.txt
Expand Up @@ -24,4 +24,5 @@ source code.
in-multiprocessing
using-events
additional-fonts
barcodes

1 change: 1 addition & 0 deletions docs/source/index.txt
Expand Up @@ -26,6 +26,7 @@ Content
basic
widgets
graphics
barcodes
generators
caching
utils
Expand Down
1 change: 1 addition & 0 deletions docs/source/next-steps.txt
Expand Up @@ -41,4 +41,5 @@ Other features
* **Caching generated reports** - (optionally) between **render_pages** and **generate_pages**
methods, make a hash key of rendered objects and find it on a cache (memcache or
file system), if does't find, generate and store it.
* **Drill down reports** - a link from a report "A" to a report "B"

Binary file added examples/additional-fonts.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/pdf2jpg
Expand Up @@ -16,4 +16,6 @@ convert charts-cairoplot-report.pdf charts-cairoplot-report.jpg
convert charts-matplotlib-report.pdf charts-matplotlib-report.jpg
convert inline-detail-report.pdf inline-detail-report.jpg
convert inline-detail-report-half-height.pdf inline-detail-report-half-height.jpg
convert additional-fonts.pdf additional-fonts.jpg
convert report-with-barcodes.pdf report-with-barcodes.jpg

Binary file added examples/report-with-barcodes.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion geraldo/__init__.py
Expand Up @@ -31,7 +31,7 @@
- tests - a package with automated doc tests.
"""

VERSION = (0, 4, 'alpha-4')
VERSION = (0, 4, 'alpha-5')

def get_version():
return '%d.%d-%s'%VERSION
Expand Down

0 comments on commit 05711bc

Please sign in to comment.