[pygtk] problem with moving too many gtk.Images inside a gtk.Layout
Victor Matheus
victormatheus at gmail.com
Mon Aug 6 22:48:09 WST 2007
hello, i'm trying to make a simple canvas, where i can move images by
dragging them with the mouse, i don't want to use the drag'n'drop functions
because i want to know when there were collisions between the images, so i
did it with the usual events 'motion-notify-event','button-press-event' and
'release-press-event'. but when there are too many images in the screen, the
position of the mouse given by motion-notify-event is wrong and the images
shakes...
do somebody know how can i solve this problem?
here is a example of the problem, see by yourself:
---------------------------------------------------------------------------=
--------------------------------------------------------------------
import gtk
class img( gtk.Image ):
#list with all images
list =3D []
def __init__(self, image, layout, img_to_follow):
gtk.Image.__init__(self)
self.drag =3D False
self.drag_x =3D 0
self.drag_y =3D 0
self.layout =3D layout
#position of the image in the layout
self.x =3D 0
self.y =3D 0
self.set_from_file( image )
self.event_box =3D gtk.EventBox()
self.event_box.set_visible_window( False )
self.event_box.add( self )
#images cannot have these events....
self.event_box.add_events( gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK )
self.event_box.connect("button-press-event", self.click)
self.event_box.connect("button-release-event", self.release)
self.event_box.connect("motion-notify-event", self.mousemove)
if img_to_follow:
self.img_to_follow =3D img_to_follow
self.follow =3D True
else:
self.follow =3D False
self.layout.put( self.event_box, 0, 0 )
self.list.append( self )
def click(self, widget, event):
#drag begin
self.drag =3D True
self.drag_x =3D event.x
self.drag_y =3D event.y
def release(self, widget, event):
self.drag =3D False
def mousemove(self, widget, event):
if self.drag:
for k in self.list:
if k.follow =3D=3D False:
#follow
self.layout.move( k.event_box, k.x+int(
event.x-self.drag_x), k.y+int(event.y-self.drag_y) )
else:
self.layout.move( k.event_box, k.img_to_follow.x + 10,
k.img_to_follow.y + 10 )
#refresh logic position
k.x, k.y =3D self.layout.child_get( k.event_box, 'x', 'y' )
class move_test( object ):
def __init__( self ):
win =3D gtk.Window( gtk.WINDOW_TOPLEVEL )
layout =3D gtk.Layout()
#try to put more images here
img1 =3D img( 'img.png', layout, None )
img2 =3D img( 'img.png', layout, img1 )
img3 =3D img( 'img.png', layout, img2 )
img4 =3D img( 'img.png', layout, img3 )
img5 =3D img( 'img.png', layout, img4 )
img6 =3D img( 'img.png', layout, img5 )
img7 =3D img( 'img.png', layout, img6 )
img8 =3D img( 'img.png', layout, img7 )
img9 =3D img( 'img.png', layout, img8 )
img10 =3D img( 'img.png', layout, img9 )
img11 =3D img( 'img.png', layout, img10 )
img12 =3D img( 'img.png', layout, img11 )
img13 =3D img( 'img.png', layout, img12 )
win.add( layout )
win.show_all()
move_test()
gtk.main()
---------------------------------------------------------------------------=
--------------------------------
sorry for any possible english error XD
bye!
victor matheus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070806/3ee2eb51/at=
tachment.htm
More information about the pygtk
mailing list