Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Lua Radio buttons, I can't get them to work< Next Oldest | Next Newest >
u2musicmike Offline





Group: Members
Posts: 149
Joined: April 2006
Posted: Jan. 24 2007,20:34 QUOTE

I am trying to get radio buttons to work in a short lua program:

Code Sample

selbc = fltk:Fl_Round_Button(130,20,18,25,"Breads_Cereals")
-- selbc:value(1)
selbc:type(fltk.FL_RADIO_BUTTON)
selbc:selection_color(fltk.FL_RED)

selmd = fltk:Fl_Round_Button(260,20,18,25,"Main Dishes")
selmd:type(fltk.FL_RADIO_BUTTON)
selmd:selection_color(fltk.FL_RED)

selveg = fltk:Fl_Round_Button(130,40,18,25,"Vegetables")
selveg:type(fltk.FL_RADIO_BUTTON)
selveg:selection_color(fltk.FL_RED)

selmisc = fltk:Fl_Round_Button(260,40,18,25,"Miscellaneous")
selmisc:type(fltk.FL_RADIO_BUTTON)
selmisc:selection_color(fltk.FL_RED)

-- setonly():void

if selmisc:value() == 1 then
foodcat = "Miscellaneous"
elseif selmd:value() == 1 then
foodcat = "Main Dishes"
elseif selveg:value() == 1 then
foodcat = "Vegetables"
elseif selbc:value() == 1 then
foodcat = "Breads_Cereals"
end


No matter what I click the value is never set unless I do it manually.  I tried to do it like the fdtool program but I am missing something.  Can somebody point me to a site that has some lua radio button code?
Back to top
Profile PM 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Jan. 24 2007,21:11 QUOTE

What is your enclosing container, group or window?
What gui is going to have the callback attached so you can display the results of the radio button selection.

We have 5 lua programs that use radio buttons, from simple to more complex for you to study.

icontool
mouse-config
rdesktop
wallpaper
fdtool
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 24 2007,22:22 QUOTE

Something like this might help?

Code Sample

function catfood(self)
foodcat=self:label();
print(foodcat);
end

w=fltk.Fl_Window(300,100,"catfood");
selbc = fltk:Fl_Round_Button(30,20,18,25,"Breads_Cereals")
selbc:type(fltk.FL_RADIO_BUTTON); selbc:callback(catfood);
--
selmd = fltk:Fl_Round_Button(160,20,18,25,"Main Dishes")
selmd:type(fltk.FL_RADIO_BUTTON); selmd:callback(catfood);
--
selveg = fltk:Fl_Round_Button(30,40,18,25,"Vegetables")
selveg:type(fltk.FL_RADIO_BUTTON); selveg:callback(catfood);
--
selmisc = fltk:Fl_Round_Button(160,40,18,25,"Miscellaneous")
selmisc:type(fltk.FL_RADIO_BUTTON); selmisc:callback(catfood);

w:show();
Fl:run();


If you have multiple sets of radio buttons you'll probably need to create a unique group for each set of buttons.  Also, this example uses the label of each button to determine the value of foodcat


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
u2musicmike Offline





Group: Members
Posts: 149
Joined: April 2006
Posted: Jan. 26 2007,15:41 QUOTE

Thanks for the help.  I was really stuck.  The radio buttons work now.  That is a pretty neat trick to pull the labels from the buttons.  I don't know the lua programming language very well but I am trying to build a data entry form for a sqlite database.  As a starting point I took the window routines from the fdtool.lua program and changed a few things like button names and input fields.  If I can get it to produce the sql statement that I want I will post the code or make a dsl package.

One thing that I found strange was the function has to be before the radio button statements.
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 26 2007,18:12 QUOTE

Apparently some languages don't require the function to be defined first, but  Lua seems to be one that does. I assume this is because Lua is interpreted line-by-line at runtime, so it needs to know what a callback does before it can use the callback. Maybe the function could first be declared without being fully defined, like in C, but I haven't really had any need or desire to experiment with that yet.

I know nothing about using sql databases yet, so I can't help there. So far my experience with saving and retreiving data has been in parsing plain text rc files, like many of the DSL tools do.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
4 replies since Jan. 24 2007,20:34 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Lua Radio buttons

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code