GNOME Bugzilla – Bug 494500
gnomecanvas.path_def_new() doesn't provide a way to build a closed path
Last modified: 2007-11-24 17:56:55 UTC
Please describe the problem: The toplevel function path_def_new() of gnomecanvas module, which is responsible for building a GnomeCanvasPathDef object from a sequence of tuples, always leaves the built path unclosed, apparently does not allow users to close it afterwards. A path needs to be closed when it is presented as a filled object. The following patch adds a feature to the above path_def_new() function that allows the constant ART_END (as gnomecanvas.END) to be used for a path closing marker, which previously had no meaning as a path code. Index: canvasmodule.c =================================================================== --- canvasmodule.c (revision 592) +++ canvasmodule.c (working copy) @@ -85,6 +85,7 @@ add_item(MOVETO_OPEN); add_item(CURVETO); add_item(LINETO); + add_item(END); #undef add_item pycanvas_register_classes (d); Index: canvas.override =================================================================== --- canvas.override (revision 592) +++ canvas.override (working copy) @@ -566,6 +566,9 @@ break; case ART_END: + gnome_canvas_path_def_closepath(path); + break; + default: gnome_canvas_path_def_unref(path); return PyErr_Format(PyExc_ValueError, "invalid path code %i", Steps to reproduce: import gtk import gnomecanvas canvas = gnomecanvas.Canvas(aa = True) c1 = canvas.root().add( gnomecanvas.CanvasGroup, x = 0, y = 10) c2 = canvas.root().add( gnomecanvas.CanvasGroup, x = 0, y = 50) c1.add( gnomecanvas.CanvasBpath, cap_style = gtk.gdk.CAP_BUTT, bpath = gnomecanvas.path_def_new([ (gnomecanvas.MOVETO, 30, 0), (gnomecanvas.LINETO, 40, 0), (gnomecanvas.CURVETO, 70, 0, 70, 30, 40, 30), (gnomecanvas.LINETO, 30, 30), (gnomecanvas.CURVETO, 0, 30, 0, 0, 10, 0) ]), fill_color = 'red', outline_color = 'black', width_units = 4.0) c2.add( gnomecanvas.CanvasBpath, cap_style = gtk.gdk.CAP_BUTT, bpath = gnomecanvas.path_def_new([ (gnomecanvas.MOVETO, 30, 0), (gnomecanvas.LINETO, 40, 0), (gnomecanvas.CURVETO, 70, 0, 70, 30, 40, 30), (gnomecanvas.LINETO, 30, 30), (gnomecanvas.CURVETO, 0, 30, 0, 0, 10, 0), (gnomecanvas.END,) ]), fill_color = 'red', outline_color = 'black', width_units = 4.0) canvas.set_size_request(80, 120) canvas.set_scroll_region(0, 0, 80, 120) wnd = gtk.Window(gtk.WINDOW_TOPLEVEL) wnd.connect("destroy", lambda widget: gtk.main_quit()) wnd.add(canvas) wnd.show_all() gtk.main() Actual results: Expected results: Does this happen every time? Other information:
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.