[pygtk] Printing inquiries
Peter Gill
peter.m.gill at gmail.com
Tue Feb 24 12:23:49 WST 2009
Bertrand Son Kintanar wrote:
>
> does anyone here has a working code for printing? I have a table in my
> sqlite database that I want to print and the sample code in pygtk-demo
> takes its input from a gtk.TextView and i cant make the sample
> draw-page callback that can be found here to work.
>
I have attached a small sample program that I know works on ubuntu 8.04
and 8.10. The program lets you select a text file and gives you four
options; you can have the print dialog display, print immediately,
export to pdf, or have a print preview. All that you would have to do is
supply the PrintExample class the data (as a string) from your database
and the type of action you want it to take. The draw_page callback that
is in the attachment is shown here.
def draw_page (self, operation, context, page_number):
cr = context.get_cairo_context()
cr.set_source_rgb(0, 0, 0)
start_line = page_number * self.lines_per_page
if page_number + 1 != operation.props.n_pages:
end_line = start_line + self.lines_per_page
else:
end_line = self.layout.get_line_count()
cr.move_to(0, 0)
iter = self.layout.get_iter()
i=0
while 1:
if i > start_line:
line = iter.get_line()
cr.rel_move_to(0, self.font_size/2)
cr.show_layout_line(line)
i += 1
if not (i < end_line and iter.next_line()):
break
-------------- next part --------------
A non-text attachment was scrubbed...
Name: printing-example2-simple.py
Type: text/x-python
Size: 5487 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20090223/891acd8d/attachment.py
More information about the pygtk
mailing list