Drawing a grid: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(inserted code)
 
(inserted code)
Line 1: Line 1:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
 
"""
"""
DESCRIPTION & USAGE:
DESCRIPTION & USAGE:
This script needs Tkinter. It will create a GUI with available options
This script needs Tkinter. It will create a GUI with available options
for easy grid creation. You'll geta grid a the specified position.
for easy grid creation. You'll geta grid a the specified position.
The units are the same as you documents.
The units are the same as you documents.
 
Steps to create:
Steps to create:
    1) Fill requested values in the Grid dialog
    1) Fill requested values in the Grid dialog
 
AUTHOR:
AUTHOR:
    Rüdiger Härtel <r_haertel [at] gmx [dot] de>
    Rüdiger Härtel <r_haertel [at] gmx [dot] de>
 
LICENSE:
LICENSE:
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
"""
"""
 
import sys
import sys
 
try:
try:
    import scribus
    import scribus
except ImportError,err:
except ImportError,err:
    print 'This Python script is written for the Scribus scripting interface.'
    print 'This Python script is written for the Scribus scripting interface.'
    print 'It can only be run from within Scribus.'
    print 'It can only be run from within Scribus.'
    sys.exit(1)
    sys.exit(1)
 
try:
try:
    # I wish PyQt installed everywhere :-/
    # I wish PyQt installed everywhere :-/
    from Tkinter import *
    from Tkinter import *
    from tkFont import Font
    from tkFont import Font
except ImportError:
except ImportError:
    print "This script requires Python's Tkinter properly installed."
    print "This script requires Python's Tkinter properly installed."
    messageBox('Script failed',
    messageBox('Script failed',
              'This script requires Python\'s Tkinter properly installed.',
                'This script requires Python\'s Tkinter properly installed.',
              ICON_CRITICAL)
                ICON_CRITICAL)
    sys.exit(1)
    sys.exit(1)
 
 
def grid(x,y,width,height,xstep,ystep,color):
def grid(x,y,width,height,xstep,ystep,color):
    """ """
    """ """
    xend = x + width
    xend = x + width
    yend = y + height
    yend = y + height
   
   
    for _x in range(x,xend+1,xstep):
    for _x in range(x,xend+1,xstep):
        line = scribus.createLine(_x,y,_x,yend)
          line = scribus.createLine(_x,y,_x,yend)
        scribus.setLineColor(color, line)
          scribus.setLineColor(color, line)
   
   
    for _y in range(y,yend+1,ystep):
    for _y in range(y,yend+1,ystep):
        line = scribus.createLine(x,_y,xend,_y)
          line = scribus.createLine(x,_y,xend,_y)
        scribus.setLineColor(color, line)
          scribus.setLineColor(color, line)
 
 
class TkGrid(Frame):
class TkGrid(Frame):
    """ GUI interface for Scribus calendar wizard.
    """ GUI interface for Scribus calendar wizard.
        It's ugly and very simple. I can say I hate Tkinter :-/"""
        It's ugly and very simple. I can say I hate Tkinter :-/"""
   
   
    def __init__(self, master=None):
    def __init__(self, master=None):
        """ Setup the dialog """
        """ Setup the dialog """
        # reference to the localization dictionary
        # reference to the localization dictionary
        self.key = 'default'
        self.key = 'default'
        Frame.__init__(self, master)
        Frame.__init__(self, master)
        self.grid()
        self.grid()
        self.master.title('Scribus Grid Wizard')
        self.master.title('Scribus Grid Wizard')
       
       
        #define variables
        #define variables
        self.x = IntVar()
        self.x = IntVar()
        self.y = IntVar()
        self.y = IntVar()
       
       
        self.w = IntVar()
        self.w = IntVar()
        self.h = IntVar()
        self.h = IntVar()
       
       
        self.xs = IntVar()
        self.xs = IntVar()
        self.ys = IntVar()
        self.ys = IntVar()
       
       
        # default values
        # default values
        self.x.set(15)
        self.x.set(15)
        self.y.set(15)
        self.y.set(15)
        self.w.set(100)
        self.w.set(100)
        self.h.set(100)
        self.h.set(100)
        self.xs.set(5)
        self.xs.set(5)
        self.ys.set(5)
        self.ys.set(5)
       
       
        #define widgets
        #define widgets
        self.xLabel = Label(self, text='x-Pos')
        self.xLabel = Label(self, text='x-Pos')
        self.yLabel = Label(self, text='y-Pos')
        self.yLabel = Label(self, text='y-Pos')
       
       
        self.wLabel = Label(self, text='Width')
        self.wLabel = Label(self, text='Width')
        self.hLabel = Label(self, text='Height')
        self.hLabel = Label(self, text='Height')
       
       
        self.xsLabel = Label(self, text='x-Step')
        self.xsLabel = Label(self, text='x-Step')
        self.ysLabel = Label(self, text='y-Step')
        self.ysLabel = Label(self, text='y-Step')
       
       
        self.xEntry = Entry(self, textvariable=self.x, width=4)
        self.xEntry = Entry(self, textvariable=self.x, width=4)
        self.yEntry = Entry(self, textvariable=self.y, width=4)
        self.yEntry = Entry(self, textvariable=self.y, width=4)
       
       
        self.wEntry = Entry(self, textvariable=self.w, width=4)
        self.wEntry = Entry(self, textvariable=self.w, width=4)
        self.hEntry = Entry(self, textvariable=self.h, width=4)
        self.hEntry = Entry(self, textvariable=self.h, width=4)
       
       
        self.xsEntry = Entry(self, textvariable=self.xs, width=4)
        self.xsEntry = Entry(self, textvariable=self.xs, width=4)
        self.ysEntry = Entry(self, textvariable=self.ys, width=4)
        self.ysEntry = Entry(self, textvariable=self.ys, width=4)
       
       
        self.okButton = Button(self, text="  OK  ", width=6, command=self.okButon_pressed)
        self.okButton = Button(self, text="  OK  ", width=6, command=self.okButon_pressed)
        self.cancelButton = Button(self, text="Cancel", command=self.quit)
        self.cancelButton = Button(self, text="Cancel", command=self.quit)
       
       
        self.xLabel.grid(column=0,row=0,padx=5,pady=5)
        self.xLabel.grid(column=0,row=0,padx=5,pady=5)
        self.xEntry.grid(column=1,row=0)
        self.xEntry.grid(column=1,row=0)
       
       
        self.yLabel.grid(column=0,row=1,padx=5,pady=5)
        self.yLabel.grid(column=0,row=1,padx=5,pady=5)
        self.yEntry.grid(column=1,row=1)
        self.yEntry.grid(column=1,row=1)
       
       
        self.wLabel.grid(column=2,row=0,padx=5,pady=5)
        self.wLabel.grid(column=2,row=0,padx=5,pady=5)
        self.wEntry.grid(column=3,row=0)
        self.wEntry.grid(column=3,row=0)
        self.hLabel.grid(column=2,row=1,padx=5,pady=5)
        self.hLabel.grid(column=2,row=1,padx=5,pady=5)
        self.hEntry.grid(column=3,row=1)
        self.hEntry.grid(column=3,row=1)
       
       
        self.xsLabel.grid(column=0,row=2,padx=5,pady=5)
        self.xsLabel.grid(column=0,row=2,padx=5,pady=5)
        self.xsEntry.grid(column=1,row=2)
        self.xsEntry.grid(column=1,row=2)
        self.ysLabel.grid(column=0,row=3,padx=5,pady=5)
        self.ysLabel.grid(column=0,row=3,padx=5,pady=5)
        self.ysEntry.grid(column=1,row=3,padx=5)
        self.ysEntry.grid(column=1,row=3,padx=5)
       
       
        self.okButton.grid(column=0,columnspan=2,row=4)
        self.okButton.grid(column=0,columnspan=2,row=4)
        self.cancelButton.grid(column=2,columnspan=2,row=4,padx=5,pady=5)
        self.cancelButton.grid(column=2,columnspan=2,row=4,padx=5,pady=5)
 
    def okButon_pressed(self):
    def okButon_pressed(self):
        grid(self.x.get(),self.y.get(),self.w.get(),self.h.get(),self.xs.get(),self.ys.get(),"Black")
        grid(self.x.get(),self.y.get(),self.w.get(),self.h.get(),self.xs.get(),self.ys.get(),"Black")
        self.quit()
        self.quit()
 
    def quit(self):
    def quit(self):
        self.master.destroy()
        self.master.destroy()
 
def main():
def main():
    """ Application/Dialog loop with Scribus sauce around """
    """ Application/Dialog loop with Scribus sauce around """
    if scribus.haveDoc() == 0:
    if scribus.haveDoc() == 0:
scribus.messageBox("Error", "Please create a Document", ICON_WARNING, BUTTON_OK)
scribus.messageBox("Error", "Please create a Document", ICON_WARNING, BUTTON_OK)
return
return
   
   
    try:
    try:
        scribus.statusMessage('Running script...')
        scribus.statusMessage('Running script...')
        scribus.progressReset()
        scribus.progressReset()
        root = Tk()
        root = Tk()
        app = TkGrid(root)
        app = TkGrid(root)
        root.mainloop()
        root.mainloop()
    finally:
    finally:
        if scribus.haveDoc():
        if scribus.haveDoc():
            scribus.redrawAll()
            scribus.redrawAll()
        scribus.statusMessage('Done.')
        scribus.statusMessage('Done.')
        scribus.progressReset()
        scribus.progressReset()
 
if __name__ == '__main__':
if __name__ == '__main__':
    main()
    main()

Revision as of 19:49, 11 December 2006

# -*- coding: utf-8 -*-

"""
DESCRIPTION & USAGE:
This script needs Tkinter. It will create a GUI with available options
for easy grid creation. You'll geta grid a the specified position.
The units are the same as you documents.

Steps to create:
    1) Fill requested values in the Grid dialog

AUTHOR:
    Rüdiger Härtel <r_haertel [at] gmx [dot] de>

LICENSE:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""

import sys

try:
    import scribus
except ImportError,err:
    print 'This Python script is written for the Scribus scripting interface.'
    print 'It can only be run from within Scribus.'
    sys.exit(1)

try:
    # I wish PyQt installed everywhere :-/
    from Tkinter import *
    from tkFont import Font
except ImportError:
    print "This script requires Python's Tkinter properly installed."
    messageBox('Script failed',
               'This script requires Python\'s Tkinter properly installed.',
               ICON_CRITICAL)
    sys.exit(1)


def grid(x,y,width,height,xstep,ystep,color):
    """ """
    xend = x + width
    yend = y + height
    
    for _x in range(x,xend+1,xstep):
         line = scribus.createLine(_x,y,_x,yend)
         scribus.setLineColor(color, line)
    
    for _y in range(y,yend+1,ystep):
         line = scribus.createLine(x,_y,xend,_y)
         scribus.setLineColor(color, line)


class TkGrid(Frame):
    """ GUI interface for Scribus calendar wizard.
        It's ugly and very simple. I can say I hate Tkinter :-/"""
    
    def __init__(self, master=None):
        """ Setup the dialog """
        # reference to the localization dictionary
        self.key = 'default'
        Frame.__init__(self, master)
        self.grid()
        self.master.title('Scribus Grid Wizard')
        
        #define variables
        self.x = IntVar()
        self.y = IntVar()
        
        self.w = IntVar()
        self.h = IntVar()
        
        self.xs = IntVar()
        self.ys = IntVar()
        
        # default values
        self.x.set(15)
        self.y.set(15)
        self.w.set(100)
        self.h.set(100)
        self.xs.set(5)
        self.ys.set(5)
        
        #define widgets
        self.xLabel = Label(self, text='x-Pos')
        self.yLabel = Label(self, text='y-Pos')
        
        self.wLabel = Label(self, text='Width')
        self.hLabel = Label(self, text='Height')
        
        self.xsLabel = Label(self, text='x-Step')
        self.ysLabel = Label(self, text='y-Step')
        
        self.xEntry = Entry(self, textvariable=self.x, width=4)
        self.yEntry = Entry(self, textvariable=self.y, width=4)
        
        self.wEntry = Entry(self, textvariable=self.w, width=4)
        self.hEntry = Entry(self, textvariable=self.h, width=4)
        
        self.xsEntry = Entry(self, textvariable=self.xs, width=4)
        self.ysEntry = Entry(self, textvariable=self.ys, width=4)
        
        self.okButton = Button(self, text="   OK   ", width=6, command=self.okButon_pressed)
        self.cancelButton = Button(self, text="Cancel", command=self.quit)
        
        self.xLabel.grid(column=0,row=0,padx=5,pady=5)
        self.xEntry.grid(column=1,row=0)
        
        self.yLabel.grid(column=0,row=1,padx=5,pady=5)
        self.yEntry.grid(column=1,row=1)
        
        self.wLabel.grid(column=2,row=0,padx=5,pady=5)
        self.wEntry.grid(column=3,row=0)
        self.hLabel.grid(column=2,row=1,padx=5,pady=5)
        self.hEntry.grid(column=3,row=1)
        
        self.xsLabel.grid(column=0,row=2,padx=5,pady=5)
        self.xsEntry.grid(column=1,row=2)
        self.ysLabel.grid(column=0,row=3,padx=5,pady=5)
        self.ysEntry.grid(column=1,row=3,padx=5)
        
        self.okButton.grid(column=0,columnspan=2,row=4)
        self.cancelButton.grid(column=2,columnspan=2,row=4,padx=5,pady=5)

    def okButon_pressed(self):
        grid(self.x.get(),self.y.get(),self.w.get(),self.h.get(),self.xs.get(),self.ys.get(),"Black")
        self.quit()

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

def main():
    """ Application/Dialog loop with Scribus sauce around """
    if scribus.haveDoc() == 0:
	scribus.messageBox("Error", "Please create a Document", ICON_WARNING, BUTTON_OK)
	return
    
    try:
        scribus.statusMessage('Running script...')
        scribus.progressReset()
        root = Tk()
        app = TkGrid(root)
        root.mainloop()
    finally:
        if scribus.haveDoc():
            scribus.redrawAll()
        scribus.statusMessage('Done.')
        scribus.progressReset()

if __name__ == '__main__':
    main()