pygnomecanvas のバグ?
gnomecanvas.path_def_new() で CanvasPathDef オブジェクトを作っても、closepath() メソッドが提供されてないのでパスを閉じることができない模様。
import gtk import gnomecanvas canvas = gnomecanvas.Canvas( aa = True ) 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, 30, 0 ) ] ) canvas.root().add( gnomecanvas.CanvasBpath, bpath = bpath, fill_color = 'red', outline_color = 'black', width_units = 1.0) canvas.set_size_request(320, 240) canvas.set_scroll_region(0, 0, 320, 240) wnd = gtk.Window(gtk.WINDOW_TOPLEVEL) wnd.connect("destroy", lambda widget: gtk.main_quit()) wnd.add(canvas) wnd.show_all() gtk.main()
ちなみに
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gnomecanvas >>> print dir(gnomecanvas.path_def_new([])) ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__gtype__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'copy']
Cで書いた場合:
#include <gtk/gtk.h> #include <libgnomecanvas/gnome-canvas.h> #include <libgnomecanvas/gnome-canvas-path-def.h> void on_destroy(GtkWindow *wnd) { gtk_main_quit(); } int main(int argc, char **argv) { GtkWindow *wnd; gtk_init(&argc, &argv); wnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); g_signal_connect_closure(G_OBJECT(wnd), "destroy", g_cclosure_new((GCallback)on_destroy, NULL, NULL), FALSE); { GnomeCanvas *canvas = GNOME_CANVAS(gnome_canvas_new_aa()); gtk_widget_set_size_request(GTK_WIDGET(canvas), 320, 240); gnome_canvas_set_scroll_region(canvas, 0, 0, 320, 240); GnomeCanvasGroup *root = gnome_canvas_root(canvas); { GnomeCanvasPathDef *bpath = gnome_canvas_path_def_new(); gnome_canvas_path_def_moveto(bpath, 30, 0); gnome_canvas_path_def_lineto(bpath, 40, 0); gnome_canvas_path_def_curveto(bpath, 70, 0, 70, 30, 40, 30); gnome_canvas_path_def_lineto(bpath, 30, 30); gnome_canvas_path_def_curveto(bpath, 0, 30, 0, 0, 30, 0); gnome_canvas_path_def_closepath(bpath); /* ここがポイント */ gnome_canvas_item_new(root, gnome_canvas_bpath_get_type(), "bpath", bpath, "outline-color", "black", "fill-color", "red", "width-units", (gdouble)1.0, NULL); } gtk_container_add(GTK_CONTAINER(wnd), GTK_WIDGET(canvas)); } gtk_widget_show_all(GTK_WIDGET(wnd)); gtk_main(); return 0; }
gnome-python | Cで書いた場合 |
gnomecanvasって消えちゃうのか存続するのか微妙なので手が出しにくい。うーん。
追記: パッチというのもおこがましいくらいのものを書いて送ってみた: GNOME Bug #494500