Re: Gtk spin button

Julien Moutinho <[email protected]>
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <20080125093449.GA14983@localhost>
On Thu, Jan 24, 2008 at 10:49:43PM -0600, Edgar Friendly wrote:
> (sorry for missent 1st email)
> 
> I'm making a simple dialog box [1], and I want w#run to return `OK (the
> default response) when the user presses <enter> in the spin-box.
> 
> I find the function gtk_entry_set_activates_default () in the GTK
> documentation, but it seems that spin_button inherits from widget
> instead of entry in lablgtk2 (2.10.0).  Did someone intend this
> mis-alignment of inheritance?  I feel hesitant at hacking things, and
> worry that maybe there's an incompatibility somewhere reflected here.
> 
> Thanks,
> E.

Indeed, perhaps a [method entry = new GEdit.entry obj]
would be welcome inside [GEdit.spin_button].

Since http://library.gnome.org/devel/gtk/stable/GtkSpinButton.html
says that: "[entry] is the GtkEntry part of the GtkSpinButton widget,
and can be used accordingly."

Still, as a workaround, a manual cast is possible with [GtkEdit.Entry.cast]:

let _ =
	let w = GWindow.dialog () ~title: "Go to page"
	  ~modal: true ~position: `CENTER in
	ignore (GMisc.label () ~text: "Page: " ~packing: w#vbox#add);
	let sb = GEdit.spin_button () ~packing: w#vbox#add
	  ~digits: 0 ~numeric: true in
	
	let entry = new GEdit.entry (GtkEdit.Entry.cast sb#as_widget) in
	
	entry#set_activates_default true;
	w#add_button_stock `OK `OK;
	w#add_button_stock `CANCEL `CANCEL;
	w#set_default_response `OK;
	let on_ok () =
		print_endline (string_of_int sb#digits);
		w#destroy ()
	in match w#run () with
	| `DELETE_EVENT
	| `CANCEL -> w#destroy ()
	| `OK     -> on_ok ()

HTH.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.