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 fltk scripting help for mpd client< Next Oldest | Next Newest >
dare2dreamer Offline

Group: Members
Posts: 113
Joined: Feb. 2005
Posted: June 07 2006,05:22 QUOTE

I'm hoping someone has better scripting skills than I do, because I could really use some help. I'm working on a simple gui front-end for the mpc extension in the myDSL repository.

I've got the basic buttons working, but I'm having a heck of a time with the volume slider. I can get it to update the mpd server's volume without a hitch, but I cannot for the life of me get it to read in the server's current volume on startup of the script.

Can someone please take a look? I'd love to get this working so I can submit it to both the repository, and the website.

I promise I'll tidy my (currently awful) code up before I release anything.

Code Sample


volnum = execute("/opt/mpc | grep volume | sed 's/[[:alpha:]]//g' | sed 's/%//g' | sed 's/[[:space:]]//g' | sed 's/://g'")
volcmd = {}
window = Window{210,65; label="jukebox control"}

b1 = Button{10,10,30,30, "<<"}
function b1.callback()
  execute("/opt/mpc prev")

b2 = Button{50,10,30,30, "->"}
function b2.callback()
  execute("/opt/mpc play")

b3 = Button{90,10,30,30, "||"}
function b3.callback()
  execute("/opt/mpc toggle")

b4 = Button{130,10,30,30, "[]"}
function b4.callback()
  execute("/opt/mpc stop")

b5 = Button{170,10,30,30, ">>"}
function b5.callback()
  execute("/opt/mpc next")

-- volume slider begin

volume = Value_Slider{20,50,185,15,"V:";
  align=Align.left, type=Slidertype.horiz,
  minimum=0, maximum = 100, step = 1,

function volume:callback()
volnum = self.value
volcmd = "/opt/mpc volume" .." "..  volnum
execute (volcmd)


-- volume slider end

window:end_layout() -- ends the layout of the window

Back to top
clacker Offline

Group: Members
Posts: 570
Joined: June 2004
Posted: June 07 2006,14:25 QUOTE

dare2dreamer, the execute function returns the exit code for the command you run, not its output.  There may be better ways, but here's one way of getting the output of a function into a string:

Code Sample
> myfilename=tmpname()
> print(myfilename)      
> execute("date > " .. myfilename)
> myfile = openfile(myfilename,"r")
> mystring = read(myfile,"*a")
> print(mystring)
Thu Jun  8 07:09:19 EDT 2006

> closefile(myfile)
> execute("rm " .. myfilename)
> mynewstring=gsub(mystring,"\n","")
> print(mynewstring)
Thu Jun  8 07:23:22 EDT 2006

The tmpfile() function gives you a unique string for your temp file's name.  The .. in the execute is a concatination of the two strings.  You may need to use gsub function to remove the trailing return character.
Back to top
Profile PM 
mikshaw Offline

Group: Members
Posts: 4856
Joined: July 2004
Posted: June 07 2006,14:41 QUOTE

Personally I'd rather have a more direct way to access an app's stdout/stderr in lua fltk, but so far that redirect to file seem to be the best alternative.  It would be sweet to be able set a variable according to stdout like the Bash $(command) or `command`.

One note, clacker: You can use "remove(myfilename)" instead of calling an external rm.

Back to top
Profile PM WEB 
2 replies since June 07 2006,05:22 < Next Oldest | Next Newest >

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

reply to topic new topic new poll
Quick Reply: lua fltk scripting help for mpd client

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