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
Pages: (3) </ [1] 2 3 >/

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

reply to topic new topic new poll
Topic: dynamic flua button creation, for redundant callbacks< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 05 2006,18:57 QUOTE

It took me almost 2 hours of error messages before coming up with something to solve my current problem.  I was looking for a way to automatically draw multiple buttons according to a list of button labels. The drawing wasn't a big problem, but i couldn't seem to get the callback functions built into the loop.  I needed a way to avoid having to type a new callback every time I added a string to the list.  The answer was to create a global function and put "callback=<that function>" into the button properties.  The function tests to see which button is being pressed, and acts accordingly.

This script builds a pack of buttons and labels them according to what is in the button_labels table.  Add more items to the table, and you get more buttons.
It draws a single column of buttons, but i'm sure the script could be tweaked to pack them into multiple columns.  Also, the callback is limited...i was just looking for a way to do the same action on each item in the list.

Code Sample
ww = 360
wh = 300

button_labels = {"first button","second button","third button","the fourth"}

w = Window{ww,wh,"Lua FLTK Templates"}
display = Output{140,10,ww-150,25}

buttons = Pack{10,10,120,wh-30}

function do_butt(self)
for i = 1,getn(button_labels) do
if self.label == button_labels[i] then
display.value = "Button label: "..button_labels[i]
break
end
end
end

button = {}
for i = 1,getn(button_labels) do
button[i] = Button{25+i*10,25+i*10,25,25,button_labels[i];callback=do_butt}
end
buttons:end_layout()

w:show()


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





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Jan. 05 2006,19:40 QUOTE

Very cool. Thanks for sharing.
I am adding that to my notebook of notes!
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 05 2006,21:52 QUOTE

This is the project that had me trying to figure this out:
http://dsl-mirror.vectori.net/tools/mikshaw/flua_templates.uci
(you'll probably need to right-click, save as)
EDIT: package was renamed to something more appropriate...check the link further down in this thread.

It's a work in progress, which should eventually provide a slew of Lua FLTK templates for reference or for using as a script base.  Currently only the first three are mine, and the rest were taken from the flua package....eventually i hope to have every widget available added to it.


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





Group: Members
Posts: 570
Joined: June 2004
Posted: Jan. 07 2006,13:05 QUOTE

mikshaw, those flua example in the flua_templates.uci are a huge help.  Great examples with the code right there in another window so you can see what's going on.  I can wait till it's done.
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 07 2006,15:12 QUOTE

It's never done.  Nothing is ever done.  At its current stage (as of last night) I'd say it's beta, but i have no idea how much better it will become....It could be finished now other than adding more widgets, or it might evolve into something more useful.  Typically if i run into a snag that i can't solve within a few hours, that project gets put in the fridge for a little while.  who knows.

One thing i do know is that i'd like to be able to select/copy text from the display window, but that will require loading the files in line by line...not something i want to script at the moment.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
11 replies since Jan. 05 2006,18:57 < Next Oldest | Next Newest >

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

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: dynamic flua button creation

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