struppi
Group: Members
Posts: 93
Joined: Dec. 2004 |
|
Posted: April 25 2005,13:41 |
|
hi. i think the dsl 1.0 version of the mydslPanel is really good - for downloading extensions from the repository.
but what about all the local stored extensions? the last, perl+dillo version was able to load extensions from the internet _and_ from local drives.
so i tried to modify the flua mydslPanel. This is the result:
mydslPanel2.lua:
Code Sample | #!/bin/flua
-- (C) Robert Shingledecker 2005 -- -- Main GUI loop for myDSL Extensions -- Modified by Struppi
w = Window{430,170, "DSL Download Extension Panel"}
b1 = Button{10,10,130,30, "&Apps"} function b1.callback() execute("mydslBrowser.lua apps") end
b2 = Button{10,50,130,30, "&Multimedia"} function b2:callback() execute("mydslBrowser.lua multimedia") end
b3 = Button{10,90,130,30, "&Themes"} function b3:callback() execute("mydslBrowser.lua themes") end
b4 = Button{150,10,130,30, "&Games"} function b4:callback() execute("mydslBrowser.lua games") end
b5 = Button{150,50,130,30, "&Net"} function b5:callback() execute("mydslBrowser.lua net") end
b6 = Button{150,90,130,30, "&UCI"} function b6:callback() execute("mydslBrowser.lua uci") end
b7 = Button{290,10,130,30, "G&tk2"} function b7:callback() execute("mydslBrowser.lua gtk2") end
b8 = Button{290,50,130,30, "&System"} function b8:callback() execute("mydslBrowser.lua system") end
b9 = Button{290,90,130,30, "&WM_Apps"} function b9:callback() execute("mydslBrowser.lua wm_apps") end
inp = Input{130,130,140,25,"MyDsl - Directory:"; callback=cb} b10 = Return_Button{290,127,100,30, "OK"} function b10:callback() myDslDir=inp.value execute("mydslLocalBrowser.lua " .. myDslDir) end
w:end_layout() w:show() |
myDslLocalBrowser.lua:
Code Sample | #!/bin/flua -f
-- (c) 2005 Robert Shingledecker -- myDSL extension browser noramlly called from mydslPanel -- Local modification by Struppi
function parseInfo(s) local i,j = strfind(s,".dsl") if not i then return nil end local t=strsub(s,1,j) --local k,l = strfind(t,'"') --s=strsub(t,k+1) s=t return s end
-- Main if getn(arg) == 1 then myDslDir = arg[1] else print("usage: mydslBrowser.lua [library_name]") exit(1) end
execute('ls /mnt/' .. myDslDir .. '/optional/*.dsl >index.txt') local file,err = openfile("index.txt", "r")
if not file then print("Cannot open file index.txt: ".. err) exit(1) end
filetable = {} fname = tmpname() filelist = openfile(fname,"w") line = read(file, "*l") while line do result = parseInfo(line) if result then tinsert(filetable,result) write(filelist, result .. "\n") end line = read(file,"*l") end closefile(file) closefile(filelist)
w = Window{300,400,'/mnt/'..myDslDir; box=Boxtype.none} function w:callback() remove(fname) remove('index.txt') exit(0) end browser = Select_Browser{0,0,300,400; type=Browsertype.single}
function browser:callback() selected_item = filetable[self.value]
if fl_ask("Install DSL-Extension " .. selected_item .. " ?") then execute("mydsl-load " .. selected_item ) remove(fname) remove('index.txt') exit(0) else return end
--execute('mydslInfo.lua ' .. myDslDir .. ' ' .. selected_item) end
if not browser:load(fname) then print("can't load ", fname) exit(1) end
browser.position = 0 w.resizable = browser w:show() |
i'm not a programmer and i think the two scripts are full of unneeded things, but it works. the user can enter the device and the script looks for all .dsl-files (.uci and .tar.gz can be added quite easy) in the /mnt/<device>/optional directory. one click on an extension asks whether to install it or not.
perhaps this is an idea for robert an the other 'dsl-professionals'
struppi
|