1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2007 Martin Owens
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
20 import inkex
21 import sys
22 from Barcode import getBarcode
24 class InsertBarcode(inkex.Effect):
25 def __init__(self):
26 inkex.Effect.__init__(self)
27 self.OptionParser.add_option("-l", "--height",
28 action="store", type="int",
29 dest="height", default=30,
30 help="Barcode Height")
31 self.OptionParser.add_option("-t", "--type",
32 action="store", type="string",
33 dest="type", default='',
34 help="Barcode Type")
35 self.OptionParser.add_option("-d", "--text",
36 action="store", type="string",
37 dest="text", default='',
38 help="Text to print on barcode")
40 def effect(self):
41 x, y = self.view_center
42 object = getBarcode( self.options.type, {
43 'text' : self.options.text,
44 'height' : self.options.height,
45 'document' : self.document,
46 'x' : x,
47 'y' : y,
48 } )
49 if object is not None:
50 barcode = object.generate()
51 if barcode is not None:
52 self.current_layer.append(barcode)
53 else:
54 sys.stderr.write("No barcode was generated\n")
55 else:
56 sys.stderr.write("Unable to make barcode with: " + str(self.options) + "\n")
58 if __name__ == '__main__':
59 e = InsertBarcode()
60 e.affect()