From: Luigi P. <lu...@la...> - 2006-02-08 15:53:51
|
Hi! I'm trying to create a customized cursor crosshair in my plot. It is inserted into a gtk.Window. I'm using GTKAGG backend. In order do this, I need to create a class CursorCrosshair for a code like this: ** CODE ** win = gtk.Window() win.connect("destroy", lambda x: gtk.main_quit()) win.set_default_size(400,300) figure = Figure() t = arange(0.0, 1.0, 0.01) s = sin(2*2*pi*t) sub1 = figure.add_subplot(111) sub1.plot(t, s, 'o') box = gtk.VBox() canvas = FigureCanvasGTKAgg(figure) cursor = CursorCrosshair() connect('motion_notify_event', cursor.draw_cursor) toolbar = NavigationToolbar2GTK( canvas, win ) toolbar.update() box.pack_start(canvas, True, True) box.pack_end(toolbar, False, False) win.add(box) win.show_all() gtk.main() ********* Into the draw_cursor method of CursorCrosshair class I'll paint the horizontal and vertical lines. Well, the canvas in my example (FigureCanvasGTKAgg) inherits from gtk.DrawingArea, that is the GTK "real" canvas I need to paint into CursorCrosshair.draw_cursor(...) method. gtk.DrawingArea has a method named draw_line(gc, x1, y1, x2, y2) that needs the coordinates and a graphics context as input parameters. OK: how can I get the graphics context? What is it? And can I really use FigureCanvasGTKAgg like a gtk.DrawingArea object? If I cannot, how can I draw a line directly on the gtk inner canvas class (gtk.DrawingArea). Thanks in advance. Luigi |