Delivered-To: lablgtk at yquem.inria.fr Message-ID: <47A01A5D.8030706 at rice.edu> Date: Wed, 30 Jan 2008 00:34:05 -0600 From: Gregory Malecha MIME-Version: 1.0 To: lablgtk at yquem.inria.fr Subject: Re: [Lablgtk] GnomeCanvas Enumerate Items References: <20080105.170933.98869039.garrigue at math.nagoya-u.ac.jp> In-Reply-To: <20080105.170933.98869039.garrigue at math.nagoya-u.ac.jp> Content-Transfer-Encoding: 7bit Reply-To: gmalecha at rice.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Length: 2704 I was able to get most of this working using wrap_item. There are a few cases that it apparently doesn't handle though. Mainly group, text, rich_text, etc, the ones that aren't GnoCanvas.items. Here's the code that I have: type annotated_item = Group of GnomeCanvas.group_p GnoCanvas.item (* I'd like this to be GnoCanvas.group *) | Line of GnoCanvas.line | Ellipse of GnoCanvas.ellipse | Polygon of GnoCanvas.polygon | Rect of GnoCanvas.rect | Bpath of GnoCanvas.bpath | Unknown ;; let annotate ent = let item = ent#as_item in if GnomeCanvas.Types.is_a item GnomeCanvas.Types.ellipse then let el = GnoCanvas.wrap_item item GnomeCanvas.Types.ellipse in Ellipse el else if GnomeCanvas.Types.is_a item GnomeCanvas.Types.line then let ln = GnoCanvas.wrap_item item GnomeCanvas.Types.line in Line ln else if GnomeCanvas.Types.is_a item GnomeCanvas.Types.polygon then let pl = GnoCanvas.wrap_item item GnomeCanvas.Types.polygon in Polygon pl else if GnomeCanvas.Types.is_a item GnomeCanvas.Types.group then let gp = GnoCanvas.wrap_item item GnomeCanvas.Types.group in Group gp else if GnomeCanvas.Types.is_a item GnomeCanvas.Types.rect then let rt = GnoCanvas.wrap_item item GnomeCanvas.Types.rect in Rect rt else if GnomeCanvas.Types.is_a item GnomeCanvas.Types.bpath then let bp = GnoCanvas.wrap_item item GnomeCanvas.Types.bpath in Bpath bp else Unknown ;; Does anyone know of a way to get a GnoCanvas.group rather than a GnomeCanvas.group_p GnoCanvas.item when performing the cast? Thanks. gmalecha@rice.edu wrote: > Hello, > > I'm working on some graphing code using GnomeCanvas and I need to enumerate all > of the items in a tree. Something like the following: > > let rec enumerate deep root = > whitespace deep; > match annotate root with > Group grp -> > print_string "- Group\r\n"; > List.iter enumerate grp#get_items > | Line lne -> > print_string "- Line\r\n"; > | Polygon poly -> > print_string "- Polygon\r\n"; > | ... > > This is going to be part of a PostScript writer, so eventually I'll need to get > the essential information about each of these but right now I'm just working on > the enumeration part. How would you go about writing the annotate function? Or > is there an easier way to do this? > > Thank you very much. > > _______________________________________________ > Lablgtk mailing list > Lablgtk@yquem.inria.fr > http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk > > -- gregory malecha _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk