caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* LablGTK Reading Properties
@ 2008-02-05 16:39 Gregory Malecha
  2008-02-06  8:57 ` [Caml-list] " Olivier Andrieu
  0 siblings, 1 reply; 5+ messages in thread
From: Gregory Malecha @ 2008-02-05 16:39 UTC (permalink / raw)
  To: caml-list

Hi,

I've been working on some code with GnomeCanvas and I'm having 
difficulty reading properties off of objects. For example, I've created 
a polygon and I want to read the points from it, but I always get back 
None. Here's my current code:

let points item =
  let prop = {Gobject.name = "points";
          Gobject.conv = GnomeCanvas.Conv.path_def} in
  let x = Gobject.get prop item in
  match x with
    None -> print_string "NONE!\n"; [] (* I always end up in this case *)
  | Some ary ->
      print_string "SOME!\n";
      let ary = GnomeCanvas.Conv.get_points ary in
      Array.to_list ary

My creation code looks like this:

let drawSourcePort group (x, y) dir =
  let lst =
    match dir with
      East ->
    let cX,cY   = x +. 5., y in
    let p1X,p1Y = x, y +. 7.5 in
    let p2X,p2Y = x, y -. 7.5 in
    [cX;cY; p1X;p1Y; p2X;p2Y]
    | West ->
    let cX,cY   = x -. 5., y in
    let p1X,p1Y = x, y +. 7.5 in
    let p2X,p2Y = x, y -. 7.5 in
    [cX;cY; p1X;p1Y; p2X;p2Y]
    | North ->
    let cX,cY   = x, y -. 5. in
    let p1X,p1Y = x +. 7.5, y in
    let p2X,p2Y = x -. 7.5, y in
    [cX;cY; p1X;p1Y; p2X;p2Y]
    | South ->
    let cX,cY   = x, y +. 5. in
    let p1X,p1Y = x +. 7.5, y in
    let p2X,p2Y = x -. 7.5, y in
    [cX;cY; p1X;p1Y; p2X;p2Y]
  in
  let ary = Array.of_list lst in
  GnoCanvas.polygon
    ~points:ary
    ~fill_color:"black"
    group
;;

I've also tried with lines and that fails as well. Does anyone know if 
there is anything special that I have to do in order to be able to read 
properties or why I keep getting null?

Thanks.

-- 
gregory malecha
wiess college
computer science
219.510.3400


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] LablGTK Reading Properties
  2008-02-05 16:39 LablGTK Reading Properties Gregory Malecha
@ 2008-02-06  8:57 ` Olivier Andrieu
  2008-02-06 17:06   ` Gregory Malecha
  0 siblings, 1 reply; 5+ messages in thread
From: Olivier Andrieu @ 2008-02-06  8:57 UTC (permalink / raw)
  To: gmalecha; +Cc: caml-list

Hi,

On Feb 5, 2008 5:39 PM, Gregory Malecha <gmalecha@rice.edu> wrote:
> Hi,
>
> I've been working on some code with GnomeCanvas and I'm having
> difficulty reading properties off of objects. For example, I've created
> a polygon and I want to read the points from it, but I always get back
> None. Here's my current code:
>
> let points item =
>   let prop = {Gobject.name = "points";
>           Gobject.conv = GnomeCanvas.Conv.path_def} in
>   let x = Gobject.get prop item in
>   match x with
>     None -> print_string "NONE!\n"; [] (* I always end up in this case *)
>   | Some ary ->
>       print_string "SOME!\n";
>       let ary = GnomeCanvas.Conv.get_points ary in
>       Array.to_list ary

you're getting None because you're using the wrong conversion
function: this "points" property is basically a float array and here
you're using the path_def conversion which is for bpath (bezier path).

Your code should work with:
    let prop = {Gobject.name = "points"; conv = GnomeCanvas.Conv.points} in ...

-- 
  Olivier


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] LablGTK Reading Properties
  2008-02-06  8:57 ` [Caml-list] " Olivier Andrieu
@ 2008-02-06 17:06   ` Gregory Malecha
  2008-02-06 19:07     ` Gregory Malecha
  0 siblings, 1 reply; 5+ messages in thread
From: Gregory Malecha @ 2008-02-06 17:06 UTC (permalink / raw)
  To: Olivier Andrieu; +Cc: caml-list

I've modified the function and I'm still getting the same behavior. Here 
is my new code:

let points item =
  let prop = {Gobject.name = "points";
          Gobject.conv = GnomeCanvas.Conv.points} in
  let x = Gobject.get prop item in
  match x with
    None -> print_string "NONE!\n"; []
  | Some ary ->
      print_string "SOME!\n";
      Array.to_list ary

Is there a particular thing that I have to do before I can get the 
points? Does anyone have an example where they are able to do this?

Thanks.

Olivier Andrieu wrote:
> Hi,
>
> On Feb 5, 2008 5:39 PM, Gregory Malecha <gmalecha@rice.edu> wrote:
>   
>> Hi,
>>
>> I've been working on some code with GnomeCanvas and I'm having
>> difficulty reading properties off of objects. For example, I've created
>> a polygon and I want to read the points from it, but I always get back
>> None. Here's my current code:
>>
>> let points item =
>>   let prop = {Gobject.name = "points";
>>           Gobject.conv = GnomeCanvas.Conv.path_def} in
>>   let x = Gobject.get prop item in
>>   match x with
>>     None -> print_string "NONE!\n"; [] (* I always end up in this case *)
>>   | Some ary ->
>>       print_string "SOME!\n";
>>       let ary = GnomeCanvas.Conv.get_points ary in
>>       Array.to_list ary
>>     
>
> you're getting None because you're using the wrong conversion
> function: this "points" property is basically a float array and here
> you're using the path_def conversion which is for bpath (bezier path).
>
> Your code should work with:
>     let prop = {Gobject.name = "points"; conv = GnomeCanvas.Conv.points} in ...
>
>   

-- 
gregory malecha
wiess college
computer science
219.510.3400


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] LablGTK Reading Properties
  2008-02-06 17:06   ` Gregory Malecha
@ 2008-02-06 19:07     ` Gregory Malecha
  2008-02-06 22:12       ` Olivier Andrieu
  0 siblings, 1 reply; 5+ messages in thread
From: Gregory Malecha @ 2008-02-06 19:07 UTC (permalink / raw)
  To: gmalecha; +Cc: Olivier Andrieu, caml-list

I got it working with lines, but not with polygons. Here's my code:

open Gdk.GC;;
open GnomeCanvas;;

let points item =
  let prop = {Gobject.name = "points";
              Gobject.conv = GnomeCanvas.Conv.points} in
  let x = Gobject.get prop item in
  match x with
    None -> print_string "NONE!\n"; []
  | Some ary ->
      print_string "SOME!\n";
      Array.to_list ary
;;

let rec draw canvas root =
  let line = GnoCanvas.line ~points:[|1.;2.;  3.;4. |] root in
  let poly = GnoCanvas.polygon ~points:[| 45.;35.; 100.;60.; 80.;70.|] 
root in

  let _ = print_string "Line Points\n" in
  let _ = List.iter (Printf.printf "%f\n") (points line#as_item) in

  let _ = print_string "Polygon Points\n" in
  let _ = List.iter (Printf.printf "%f\n") (points poly#as_item) in

  let _ = flush stdout in
  ()
;;

let createCanvas window =
(*  GtkBase.Widget.push_colormap (Gdk.Rgb.get_cmap ()) ; *)
  let canvas = GnoCanvas.canvas ~width:600 ~height:450 () in
  canvas#set_center_scroll_region false ;
  GtkBase.Widget.pop_colormap () ;
 
  let table = GPack.table ~rows:2 ~columns:2
      ~row_spacings:4 ~col_spacings:4 ~packing:window#add () in
  let frame = GBin.frame ~shadow_type:`IN () in
  table#attach ~left:0 ~right:1 ~top:0 ~bottom:1
    ~expand:`BOTH ~fill:`BOTH ~shrink:`BOTH ~xpadding:0 ~ypadding:0
    frame#coerce ;
  canvas#set_scroll_region 0. 0. 900. 450. ;
  frame#add canvas#coerce ;
  let w = GRange.scrollbar `HORIZONTAL ~adjustment:canvas#hadjustment () in
  table#attach ~left:0 ~right:1 ~top:1 ~bottom:2
    ~expand:`X ~fill:`BOTH ~shrink:`X ~xpadding:0 ~ypadding:0
    w#coerce ;
  let w = GRange.scrollbar `VERTICAL ~adjustment:canvas#vadjustment () in
  table#attach ~left:1 ~right:2 ~top:0 ~bottom:1
    ~expand:`Y ~fill:`BOTH ~shrink:`Y ~xpadding:0 ~ypadding:0
    w#coerce ;
  canvas#misc#set_can_focus true ;
  canvas#misc#grab_focus () ;
  canvas
;;

let createGui () =
  let window = GWindow.window () in
  let canvas = createCanvas window in
  begin
    canvas#event#connect#button_press
      ~callback:(fun _ -> draw canvas canvas#root; false);
    ignore (window#connect#destroy ~callback:GMain.Main.quit);
    window#show ();
    draw canvas canvas#root;
    GMain.Main.main
  end
;;

let _ =
  let main = createGui () in
  main ()
;;

The output from this is:

Line Points
SOME!
1.000000
2.000000
3.000000
4.000000
Polygon Points
NONE!

Is this done for polygons differently?

Thanks.



Gregory Malecha wrote:
> I've modified the function and I'm still getting the same behavior. 
> Here is my new code:
>
> let points item =
>  let prop = {Gobject.name = "points";
>          Gobject.conv = GnomeCanvas.Conv.points} in
>  let x = Gobject.get prop item in
>  match x with
>    None -> print_string "NONE!\n"; []
>  | Some ary ->
>      print_string "SOME!\n";
>      Array.to_list ary
>
> Is there a particular thing that I have to do before I can get the 
> points? Does anyone have an example where they are able to do this?
>
> Thanks.
>
> Olivier Andrieu wrote:
>> Hi,
>>
>> On Feb 5, 2008 5:39 PM, Gregory Malecha <gmalecha@rice.edu> wrote:
>>  
>>> Hi,
>>>
>>> I've been working on some code with GnomeCanvas and I'm having
>>> difficulty reading properties off of objects. For example, I've created
>>> a polygon and I want to read the points from it, but I always get back
>>> None. Here's my current code:
>>>
>>> let points item =
>>>   let prop = {Gobject.name = "points";
>>>           Gobject.conv = GnomeCanvas.Conv.path_def} in
>>>   let x = Gobject.get prop item in
>>>   match x with
>>>     None -> print_string "NONE!\n"; [] (* I always end up in this 
>>> case *)
>>>   | Some ary ->
>>>       print_string "SOME!\n";
>>>       let ary = GnomeCanvas.Conv.get_points ary in
>>>       Array.to_list ary
>>>     
>>
>> you're getting None because you're using the wrong conversion
>> function: this "points" property is basically a float array and here
>> you're using the path_def conversion which is for bpath (bezier path).
>>
>> Your code should work with:
>>     let prop = {Gobject.name = "points"; conv = 
>> GnomeCanvas.Conv.points} in ...
>>
>>   
>

-- 
gregory malecha
wiess college
computer science
219.510.3400


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] LablGTK Reading Properties
  2008-02-06 19:07     ` Gregory Malecha
@ 2008-02-06 22:12       ` Olivier Andrieu
  0 siblings, 0 replies; 5+ messages in thread
From: Olivier Andrieu @ 2008-02-06 22:12 UTC (permalink / raw)
  To: gmalecha; +Cc: caml-list

On Feb 6, 2008 8:07 PM, Gregory Malecha <gmalecha@rice.edu> wrote:
> I got it working with lines, but not with polygons. Here's my code:

Right, your code's correct but I had a look at the library's source
code and it turns out that the "getter" for this property is simply
unimplemented for the polygon object !

-- 
  Olivier


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-02-06 22:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-05 16:39 LablGTK Reading Properties Gregory Malecha
2008-02-06  8:57 ` [Caml-list] " Olivier Andrieu
2008-02-06 17:06   ` Gregory Malecha
2008-02-06 19:07     ` Gregory Malecha
2008-02-06 22:12       ` Olivier Andrieu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).