[pygtk] Re: GdkGC GdkColor GtkDrawingArea
Philip Porter
plporter@hwy97.com
10 Nov 2000 16:27:40 +0800
> Could someone please help me with this problem. I would like to have a
> better understanding of how to use GdkGC's. Here is some example code to
> explain what I would like to be able to do:
>
>
> def on_button1_clicked(widget, mainObj):
>
> GdkWindow = widget.get_parent_window()
> gc = GdkWindow.new_gc()
>
> for x in range(1,64):
> for y in range(1,48):
>
> color = GdkColor(x * 100, y * 100, 0)
> gc.foreground = color
>
> mainObj.drawingarea1.draw_point(gc, x, y)
>
>
> This code does not work the way I would expect, the color used is
> allways the default foreground of the theme I have installed.
>
> I have tried to find an example of someone changing the color in a GdkGC
> and drawing on a DrawingArea. The code I have seen only uses the default
> colors.
>
> Thanks allot,
>
> Phil
> .
>
Well this is what I came up with, I'll put it here for anyone else.
Thanks to François Pinard's post
http://www.daa.com.au/pipermail/pygtk/2000-August/000247.html
and acano@systec.com post
http://www.daa.com.au/pipermail/pygtk/2000-August/000219.html
def on_button1_clicked(widget, mainObj):
xmax = 64.
ymax = 48.
zoom = 16
bdr = 1
area = mainObj.drawingarea1.get_window()
pixmap = create_pixmap(area, area.width, area.height)
gc = area.new_gc()
cm = mainObj.drawingarea1.get_style().colormap
black_gc = mainObj.drawingarea1.get_style().black_gc
white_gc = mainObj.drawingarea1.get_style().white_gc
x = 0
y = 0
FILL = 1
NOFILL = 0
for x in range(0, xmax):
for y in range(0, ymax):
r = (y / ymax) * 65535
g = (x / xmax) * 65535
b = (r + g) / 2
color = cm.alloc(r, g, b)
gc.foreground = color
#draw_arc(pixmap, gc, FILL, x * zoom, y * zoom ,
zoom-bdr , zoom-bdr , 90 * 64, 360 * 64)
draw_rectangle(pixmap, gc, FILL, x * zoom + 1, y * zoom,
zoom - bdr, zoom - bdr)
#draw_point(pixmap, white_gc, x * zoom + (zoom/2), y * zoom
+ (zoom/2))
draw_pixmap(area, gc, pixmap, 0, 0, 0, 0, (xmax) * zoom, (ymax) *
zoom)
Phil
.