Here comes a script for imposing docs like business cards, postcards, flyers, 
etc. 
All it does is asking you for the sheet size, the doc size and the bleeds and 
then layouts image frames onto the sheet and puts the corresponding crop 
marks on.
Im working on a whole collection of scripts for imposing purposes like 
imposing tickets and having them numbered automatically, a more sophisticaded 
way of handling bleeds and crop marks, automatic generation of calibration 
bars, etc. It is going to take me a while as I am having too much work in our 
firm.

This collection is _NOT_ an imposition solution for scribus documents but 
rather semi automizes imposition tasks that are traditionally done with 
programs like FreeHand, Quark, etc.

===
from Tkinter import *
from scribus import *


class Application(Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.pack(fill=BOTH, expand=1)
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        self.sheetHeight = StringVar()
        self.sheetHeight.set("700")
        self.sheetWidth  = StringVar()
        self.sheetWidth.set("1000")
        self.pageHeight  = StringVar()
        self.pageHeight.set("55")
        self.pageWidth   = StringVar()
        self.pageWidth.set("85")
        self.bottomMargin= StringVar()
        self.bottomMargin.set("20")
        self.topMargin   = StringVar()
        self.topMargin.set("15")
        self.lateralMargin= StringVar()
        self.lateralMargin.set("5")
        self.bleed       = StringVar()
        self.bleed.set("2")
        self.units       = StringVar()
        self.units.set("mm")

        self.cols=StringVar()
        self.rows=StringVar()
        self.gaps=StringVar()
        self.colsOffset=None
        self.rowsOffset=None

        self.cropMarkSize=4
        self.cropMarkWidth=0.3

        self.sheetFrame = Frame(self, relief=GROOVE, borderwidth=2)
        self.sheetFrame.grid(row=0, column=1, columnspan=1, sticky=NW) 

        label = Label(self.sheetFrame, text="Sheet Width:")
        label.grid(row=0, column=1,sticky=E)

        self.sheetHeightEntry = Entry(self.sheetFrame, width=5, 
textvariable=self.sheetWidth)
        self.sheetHeightEntry.grid(row=0, column=2)
        self.sheetHeightEntry.bind("<FocusOut>",self.OnPageEntries)

        label = Label(self.sheetFrame, text="Sheet Height:")
        label.grid(row=1, column=1,sticky=E)

        self.sheetWidthEntry = Entry(self.sheetFrame, width=5, 
textvariable=self.sheetHeight)
        self.sheetWidthEntry.grid(row=1, column=2)
        self.sheetWidthEntry.bind("<FocusOut>",self.OnPageEntries)

        label = Label(self.sheetFrame, text="Top Margin:")
        label.grid(row=2, column=1,sticky=E)

        self.topMarginEntry = Entry(self.sheetFrame, width=5, 
textvariable=self.topMargin)
        self.topMarginEntry.grid(row=2, column=2)

        label = Label(self.sheetFrame, text="Bottom Margin:")
        label.grid(row=3, column=1,sticky=E)

        self.bottomMarginEntry = Entry(self.sheetFrame, width=5, 
textvariable=self.bottomMargin)
        self.bottomMarginEntry.grid(row=3, column=2)

        label = Label(self.sheetFrame, text="Lateral Margin:")
        label.grid(row=4, column=1,sticky=E)

        self.lateralMarginEntry = Entry(self.sheetFrame, width=5, 
textvariable=self.lateralMargin)
        self.lateralMarginEntry.grid(row=4, column=2)

        self.PageFrame = Frame(self, relief=GROOVE, borderwidth=2)
        self.PageFrame.grid(row=0, column=2, columnspan=1, sticky=NW) 

        label = Label(self.PageFrame, text="Page Width:")
        label.grid(row=0, column=1,sticky=E)

        self.PageWidthEntry = Entry(self.PageFrame, width=5, 
textvariable=self.pageWidth)
        self.PageWidthEntry.grid(row=0, column=2)
        self.PageWidthEntry.bind("<FocusOut>",self.OnPageEntries)

        label = Label(self.PageFrame, text="Page Height:")
        label.grid(row=1, column=1,sticky=E)

        self.pageHeightEntry = Entry(self.PageFrame, width=5, 
textvariable=self.pageHeight)
        self.pageHeightEntry.grid(row=1, column=2)
        self.pageHeightEntry.bind("<FocusOut>",self.OnPageEntries)

        label = Label(self.PageFrame, text="Bleed:")
        label.grid(row=2, column=1,sticky=E)

        self.bleedEntry = Entry(self.PageFrame, width=5, 
textvariable=self.bleed)
        self.bleedEntry.grid(row=2, column=2)

        self.buttonFrame = Frame(self, relief=GROOVE, borderwidth=2)
        self.buttonFrame.grid(row=1, column=1, columnspan=2, sticky=NW)

        self.okButton = Button(self.buttonFrame, text="OK", command=self.OnOk)
        self.okButton.grid(row=0, column=1, padx=5)

        self.cancelButton = Button(self.buttonFrame, text="Cancel", 
command=self.OnCancel)
        self.cancelButton.grid(row=0, column=2, padx=5)

        self.OptimizeButton = Button(self.buttonFrame, text="Best Fit", 
command=self.optimizeOrientation)
        self.OptimizeButton.grid(row=0, column=3, padx=5)

        self.UnitButton = OptionMenu(self.buttonFrame, self.units, "pts","mm", 
"in", 
"p")
        self.UnitButton.grid(row=0, column=4, padx=5)

        self.StatusFrame = Frame(self, relief=GROOVE, borderwidth=2)
        self.StatusFrame.grid(row=2, column=1, columnspan=3, sticky=N)

        label=Label(self.StatusFrame, text="Rows:")
        label.grid(row=0,column=1)

        label=Label(self.StatusFrame, textvariable=self.rows)
        label.grid(row=0,column=2)

        label=Label(self.StatusFrame, text="Columns:")
        label.grid(row=0,column=3)

        label=Label(self.StatusFrame, textvariable=self.cols)
        label.grid(row=0,column=4)

        label=Label(self.StatusFrame, text="Total:")
        label.grid(row=0,column=5)

        label=Label(self.StatusFrame, textvariable=self.gaps)
        label.grid(row=0,column=6)

#       self.testvar=StringVar()
#       label=Label(self.StatusFrame, textvariable=self.testvar)
#       label.grid(row=0,column=7)

        #set Rows and Cols
        self.__computeRowNum__()
        self.__computeColNum__()
        self.__computeGapNum__()
        ###



    def OnPageEntries(self,event):
        event.char
        self.__computeRowNum__()
        self.__computeColNum__()
        self.__computeGapNum__()

    def __computeGapNum__(self):
        self.gaps.set(int(self.cols.get())*int(self.rows.get()))

    def __computeRowNum__(self):
        height = 
int(self.sheetHeight.get())-(int(self.topMargin.get())+int(self.bottomMargin.get()))
        rows,rowsOffset = divmod(height,int(self.pageHeight.get()))
        self.rows.set(rows)
        self.rowsOffset=rowsOffset / 2.0

    def __computeColNum__(self):
        width = int(self.sheetWidth.get())-(int(self.lateralMargin.get())*2)
        cols, colsOffset = divmod(width,int(self.pageWidth.get()))
        self.cols.set(cols)
        self.colsOffset = colsOffset / 2.0

    def optimizeOrientation(self):
        width = int(self.sheetWidth.get())-(int(self.lateralMargin.get())*2)    
        height = 
int(self.sheetHeight.get())-(int(self.topMargin.get())+int(self.bottomMargin.get()))
        #now set hypothetical values for pageWidth and pageHeight
        pageWidth  = int(self.pageHeight.get())
        pageHeight = int(self.pageWidth.get())
        #compute hypothetical rows and cols...
        rows,rowsOffset = divmod(height,pageHeight)
        cols, colsOffset = divmod(width,pageWidth)  
        if rows*cols > (int(self.rows.get())*int(self.cols.get())):

            self.pageHeight.set(pageHeight)
            self.pageWidth.set(pageWidth)
            self.__computeRowNum__()
            self.__computeColNum__()
            self.__computeGapNum__()

    def createFrames(self):
        x = self.colsOffset+int(self.lateralMargin.get())
        y = self.rowsOffset+int(self.topMargin.get())

        for j in range(0,int(self.rows.get())):
            for i in range(0,int(self.cols.get())):

CreateImage(x+i*int(self.pageWidth.get()),y+j*int(self.pageHeight.get()),int(self.pageWidth.get()),int(self.pageHeight.get()))

    def createVerticalCropmarks(self,x):
        Offset = int(self.topMargin.get())+self.rowsOffset
        for i in range(0,int(self.rows.get())):
            y=Offset+int(self.pageHeight.get())*i+int(self.bleed.get())
            newLine = CreateLine(x-self.cropMarkSize,y,x,y)
            SetLineWidth(self.cropMarkWidth,newLine)

y=Offset+int(self.pageHeight.get())*i+int(self.pageHeight.get())-int(self.bleed.get())
            newLine = CreateLine(x-self.cropMarkSize,y,x,y)
            SetLineWidth(self.cropMarkWidth,newLine)

    def createHorizontalCropmarks(self,y):
        Offset = int(self.lateralMargin.get())+self.colsOffset
        for i in range(0,int(self.cols.get())):
            x=Offset+(int(self.pageWidth.get())*i+int(self.bleed.get()))
            newLine = CreateLine(x,y-self.cropMarkSize,x,y)
            SetLineWidth(self.cropMarkWidth,newLine)

x=Offset+(int(self.pageWidth.get())*i+int(self.pageWidth.get())-int(self.bleed.get()))
            newLine = CreateLine(x,y-self.cropMarkSize,x,y)
            SetLineWidth(self.cropMarkWidth,newLine)

    def OnOk(self):
        size           = 
(int(self.sheetWidth.get()),int(self.sheetHeight.get()))
        margins        = 
(int(self.lateralMargin.get()),int(self.lateralMargin.get()),int(self.topMargin.get()),int(self.bottomMargin.get()))
        orientation    = 0
        firstPageNumber= 1
#       unit           = 1
        FacingPages    = 0
        FirstSideLeft  = 0
        if self.units.get()=="pts": unit=0
        elif self.units.get()=="mm": unit=1
        elif self.units.get()=="in": unit=2
        elif self.units.get()=="p": unit=3

        
NewDoc(size,margins,orientation,firstPageNumber,unit,FacingPages,FirstSideLeft)
        #This should go in a different place
        self.__computeRowNum__()
        self.__computeColNum__()
        ###
        self.createFrames()
        
self.createVerticalCropmarks(self.colsOffset+int(self.lateralMargin.get()))

self.createVerticalCropmarks(int(self.sheetWidth.get())-(int(self.lateralMargin.get())+self.colsOffset-self.cropMarkSize))
        
self.createHorizontalCropmarks(self.rowsOffset+int(self.topMargin.get()))

self.createHorizontalCropmarks(int(self.sheetHeight.get())-(int(self.bottomMargin.get())+self.rowsOffset-self.cropMarkSize))
        self.master.destroy()

    def OnCancel(self):
        self.master.destroy()

root = Tk()
app = Application(root)
app.master.resizable(0, 0)
app.master.title("Impose by size")
app.mainloop()


Reply via email to