gtk.PrintContext Encapsulates context for drawing pages (new in PyGTK 2.10) Synopsis gtk.PrintContext gobject.GObject get_cairo_context get_page_setup get_width get_height get_dpi_x get_dpi_y get_pango_fontmap create_pango_context create_pango_layout set_cairo_context cr dpi_x dpi_y Ancestry +-- gobject.GObject +-- gtk.PrintContext gtk.PrintContext Signal Prototypes gobject.GObject Signal Prototypes Description A 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 <link linkend="class-gtkprintcontext"><classname>gtk.PrintContext</classname></link> 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. Methods gtk.PrintContext.get_cairo_context get_cairo_context Returns : the cairo context This 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_setup get_page_setup Returns : the page setup This 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_width get_width Returns : the width This 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_height get_height Returns : the height This 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_x get_dpi_x Returns : the horizontal resolution This 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_y get_dpi_y Returns : the vertical resolution This 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_fontmap get_pango_fontmap Returns : the font map This 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_context create_pango_context Returns : a new pango.Context This 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_layout create_pango_layout Returns : a new pango.Layout This 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_context set_cairo_context cr dpi_x dpi_y cr : 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.