>>>>> "Steve" == Steve McClure <[EMAIL PROTECTED]> writes:

    Steve> That's probably not practical, but I am using the new gc in
    Steve> the draw_line and draw_point commands.

Hmmm...  Here's an old script I worked with when I was first learning
pygtk that should run under pygtk-0.6.4 and draws in a specified
color.  Does it draw in dark slate gray when you run it?  If so, try
and figure out what is different from your code.

import sys
from gtk import *
import random
import time

pixmap = None

class MyClass:
   def __init__(self):
      self._count1 = 0
      self._count2 = 0
      
   def idle_function(self, widget):
      x = int(random.uniform(0,500))
      y = int(random.uniform(0,500))
      r1 = int(random.uniform(10,100))
      r2 = int(random.uniform(10,100))
      fill = 1
      cmap = widget.get_colormap()

      # this is DarkSlateGray on a (255,255,255) color scale.  I
      # multiply by 255 to scale to the units of alloc, which are
      # 0-65535 for each (R,G,B) value
      color = cmap.alloc(49*255,79*255,79*255)
      
      gc = widget.get_parent_window().new_gc()
      gc.foreground = color 
      widget.draw_arc(gc,
                      fill, x, y,
                      r1, r2,
                      0,360*64)
      time.sleep(.001)
      return TRUE
   
   def timer_function(self):   
      self._count2 = self._count2 + 1
      print 'Timer %d' % self._count2
      return TRUE


def configure_event(widget, event):
   global pixmap
   win = widget.get_window()
   pixmap = create_pixmap(win, win.width, win.height, -1)
   draw_rectangle(pixmap, widget.get_style().white_gc, TRUE,
                  0, 0, win.width, win.height)

   # could also be placed in expose_event
   c = MyClass()
   idle_add(c.idle_function, widget)
   timeout_add(1000,c.timer_function)
   return TRUE

def expose_event(widget, event):
   area = event.area
   gc = widget.get_style().fg_gc[STATE_NORMAL]
   widget.draw_pixmap(gc, pixmap, area[0], area[1], area[0], area[1],
                      area[2], area[3])
   widget.draw_arc(widget.get_style().black_gc,
                   0, 100, 200,
                   60,60,
                   0,360*64)

   return FALSE

def button_press_event(widget, event):
   if event.button == 1 and pixmap != None:
      draw_arcs(widget, event.x, event.y)
   return TRUE

def motion_notify_event(widget, event):
   if event.is_hint:
      x, y = event.window.pointer
      state = event.window.pointer_state
   else:
      x = event.x; y = event.y
      state = event.state
   if state & GDK.BUTTON1_MASK and pixmap != None:
      draw_arcs(widget, x, y)
   return TRUE

def draw_arcs(widget, x, y):
   fill = 0
   color = GdkColor(0.1,0.3,0.8)
   widget.draw_arc(widget.get_style().black_gc, fill, x, y,
                   60,60,
                   0,360*64)
   return TRUE

   
def main():
   win = GtkWindow()
   win.set_name("Test Input")
   win.connect("destroy", mainquit)
   win.set_border_width(5)

   vbox = GtkVBox(spacing=3)
   win.add(vbox)
   vbox.show()

   drawing_area = GtkDrawingArea()
   drawing_area.size(500, 500)
   vbox.pack_start(drawing_area)

   drawing_area.show()

   drawing_area.connect("expose_event", expose_event)
   drawing_area.connect("configure_event", configure_event)
   drawing_area.connect("motion_notify_event", motion_notify_event)
   drawing_area.connect("button_press_event", button_press_event)
   drawing_area.set_events(GDK.EXPOSURE_MASK |
                           GDK.LEAVE_NOTIFY_MASK |
                           GDK.BUTTON_PRESS_MASK |
                           GDK.POINTER_MOTION_MASK |
                           GDK.POINTER_MOTION_HINT_MASK)

   button = GtkButton("Quit")
   vbox.pack_start(button, expand=FALSE, fill=FALSE)
   button.connect("clicked", win.destroy)
   button.show()
   win.show()
   mainloop()

if __name__ == '__main__':
   main()
   

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to