| mikshaw  
 
  
 
 
 Group: Members
 Posts: 4856
 Joined: July 2004
 | 
|  | Posted: 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();
 
 | 
 
 --------------
 http://www.tldp.org/LDP/intro-linux/html/index.html
 |