MakodFilu
Group: Members
Posts: 65
Joined: Jan. 2006 |
|
Posted: Mar. 11 2007,04:10 |
|
Sure!
Code Sample | #!/bin/lua -- Launches applications under X -- by Daniel Plata Lorenzo "MakodFilu"
version="0.9.1" max_history=10 history_file=os.getenv("HOME").."/.flrun_history" ww=250 --window width wh=100 --window height bw=60 --button width bh=25 --button height
-- L10N (Somewhat) window_text="flRun v"..version input_text="Launch Application" cancel_text="&Cancel" cancel_tooltip="Cancel launch" ok_text="&Ok" ok_tooltip="Launch application" browse_text="&Browse" browse_tooltip="Browse for command" choose_text="Choose Application"
-- Code w=fltk:Fl_Window(ww,wh,window_text)
history_table={} table_length=0 file = io.open(history_file, "r") if file then for line in file:lines() do table.insert(history_table, line) end file:close() table_length=table.maxn(history_table) if not table_length then table_length=0 end end
input = fltk:Fl_Input_Choice(10,30,230,bh,input_text) input:align(fltk.FL_ALIGN_TOP) if table_length~=0 then input:value(history_table[table_length]) -- Show last feed command -- input:mark(1) for i=1,table_length,1 do input:add(history_table[i]) end end
ok = fltk:Fl_Return_Button(ww-3*bw*1.2,wh-35,bw,bh,ok_text) ok:tooltip(ok_tooltip) ok:callback( function(ok) if input:value() == "" then io.write(string.char(7)) io.flush() else if table_length < max_history then start=1 else start=table_length-(max_history-2) -- Discard older entries end io.output(io.open(history_file,"w+")) for i=start,table_length,1 do if history_table[i]~=input:value() then io.write(history_table[i]..'\n') end end io.write(input:value()..'\n') io.close() os.execute(input:value()..' 2>/dev/null &') os.exit(0) end end)
cancel = fltk:Fl_Button(ww-2*bw*1.2,wh-35,bw,bh,cancel_text) cancel:tooltip(cancel_tooltip) cancel:callback( function(cancel) os.exit(0) end)
browse = fltk:Fl_Button(ww-1*bw*1.2,wh-35,bw,bh,browse_text) browse:tooltip(browse_tooltip) browse:callback( function(browse) input:value(fltk.fl_file_chooser(choose_text,"*",single,nil)) end)
w:show() Fl:run()
|
|