Making layout grid with guides: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(Make a layout grid with guides)
 
No edit summary
Line 12: Line 12:
numLinStr1 = 'Número de linhas'  #How many rows
numLinStr1 = 'Número de linhas'  #How many rows
numLinStr2 = 'Quantas linhas de módulos?' #How many rows?
numLinStr2 = 'Quantas linhas de módulos?' #How many rows?
gutterStr1 = 'Largura da valeta' #Gutter measure
gapStr1 = 'Largura da valeta' #gap measure
gutterStr2 = 'Qual a largura das valetas em pontos?' #Gutter measure in points?
gapStr2 = 'Qual a largura das valetas em pontos?' #gap measure in points?
TITLE = "Gera linhas-guia" #Generate guides
TITLE = "Gera linhas-guia" #Generate guides
noDocMsg = "<h2>Abra um documento, primeiramente</h2>Ops! Este script só funciona com um documento aberto. <b>Abra um documento</b> antes de rodar o script." # <h2>First, open a doc</h2>This script only work on opened document. <b>Open a document</b> before run this script.
noDocMsg = "<h2>Abra um documento, primeiramente</h2>Ops! Este script só funciona com um documento aberto. <b>Abra um documento</b> antes de rodar o script." # <h2>First, open a doc</h2>This script only work on opened document. <b>Open a document</b> before run this script.
Line 22: Line 22:
defaultNumColumns = '5'
defaultNumColumns = '5'
defaultNumRows = '8'
defaultNumRows = '8'
defaultGutter = '14.1732' #In points, due a bug in getPageMargins
defaultGap = '14.1732' #In points, due a bug in getPageMargins


""" You don't need change nothing below this line """
""" You don't need change nothing below this line """
Line 39: Line 39:
         numColumns = int(scribus.valueDialog(numColStr1, numColStr2, defaultNumColumns))
         numColumns = int(scribus.valueDialog(numColStr1, numColStr2, defaultNumColumns))
         numRows = int(scribus.valueDialog(numLinStr1, numLinStr2, defaultNumRows))
         numRows = int(scribus.valueDialog(numLinStr1, numLinStr2, defaultNumRows))
         gutter = float(scribus.valueDialog(gutterStr1, gutterStr2, defaultGutter))
         gap = float(scribus.valueDialog(gapStr1, gapStr2, defaultGap))
         unit = scribus.getUnit()  # save original unit
         unit = scribus.getUnit()  # save original unit
         scribus.setUnit(UNIT_POINTS) # working in points, due a bug in getPageMargins
         scribus.setUnit(UNIT_POINTS) # working in points, due a bug in getPageMargins
       
         pageSize = scribus.getPageSize()
         pageSize = scribus.getPageSize()
         pageWidth = pageSize[0]
         pageWidth = pageSize[0]
         pageHeight = pageSize[1]
         pageHeight = pageSize[1]
       
         pageMargins = scribus.getPageMargins()
         pageMargins = scribus.getPageMargins()
         leftMargin  = pageMargins[0]
         leftMargin  = pageMargins[0]
Line 50: Line 52:
         topMargin    = pageMargins[2]
         topMargin    = pageMargins[2]
         bottomMargin = pageMargins[3]
         bottomMargin = pageMargins[3]
       
         printArea = ([  
         printArea = ([  
             pageWidth - leftMargin - rightMargin,  
             pageWidth - leftMargin - rightMargin,  
             pageHeight - topMargin - bottomMargin  
             pageHeight - topMargin - bottomMargin  
         ])
         ])
         numVGutters = numColumns-1
         numVgaps = numColumns-1
         numHGutters = numRows-1
         numHgaps = numRows-1
         columnWidth = ((printArea[0]-(numVGutters*gutter)) / numColumns)
         columnWidth = ((printArea[0]-(numVgaps*gap)) / numColumns)
         rowHeight = ((printArea[1]-(numHGutters*gutter)) / numRows )
         rowHeight = ((printArea[1]-(numHgaps*gap)) / numRows )
       
         VGuides = []
         VGuides = []
         HGuides = []
         HGuides = []
         for i in range(1,numColumns):
         for i in range(1,numColumns):
             res = pageMargins[0]+(i*columnWidth)+((i-1)*gutter)
             res = pageMargins[0]+(i*columnWidth)+((i-1)*gap)
             VGuides.append(res)
             VGuides.append(res)
             VGuides.append(res+gutter)
             VGuides.append(res+gap)
         scribus.setVGuides(VGuides)
         scribus.setVGuides(VGuides)
         for i in range(1,numRows):  
         for i in range(1,numRows):  
             res = pageMargins[3]+(i*rowHeight)+((i-1)*gutter)
             res = pageMargins[3]+(i*rowHeight)+((i-1)*gap)
             HGuides.append(res)
             HGuides.append(res)
             HGuides.append(res+gutter)
             HGuides.append(res+gap)
         scribus.setHGuides(HGuides)
         scribus.setHGuides(HGuides)
          
          

Revision as of 22:06, 17 April 2005

This script make a "layout grid" useful for newspapers and magazines.

#!/usr/bin/env python2.3
# -*- coding: utf-8 -*-

import sys

"""Locale strings to be translated """
numColStr1 = 'Número de colunas' #How many columns
numColStr2 = 'Quantas colunas?'  #How many columns?
numLinStr1 = 'Número de linhas'  #How many rows
numLinStr2 = 'Quantas linhas de módulos?' #How many rows?
gapStr1 = 'Largura da valeta' #gap measure
gapStr2 = 'Qual a largura das valetas em pontos?' #gap measure in points?
TITLE = "Gera linhas-guia" #Generate guides
noDocMsg = "<h2>Abra um documento, primeiramente</h2>Ops! Este script só funciona com um documento aberto. <b>Abra um documento</b> antes de rodar o script." # <h2>First, open a doc</h2>This script only work on opened document. <b>Open a document</b> before run this script.
runningMsg = "Rodando o script..." #"Running script..."
noScribusMsg = "This Python script is written for the Scribus scripting interface.\nIt can only be run from within Scribus."

""" Feel free to change defaults"""
defaultNumColumns = '5'
defaultNumRows = '8'
defaultGap = '14.1732' #In points, due a bug in getPageMargins

""" You don't need change nothing below this line """
try:
    import scribus
except ImportError,err:
    print noScribusMsg
    sys.exit(1)
    
from scribus import UNIT_POINTS,BUTTON_OK,ICON_WARNING

def main(argv):
    """Generate guides"""
    if scribus.haveDoc():
        scribus.setRedraw(False)
        numColumns = int(scribus.valueDialog(numColStr1, numColStr2, defaultNumColumns))
        numRows = int(scribus.valueDialog(numLinStr1, numLinStr2, defaultNumRows))
        gap = float(scribus.valueDialog(gapStr1, gapStr2, defaultGap))
        unit = scribus.getUnit()  # save original unit
        scribus.setUnit(UNIT_POINTS) # working in points, due a bug in getPageMargins
        
        pageSize = scribus.getPageSize()
        pageWidth = pageSize[0]
        pageHeight = pageSize[1]
        
        pageMargins = scribus.getPageMargins()
        leftMargin   = pageMargins[0]
        rightMargin  = pageMargins[1]
        topMargin    = pageMargins[2]
        bottomMargin = pageMargins[3]
        
        printArea = ([ 
            pageWidth - leftMargin - rightMargin, 
            pageHeight - topMargin - bottomMargin 
        ])
        numVgaps = numColumns-1
        numHgaps = numRows-1
        columnWidth = ((printArea[0]-(numVgaps*gap)) / numColumns)
        rowHeight = ((printArea[1]-(numHgaps*gap)) / numRows )
        
        VGuides = []
        HGuides = []
        for i in range(1,numColumns):
            res = pageMargins[0]+(i*columnWidth)+((i-1)*gap)
            VGuides.append(res)
            VGuides.append(res+gap)
        scribus.setVGuides(VGuides)
        for i in range(1,numRows): 
            res = pageMargins[3]+(i*rowHeight)+((i-1)*gap)
            HGuides.append(res)
            HGuides.append(res+gap)
        scribus.setHGuides(HGuides)
        
        scribus.setUnit(unit) # restore original unit
        
    else:
        scribus.messageBox(TITLE, noDocMsg, ICON_WARNING, BUTTON_OK)

def main_wrapper(argv):
    try:
        scribus.statusMessage(runningMsg)
        scribus.progressReset()
        main(argv)
    finally:
        if scribus.haveDoc():
            scribus.setRedraw(True)
        scribus.statusMessage("")
        scribus.progressReset()

if __name__ == '__main__':
    main_wrapper(sys.argv)