Generating a Postnet barcode

From Scribus Wiki
Revision as of 03:44, 28 February 2006 by Gpittman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/usr/bin/env python

# File: postnet.py
# originally created 2006.02.26

import scribus
import Tkinter

class ImageDialog(Tkinter.Toplevel):
    
    def __init__(self, parent):
        Tkinter.Toplevel.__init__(self, parent, bg="#bbbbff")

        Tkinter.Label(self, text='Enter the Postal Code, Click OK',bg="#bbbbff").grid(row=0,columnspan=6)

        self.e = Tkinter.Entry(self)
        self.e.grid(row=1,columnspan=6)
        b = Tkinter.Button(self, text='OK', bg="#55ff88", command=self.ok)
        b.grid(row=2,columnspan=6)
        self.protocol("WM_DELETE_WINDOW", self.quit)

    def ok(self):
        S = self.e.get()
        m = Tkinter.Message(root, text=self.e.get()+'\nClose this\n window')
        m.grid(row=0, columnspan=4)
        postcode = ['llsss','sssll','sslsl','sslls','slssl','slsls','sllss','lsssl','lssls','lslss']
        a = 1.44      #line width
        b="Black"     #line color
        relx=130      #Start X
        rely=130      #Start Y
        if scribus.haveDoc():
            scribus.setRedraw(1)
            scribus.setUnit(0)
            d = scribus.createLine(relx,rely,relx+9,rely,) #Long line
            scribus.setLineWidth(a, d)
            scribus.setLineColor(b, d)
            scribus.setFillColor(b, d)
            rely = rely + 3.4
            for x in S[0:]:
               if x.isdigit():
                  xnum = int(x)
                  code = postcode[xnum]
                  for y in code[0:]:
                     if y == 'l':
                        d = scribus.createLine(relx,rely,relx+9,rely,) #Long line
                        scribus.setLineWidth(a, d)
                        scribus.setLineColor(b, d)
                        scribus.setFillColor(b, d)
                        rely = rely + 3.4
                     elif y == 's':
                        d = scribus.createLine(relx,rely,relx+3.6,rely,) #short line
                        scribus.setLineWidth(a, d)
                        scribus.setLineColor(b, d)
                        scribus.setFillColor(b, d)
                        rely = rely + 3.4
            d = scribus.createLine(relx,rely,relx+9,rely,) #long line
            scribus.setLineWidth(a, d)
            scribus.setLineColor(b, d)
            scribus.setFillColor(b, d)
            
            redrawAll()
            self.Tkinter.Toplevel.destroy()

root = Tkinter.Tk()
root.update()
z = ImageDialog(root)
root.wait_window(z)