[pygtk] GNOME printing in Python?

Magnus Therning magnus at therning.org
Sat May 26 00:24:41 WST 2007


On Fri, May 25, 2007 at 16:22:18 +0200, Gian Mario Tagliaretti wrote:
>2007/5/25, Magnus Therning <magnus at therning.org>:
>>What I'd like to do is very simple, just send the contents of a string,
>>prepared in a Python script, to the printer.  If possible I'd like to
>>use the GNOME printing thingamajig rather than just throwing it in a
>>file and sending lpr on it.  I can't seem to find any documention on how
>>to work with printing in GNOME though.  Can anyone offer me some good
>>pointers?
>>
>
>in pygtk you can use the new gtk.Print* stuff, documented with the
>rest of pygtk in the reference manual:
>http://www.pygtk.org/docs/pygtk/index.html
>
>the old gnome print stuff is documented as well:
>http://www.pygtk.org/pygnomeprint/index.html

Thanks for the pointers.  However this turns out to be a little more
complicated than I had hoped :-(

This is what I have so far, but it prints one blank page:

    def print_text(text):
        p = gtk.PrintOperation()
        
        p.connect("begin-print", begin_print)
        p.connect("draw-page", draw_page)
    
        r = p.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
    
        print r
    
    
    def begin_print(op, ctx):
        op.set_n_pages(1)
    
    
    def draw_page(op, ctx, page_nr):
        cairo_ctx = ctx.get_cairo_context()
    
        layout = cairo_ctx.create_layout()
        layout.set_text('Some text'.decode('utf8'))
        desc = pango.FontDescription("sans 28")
        layout.set_font_description(desc)
    
        cairo_ctx.move_to(30, 30)
        cairo_ctx.layout_path(layout)
    
    
    print_text()

Any more pointers?

/M

-- 
Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus at therning.org             Jabber: magnus.therning at gmail.com
http://therning.org/magnus

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

The day after tomorrow is the third day of the rest of your life.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20070525/e52c1f62/attachment.pgp


More information about the pygtk mailing list