Hello,
         i'm having some trouble trying to move a custom widget(in this case an ellipse) in the Drawing Area. It seems to get the required mouse click and motion signals but does not move.

The code :


import gtk
import gtk.gdk
import math

class Ellipse(gtk.DrawingArea):
    def __init__(self):
        gtk.DrawingArea.__init__(self)
    self.add_events(gtk.gdk.BUTTON_PRESS_MASK |
                gtk.gdk.BUTTON1_MOTION_MASK)

    self.connect("expose_event", self.expose)
    self.connect("button_press_event", self.pressing)
    self.connect("motion_notify_event", self.moving)

    self.desp = 0

    def pressing(self, widget, event):
    print "Button Press"
    self.pressing_x = event.x
       
    def moving(self, widget, event):
    print "Move"
    if (self.pressing_x - event.x) > 1:
        self.desp = self.desp + 0.1
    else:
        self.desp = self.desp - 0.1
       
    self.pressing_x = event.x
       

    self.draw(self.context)

    self.queue_draw()

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

        self.context.rectangle(event.area.x, event.area.y,
                               event.area.width, event.area.height)
        self.context.clip()
       
        self.draw(self.context)
       
        return False
   
    def draw(self, context):
        rect = self.get_allocation()

    x = rect.width / 2
    y = rect.height / 2
    ex = x
    ey = y
    ew = rect.width / 4.0
    eh = rect.height / 12.0
       
    context.save()
    context.translate (ex, ey)
    context.scale (ew / 2.0 , eh / 2.0)


    context.arc (0, 0, 1., 0 + self.desp, (2 * math.pi) + self.desp)
    print self.desp

    context.set_source_rgb(0, 0, 0)
    context.fill_preserve()
    context.set_source_rgb(1, 1, 1)
    context.stroke()
    context.restore ()

def main():
    window = gtk.Window()
    clock = Ellipse()
   
    window.add(clock)
    window.connect("destroy", gtk.main_quit)
    window.show_all()
   
    gtk.main()
   
if __name__ == "__main__":
    main()



i tried it out looking at the code :

http://www.oluyede.org/blog/writing-a-widget-using-cairo-and-pygtk-28/

and

http://pupeno.com/blog/making-a-widget-with-pygtk

and

http://www.pygtk.org/articles/cairo-pygtk-widget-signals-es/cairo-pygtk-widget-signals.html

(i don't speak Spanish so i didn't fully understand the inlilne comments and the documentation)

thanks in advance!

regards,

- vihan

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

Reply via email to