murgaLua tests


Forum: Programming and Scripting
Topic: murgaLua tests
started by: mikshaw

Posted by mikshaw on Aug. 21 2006,05:55
Since MaxiJavi introduced < murgaLua > to these forums, and since John Murga himself was kind enough to build a version which works great in DSL with no additional dependencies, I thought it'd be a crime not to dive into it.  So....as I struggle to learn the differences between this application and Lua-FLTK, I'll be posting what I learn here.

The first bit is a demonstration of standard buttons.  Comparing murgaLua to FLTK, there seem to be only 3 button types that are not supported: shadow, rounded, and diamond.  Those three are, in my opinion, fairly useless anyway =o)

Code Sample
ww=360 --window width
wh=420 --window height

presses = 0 -- used for the repeat button
function button_press(self)
if self == butts[10] or self == butts[11] or self == butts[12] then
if self:value() == 1 then status="activated" else status="deactivated" end
out:value("\""..self:label().."\" was "..status)
presses = 0
elseif self == butts[9] then
presses = presses+1
out:value("\""..self:label().."\" was pressed "..presses.." times")
else
out:value("\""..self:label().."\" was pressed")
presses = 0
end
end

w=fltk:Fl_Window(ww,wh,"murgaLua Button Demo")
butts={}

----------
---- Here are two methods of laying out an array of similar widgets

-- Method 1
--butts[1]=fltk:Fl_Button(10,10,ww-20,25,"Fl_Button default")
--butts[2]=fltk:Fl_Button(10,40,ww-20,25,"Fl_Button down")
--butts[3]=fltk:Fl_Button(10,70,ww-20,25,"Fl_Button thin")
--butts[4]=fltk:Fl_Button(10,100,ww-20,25,"Fl_Button thin down")
--butts[5]=fltk:Fl_Button(10,130,ww-20,25,"Fl_Button engraved")
--butts[6]=fltk:Fl_Button(10,160,ww-20,25,"Fl_Button embossed")
--butts[7]=fltk:Fl_Button(10,190,ww-20,25,"Fl_Button border")

-- Method 2
labels={"default","down","thin","thin down","engraved","embossed","border"}
for i = 1,7 do butts[i]=fltk:Fl_Button(10,30*i-20,ww-20,25,"Fl_Button "..labels[i]) end
----------

butts[2]:box(fltk.FL_DOWN_BOX)
butts[3]:box(fltk.FL_THIN_UP_BOX)
butts[4]:box(fltk.FL_THIN_DOWN_BOX)
butts[5]:box(fltk.FL_ENGRAVED_BOX)
butts[6]:box(fltk.FL_EMBOSSED_BOX)
butts[7]:box(fltk.FL_BORDER_BOX)
butts[8]=fltk:Fl_Return_Button(10,220,ww-20,25,"Fl_Return_Button")
butts[9]=fltk:Fl_Repeat_Button(10,250,ww-20,25,"Fl_Repeat_Button")
butts[10]=fltk:Fl_Light_Button(10,280,ww-20,25,"Fl_Light_Button")
butts[11]=fltk:Fl_Round_Button(10,310,ww-20,25,"Fl_Round_Button")
butts[12]=fltk:Fl_Check_Button(10,340,ww-20,25,"Fl_Check_Button")

for i = 1,12 do
butts[i]:callback(button_press)
end
out=fltk:Fl_Output(10,370,ww-20,25)

w:show()
Fl:run()


The second one is just a clock widget...nothing special or interactive added to it, but i thought it was kind of an interesting widget to include in such a small toolbox.
Code Sample
ww=180 --window width
wh=200 --window height

w=fltk:Fl_Window(ww,wh,"murgaLua Clock Demo")

clock=fltk:Fl_Clock(5,5,ww-10,ww-10,"a clock")
clock:box(fltk.FL_DOWN_BOX)

w:show()
Fl:run()

Posted by u2musicmike on Aug. 21 2006,14:49
Do you know if murgaLua is compatable with the version of sqlite in DSL?  I was going to try to check it out but haven't had time.
Posted by roberts on Aug. 21 2006,17:26
I have the latest sqlite in dsl-3.1 pre testing.
And murgaLua sql example worked fine.
So stay tuned for that.

Posted by mikshaw on Aug. 21 2006,17:39
Fl_Positioner:
I'm not sure what use I'd have for this this particular widget, but it's pretty cool.
Code Sample
ww=350 --window width
wh=400 --window height

function thing_cb()
xpos=string.format("%.2f",thing:xvalue()*100)
ypos=string.format("%.2f",thing:yvalue()*100)
out:value("X: "..xpos.."  Y: "..ypos)
--out:value("X: "..thing:xvalue().."  Y: "..thing:yvalue())
end

w=fltk:Fl_Window(ww,wh,"murgaLua Positioner Demo")

frame=fltk:Fl_Box(2,2,ww-4,ww-4); frame:box(fltk.FL_UP_BOX)

thing=fltk:Fl_Positioner(5,5,ww-10,ww-10,"percentage of window size"); thing:box(fltk.FL_DOWN_BOX)
thing:callback(thing_cb)

out=fltk:Fl_Output(5,wh-30,ww-10,25)

w:show()
Fl:run()


Fl_Progress:
A progress bar. It was actually kinda difficult to come up with a demo for this, since lua apparently has no sleep function and the widget apparently cannot be controlled through a single loop....so i just made it a button instead.
Code Sample
ww=350 --window width
wh=100 --window height

w=fltk:Fl_Window(ww,wh,"murgaLua Progress Demo")

thing=fltk:Fl_Progress(10,10,ww-20,30,"0 %"); thing:box(fltk.FL_DOWN_BOX)
thing:selection_color(fltk.FL_BLACK)

function go_cb()
if thing:value() == 100 then
thing:selection_color(fltk.FL_BLACK)
thing:value(0)
else
if thing:value() >= 75 then thing:selection_color(fltk.FL_RED) end
thing:value(thing:value()+1)
end
thing:label(thing:value().." %")
end

go=fltk:Fl_Repeat_Button(10,50,ww-20,30,"hold me down"); go:callback(go_cb)

w:show()
Fl:run()


I probably should start properly terminating my lines, but you get into a habit and end up continuing it....

EDIT: There is a wait feature available in FLTK (i should have assumed that), but at this time I haven't tried anything with it, and not sure how it ties in with Lua scripting.

Posted by mikshaw on Aug. 21 2006,21:59
Icons:
This will display png and gif images in $HOME/.xtdesktop.
There seems to be an issue either with xpm images or with a very large number of images...i haven't discovered which it is yet.
Code Sample
ww=400 --window width
wh=350 --window height

dir=os.getenv("HOME").."/.xtdesktop/" -- ending slash is vital
images = murgaLua.readDirectory(dir)
fltk.fl_register_images()

function get_image_data(self)
for i=0,table.getn(images) do
if self:tooltip() == dir..images[i] then -- find the right image
display:image(icon[i]:copy(128,128)) --show it bigger!
display_label:label(images[i].."\n"..icon[i]:w().."x"..icon[i]:h()) -- show height and width
display:redraw()
break
end
end
end

w=fltk:Fl_Window(ww,wh,"murgaLua Gif/Png Icon Demo")

display=fltk:Fl_Box(120,30,256,256) -- big image
display_label=fltk:Fl_Box(120,290,256,40)
display_label:label("nothing")
display:box(fltk.FL_THIN_DOWN_BOX)

scroll=fltk:Fl_Scroll(5,5,90,330)
pack=fltk:Fl_Pack(5,5,68,300)
pack:spacing(2)
icon={}; butt={}
row=1;col=1
-- since the images table contains more than just images (*.lnk gets in too)
-- i'm building the icons from specific items in the table.
for i=0,table.getn(images) do
if string.find (images[i],".png",-4,plain) or string.find (images[i],".gif",-4,plain)
then
icon[i]=Fl_Shared_Image.get(dir..images[i])
butt[i]=fltk:Fl_Button(0,0,64,64)
butt[i]:align(fltk.FL_ALIGN_CLIP)
butt[i]:image(icon[i])
butt[i]:tooltip(dir..images[i])
butt[i]:callback(get_image_data)
end
end
w:show()
Fl:run()


I don't know if "readDirectory" is something that Murga added, but i didn't see anything about it in the lua or fltk docs.
EDIT: I see now that it is an xml function added to complement Lua.

Posted by mikshaw on Aug. 22 2006,00:26
256 pretty colors
mouse over them to get the color number
Code Sample
ww = 380
wh = 360
w = fltk:Fl_Window(ww,wh,"FLTK Colors, murgaLua")

colors = {}
row=20;switch=15;bw=20;left=10
for i = 0,255 do
colors[i]=fltk:Fl_Box(left+bw,row,bw,bw)
colors[i]:color(i)
colors[i]:box(fltk.FL_THIN_UP_BOX)
colors[i]:tooltip("color "..i)
left=left+bw
if i == switch then
switch = switch+16
row = row+bw
left = 10
end
end

w:show()
Fl:run()


Here's the same thing written for Lua-FLTK.  It looks like they're almost identical, except for colors 15-31
Code Sample
ww = 380
wh = 360
w = Window{ww,wh,"FLTK Colors, lua-FLTK"}

colors = {}
row=20;switch=15;bw=20;left=10
for i = 0,255 do
colors[i]=Box{left+bw,row,bw,bw;color=i,box=Boxtype.thin_up}
left=left+bw
if i == switch then
switch = switch+16
row = row+bw
left = 10
end
end

w:end_layout()
w:show()

Posted by mikshaw on Aug. 22 2006,03:14
Tabs:
Code Sample
ww=320 --window width
wh=240 --window height

function show2()
if on2:takesevents() == 1 then
on2:hide()
tab2:deactivate()
on1:label("unlock tab2")
else
tab2:activate()
on2:show()
on1:label("lock tab2")
end
end

w=fltk:Fl_Window(ww,wh,"murgaLua Tabs Demo")
tabs=fltk:Fl_Tabs(10,20,ww-20,wh-25,"Tabs")

tab1 = fltk:Fl_Group(10,40,ww-20,wh-45,"Tab1")
on1=fltk:Fl_Button(20,60,100,30,"unlock tab 2");on1:callback(show2)
fltk:Fl_End() --end of tab1 group
tab2 = fltk:Fl_Group(10,40,ww-20,wh-45,"Tab2")
on2=fltk:Fl_Box(20,60,ww-40,wh-85);on2:box(fltk.FL_THIN_DOWN_BOX)
on2:label("Congratulations!\nYou pressed a button!")
fltk:Fl_End()

tab2:deactivate()
on2:hide()
w:show()
Fl:run()

There's a "wizard" widget that's similar to this, but you are restricted to linear navigation (page 1 <-> page 2 <-> page 3, no page 1 <-> page 4 <-> page 2). I can't understand how to build the navigation, though, so that's in the trash for now.

Posted by mikshaw on Aug. 22 2006,18:12
More Colors....

I haven't figured out how to do anything useful with the rgb color picker.  It seems to return unuseable values, even when using the format function (as could be done with Lua-FLTK).  However, there is an interactive color map which works great for the 256 default colors.  I didn't notice this in Lua-FLTK, but maybe it's there...

Code Sample
ww=220 --window width
wh=200 --window height

function cmap()
-- open the color map with the 'pop' button's color selected
newcolor=fltk.fl_show_colormap(pop:color())
-- set button's color and label from the new color
pop:color(newcolor);pop:label("FLTK Color "..newcolor)
end

w=fltk:Fl_Window(ww,wh,"murgaLua Colormap Demo")

pop=fltk:Fl_Button(20,20,ww-40,ww-80,"push for colors")
pop:align(fltk.FL_ALIGN_BOTTOM)
pop:callback(cmap)

w:show()
Fl:run()


I still haven't yet seen any way to return hex (html) colors or rgb.txt-type colors from murgaLua.

Posted by mikshaw on Aug. 24 2006,03:51
I think I know what was up with the color chooser.  FLTK seems to have two ways to create some of its choosers.  One way is to do Fl_Color_Chooser as a FLTK class, and the other is to do fl_color_chooser as a function.  I'm not sure why there is a distinction, but i got it figured out anyway.

so, next....

ucitool.lua, second generation

This is a work in progress.  I haven't fully worked out how I'm going to layout a uci builder or what features it will have, so that hasn't been added yet.  So far it will umount uci packages like the original version does, plus it will list and mount extensions from a specified directory...specified either from a ~/.ucitool file or by browsing to a directory.
Code Sample
-- i made a few bad choices for variable names in this script =o)

ww=400; wh=300;      -- window size
tx=2; ty=27;         -- tab position
tw=ww-4; th=wh-ty-2; -- tab size
bw=120; bh=30;       -- button size
tempfile="/tmp/"..os.getenv("USER")..".uci2ool"
tooltips=1 -- 0 disables tooltips
--ucidir="/mnt/hda3/home/dsl/mydsl/optional" -- path to a dir containing ucis
ucidir="/cdrom/mydsl/optional"

-- if you have a $HOME/.ucitool file with the variables
-- above, your values will override the defaults
rcfile=os.getenv("HOME").."/.ucitool";
if io.open(rcfile,"r") then dofile(rcfile) end;


function build_uci_lists()
-- runs at startup, each time you add or remove a uci, and when "refresh" is pressed.
-- list mounted uci files from mtab
os.execute("grep \"^.*.uci \" /etc/mtab | awk '{print $1}' >"..tempfile)
ufiles:clear()
for line in io.lines(tempfile) do ufiles:add(line) end -- print output to mntout
ufiles:redraw()
-- build list of available unmounted uci files.
-- I don't know why they're not listed alphabetically
if murgaLua.isDirectory(ucidir) then
input=io.open(tempfile,"r")
mounted=input:read("*a")
io.close(input)
allfiles=murgaLua.readDirectory(ucidir)
mfiles:clear()
for i=0,table.getn(allfiles) do
if string.find(allfiles[i],".uci",-4,plain) then
-- compare available files to mounted files
if not string.find(mounted,allfiles[i].."\n") then mfiles:add(ucidir.."/"..allfiles[i]) end
end
end
mfiles:redraw()
os.remove(tempfile)
end
end


function browse_cb()
new_ucidir=fltk.fl_dir_chooser("choose a uci directory",ucidir,"*",0)
if murgaLua.isDirectory(new_ucidir) then
-- return a new ucidir, without a trailing slash
ucidir=string.gsub(new_ucidir,"%/$","")
build_uci_lists() end
end

function mount_cb()
-- run mydsl-load on selected files
for i = 1,mfiles:nitems() do
if mfiles:checked(i)==1 then
os.execute("mydsl-load "..mfiles:text(i).." &>"..tempfile)
for line in io.lines(tempfile) do mntout:add(line) end -- print output to mntout
mntout:bottomline(mntout:size())
end
end
build_uci_lists()
end

function umount_cb()
-- run mydsl-load on selected files
-- this is nearly identical to mount_cb, so i should try to merge them
for i = 1,ufiles:nitems() do
if ufiles:checked(i)==1 then
os.execute("mydsl-load "..ufiles:text(i).." &>"..tempfile)
for line in io.lines(tempfile) do umntout:add(line) end -- print output to umntout
umntout:bottomline(umntout:size())
end
end
build_uci_lists()
end

w=fltk:Fl_Double_Window(ww,wh,"UCI Tool");

tabs=fltk:Fl_Tabs(tx,2,ww-4,wh-4);
tabs:selection_color(51);
tabs:color(1);

tab1 = fltk:Fl_Group(tx,ty,tw,th,"  create  ");
frame=fltk:Fl_Box(tx+2,ty+2,tw-4,th-4); -- just a frame, but it hides a strip of selection color
frame:box(fltk.FL_THIN_DOWN_BOX);
fltk:Fl_End();

tab2 = fltk:Fl_Group(tx,ty,tw,th,"  mount  ");
-- checklist of unmounted ucis
mfiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); mfiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
mntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76); mntout:format_char(0);
mount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"mount"); mount:box(fltk.FL_THIN_UP_BOX);
mount:callback(mount_cb);
browse=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"browse"); browse:box(fltk.FL_THIN_UP_BOX);
browse:callback(browse_cb);
fltk:Fl_End();

tab3 = fltk:Fl_Group(tx,ty,tw,th,"  umount  ");
-- checklist of mounted ucis
ufiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); ufiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
umntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76);
umount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"umount"); umount:box(fltk.FL_THIN_UP_BOX);
umount:callback(umount_cb);
refresh=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"refresh"); refresh:box(fltk.FL_THIN_UP_BOX);
refresh:callback(build_uci_lists);
fltk:Fl_End();

tab4 = fltk:Fl_Group(tx,ty,tw,th,"  about  ");
about=fltk:Fl_Box(tx+2,ty+2,tw-4,th-4);
about:box(fltk.FL_THIN_DOWN_BOX);
about:label("UCITOOL 2: THE REMOUNTENING\n\n\
A MurgaLua tool for creating and managing\
*.uci packages in Damn Small Linux.\
INCOMPLETE TEST RELEASE!\
\n\n(c)2006 mikshaw [mrblog|yahoo|com]");
fltk:Fl_End();

if tooltips ~= 0 then
mfiles:tooltip("If you have any *.uci files in \n"..ucidir.."\nthey will be listed here");
ufiles:tooltip("These are the currently mounted uci packages");
mount:tooltip("mount all checked files");
mntout:tooltip("output from the mydsl-load command");
umntout:tooltip("output from the mydsl-load command");
browse:tooltip("select a new directory");
umount:tooltip("umount all checked files");
refresh:tooltip("refresh the list of mounted files");
end

build_uci_lists();

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

Posted by mikshaw on Aug. 25 2006,03:40
Playing a little with themes....

FLTK currently includes one 'scheme' in addition to the default, which is called "plastic". This scheme gives the widgets a more glossy look, similar to some themes found in other widget sets.  It's not really an amazing thing, but it provides an option if flat colors are not your taste.
You can access this scheme in MurgaLua with Fl:scheme("plastic"), or with a combination of Fl:scheme(nil) and the environment variable FLTK_SCHEME="plastic".  I assume this second method would allow the developer to include that option in his application without forcing the scheme on the user.

Color schemes can be created fairly quickly by setting Fl:background, Fl:background2, and Fl:foreground. The first is the typical background color, and the second is the background of text fields and other widgets that are typically white. The foreground is the text. The syntax is Fl:background(red_value,green_value,blue_value), but for now I prefer to combine it with Fl:getcolor so i can simply use the numbered colors displayed in the colormap:

Fl:background(Fl:get_color(16,r,g,b))
Fl:background2(Fl:get_color(17,r,g,b))
Fl:foreground(Fl:get_color(18,r,g,b))

Setting the default font can be done with Fl:set_font(fltk.FL_HELVETICA,"fontname") or Fl:set_font(0,"fontname"), where fontname is an alias or full X font name.  The same can be done with other default fonts:
Quote (documentation @ fltk.org)
The following constants define the standard FLTK fonts:

   * FL_HELVETICA - Helvetica (or Arial) normal (0).
   * FL_HELVETICA_BOLD - Helvetica (or Arial) bold.
   * FL_HELVETICA_ITALIC - Helvetica (or Arial) oblique.
   * FL_HELVETICA_BOLD_ITALIC - Helvetica (or Arial) bold-oblique.
   * FL_COURIER - Courier normal.
   * FL_COURIER_BOLD - Courier bold.
   * FL_COURIER_ITALIC - Courier italic.
   * FL_COURIER_BOLD_ITALIC - Courier bold-italic.
   * FL_TIMES - Times roman.
   * FL_TIMES_BOLD - Times bold.
   * FL_TIMES_ITALIC - Times italic.
   * FL_TIMES_BOLD_ITALIC - Times bold-italic.
   * FL_SYMBOL - Standard symbol font.
   * FL_SCREEN - Default monospaced screen font.
   * FL_SCREEN_BOLD - Default monospaced bold screen font.
   * FL_ZAPF_DINGBATS - Zapf-dingbats font.

IMPORTANT: This works only partially with Xft. The font names are different (i have no idea where the names come from, but they are not standard X names or aliases), and some fonts will crash murgaLua.  Fortunately DSL has a Xft-disabled version, so these probelms will occur only if you are coding for another system.

Posted by JohnMurga on Aug. 28 2006,18:11
Wow

Thanks for the tests ... I am currently traveling, but I hope to release a new version soon and will incorporate your feedback (and if it's OK), some of your tests.

I have some fixes and additions to the FLTK stuff and changes to the sqLite stuff that should reduce the size of the runtime.

Cheers
JohnM

Posted by mikshaw on Aug. 28 2006,19:38
sweet! =o)

Just please don't include the full ucitool (parts are fine, if anything is of use to you), since it is incomplete and represents the DSL project to an extent.

Posted by mikshaw on Oct. 22 2006,17:11
ucitool update

Shows mounted and available uci packages, and includes a very basic uci builder.  What this builder does is simply create a cloop from a chosen directory and place it in the current directory. I had considered adding more features to the builder, but i came to the conclusion that it would make the script much too complex for what little benefit it would give.

The directory containing available uci packages is /cdrom/mydsl/optional by default, but can be changed by setting the UCITOOL_DIR environment variable or by browsing from within the application.

Code Sample

-- mounts, umounts and builds .uci extensions
-- (c) 2005,2006 mikshaw
--
-- Changelog (yyyy/mm/dd)
--    2006/10/23: Fixed multiple trailing slashes on dir name
--                Sort the list of available packges
--                Consolidated mount and umount functions
--    2006/10/21: Added basic feature to build UCI packages
--                UCI directory can be specified via UCITOOL_DIR
--    2006/09/05: Port to MurgaLua
--                Added tabs and ability to mount packages
--                Output of mydsl-load is displayed in the gui
--    2005/12/30: Changed UI to match DSL tools
--                Added hotkey support
--                Auto-selects first line for better keyboard support
--    2005/12/09: Displays total number of mounted UCIs
--    2005/12/08: First release
--
-- TODO: Make it fully keyboard controllable (is that possible with fltk?)
-----------------------------------------------------------------------------

ww=400; wh=300;      -- window size
tx=2; ty=27;         -- tab position
tw=ww-4; th=wh-ty-2; -- tab size
bw=120; bh=30;       -- button size
tempfile="/tmp/"..os.getenv("USER")..".uci2ool"
pwd=os.getenv("PWD")
ucidir="/cdrom/mydsl/optional" -- default uci directory

-- check for UCITOOL_DIR environment variable
ucivar=os.getenv("UCITOOL_DIR")
if murgaLua.isDirectory(ucivar) then ucidir=ucivar end


-- done at startup, add/remove a uci, and when "refresh" is pressed
function build_uci_lists()
-- add mounted files from mtab to ufiles window
os.execute("grep \"^.*.uci \" /etc/mtab | awk '{print $1}' | sort >"..tempfile)
ufiles:clear()
for line in io.lines(tempfile) do ufiles:add(line) end
ufiles:redraw()
-- compare mtab UCI files (tempfile) with files in ucidir
if murgaLua.isDirectory(ucidir) then
input=io.open(tempfile,"r")
mounted=input:read("*a")
io.close(input)
allfiles=murgaLua.readDirectory(ucidir)
table.sort(allfiles)
mfiles:clear()
for i=0,table.getn(allfiles) do
if string.find(allfiles[i],".uci",-4,plain) then
-- list only *.uci files that are not in mtab
if not string.find(mounted,allfiles[i].."\n") then mfiles:add(ucidir.."/"..allfiles[i]) end
end
end
mfiles:redraw()
end
os.remove(tempfile)
end

-- choose a different uci directory
function browse_cb()
new_ucidir=fltk.fl_dir_chooser("choose a uci directory",ucidir,"*",0)
if murgaLua.isDirectory(new_ucidir) then
-- remove trailing slash if found
ucidir=string.gsub(new_ucidir,"%/*$","")
build_uci_lists() end
end

-- run mydsl-load on selected files
function mount_cb(self)
-- mount or umount? Uses the button label
if self:label() == "mount" then lst=mfiles; out=mntout else lst=ufiles; out=umntout end
for i = 1,lst:nitems() do
if lst:checked(i)==1 then
os.execute("mydsl-load "..lst:text(i).." &>"..tempfile)
-- print mydsl-load output (tempfile) to mntout or umntout
for line in io.lines(tempfile) do out:add(line) end
out:bottomline(out:size())
end
end
build_uci_lists()
end

-- BEGIN interface
w=fltk:Fl_Double_Window(ww,wh,"UCI Tool");

tabs=fltk:Fl_Tabs(tx,2,ww-4,wh-4);
tabs:selection_color(51);
tabs:color(1);

tab1 = fltk:Fl_Group(tx,ty,tw,th,"  mount  ");
-- checklist of unmounted ucis
mfiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); mfiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
mntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76); mntout:box(fltk.FL_THIN_DOWN_BOX)
mntout:format_char(0);
-- this label MUST be "mount"
mount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"mount"); mount:box(fltk.FL_THIN_UP_BOX);
mount:callback(mount_cb);
browse=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"change directory"); browse:box(fltk.FL_THIN_UP_BOX);
browse:callback(browse_cb);
fltk:Fl_End();

tab2 = fltk:Fl_Group(tx,ty,tw,th,"  umount  ");
-- checklist of mounted ucis
ufiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); ufiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
umntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76); umntout:box(fltk.FL_THIN_DOWN_BOX)
umount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"umount"); umount:box(fltk.FL_THIN_UP_BOX);
umount:callback(mount_cb);
refresh=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"refresh list"); refresh:box(fltk.FL_THIN_UP_BOX);
refresh:callback(build_uci_lists);
fltk:Fl_End();

tab3 = fltk:Fl_Group(tx,ty,tw,th,"  build  ");
frame=fltk:Fl_Box(tx+2,ty+2,tw-4,th-4); frame:box(fltk.FL_THIN_DOWN_BOX);
createinfo=fltk:Fl_Box(tx+12,ty+12,tw-24,th-24-(bh*2),"The \"MAKE PACKAGE\" button will build a UCI extension using the directory entered in the box below.\n\
Created files will include "..pwd.."/name.uci and "..pwd.."/name.uci.md5.txt, where \"name\" is the basename of the source directory.")
createinfo:align(fltk.FL_ALIGN_WRAP)
createdir=fltk:Fl_Input(tx+12,wh-bh*2-18,tw-bh-24,bh); createdir:box(fltk.FL_THIN_DOWN_BOX)
createdir:align(fltk.FL_ALIGN_TOP)
createbut=fltk:Fl_Button(tx+12,wh-bh-18,tw-24,bh,"MAKE PACKAGE")
createbut:box(fltk.FL_THIN_UP_BOX); createbut:labelfont(fltk.FL_HELVETICA_BOLD)
cdbut=fltk:Fl_Button(tw-40,wh-bh*2-18,bh,bh,"...")
cdbut:box(fltk.FL_THIN_UP_BOX)
cdbut:callback (
function(cd_cb)
ucisource=fltk.fl_dir_chooser("choose a source directory",pwd,"*",0)
if murgaLua.isDirectory(ucisource) then createdir:value(ucisource) end
end
)
createbut:callback (
function(make_package)
if murgaLua.isDirectory(createdir:value()) then
-- trim trailing slash(es), if needed
trim=string.gsub(createdir:value(),"%/*$","")
-- get basename
newuciname=string.gsub(trim,".*/","")
-- build uci
-- TODO: should the block size be user-configurable?
os.execute("cd "..trim.."/../ && aterm -e sudo su -c \"mkisofs -R -hide-rr-moved -cache-inodes -pad "..newuciname.."/ | create_compressed_fs - 65536 > "..pwd.."/"..newuciname..".uci\" && cd && md5sum "..newuciname..".uci > "..newuciname..".uci.md5.txt")
end
end
)
fltk:Fl_End();

tab4 = fltk:Fl_Group(tx,ty,tw,th,"  about  ");
about=fltk:Fl_Box(tx+2,ty+2,tw-4,th-4,"UCITOOL 2: THE REMOUNTENING - Beta\n\n\
A MurgaLua tool for creating and managing\
*.uci MyDSL packages in Damn Small Linux.\
\n\n(c)2006 mikshaw [mrblog|yahoo|com]");
about:box(fltk.FL_THIN_DOWN_BOX);
fltk:Fl_End();

build_uci_lists();

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


EDIT: cleared up some misplaced/vague comments
EDIT2: fixed the multiple slash issue
EDIT3: sorted uci list and joined the mount & umount functions

Posted by mikshaw on Nov. 12 2006,18:42
A couple of changes...removed the "about" tab and fixed a build problem with md5sum not finding the package if you're not in $HOME.
I have to work on the default uci location...probably use /opt/.mydsl_dir to be consistent with other DSL tools.

Code Sample
#!/bin/murgaLua
-- mounts, umounts and builds .uci extensions
-- (c) 2005,2006 mikshaw
--
-- Changelog (yyyy/mm/dd)
--    2006/11/12: Fixed md5sum not finding uci file
--                Removed unnecessary "about" tab
--    2006/10/23: Fixed multiple trailing slashes on dir name
--                Sort the list of available packges
--                Consolidated mount and umount functions
--    2006/10/21: Added basic feature to build UCI packages
--                UCI directory can be specified via UCITOOL_DIR
--    2006/09/05: Port to MurgaLua
--                Added tabs and ability to mount packages
--                Output of mydsl-load is displayed in the gui
--    2005/12/30: Changed UI to match DSL tools
--                Added hotkey support
--                Auto-selects first line for better keyboard support
--    2005/12/09: Displays total number of mounted UCIs
--    2005/12/08: First release
--
-- TODO: Make it fully keyboard controllable (is that possible with fltk?)
-----------------------------------------------------------------------------

ww=400; wh=300;      -- window size
tx=2; ty=27;         -- tab position
tw=ww-4; th=wh-ty-2; -- tab size
bw=120; bh=30;       -- button size
tempfile="/tmp/"..os.getenv("USER")..".uci2ool"
pwd=os.getenv("PWD")
ucidir="/cdrom/mydsl/optional" -- default uci directory

-- check for UCITOOL_DIR environment variable
ucivar=os.getenv("UCITOOL_DIR")
if murgaLua.isDirectory(ucivar) then ucidir=ucivar end


-- done at startup, add/remove a uci, and when "refresh" is pressed
function build_uci_lists()
-- add mounted files from mtab to ufiles window
os.execute("grep \"^.*.uci \" /etc/mtab | awk '{print $1}' | sort >"..tempfile)
ufiles:clear()
for line in io.lines(tempfile) do ufiles:add(line) end
ufiles:redraw()
-- compare mtab UCI files (tempfile) with files in ucidir
if murgaLua.isDirectory(ucidir) then
input=io.open(tempfile,"r")
mounted=input:read("*a")
io.close(input)
allfiles=murgaLua.readDirectory(ucidir)
table.sort(allfiles)
-- list only *.uci files that are not in mtab
mfiles:clear()
for i=0,table.getn(allfiles) do
if string.find(allfiles[i],".uci",-4,plain) then
if not string.find(mounted,allfiles[i].."\n") then mfiles:add(ucidir.."/"..allfiles[i]) end
end
end
mfiles:redraw()
end
os.remove(tempfile)
end

-- choose a different uci directory
function browse_cb()
new_ucidir=fltk.fl_dir_chooser("choose a uci directory",ucidir,"*",0)
if murgaLua.isDirectory(new_ucidir) then
-- remove trailing slash if found
ucidir=string.gsub(new_ucidir,"%/*$","")
build_uci_lists() end
end

-- run mydsl-load on selected files
function mount_cb(self)
-- mount or umount? Uses the button label
if self:label() == "mount" then lst=mfiles; out=mntout else lst=ufiles; out=umntout end
for i = 1,lst:nitems() do
if lst:checked(i)==1 then
os.execute("mydsl-load "..lst:text(i).." &>"..tempfile)
-- print mydsl-load output (tempfile) to mntout or umntout
for line in io.lines(tempfile) do out:add(line) end
out:bottomline(out:size())
end
end
build_uci_lists()
end

-- BEGIN interface
w=fltk:Fl_Double_Window(ww,wh,"UCI Tool");

tabs=fltk:Fl_Tabs(tx,2,ww-4,wh-4);
tabs:selection_color(51);
tabs:color(1);

tab1 = fltk:Fl_Group(tx,ty,tw,th,"  mount  ");
-- checklist of unmounted ucis
mfiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); mfiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
mntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76); mntout:box(fltk.FL_THIN_DOWN_BOX)
mntout:format_char(0);
-- this label MUST be "mount"
mount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"mount"); mount:box(fltk.FL_THIN_UP_BOX);
mount:callback(mount_cb);
browse=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"change directory"); browse:box(fltk.FL_THIN_UP_BOX);
browse:callback(browse_cb);
fltk:Fl_End();

tab2 = fltk:Fl_Group(tx,ty,tw,th,"  umount  ");
-- checklist of mounted ucis
ufiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh-80); ufiles:box(fltk.FL_THIN_DOWN_BOX);
-- output from mydsl-load
umntout=fltk:Fl_Browser(tx+2,ty+th-bh-76,tw-4,76); umntout:box(fltk.FL_THIN_DOWN_BOX)
umount=fltk:Fl_Button(tx,wh-bh-2,bw,bh,"umount"); umount:box(fltk.FL_THIN_UP_BOX);
umount:callback(mount_cb);
refresh=fltk:Fl_Button(ww-bw-2,wh-bh-2,bw,bh,"refresh list"); refresh:box(fltk.FL_THIN_UP_BOX);
refresh:callback(build_uci_lists);
fltk:Fl_End();

tab3 = fltk:Fl_Group(tx,ty,tw,th,"  build  ");
frame=fltk:Fl_Box(tx+2,ty+2,tw-4,th-4); frame:box(fltk.FL_THIN_DOWN_BOX);
createinfo=fltk:Fl_Box(tx+12,ty+12,tw-24,th-24-(bh*2),"The \"MAKE PACKAGE\" button will build a UCI extension using the directory entered in the box below.\n\
Created files will include "..pwd.."/name.uci and "..pwd.."/name.uci.md5.txt, where \"name\" is the basename of the source directory.")
createinfo:align(fltk.FL_ALIGN_WRAP)
createdir=fltk:Fl_Input(tx+12,wh-bh*2-18,tw-bh-24,bh); createdir:box(fltk.FL_THIN_DOWN_BOX)
createdir:label("source directory:"); createdir:align(fltk.FL_ALIGN_LEFT_TOP)
createbut=fltk:Fl_Button(tx+12,wh-bh-18,tw-24,bh,"MAKE PACKAGE")
createbut:box(fltk.FL_THIN_UP_BOX); createbut:labelfont(fltk.FL_HELVETICA_BOLD)
cdbut=fltk:Fl_Button(tw-40,wh-bh*2-18,bh,bh,"...")
cdbut:box(fltk.FL_THIN_UP_BOX)
cdbut:callback (
function(cd_cb)
ucisource=fltk.fl_dir_chooser("choose a source directory",pwd,"*",0)
if murgaLua.isDirectory(ucisource) then createdir:value(ucisource) end
end
)
createbut:callback (
function(make_package)
if murgaLua.isDirectory(createdir:value()) then
-- trim trailing slash(es), if needed
trim=string.gsub(createdir:value(),"%/*$","")
-- get basename
newuciname=string.gsub(trim,".*/","")
-- build uci
-- TODO: should the block size be user-configurable?
os.execute("cd `dirname "..createdir:value().."` && aterm -e sudo su -c \"mkisofs -R -hide-rr-moved -cache-inodes -pad "..newuciname.."/ | create_compressed_fs - 65536 > "..pwd.."/"..newuciname..".uci\" && cd "..pwd.." && md5sum "..newuciname..".uci > "..newuciname..".uci.md5.txt")
end
end
)
fltk:Fl_End();

build_uci_lists();

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

Posted by mikshaw on Feb. 05 2007,17:34
Here's a murgaLua frontend for the xdesktopwaves application.
It should work with the xdesktopwaves mydsl extension, but you may need to change the "program" variable to point to the proper executable. I think it's /opt/xdesktopwaves/xdesktopwaves, but I can't recall exactly.
As always, feedback is appreciated.

Latest update: Feb 07, 2007

Code Sample
#!/bin/murgaLua

-- A MurgaLua frontend for xdesktopwaves.
-- This does not cover all options, but should provide a decent
-- amount of control for most features.
-- Note: The 'z' variables are placeholders..dunno if there's a better way

-- Changelog
-- 2007-02-07: Custom colors persist for fl_color_chooser
--             Colors are set accurately with set_color instead of fl_color_cube
--             Tooltips added in case of too-dark color
--             More code cleanup
-- 2007-02-05: Fixed fl_color_chooser not ignoring change when cancelled
--             Code cleanup
-- 2007-02-04: Dumped Lua-FLTK
--             Added custom color controls
-- 2006-10-28: Can use either Lua-FLTK or MurgaLua
--             Removed unnecessary stuff (decoration, about, version, rc file)
-- 2005-01-28: First version (Lua-FLTK)

--program="/opt/xdesktopwaves/xdesktopwaves"
program="xdesktopwaves"

-- LAUNCH XDESKTOPWAVES
function start_waves()
if colors:value() > 0 then colscheme=" -c "..colors:value()
elseif usemycolor:value() == 1 then colscheme=" -wc "..watercolor.." -sc "..skycolor.." -lc "..lightcolor
else colscheme="" end
if tog1:value() == 1 then stip=" -t"   else stip=""   end
if tog2:value() == 1 then opaque=" -o" else opaque="" end
if tog3:value() == 1 then win=" -w"    else win=""    end
if tog4:value() == 1 then nwm=" -nwm"  else nwm=""    end
if tog5:value() == 1 then nww=" -nww"  else nww=""    end
os.execute(program..colscheme..stip..opaque..win..nwm..nww..
" -q   "..quals:value()..
" -rn  "..rains:value()..
" -st  "..winds:value()..
" -vs  "..viscs:value()..
" -si  "..skys:value()..
" -li  "..lights:value()..
" -lal "..alts:value()..
" -laz "..azs:value()..
" &")
end

-- MAIN WINDOW
wh = 240
ww = 480
w = fltk:Fl_Window(ww,wh, "xdesktopwaves")

sl = 120    -- slider left edge
sw = 190    -- slider width
sh = 18     -- slider height
st = 10     -- first slider y_position
ss = 20     -- spacing
bw=140      -- button width
bx=ww-bw-ss -- button x position

-- SLIDERS
colors = fltk:Fl_Value_Slider(sl,st,sw,sh,"color scheme ");
colors:type(fltk.FL_HORIZONTAL); colors:align(fltk.FL_ALIGN_LEFT);
colors:step(1); colors:minimum(0); colors:maximum(9); colors:value(0);
colors:tooltip("Preset color schemes ");
--
quals = fltk:Fl_Value_Slider(sl,st+ss,sw,sh,"wave quality ");
quals:type(fltk.FL_HORIZONTAL); quals:align(fltk.FL_ALIGN_LEFT);
quals:step(1); quals:minimum(0); quals:maximum(9); quals:value(5);
quals:tooltip("Overall quality of the waves. \nThe higher the quality, the \nhigher the CPU load. ");
--
rains = fltk:Fl_Value_Slider(sl,st+ss*2,sw,sh,"rain amount ");
rains:type(fltk.FL_HORIZONTAL); rains:align(fltk.FL_ALIGN_LEFT);
rains:step(1); rains:minimum(0); rains:maximum(10); rains:value(0);
rains:tooltip("Simulate raindrops falling on the water ");
--
winds = fltk:Fl_Value_Slider(sl,st+ss*3,sw,sh,"wind amount ");
winds:type(fltk.FL_HORIZONTAL); winds:align(fltk.FL_ALIGN_LEFT);
winds:step(1); winds:minimum(0); winds:maximum(10); winds:value(0);
winds:tooltip("Simulate a storm blowing on the water ");
--
viscs = fltk:Fl_Value_Slider(sl,st+ss*4,sw,sh,"viscosity ");
viscs:type(fltk.FL_HORIZONTAL); viscs:align(fltk.FL_ALIGN_LEFT);
viscs:step(1); viscs:minimum(1); viscs:maximum(5); viscs:value(3);
viscs:tooltip("The higher the viscosity, the \nshorter the lifetime of waves ");
--
skys = fltk:Fl_Value_Slider(sl,st+ss*5,sw,sh,"sky ");
skys:type(fltk.FL_HORIZONTAL); skys:align(fltk.FL_ALIGN_LEFT);
skys:step(1); skys:minimum(1); skys:maximum(10); skys:value(5);
skys:tooltip("Intensity of sky reflections ");
--
lights = fltk:Fl_Value_Slider(sl,st+ss*6,sw,sh,"light ");
lights:type(fltk.FL_HORIZONTAL); lights:align(fltk.FL_ALIGN_LEFT);
lights:step(1); lights:minimum(1); lights:maximum(10); lights:value(5);
lights:tooltip("Intensity of light reflections ");
--
alts = fltk:Fl_Value_Slider(sl,st+ss*7,sw,sh,"altitude ");
alts:type(fltk.FL_HORIZONTAL); alts:align(fltk.FL_ALIGN_LEFT);
alts:step(1); alts:minimum(0); alts:maximum(90); alts:value(30);
alts:tooltip("Altitude of light source \(degrees\) ");
--
azs = fltk:Fl_Value_Slider(sl,st+ss*8,sw,sh,"azimuth ");
azs:type(fltk.FL_HORIZONTAL); azs:align(fltk.FL_ALIGN_LEFT);
azs:step(1); azs:minimum(-360); azs:maximum(360); azs:value(-35);
azs:tooltip("Azimuth of light source \(degrees\) ");

-- CUSTOM COLORS
function get_rgbh(i)
r,g,b=Fl:get_color(i:color(),r,g,b);
h=string.format("\\#%.2X%.2X%.2X",r,g,b);
return r,g,b,h
end

function mycolor(self)
get_rgbh(self);
c_ok,r,g,b=fltk.fl_color_chooser("pick color",r,g,b);
if c_ok == 1 then
Fl:set_color(self:color(),r,g,b)
hex=string.format("\\#%.2X%.2X%.2X",r,g,b)
if self:label() == "water color" then watercolor=hex
elseif self:label() == "sky color" then skycolor=hex
else lightcolor=hex end
end
end
-- colors 15, 6, and 255 are changed dynamically
usemycolor = fltk:Fl_Round_Button(bx,st,bw,ss,"Use My Colors: ");
usemycolor:tooltip("This option is overridden by \na nonzero color scheme");
wcolor = fltk:Fl_Button(bx,st+ss,bw,ss,"water color");
wcolor:color(15); wcolor:callback(mycolor); wcolor:tooltip("water color");
scolor = fltk:Fl_Button(bx,st+ss*2,bw,ss,"sky color");
scolor:color(6); scolor:callback(mycolor); scolor:tooltip("sky color");
hcolor = fltk:Fl_Button(bx,st+ss*3,bw,ss,"light color");
hcolor:color(255); hcolor:callback(mycolor); hcolor:tooltip("light color");
-- set initial "my colors"
z,z,z,watercolor=get_rgbh(wcolor);
z,z,z,skycolor=get_rgbh(scolor);
z,z,z,lightcolor=get_rgbh(hcolor);

-- CONTROLS: start, stop
bstart = fltk.Fl_Return_Button(bx,st+ss*5,bw,ss*2, "start");
bstop = fltk.Fl_Button(bx,st+ss*7,bw,ss*2, "stop");
bstart:callback(start_waves)
function stop_waves() os.execute(program.." -end") end
bstop:callback(stop_waves);
-- TOGGLES
tog1 = fltk:Fl_Round_Button(20,wh-40,80,25, "stipple");
tog1:tooltip("Fake transparency. \nThis option is not as \"transparent\" \nas the default transparency, but \nit is easier on your cpu.");
tog2 = fltk:Fl_Round_Button(110,wh-40,80,25, "opaque");
tog2:tooltip("No transparency ");
tog3 = fltk:Fl_Round_Button(200,wh-40,80,25, "window");
tog3:tooltip("Open in its own normal window \nrather than the root window.\nSome window managers\nmay require \"opaque\" as well.");
tog4 = fltk:Fl_Round_Button(290,wh-40,80,25, "ignore\n mouse");
tog4:tooltip("Mouse cursor does not create waves ");
tog5 = fltk:Fl_Round_Button(380,wh-40,80,25, " ignore\nwindows");
tog5:tooltip("Windows do not create waves ");

w:show()
Fl:run()

Posted by mikshaw on Feb. 08 2007,19:12
xdesktopwaves frontend updated Feb 7. That will probably be the last bit of development on that particular project for a while.

I'm going back to the ucitool script soon, but I may need to rethink its behavior...maybe wrap it in a bash script with whiptail so it can be used in textmode if necessary...or just use a plain text list of files in Lua. Still also debating whether the "build package" feature is indeed useful.

In the meantime, there is much more that murgaLua can do on the Lua side of the coin, besides just providing a clickable interface. Robert has demonstrated this several times in his scripts written for DSL.  As far as I have been able to tell, the murgaLua program is a complete Lua 5.1 interpreter, which might be useable for Lua scripts that were not written specifically for murgaLua.  I haven't tested much so far, but there's another thing to look into.

Posted by mikshaw on May 16 2007,07:03
With the recent addition of popen support in murgaLua, it was necessary to dive into that a little.  Here are a few simple examples of using shell command output within a gui.

Code Sample

ww=300
wh=180
cmd="ls"

w = fltk:Fl_Window(ww,wh,"Hello")

-- DISPLAY SINGLE-LINE COMMAND OUTPUT
butt=fltk:Fl_Button(10,10,100,20,"display output")
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40)
butt:callback(
function(butt)
local c=io.popen("date")
local o=c:read("*a")
c:close()
outpoot:add(o)
end
)

-- DISPLAY MULTILINE COMMAND OUTPUT (no file close)
butt=fltk:Fl_Button(10,10,100,20,"display output");
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40);
butt:callback(
function(butt)
for line in io.popen(cmd):lines() do
outpoot:add(line)
end
end
)

-- DISPLAY MULTILINE COMMAND OUTPUT
butt=fltk:Fl_Button(10,10,100,20,"display output")
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40)
butt:callback(
function(butt)
outpoot:clear()
local c=io.popen(cmd)
for line in c:lines() do outpoot:add(line) end
c:close()
end
)

w:show()
Fl:run()


Note the three variants are redundant and overlapping. They aren't all meant to be used in the same script.
I'm also not sure if the middle one is any better or worse than the last.

Posted by MakodFilu on May 16 2007,20:24
Mmmmm, I didn't even know I would need that for substituting gtkfind :D

Thx, mikshaw

...if only I could dedicate less time to my Nokia and more time to DSL :D

Posted by mikshaw on May 18 2007,19:13
Update to ucitool.lua.
It now uses io.popen to avoid the need for a temp file. This means murgaLua 0.4.1 is required, which is not yet available in DSL.
< http://www.murga-projects.com/murgaLua/index.html >

I'm still not completely happy with the way packages are built (seems a bit messy), and I have to find a more dependable way to compare files in /ramdisk with those in /home/dsl, /opt, and others.
I also have done very little streamlining. I'm sure there are things that could improve its performance.

Code Sample
#!/home/dsl/bin/murgaLua
-- mounts, umounts and builds .uci extensions
-- (c) 2005,2006 mikshaw
--
-- Changelog (yyyy/mm/dd)
--    2007/05/18: Removed the need for a temp file
--                  (requires murgaLua 0.4.1 or newer)
--                Cut "/ramdisk" from mtab names to prevent duplicate listings
--                  (must watch for possible bugs from this)
--    2006/11/12: Fixed md5sum not finding uci file
--                Removed unnecessary "about" tab
--    2006/10/23: Fixed multiple trailing slashes on dir name
--                Sort the list of available packges
--                Consolidated mount and umount functions
--    2006/10/21: Added basic feature to build UCI packages
--                UCI directory can be specified via UCITOOL_DIR
--    2006/09/05: Port to MurgaLua
--                Added tabs and ability to mount packages
--                Output of mydsl-load is displayed in the gui
--    2005/12/30: Changed UI to match DSL tools
--                Added hotkey support
--                Auto-selects first line for better keyboard support
--    2005/12/09: Displays total number of mounted UCIs
--    2005/12/08: First release
--
-- TODO: Make it fully keyboard controllable (is that possible with fltk?)
-----------------------------------------------------------------------------

ww=420; wh=240;      -- window size
tx=2; ty=27;         -- tab position
tw=ww-4; th=wh-2; -- tab size
bw=120; bh=30;       -- button size
pwd=os.getenv("PWD")
--ucidir="/cdrom/mydsl/optional" -- default uci directory
ucidir="/home/dsl/mydsl/optional" -- default uci directory

-- check for UCITOOL_DIR environment variable
ucivar=os.getenv("UCITOOL_DIR")
if murgaLua.isDirectory(ucivar) then ucidir=ucivar end


-- done at startup, add/remove a uci, and when "refresh" is pressed
function build_uci_lists()
-- add mounted files from mtab to ufiles window
local cmd=io.popen("grep \"^.*.uci \" /etc/mtab | awk '{print $1}' | sed 's/ramdisk\\/home/home/' | sort") --
ufiles:clear()
--for line in io.lines(tempfile) do ufiles:add(line) end
for line in cmd:lines() do ufiles:add(line) end --
mounted=cmd:read("*a") --
cmd:close() --
ufiles:redraw()
-- compare mtab UCI files (tempfile) with files in ucidir
if murgaLua.isDirectory(ucidir) then
allfiles=murgaLua.readDirectory(ucidir)
table.sort(allfiles)
-- list only *.uci files that are not in mtab
mfiles:clear()
for i=0,table.getn(allfiles) do
if string.find(allfiles[i],".uci",-4,plain) then
if not string.find(mounted,allfiles[i].."\n") then mfiles:add(ucidir.."/"..allfiles[i]) end
end
end
mfiles:redraw()
end
end

-- choose a different uci directory
function browse_cb()
new_ucidir=fltk.fl_dir_chooser("choose a uci directory",ucidir,"*",0)
if murgaLua.isDirectory(new_ucidir) then
-- remove trailing slash if found
ucidir=string.gsub(new_ucidir,"%/*$","")
build_uci_lists() end
end

-- run mydsl-load on selected files
function mount_cb(self)
tab3:show()
tab1:hide()
tab2:hide()
-- mount or umount? Uses the button label
if self:label() == "mount" then lst=mfiles else lst=ufiles end
for i = 1,lst:nitems() do
if lst:checked(i)==1 then
local cmd=io.popen("mydsl-load "..lst:text(i))
-- print mydsl-load output to browser
for line in cmd:lines() do outpoot:add(line) end
outpoot:bottomline(outpoot:size())
cmd:close()
end
end
build_uci_lists()
end

-- BEGIN interface
w=fltk:Fl_Double_Window(ww,wh,"UCI Tool");

tabs=fltk:Fl_Tabs(tx,2,tw,th);
tabs:selection_color(7);
tabs:color(1);

tab1 = fltk:Fl_Group(tx,ty,tw,th,"available UCIs");
-- checklist of unmounted ucis
mfiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh*2); mfiles:box(fltk.FL_THIN_DOWN_BOX);
-- this label MUST be "mount"
mount=fltk:Fl_Button(tx,th-bh,bw,bh,"mount"); mount:box(fltk.FL_THIN_UP_BOX);
mount:callback(mount_cb);
browse=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"change directory"); browse:box(fltk.FL_THIN_UP_BOX);
browse:callback(browse_cb);
fltk:Fl_End();

tab2 = fltk:Fl_Group(tx,ty,tw,th,"mounted UCIs");
-- checklist of mounted ucis
ufiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh*2); ufiles:box(fltk.FL_THIN_DOWN_BOX);
umount=fltk:Fl_Button(tx,th-bh,bw,bh,"umount"); umount:box(fltk.FL_THIN_UP_BOX);
umount:callback(mount_cb);
refresh=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"refresh list"); refresh:box(fltk.FL_THIN_UP_BOX);
refresh:callback(build_uci_lists);
fltk:Fl_End();

tab3 = fltk:Fl_Group(tx,ty,tw,th-bh,"output")
-- output display
outpoot=fltk:Fl_Browser(tx+2,ty+2,tw-4,th-bh*2); outpoot:box(fltk.FL_THIN_DOWN_BOX)
outpoot:format_char(0);
clearout=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"clear"); clearout:box(fltk.FL_THIN_UP_BOX);
clearout:callback(function(clearout) outpoot:clear() end)
fltk:Fl_End();

tab4 = fltk:Fl_Group(tx,ty,tw,th-bh,"build your own");
frame=fltk:Fl_Box(tx+2,ty+2,tw-4,th-bh); frame:box(fltk.FL_THIN_DOWN_BOX);
createinfo=fltk:Fl_Box(tx+12,ty,tw-24,th-bh*3,"The \"MAKE PACKAGE\" button will build a UCI extension using the directory entered in the box below.\n\
Created files will include "..pwd.."/name.uci and "..pwd.."/name.uci.md5.txt, where \"name\" is the basename of the source directory.")
createinfo:align(fltk.FL_ALIGN_WRAP)
createdir=fltk:Fl_Input(tx+12,th-bh*2-4,tw-bh-24,bh); createdir:box(fltk.FL_THIN_DOWN_BOX)
createdir:label("source directory:"); createdir:align(fltk.FL_ALIGN_LEFT_TOP)
createbut=fltk:Fl_Button(tx+12,th-bh-4,tw-24,bh,"MAKE PACKAGE")
createbut:box(fltk.FL_THIN_UP_BOX); createbut:labelfont(fltk.FL_HELVETICA_BOLD)
cdbut=fltk:Fl_Button(tw-40,th-bh*2-4,bh,bh,"...")
cdbut:box(fltk.FL_THIN_UP_BOX)
cdbut:callback (
function(cd_cb)
ucisource=fltk.fl_dir_chooser("choose a source directory",pwd,"*",0)
if murgaLua.isDirectory(ucisource) then createdir:value(ucisource) end
end
)
createbut:callback (
function(make_package)
if murgaLua.isDirectory(createdir:value()) then
-- trim trailing slash(es), if needed
trim=string.gsub(createdir:value(),"%/*$","")
-- get basename
newuciname=string.gsub(trim,".*/","")
-- build uci
-- TODO: should the block size be user-configurable?
os.execute("cd `dirname "..createdir:value().."` && aterm -e sudo su -c \"mkisofs -R -hide-rr-moved -cache-inodes -pad "..newuciname.."/ | create_compressed_fs - 65536 > "..pwd.."/"..newuciname..".uci\" && cd "..pwd.." && md5sum "..newuciname..".uci > "..newuciname..".uci.md5.txt")
end
end
)
fltk:Fl_End();

build_uci_lists();

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

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.