Description

All drawing operations in PyGTK take a graphics
context (gtk.gdk.GC) argument
(See the gtk.gdk.Drawable
description). A graphics context encapsulates information about the way
things are drawn, such as the foreground color or line width. By using
graphics contexts, the number of arguments to each drawing call is greatly
reduced, and communication overhead is minimized, since identical arguments
do not need to be passed repeatedly. Most values of a graphics context can
be set at creation time by using gtk.gdk.Drawable.new_gc(),
or can be set one-by-one using functions such as set_foreground()
or by setting a gtk.gdk.GC attribute. A
few of the values in the gtk.gdk.GC, such as the
dash pattern, can only be set by the latter method.

Note that all coordinates except for clip mask and clip region are relative to
destination drawable (e.g. gtk.gdk.Window)
origin. In particular, coordinates are not related to widget
allocation.

Creates a new gtk.gdk.GC object for
the gtk.gdk.Drawable
specified by drawable with the optional attributes as
specified by the arguments. The drawable parameter must be specified but the
rest of the parameters are optional. Any attributes not specified will use a
default value. This is an alternative to the gtk.gdk.Drawable.new_gc()
method. Since there are a large number of optional attribute parameters it's
probably best to specify the attribute values using keywords.

the line style - one of:
gtk.gdk.LINE_SOLID,
gtk.gdk.LINE_ON_OFF_DASH,
gtk.gdk.LINE_DOUBLE_DASH

cap_style :

the style of line ends - one of:
gtk.gdk.CAP_NOT_LAST,
gtk.gdk.CAP_BUTT, gtk.gdk.CAP_ROUND,
gtk.gdk.CAP_PROJECTING

join_style :

the style of line joins - one of:
gtk.gdk.JOIN_MITER,
gtk.gdk.JOIN_ROUND,
gtk.gdk.JOIN_BEVEL

The set_values() method sets the
attributes of a graphics context in bulk using the optional parameters.
Since there are a large number of attribute parameters it's probably best to
specify the attribute values using keywords. Any attributes not specified
will be left as is.

gtk.gdk.GC.set_background

The set_background() method sets the
background gtk.gdk.Color to the
value specified by color.

gtk.gdk.GC.set_function

def set_function(function)

function :

the bitwise operator used to combine the
existing pixel value and a new pixel value - usually one of:
gtk.gdk.COPY, gtk.gdk.XOR or
gtk.gdk.INVERT.

The set_function() method sets the
function attribute to the value specified by
function. The value of
function must be one of:

gtk.gdk.COPY

gtk.gdk.INVERT

gtk.gdk.XOR

gtk.gdk.CLEAR

gtk.gdk.AND

gtk.gdk.AND_REVERSE.

gtk.gdk.AND_INVERT

gtk.gdk.NOOP

gtk.gdk.OR

gtk.gdk.EQUIV

gtk.gdk.OR_REVERSE

gtk.gdk.COPY_INVERT

gtk.gdk.OR_INVERT

gtk.gdk.NAND

gtk.gdk.NOR

gtk.gdk.SET

Only a couple of these values are usually useful. For colored
images, only gtk.gdk.COPY, gtk.gdk.XOR
and gtk.gdk.INVERT are generally useful. For bitmaps,
gtk.gdk.AND and gtk.gdk.OR are also
useful.

gtk.gdk.GC.set_fill

def set_fill(fill)

fill :

the new fill mode

The set_fill() method sets the fill
mode for the graphics context to the value specified by
fill. The value of fill must
be one of:

gtk.gdk.SOLID

draw with the foreground color.

gtk.gdk.TILED

draw with a tiled pixmap.

gtk.gdk.STIPPLED

draw using the stipple bitmap. Pixels corresponding to
bits in the stipple bitmap that are set will be drawn in the foreground
color; pixels corresponding to bits that are not set will be left
untouched.

gtk.gdk.OPAQUE_STIPPLED

draw using the stipple bitmap. Pixels corresponding to
bits in the stipple bitmap that are set will be drawn in the foreground
color; pixels corresponding to bits that are not set will be drawn with the
background color.

gtk.gdk.GC.set_stipple

The set_stipple() method sets the gtk.gdk.Pixmap
bitmap specified by stipple to be used for stippling
the background. stipple will only be used if the fill
mode is gtk.gdk.STIPPLED or
gtk.gdk.OPAQUE_STIPPLED.

gtk.gdk.GC.set_ts_origin

def set_ts_origin(x, y)

x :

the x origin of the tile or
stipple

y :

the y origin of the tile or
stipple

The set_ts_origin() method sets the
origin of the tile or stipple to the value specified by
x and y. The tile or stipple
will be aligned such that the upper left corner of the tile or stipple will
coincide with this point.

gtk.gdk.GC.set_clip_origin

def set_clip_origin(x, y)

x :

the x origin of the clip
mask

y :

the y origin of the clip
mask

The set_clip_origin() method sets the
origin of the clip mask to the value specified by x
and y. The coordinates are interpreted relative to
the upper-left corner of the destination drawable of the current
operation.

gtk.gdk.GC.set_clip_rectangle

The set_clip_rectangle() method sets
the clip mask for the graphics context from the gtk.gdk.Rectangle
specified by rectangle and sets the clip origin to
(0, 0). The clip origin can be changed using the set_clip_origin()
method.

gtk.gdk.GC.set_clip_region

Note

This method is available in PyGTK 2.10 and above.

The set_clip_region() method sets the
clip mask for a graphics context from the gtk.gdk.Region
specified by region. The clip mask is
interpreted relative to the clip origin. (See the set_clip_origin()
method).

gtk.gdk.GC.set_subwindow

def set_subwindow(mode)

mode :

the new subwindow mode

The set_subwindow() method sets the
mode of drawing on subwindows when drawing on a gtk.gdk.Window to
the value specified by mode. The value of mode must
be one of:

gtk.gdk.CLIP_BY_CHILDREN

only draw onto the window itself not the
subwindows.

gtk.gdk.INCLUDE_INFERIORS

draw onto the window and child windows.

gtk.gdk.GC.set_exposures

def set_exposures(exposures)

exposures :

if True exposure events will
be generated for non-visible areas

The set_exposures() method sets an
attribute that determines if copying non-visible portions of a drawable
using this graphics context will generate exposure events for the
corresponding regions of the destination drawable. If
exposures is True exposure events
will be generated for non-visible areas. See the gtk.gdk.Drawable.draw_drawable()
method.

The set_line_attributes() method sets
the attributes to be used when drawing a line using the graphics context to
the values specified by line_width,
line_style, cap_style and
join_style. The value of
line_style must be one of:

gtk.gdk.LINE_SOLID

Lines are drawn solid.

gtk.gdk.LINE_ON_OFF_DASH

Lines are drawn dashed where even segments are drawn
but odd segments are not drawn.

gtk.gdk.LINE_DOUBLE_DASH

Lines are drawn dashed where even segments are drawn
normally but odd segments are drawn in the background color if the fill
style is gtk.gdk.SOLID, or in the background color masked
by the stipple if the fill style is
gtk.gdk.STIPPLED.

The value of cap_style must be one of:

gtk.gdk.CAP_NOT_LAST

The same as gtk.gdk.CAP_BUTT for
lines of non-zero width but for zero width lines, the final point on the
line will not be drawn.

gtk.gdk.CAP_BUTT

The ends of the lines are drawn squared off and
extending to the coordinates of the end point.

gtk.gdk.CAP_ROUND

The ends of the lines are drawn as semicircles with the
diameter equal to the line width and centered at the end point.

gtk.gdk.CAP_PROJECTING

The ends of the lines are drawn squared off and
extending half the width of the line beyond the end point.

The value of join_style must be one of:

gtk.gdk.JOIN_MITER

The sides of each line are extended to meet at an
angle.

gtk.gdk.JOIN_ROUND

The sides of the two lines are joined by a circular
arc.

gtk.gdk.JOIN_BEVEL

The sides of the two lines are joined by a straight
line which makes an equal angle with each line.

gtk.gdk.GC.set_dashes

def set_dashes(dash_offset, dash_list, n)

dash_offset :

the index of the length in
dash_list to use as the firstst
dash

dash_list :

the tuple or list of dash lengths in
pixels

The set_dashes() method sets the
pattern for drawing dashed lines using the tuple or list of dash lengths
specified by dash_list with the index of the starting
dash length specified by dash_offset. The dashes are
drawn starting with the number of pixels at the offset position; then the
next number of pixels is skipped; and then the next number is drawn; and so
on rotating through all the dash_list numbers and
starting over when the end is reached. For example, if
dash_list is (2, 4, 8, 16) and the offset is 1, the
dashes will be drawn as: draw 4 pixels, skip 8 pixels, draw 16 pixels, skip
2 pixels, draw 4 pixels and so on.

gtk.gdk.GC.offset

def offset(x_offset, y_offset)

x_offset :

the amount by which to offset the graphics context in the X
direction

y_offset :

the amount by which to offset the graphics context in the Y
direction

The offset() method sets offset
attributes such as the clip and tile-stipple origins of the graphics context so that
drawing at x - x_offset, y -
y_offset with the offset graphics context has the same effect as
drawing at x, y with the original graphics context.

gtk.gdk.GC.set_colormap

The set_colormap() method sets the
colormap for the graphics context to the specified
colormap. The depth of the colormap's visual must
match the depth of the drawable for which the graphics context was
created.

gtk.gdk.GC.get_colormap

def get_colormap()

Returns :

the colormap used by the graphics
context

The get_colormap() method returns the
colormap for the graphics context, if it exists. A graphics context will
have a colormap if the drawable for which it was created has a colormap, or
if a colormap was set explicitly with the set_colormap()
method.

gtk.gdk.GC.set_rgb_fg_color

The set_rgb_fg_color() method sets the
foreground color of a graphics context using the specified unallocated
color. The pixel value for
color will be determined using GdkRGB. If the
colormap for the graphics context has not previously been initialized for
GdkRGB, then for pseudo-color colormaps (colormaps with a small modifiable
number of colors), a colorcube will be allocated in the colormap. Calling
this method for a graphics context without a colormap is an error.

gtk.gdk.GC.set_rgb_bg_color

The set_rgb_bg_color() method sets the
background color of a graphics context using the specified unallocated
color. The pixel value for
color will be determined using GdkRGB. If the
colormap for the graphics context has not previously been initialized for
GdkRGB, then for pseudo-color colormaps (colormaps with a small modifiable
number of colors), a colorcube will be allocated in the colormap. Calling
this method for a graphics context without a colormap is an error.