|
There are a general set of methods that can be used to draw onto the drawing area 'canvas'. These drawing methods can be used for any gtk.gdk.Drawable subclass (either a gtk.gdk.Window or a gtk.gdk.Pixmap). The drawing methods are:
gc is the Graphics Context to be used to do the drawing. x and y are the coordinates of the point.
gc is the Graphics Context. x1 and y1 specify the starting point of the line. x2 and y2 specify the ending point of the line.
where gc is the Graphics Context. filled is a boolean indicating the rectangle should be filled with the foreground color if TRUE or not filled, if FALSE. x and y are the top left corner of the rectangle. width and height are the width and height of the rectangle.
gc is the Graphics Context. filled is a boolean indicating the arc should be filled with the foreground color if TRUE or not filled, if FALSE. x and y are the top left corner of the bounding rectangle. width and height are the width and height of the bounding rectangle. angle1 is the start angle of the arc, relative to the 3 o'clock position, counter-clockwise, in 1/64ths of a degree. angle2 is the end angle of the arc, relative to angle1, in 1/64ths of a degree counter clockwise.
gc is the Graphics Context. filled is a boolean indicating the polygon should be filled with the foreground color if TRUE or not filled, if FALSE. points is a list of coordinate pairs in tuples e.g. [ (0,0), (2,5), (3,7), (4,11) ] of the points to be drawn as a connected polygon.
font is the gtk.gdk.Font to use to render the string. gc is the Graphics Context. x and y are the coordinates of the point to start rendering the string i.e the left baseline. string is the string of characters to render. NoteBoth the draw_string() and draw_text() methods are deprecated - use a pango.Layout instead with the draw_layout() method.
gc is the Graphics Context. x and y are the coordinates of the point to start rendering the layout. layout is the pango.Layout that is to be rendered.
gc is the Graphics Context. src is the source drawable. xsrc and ysrc are the coordinates of the top left rectangle in the source drawable. xdest and ydest are the coordinates of the top left corner in the drawing area. width and height are the width and height of the source drawable area to be copied to the drawable. If width or height is -1 then the full width or height of the drawable is used.
gc is the Graphics Context. image is the source image. xsrc and ysrc are the coordinates of the top left rectangle in the source drawable. xdest and ydest are the coordinates of the top left corner in the drawing area. width and height are the width and height of the source drawable area to be copied to the drawable. If width or height is -1 then the full width or height of the image is used.
gc is the Graphics Context. points is a list or tuple of coordinate pairs in tuples e.g. [ (0,0), (2,5), (3,7), (4,11) ] of the points to be drawn.
gc is the Graphics Context. segs is a list or tuple of start and end coordinate pairs in tuples e.g. [ (0,0, 1,5), (2,5, 1,7), (3,7, 1,11), (4,11, 1,13) ] of the line segments to be drawn.
gc is the Graphics Context. points is a list or tuple of coordinate pairs in tuples e.g. [ (0,0), (2,5), (3,7), (4,11) ] of the points to be connected with lines.
gc is the Graphics Context. x and y are the top left corner of the image bounding rectangle. width and height are the width and height of the image bounding rectangle. dith is the dither mode as described below For the draw_rgb_image() method, rgb_buf is the RGB Image data packed in a string as a sequence of 8-bit RGB pixel triplets. For the draw_rgb_32_image() method, buf is the RGB Image data packed in a string as a sequence of 8-bit RGB pixel triplets with 8-bit padding (4 characters per RGB pixel). For the draw_gray_image() method, buf is the gray image data packed in a string as 8-bit pixel data. rowstride is the number of characters from the start of one row to the start of the next row of the image. rowstride usually defaults to: 3 * width for the draw_rgb_image() method; 4 * width for the draw_rgb_32_image(); and, width for the draw_gray_image() method. If rowstride is 0 the line will be replicated height times. The dither modes are:
The drawingarea.py example program demonstrates the use of most of the DrawingArea methods. It also puts the DrawingArea inside a ScrolledWindow and adds horizontal and vertical Ruler widgets. Figure 12.1, “Drawing Area Example” shows the program in operation: The drawingarea.py source code is below and uses the gtk.xpm pixmap:
|