Re: GnomeCanvas Enumerate Items
Gregory Malecha <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
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.
[email protected] 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
> [email protected]
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk
>
>
--
gregory malecha