Thanks James! I was able to get GdkColor like you descibed except the
method I was trying to use "Drawingarea.draw_line" want a GdkGC (graphic
context?) instead of GdkColor. Anyway, after much experimenting, I was
finally able to draw stuff on DrawingArea. It turned out that I had to
implement the "expose" event of a DrawingArea to do the actual drawing.

Any one can help me with the following quesions?

(1) Can you call drawing method directly instead of implementing its
"expose" signal to draw stuff?

(2) I was able to get gc from  GdkWidget.get_style().black_gc. How do I
get other colors? (I tried get_style().blue_gc, didn't work)

(3) How do you get a GdkFont object used by draw_string()?


Thanks a lot!
Fuming Wang

Here is experiment code:

drawing_area = GtkDrawingArea()
drawing_area.set_usize(300, 300)
vbox.pack_start(drawing_area)
drawing_area.show()

def expose_event(darea, event):
        drawable = darea.get_window()
        white_gc = darea.get_style().white_gc
        grey_gc = darea.get_style().bg_gc[STATE_NORMAL]
        black_gc = darea.get_style().black_gc
        max_width = drawable.width
        max_height = drawable.height
        draw_rectangle(drawable, white_gc, TRUE, 0, 0,
                       max_width, max_height / 2)
        draw_rectangle(drawable, black_gc, TRUE, 100, 100,
                       100, 100)
        draw_line(drawable, black_gc, 20, 250, 280, 250)

#        font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
#        draw_string(drawable, font, black_gc, 50, 280, "hello world!")

        draw_arc(drawable, black_gc, TRUE, 50, 50, 25, 25, 0, 90)

drawing_area.connect("expose_event", expose_event)



James Henstridge wrote:
> 
> majordomo doesn't seem to like it when people put the strings help or
> unsub in the first line of the message.  I will really have to fix that.
> 
> In answer to your question, you would have to set the foreground or
> background colour for the GC.  You do this by assigning GdkColor objects
> to the forground or background attributes of the GC.  You create GdkColor
> objects with the alloc() method of the GdkColormap object (it either takes
> 3 16-bit R,G,B values, or a string name for the colour).  You can get to
> the colormap for a widget with the get_colormap() method of the widget.
> 
> Hopefully this should help.  Try taking a look at the description.py file
> that comes with pygtk.  It describes some of the internal objects in pygtk
> (note that they aren't implemented as classes in pygtk, so don't ask about
> subclassing them, or where their constructors are).
> 
> James Henstridge.
> 
> --
> Email: [EMAIL PROTECTED]
> WWW:   http://www.daa.com.au/~james/
> 
> On Wed, 14 Apr 1999 [EMAIL PROTECTED] wrote:
> 
> > >From [EMAIL PROTECTED]  Wed Apr 14 22:16:59 1999
> > Received: from chmls06.mediaone.net (chmls06.mediaone.net [24.128.1.71])
> >       by quoll.daa.com.au (8.9.2/8.9.2) with ESMTP id WAA00763
> >       for <[EMAIL PROTECTED]>; Wed, 14 Apr 1999 22:16:56 +0800 (WST)
> > Received: from mediaone.net (fumingwang.ne.mediaone.net [24.128.163.152])
> >       by chmls06.mediaone.net (8.8.7/8.8.7) with ESMTP id KAA24913
> >       for <[EMAIL PROTECTED]>; Wed, 14 Apr 1999 10:09:22 -0400 (EDT)
> > Message-ID: <[EMAIL PROTECTED]>
> > Date: Wed, 14 Apr 1999 10:09:56 -0400
> > From: Fuming Wang <[EMAIL PROTECTED]>
> > X-Mailer: Mozilla 4.51 [en] (Win98; U)
> > X-Accept-Language: en,zh
> > MIME-Version: 1.0
> > To: [EMAIL PROTECTED]
> > Subject: Help
> > Content-Type: text/plain; charset=us-ascii
> > Content-Transfer-Encoding: 7bit
> >
> >
> > Hi,
> >
> > I am trying to learn to use pygtk to draw things on GtkDrawingArea. I
> > just could not find out how to specify the color requested by drawing
> > routines.
> > Please help me!
> >
> > Thanks!
> > Fuming Wang
> >
> > My test code here:
> >
> > #!/usr/bin/env python
> >
> > # this is a translation of "Hello World III" from the GTK manual,
> > # using gtk.py
> >
> > from gtk import *
> >
> > def hello(*args):
> >     print "Hello World"
> >     window.destroy()
> >
> > def world(*args):
> >     print "New World"
> >     window.destroy()
> >
> > def destroy(*args):
> >     window.hide()
> >     mainquit()
> >
> > window = GtkWindow(WINDOW_TOPLEVEL)
> > window.connect("destroy", destroy)
> > window.set_border_width(10)
> >
> > vbox = GtkVBox()
> > window.add(vbox)
> > vbox.show()
> >
> > drawing_area = GtkDrawingArea()
> > drawing_area.size(200, 200)
> > vbox.pack_start(drawing_area)
> > drawing_area.show()
> >
> > #win = (GtkWidget(drawing_area)).get_window()
> > #win = GtkWidget(window)
> > #pixmap = create_pixmap(win, win.width, win.height, -1)
> > #pixmap = create_pixmap(win, 150, 150, -1)
> > #draw_rectangle(pixmap, win.get_style().white_gc, TRUE,
> > #                      0, 0, win.width, win.height)
> > drawing_area.draw_line(gc, 50, 50, 60, 60)
> >                        -----> how to specify color
> > drawing_area.queue_draw()
> >
> >
> > button = GtkButton("Hello World")
> > button.connect("clicked", hello)
> > vbox.pack_start(button)
> > button.show()
> >
> > window.show()
> >
> > mainloop()
> >
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to