From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16055.51641.335621.554997 at akasha.ijm.jussieu.fr> Date: Tue, 6 May 2003 16:42:01 +0200 To: Richard Jones Cc: lablgtk at kaba.or.jp Subject: Re: Toggle button callback question In-Reply-To: <20030506141056.GB9761 at redhat.com> References: <20030506141056.GB9761 at redhat.com> Richard Jones [Tuesday 6 May 2003] : > > I think this is a very simple question - but it seems to be defeating > me nevertheless. > > I have code which looks like this: > > let menu_bold () = > (* I want this function to do two different things depending on whether > the toggle button is now active or inactive. *) > > let main () = > (* ..... *) > > (* This is where I create my toolbar containing a toggle button. *) > let toolbar = GButton.toolbar ~packing:vbox#pack () in > toolbar#insert_toggle_button ~text:"Bold" ~callback: menu_bold (); > > > The problem is that > > (a) The menu_bold cannot 'see' the button object, so it can't call > button#active to find the state. Hum, I see. For a "standalone" button (ie a button not in a toolbar) you would pass the button as an argument to the callback : let menu_bold button = ... if button#active ... let main () = ... let button = (* create the button *) in button#connect#toggled ~callback:(menu_bold button) ; But here you're using toolbar#insert_toggle_button which creates a button and connects a callback on the fly. So simply insert the button and connect it afterwards like a simple button : let button = toolbar#insert_toggle_button ~text:"Bold" () in button#connect#toggled ~callback:(menu_bold button) -- Olivier