[pygtk] Using draw_rectangle with a fill colour

2011-03-01 Thread mercado
Hello all,

I am trying to use gtk.DrawingArea to draw an orange rectangle, using
some of the information at
http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html.

I have included a sample of my code below, which draws a black
rectangle.  However, I cannot get it to accept the color information
from gc.

Can anyone tell me what I'm doing wrong?

Thanks in advance.



import gtk

class CustomDrawingArea(gtk.DrawingArea):
def __init__(self):
gtk.DrawingArea.__init__(self)
self.connect(expose_event, self.expose)

def expose(self, widget, event):
self.context = widget.window.cairo_create()
self.draw(self.context)

return False

def draw(self, context):
drawable = self.window
gc = drawable.new_gc()

gc.foreground = gtk.gdk.color_parse(orange)

gc.fill = gtk.gdk.SOLID

drawable.draw_rectangle(gc, True, x=100, y=100, width=10, height=50)

def main():
window = gtk.Window()
window.set_size_request(500, 500)

cda = CustomDrawingArea()

window.add(cda)
window.connect(destroy, gtk.main_quit)
window.show_all()

gtk.main()

if __name__ == __main__:
main()
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Using draw_rectangle with a fill colour

2011-03-01 Thread Timo

On 01-03-11 15:20, mercado wrote:

Hello all,

I am trying to use gtk.DrawingArea to draw an orange rectangle, using
some of the information at
http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html.

I have included a sample of my code below, which draws a black
rectangle.  However, I cannot get it to accept the color information
from gc.

Can anyone tell me what I'm doing wrong?

Thanks in advance.



import gtk

class CustomDrawingArea(gtk.DrawingArea):
 def __init__(self):
 gtk.DrawingArea.__init__(self)
 self.connect(expose_event, self.expose)

 def expose(self, widget, event):
 self.context = widget.window.cairo_create()
 self.draw(self.context)

 return False

 def draw(self, context):
 drawable = self.window
 gc = drawable.new_gc()

 gc.foreground = gtk.gdk.color_parse(orange)

Try the following line instead:
gc.set_foreground(self.get_colormap().alloc_color(#FF8000))

Cheers,
Timo


 gc.fill = gtk.gdk.SOLID

 drawable.draw_rectangle(gc, True, x=100, y=100, width=10, height=50)

def main():
 window = gtk.Window()
 window.set_size_request(500, 500)

 cda = CustomDrawingArea()

 window.add(cda)
 window.connect(destroy, gtk.main_quit)
 window.show_all()

 gtk.main()

if __name__ == __main__:
 main()
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Using draw_rectangle with a fill colour

2011-03-01 Thread mercado
On Tue, Mar 1, 2011 at 11:56 AM, Timo timomli...@gmail.com wrote:
         gc.foreground = gtk.gdk.color_parse(orange)

 Try the following line instead:
        gc.set_foreground(self.get_colormap().alloc_color(#FF8000))

 Cheers,
 Timo

Yes, that works.  Thanks for your help Timo.
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/