Code

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