[Scribus] Please help with 'simple' scripting task - print the current document

Bill Hudacek bill.hudacek
Fri Jun 22 14:48:17 CEST 2007


Sorry, thunderbird is not honoring 'Reply-To:' for emails on this list...

At this point, I'm either going to have to start over, using Gregory's 
approach and build a 90-page document, or use ms-word and vba :-/

Please help.  Is there no way to cause the document to print, on the 
default printer, from a script?

TIA

/Bill

Bill Hudacek wrote:
>
> Christoph Sch?fer wrote:
>> Hi Bill,
>>
>> I'm not sure I understood correctly what you mean. Do you mean you 
>> can't let Scribus print using Python scripts? Is your printer not 
>> working? Anything else?
>>
>> Christoph
>>   
>
> Hi, Christoph -
>
> I read your reply, and Gregory's (wow, that was alot of information!  
> I've saved it to study later :)
>
> I'm sorry if I made it seem so difficult.  I already have a real, 
> working solution.  I just need to print the current page of the 
> current document to the default printer.  The document is only one page.
> I have four 'tickets' all laid out, and small text boxes in 8 places 
> to insert the ticket number.  The text boxes are named (num11, num12 
> for the first ticket stub and ticket)...my script works great at 
> numbering & setting the text box values.  But, after numbering the 
> boxes 0001-0004, for instance, I need to print it on my printer.  Then 
> I need to set up tickets 5-8, and print again...
>
> I tried
>
>    Printer.print()
>    scribus.print()
>    self.print()
>    etc.
>
> I get syntax errors with every attempt.  It must be simple, but I 
> don't know the python interface very well at all.  Isn't there a 
> simple way to just have the document print, with all printer defaults? 
> I don't want to print to PDF - just the printer.
>
> I'm pasting the script here, in the hopes that it'll help you help 
> me.  It's based on the boilerplate.py script that's included with 
> Scribus.
>
> Thanks for the responses so far! I feel like I'm so close......
>
> /Bill
>
> #!/usr/bin/env python2.4
> # -*- coding: utf-8 -*-
>
> import sys
>
> try:
>    # Please do not use 'from scribus import *' . If you must use a 
> 'from import',
>    # Do so _after_ the 'import scribus' and only import the names you 
> need, such
>    # as commonly used constants.
>    import scribus
>    from scribus import progressTotal
>    from scribus import progressSet
>    from scribus import setText
>    from scribus import messageBox
>    from scribus import Printer
> 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)
>
> #########################
> # YOUR IMPORTS GO HERE  #
> #########################
>
> def main(argv):
>    """This is a documentation string. Write a description of what your 
> code
>    does here. You should generally put documentation strings 
> ("docstrings")
>    on all your Python functions."""
>    #########################
>    #  YOUR CODE GOES HERE  #
>    #########################
>    # 352 pages at 4 tickets/page == 88 pages to complete
>    pageLimit=88
>    idx=0
>    for idx in range(1,pageLimit):
>        setText(unicode(("00" + `(idx*2)+0`)[-3:], 'iso-8859-1'), "num11")
>        setText(unicode(("00" + `(idx*2)+0`)[-3:], 'iso-8859-1'), "num12")
>        setText(unicode(("00" + `(idx*2)+1`)[-3:], 'iso-8859-1'), "num21")
>        setText(unicode(("00" + `(idx*2)+1`)[-3:], 'iso-8859-1'), "num22")
>        setText(unicode(("00" + `(idx*2)+2`)[-3:], 'iso-8859-1'), "num31")
>        setText(unicode(("00" + `(idx*2)+2`)[-3:], 'iso-8859-1'), "num32")
>        setText(unicode(("00" + `(idx*2)+3`)[-3:], 'iso-8859-1'), "num41")
>        setText(unicode(("00" + `(idx*2)+3`)[-3:], 'iso-8859-1'), "num42")
>        idx+=1
>        # this is the line that's broken...
>        Printer.print()
>
> def main_wrapper(argv):
>    """The main_wrapper() function disables redrawing, sets a sensible 
> generic
>    status bar message, and optionally sets up the progress bar. It 
> then runs
>    the main() function. Once everything finishes it cleans up after 
> the main()
>    function, making sure everything is sane before the script 
> terminates."""
>    try:
>        scribus.statusMessage("Running script...")
>        scribus.progressReset()
>        main(argv)
>    finally:
>        # Exit neatly even if the script terminated with an exception,
>        # so we leave the progress bar and status bar blank and make sure
>        # drawing is enabled.
>        if scribus.haveDoc():
>            scribus.setRedraw(True)
>        scribus.statusMessage("")
>        scribus.progressReset()
>
> # This code detects if the script is being run as a script, or 
> imported as a module.
> # It only runs main() if being run as a script. This permits you to 
> import your script
> # and control it manually for debugging.
> if __name__ == '__main__':
>    main_wrapper(sys.argv)
>
>



More information about the scribus mailing list