Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top