[Scribus] Python scripting: request for a printed introduction/feature
José Antonio Meira da Rocha
joseantoniorocha
Fri Jun 10 09:24:01 CEST 2005
2005/6/7, Christoph Sch?fer <christoph-schaefer at gmx.de>:
>
> 2. I have found a nice OOo macro on oomacros.org <http://oomacros.org>,
> and I think a similar
> functionality would be *extremely* useful for scribus. The macro
> "Seitenspiegel"
> (
> http://sourceforge.net/project/showfiles.php?group_id=87718&package_id=138122
> )
> sets the page margins/print space exactly the way Gutenberg did, which
> is (for good reasons) still standard in modern page layout. Since
> scribus doesn't (yet) support facing pages, I always used OOo and a
> calculator to set proper margins in scribus. The author of the macro is
> Christian Kotz, and it is released under the LPGL, so I'm sure I'm not
> violating any copyrights by disclosing it in this forum:
Hello, Mr. Sch?fer!
Thank you for your valuable information about the great Gutemberg.
I'm learning Python too, and made a Scribus Script that do the job you want.
The kernel logic is:
ratio = oStyle.Height / oStyle.Width REM Sqr(2.0)
pageWidth, pageHeight = scribus.getPageSize()
ratio = pageHeight / pageWidth
oStyle.TopMargin = oStyle.LeftMargin * ratio
> oStyle.RightMargin = oStyle.LeftMargin * 2
> oStyle.BottomMargin = oStyle.RightMargin * ratio
topMargin, leftMargin, rightMargin, bottomMargin = scribus.getPageMargins()
topMargin = leftMargin * ratio
rightMargin = leftMargin * 2
bottomMargin = rightMargin * ratio
The complete script:
------------------------------
#!/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</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 guides"""
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)
-----------------------------------------------
--
Prof. Ms. Jos? Antonio Meira da Rocha
joseantoniorocha at gmail.com
http://meiradarocha.jor.br
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://nashi.altmuehlnet.de/pipermail/scribus/attachments/20050610/c22d69c8/attachment.html
More information about the scribus
mailing list