gtk.PrintContextEncapsulates context for drawing pages (new in PyGTK 2.10)Synopsisgtk.PrintContextgobject.GObjectget_cairo_contextget_page_setupget_widthget_heightget_dpi_xget_dpi_yget_pango_fontmapcreate_pango_contextcreate_pango_layoutset_cairo_contextcrdpi_xdpi_yAncestry+-- gobject.GObject
+-- gtk.PrintContext
gtk.PrintContext Signal Prototypesgobject.GObject Signal PrototypesDescriptionA gtk.PrintContext
encapsulates context information that is required when drawing pages for
printing, such as the cairo context and important parameters like page
size and resolution. It also lets you easily create pango.Layout
and pango.Context
objects that match the font metrics of the cairo surface.gtk.PrintContext
objects gets passed to the "begin-print", "end-print",
"request-page-setup" and "draw-page" signals on the gtk.PrintOperation.Using gtk.PrintContext
in a "draw-page" callback
def draw_page(operation, context, page_nr):
cr = context.get_cairo_context()
# Draw a red rectangle, as wide as the paper (inside the margins)
cr.set_source_rgb(1.0, 0, 0)
cr.rectangle(0, 0, context.get_width(), 50)
cr.fill()
# Draw some lines
cr.move_to(20, 10)
cr.line_to(40, 20)
cr.arc(60, 60, 20, 0, M_PI)
cr.line_to(80, 20)
cr.set_source_rgb(0, 0, 0)
cr.set_line_width(5)
cr.set_line_cap(cairo.LINE_CAP_ROUND)
cr.set_line_join(cairo.LINE_JOIN_ROUND)
cr.stroke()
# Draw some text
layout = cr.create_layout()
layout.set_text("Hello World! Printing is easy")
desc = pango.FontDescription("sans 28")
layout.set_font_description(desc)
cr.move_to(30, 20)
cr.layout_path(layout)
# Font Outline
cr.set_source_rgb(0.93, 1.0, 0.47)
cr.set_line_width(0.5)
cr.stroke_preserve()
# Font Fill
cr.set_source_rgb(0, 0.0, 1.0)
cr.fill()
Printing support was added in GTK+ 2.10.Methodsgtk.PrintContext.get_cairo_contextget_cairo_contextReturns :the cairo contextThis method is available in PyGTK 2.10 and above.The get_cairo_context() method returns
the cairo context that is associated with the gtk.PrintContext.gtk.PrintContext.get_page_setupget_page_setupReturns :the page setupThis method is available in PyGTK 2.10 and above.The get_page_setup() method returns the
gtk.PageSetup
that determines the page dimensions of the gtk.PrintContext.gtk.PrintContext.get_widthget_widthReturns :the widthThis method is available in PyGTK 2.10 and above.The get_width() method returns the width
of the gtk.PrintContext,
in pixels.gtk.PrintContext.get_heightget_heightReturns :the heightThis method is available in PyGTK 2.10 and above.The get_height() method returns the
width of the gtk.PrintContext,
in pixels.gtk.PrintContext.get_dpi_xget_dpi_xReturns :the horizontal resolutionThis method is available in PyGTK 2.10 and above.The get_dpi_x() method returns the
horizontal resolution of the gtk.PrintContext,
in dots per inch.gtk.PrintContext.get_dpi_yget_dpi_yReturns :the vertical resolutionThis method is available in PyGTK 2.10 and above.The get_dpi_y() method returns the
vertical resolution of the gtk.PrintContext,
in dots per inch.gtk.PrintContext.get_pango_fontmapget_pango_fontmapReturns :the font mapThis method is available in PyGTK 2.10 and above.The method returns a pango.FontMap
that is suitable for use with the gtk.PrintContext.gtk.PrintContext.create_pango_contextcreate_pango_contextReturns :a new pango.ContextThis method is available in PyGTK 2.10 and above.The create_pango_context() method
creates a new pango.Context
that can be used with the gtk.PrintContext.gtk.PrintContext.create_pango_layoutcreate_pango_layoutReturns :a new pango.LayoutThis method is available in PyGTK 2.10 and above.The create_pango_layout() method
creates a new pango.Layout
that is suitable for use with the gtk.PrintContext.gtk.PrintContext.set_cairo_contextset_cairo_contextcrdpi_xdpi_ycr :dpi_x :dpi_y :This method is available in PyGTK 2.10 and above.The set_cairo_context() method sets the
CairoContext specified by cr as the cairo
context for the print context. dpi_x and
dpi_y specify the horizontal and vertical
resolution of the print context.