views:

75

answers:

2

I'm currently experimenting with using OCaml and GTK together (using the lablgtk bindings). However, the documentation isn't the best, and while I can work out how to use most of the features, I'm stuck with changing notebook pages (switching to a different tab).

I have found the function that I need to use, but I don't know how to use it. The documentation seems to suggest that it is in a sub-module of GtkPackProps.Notebook, but I don't know how to call this.

Also, this function has a type signature different to any I have seen before.

 val switch_page : ([> `notebook ], Gpointer.boxed option -> int -> unit) GtkSignal.t

I think it returns a GtkSignal.t, but I have no idea how to pass the first parameter to the function (the whole part in brackets).

Has anyone got some sample code showing how to change the notebook page, or can perhaps give me some tips on how to do this?

+4  A: 

You've found a polymorphic variant; they're described in the manual in Section 4.2, and the typing rules always break my head. I believe what the signature says is that the function switch_page expects as argument a GtkSignal.t, which is an abstraction parameterized by two types:

  • The first type parameter,

    [> `notebook]
    

    includes as values any polymorphic variant including notebook (that's what the greater-than means).

  • The second type parameter is an ordinary function.

If I'm reading the documentation for GtkSignal.t correctly, it's not a function at all; it's a record with three fields:

  • name is a string.
  • classe is a polymorphic variant which could be `notebook or something else.
  • marshaller is a marshaller for the function type Gpointer.boxed option -> int -> unit.

I hope this helps. If you have more trouble, section 4.2 of the manual, on polymorphic variants, might sort you out.

Norman Ramsey
Thanks, that helps a bit - at least I know where to start looking now.
a_m0d
Any advice on how I might go about calling this function - should it be `source_notebook#S#switch_page`, or perhaps `GPack.notebook.S#switch_page` or some other way?
a_m0d
This is not a function, but it is `GtkPackProps.Notebook.S.switch_page` (`#` is for method, `.` for module field (function or value))
Rémi
+4  A: 

What you have found is not a function but the signal. The functional type you see in its type is the type of the callback that will be called when the page switch happen, but won't cause it.

by the way the type of switch_page is read as: a signal (GtkSignal.t) raised by notebook [> `notebook ], whose callbacks have type Gpointer.boxed option -> int -> unit

Generally speaking, with lablgtk, you'd better stay away of the Gtk* low level modules, and use tge G[A-Z] higher level module. Those module API look like the C Gtk one, and I always use the main Gtk doc to help myself.

In your case you want to use the GPack.notebook object and its goto_page method.

Rémi
@Remi - As far as I can see, `GPack.notebook` does not have any goto_page method (http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgtk/html/GtkPackProps.Notebook.html)
a_m0d
Sorry, I just reread your answer properly, and you are right - GPack.notebook *does* have a `goto_page` method - I will try using that instead (using the correct documentation would certainly help a lot :)
a_m0d