* [Caml-list] lablGtk - newbie question
@ 2001-10-06 14:34 Andrew Lawson
2001-10-06 19:36 ` Maxence Guesdon
2001-10-06 22:50 ` Jacques Garrigue
0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lawson @ 2001-10-06 14:34 UTC (permalink / raw)
To: caml-list
Hi all
I've just started learning ocaml and lablGtk. I'm writing a
small utility and I'm trying to encapsulate the gui in a class, a
simplified example is below;
class mainWindow () =
object (self)
val winMain = GWindow.window ~title:"Cadb" ~border_width:10
i ~width:400 ~height:400 ()
val butNew = GButton.button ~label:"New" ()
initializer
winMain#add butNew; (* This would seem the obvious thing to
do but it doesn't work *)
winMain#connect#destroy ~callback:Main.quit;
winMain#show ()
end
Now I have to pack the button into the window, obviously I can't
do it in the val expression but I can't work out how to do it in the
initializer. Can someone help?
Andrew
--
Andrew Lawson
andrew@absentis.com
Swindon, Wilts, Uk
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] lablGtk - newbie question
2001-10-06 14:34 [Caml-list] lablGtk - newbie question Andrew Lawson
@ 2001-10-06 19:36 ` Maxence Guesdon
2001-10-06 22:50 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Maxence Guesdon @ 2001-10-06 19:36 UTC (permalink / raw)
To: Andrew Lawson; +Cc: caml-list
Andrew Lawson a écrit :
>
> Hi all
> I've just started learning ocaml and lablGtk. I'm writing a
> small utility and I'm trying to encapsulate the gui in a class, a
> simplified example is below;
>
> class mainWindow () =
> object (self)
> val winMain = GWindow.window ~title:"Cadb" ~border_width:10
> i ~width:400 ~height:400 ()
> val butNew = GButton.button ~label:"New" ()
> initializer
> winMain#add butNew; (* This would seem the obvious thing to
> do but it doesn't work *)
> winMain#connect#destroy ~callback:Main.quit;
> winMain#show ()
> end
>
> Now I have to pack the button into the window, obviously I can't
> do it in the val expression but I can't work out how to do it in the
> initializer. Can someone help?
>
to pack the button in the window :
winMain#add butNew#coerce;
BTW, a cool way to make the same but using the ~packing parameters :
class mainWindow () =
let winMain = GWindow.window ~title:"Cadb" ~border_width:10 ... in
let _ = winMain#connect#destroy ~callback:Main.quit in
let butNew = GButton.button ~label:"New" ~packing: winMain#add () in
object (self)
initializer
winMain#show ()
end
--
Maxence Guesdon
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] lablGtk - newbie question
2001-10-06 14:34 [Caml-list] lablGtk - newbie question Andrew Lawson
2001-10-06 19:36 ` Maxence Guesdon
@ 2001-10-06 22:50 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2001-10-06 22:50 UTC (permalink / raw)
To: andrew; +Cc: caml-list
From: Andrew Lawson <andrew@absentis.com>
Subject: [Caml-list] lablGtk - newbie question
Date: Sat, 6 Oct 2001 15:34:39 +0100
> Hi all
> I've just started learning ocaml and lablGtk. I'm writing a
> small utility and I'm trying to encapsulate the gui in a class, a
> simplified example is below;
> Now I have to pack the button into the window, obviously I can't
> do it in the val expression but I can't work out how to do it in the
> initializer. Can someone help?
I suppose your "does not work" comment is about a type error.
You should be more explicit, since GTK misbehaviour is also a frequent
problem :-)
The type problem is solved by
winMain#add butNew#coerce
On the other hand, using val to define winMain does not allow for the
most natural lablGTK style:
class mainWindow () =
let winMain = GWindow.window ~title:"Cadb" ~border_width:10
~width:400 ~height:400 () in
let butNew = GButton.button ~label:"New" ~packing:winMain#add () in
object
method winMain = winMain
method butNew = butNew
initializer
winMain#connect#destroy ~callback:Main.quit;
winMain#show ()
end
Andrew
--
Andrew Lawson
andrew@absentis.com
Swindon, Wilts, Uk
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-10-08 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-06 14:34 [Caml-list] lablGtk - newbie question Andrew Lawson
2001-10-06 19:36 ` Maxence Guesdon
2001-10-06 22:50 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox