1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens# Copyright (C) 2014 Martin Owens
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# This program is free software; you can redistribute it and/or modify
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# it under the terms of the GNU General Public License as published by
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# the Free Software Foundation; either version 2 of the License, or
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# (at your option) any later version.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# This program is distributed in the hope that it will be useful,
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# but WITHOUT ANY WARRANTY; without even the implied warranty of
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# GNU General Public License for more details.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# You should have received a copy of the GNU General Public License
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# along with this program; if not, write to the Free Software
107e00c8104649437b9520d0ba298dba659e7cd7JazzyNico# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico"""
12a239f8730c2bb6e3738d5e75b3237877594d07Martin OwensRenderer for barcodes, SVG extention for Inkscape.
040e298be5b23e77e33309d65449072183c82d5cacspike
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoFor supported barcodes see Barcode module directory.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico"""
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspike# This lists all known Barcodes missing from this package
040e298be5b23e77e33309d65449072183c82d5cacspike# ===== UPC-Based Extensions ====== #
040e298be5b23e77e33309d65449072183c82d5cacspike# Code11
040e298be5b23e77e33309d65449072183c82d5cacspike# ========= Code25-Based ========== #
040e298be5b23e77e33309d65449072183c82d5cacspike# Codabar
040e298be5b23e77e33309d65449072183c82d5cacspike# Postnet
040e298be5b23e77e33309d65449072183c82d5cacspike# ITF25
040e298be5b23e77e33309d65449072183c82d5cacspike# ========= Alpha-numeric ========= #
040e298be5b23e77e33309d65449072183c82d5cacspike# Code39Mod
040e298be5b23e77e33309d65449072183c82d5cacspike# USPS128
040e298be5b23e77e33309d65449072183c82d5cacspike# =========== 2D Based ============ #
040e298be5b23e77e33309d65449072183c82d5cacspike# PDF417
040e298be5b23e77e33309d65449072183c82d5cacspike# PDF417-Macro
040e298be5b23e77e33309d65449072183c82d5cacspike# PDF417-Truncated
040e298be5b23e77e33309d65449072183c82d5cacspike# PDF417-GLI
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspikeimport sys
040e298be5b23e77e33309d65449072183c82d5cacspike
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owensclass NoBarcode(object):
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens """Simple class for no barcode"""
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens def generate(self):
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens return None
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owensdef getBarcode(code, **kw):
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens """Gets a barcode from a list of available barcode formats"""
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens if not code:
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens return sys.stderr.write("No barcode format given!\n")
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens code = str(code).replace('-', '').strip()
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens mod = 'Barcode'
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens try:
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens return getattr(__import__(mod+'.'+code, fromlist=[mod]), code)(kw)
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens except ImportError:
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens sys.stderr.write("Invalid type of barcode: %s\n" % code)
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens except AttributeError:
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens sys.stderr.write("Barcode module is missing barcode class: %s\n" % code)
ad9933c3bdd809813acc78673fcc580cd326bcd6Martin Owens return NoBarcode()
040e298be5b23e77e33309d65449072183c82d5cacspike