Difference between revisions of "Making margins in Guttenberg way"

From Scribus Wiki
Jump to: navigation, search
(Make proportional margins à la Gutemberg)
 
m
Line 1: Line 1:
This script makes propotional margins in Gutemberg way, based in left margin value. Scribus automaticaly mirror margin in facing page documents.
+
This script makes proportional margins in Gutemberg way, based in left margin value. Scribus automaticaly mirror margin in facing page documents.
  
 
Made après Sitespiegel OpenOffice.org macro.
 
Made après Sitespiegel OpenOffice.org macro.
  
-- José Antonio Rocha
+
--[[User:Meira|Meira da Rocha]] 18:37, 10 Jun 2005 (UTC)
joseantoniorocha@gmail.com
 
http://meiradarocha.jor.br
 
  
 
  #!/usr/bin/env python2.3
 
  #!/usr/bin/env python2.3

Revision as of 18:37, 10 June 2005

This script makes proportional margins in Gutemberg way, based in left margin value. Scribus automaticaly mirror margin in facing page documents.

Made après Sitespiegel OpenOffice.org macro.

--Meira da Rocha 18:37, 10 Jun 2005 (UTC)

#!/usr/bin/env python2.3
# -*- coding: utf-8 -*-
"""Generate margins according Gutemberg way.
"""
import sys
 
"""Locale strings to be translated """
TITLE = "Generate margins"
noDocMsg = "<h2>First, open a doc</h2>This script only work on opened document.\
<b>Open a document&lt/b> before run this script." 
runningMsg = "Running script..." 
noScribusMsg = "This Python script is written for the Scribus scripting interface.\
\nIt can only be run from within Scribus." 

try:
    import scribus
except ImportError,err:
    print noScribusMsg
    sys.exit(1)
    
from scribus import UNIT_POINTS,BUTTON_OK,ICON_WARNING

def main(argv):
    """Generate margins"""
    if scribus.haveDoc():
        scribus.setRedraw(False)
        unit = scribus.getUnit()  # save original unit
        scribus.setUnit(UNIT_POINTS) # working in points, due a bug in getPageMargins
        
        pageWidth, pageHeight = scribus.getPageSize()
        ratio = pageHeight / pageWidth
        topMargin, leftMargin, rightMargin, bottomMargin = scribus.getPageMargins()
        topMargin = leftMargin * ratio
        rightMargin = leftMargin * 2
        bottomMargin = rightMargin * ratio
        scribus.setMargins(leftMargin, rightMargin, topMargin, bottomMargin)
        
        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)