Re: EuGTK - GtkRadioMenuItem
- Posted by irv Oct 20, 2010
- 1357 views
You should update your EuGtk library, since I don't know if the version you have implements radio menu items: EuGTK 4.2.5 (2 megs) http://etcwebspace.com/users/irvm
http://sites.google.com/site/m4rm2duk/gtk
There are several added new features as well. Here's a demo of the radio menu items:
include GtkEngine.e include std/machine.e constant win = create(GtkWindow) connect(win,"destroy",quit) set(win,"default size", 300,200) constant panel = create(GtkVBox) add(win,panel) constant menu = create(GtkMenuBar) pack(panel,menu) constant rb1 = create(GtkRadioMenuItem,0,"One",0) constant rb2 = create(GtkRadioMenuItem,get(rb1,"group"),"Two") constant rb3 = create(GtkRadioMenuItem,get(rb2,"group"),"Three") -- following 3 lines make them show as checkmarks -- rather than round radio buttons: set(rb1,"draw as radio",FALSE) set(rb2,"draw as radio",FALSE) set(rb3,"draw as radio",FALSE) constant menuitem1 = create(GtkMenuItem,"_File"), filemenu = create(GtkMenu) set(filemenu,"append",rb1) set(filemenu,"append",rb2) set(filemenu,"append",rb3) set(menuitem1,"submenu",filemenu) set(menu,"append",menuitem1) show_all(win) main()
Oh - the signal to use is probably "toggled". Remember, however, that when you click on one radio button, another one is toggled "off", so you'll get two signals emitted. One for the item you clicked "on", another for the one which was switched "off".
The way you handle this depends on whether you want to connect all the radio group to one function, or whether you connect each radio item to call a different function. If all are connected to one function (foo), then this works:
function foo(atom x) -- which radio item? if get(x,"active") then -- ignore the one which was turned off switch x do case rb1 then puts(1,"rb1 on\n") case rb2 then puts(1,"rb2 on\n") case rb3 then puts(1,"rb3 on\n") end switch else -- do something for the one which was just de-selected here: end if return 1 end function