mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Jan. 31 2008,19:54 |
|
It used to work out of the box, but that was when DSL used lua-fltk. That has been replaced with murgaLua, and I was too lazy to update the extension. I did do a port to murgaLua a long time ago, but it should be reworked a bit.
EDIT: I did a little work on it yesterday, and realized it *can* be used (outside of the read-only uci directory) without the bash wrapper if you do a little work on it. The first few lines after "DEFAULTS" are where you can set paths to the xjig and convert binaries and to the default image directory. Or you can change them by manually setting the environment variables XJIG, CONVERT, and IMG_DIR. That last one will probably need its variable name changed sometime in the future...it's a little too generic.
Code Sample | #!/bin/murgaLua
-- xjig.flua -- GUI frontend for xjig -- mikshaw 2006 -- IMPORTANT: This script needs the bash wrapper for some variables. -- It will still work, but only with gif images and only -- if xjig is in your $PATH -- -- Changelog, yyyy/mm/dd -- 2008/02/01: Code cleanup -- 2006/09/21: Port to MurgaLua -- 2006/03/29: Added a symlink check to the bash wrapper -- 2006/02/24: first release -- -- TODO: Incorporate bash wrapper commands into this script
-- DEFAULTS convert=os.getenv("CONVERT") img_dir=os.getenv("IMG_DIR") xjig=os.getenv("XJIG") -- fallback in case the script is run without the wrapper if not convert then convert = "no" end if not img_dir then img_dir = os.getenv("HOME") end if not xjig then xjig = "xjig" end xjig_options = "" temp_img = "/tmp/xjig_image.gif" -- used for non-gif images if convert is found bh = 20 -- button height ww = 345 -- window width wh = bh*8 -- window height col2 = ww/2+2 fltk.fl_register_images()
-- MAIN WINDOW w = fltk:Fl_Double_Window(ww,wh, "xjig");
-- initial list of image files files = fltk:Fl_Select_Browser(2,2,ww/2-4,wh-bh-4) function files_cb() if files:value() > 0 then filename = img_dir.."/"..files:text(files:value()) filename_display:value(files:text(files:value())) end end files:callback(files_cb); -- name of chosen image filename_display = fltk:Fl_Output(col2,wh-bh*2-4,ww/2-4,bh)
-- look for other images b_browse = fltk:Fl_Button(2,wh-bh-2,ww/2-4,bh,"Browse...") function b_browse_cb() if filename then old_filename = filename end filename = fltk.fl_file_chooser("Open a File","*.gif",img_dir.."/") if not filename or filename == "" then -- fall back to original filename if chooser is cancelled filename = old_filename else filename_display:value(filename) end end b_browse:callback(b_browse_cb)
b_start = fltk:Fl_Button(col2,wh-bh-2,ww/2-14,bh,"PLAY") function b_start_cb() if filename then -- check to see if we can convert other image types to gif if convert ~= "no" and not string.find(string.lower(filename),".gif",-4) then execute(convert.." "..filename.." "..temp_img) filename = temp_img end if filename and string.find(string.lower(filename),".gif",-4) then -- build the execute string and run it if nocrop:value() == 1 then xjig_options = "-no_crop " end if shapes:value() == 1 then xjig_options = xjig_options.."-shapes " end if noanim:value() == 1 then xjig_options = xjig_options.."-no_anim " end if noflip:value() == 1 then xjig_options = xjig_options.."-side 0 " end w:iconize() os.execute(xjig.." -ts "..ts:value().." "..xjig_options.." -file "..filename.." &>/dev/null") w:show() os.remove(temp_img) end end end b_start:callback(b_start_cb);
controls_help = fltk:Fl_Button(ww-12,wh-bh-2,10,bh,"?") controls_help:callback(function() controls:show() end ) -- command options nocrop = fltk:Fl_Round_Button(col2,2,ww/2-4,bh,"don't crop") shapes = fltk:Fl_Round_Button(col2,bh+2,ww/2-4,bh,"no background") noanim = fltk:Fl_Round_Button(col2,bh*2+2,ww/2-4,bh,"no animation") noflip = fltk:Fl_Round_Button(col2,bh*3+2,ww/2-4,bh,"no flipped pieces") nocrop:tooltip("The image is usually automatically cropped, since many images are surrounded by frames or textual comments. If this is not desired you should disable this feature.") shapes:tooltip("If the SHAPE-extension is supported by your display, you can use this option to let each puzzle tile appear in its own shaped window. It may be very slow to pan and zoom.") noanim:tooltip("Turns off animation of rotation and flipping, in case the machine isn't fast enough to make it look nice.") noflip:tooltip("Normally puzzle pieces are initially displayed with a random side up, so you have to figure out whether each piece needs to be flipped.")
ts = fltk:Fl_Value_Slider(col2,bh*4+4,ww/3-4,bh,"tile size")--; ts:value(32); ts:step(8); ts:minimum(16); ts:maximum(128); ts:type(fltk.FL_HORIZONTAL); ts:align(fltk.FL_ALIGN_RIGHT);
fltk:Fl_End();
controls = fltk:Fl_Window(ww,wh*1.5,"xjig controls") con_text = fltk:Fl_Box(2,2,0,wh*1.5-4, "click left: rotate 90 degrees left\n".. "click right: rotate 90 degrees right\n".. "click middle: flip tile to backside\n".. "drag left: rotator drag\n".. " +middle: pause rotator drag for straight drag\n".. "drag middle: straight drag\n".. " +left: pause drag for a static rotation\n".. " +click left: rotate 90 degrees left during drag\n".. " +click right: rotate 90 degrees right during drag\n".. "drag right: same as drag middle\n".. "CTRL+click left: same as click middle\n\n".. "Cursor Keys: Pan View\n".. "Page-Up or Add: Zoom in\n".. "Page-Down or Sub: Zoom out\n".. "Home: Reset to original size\n".. "End: Set maximum zooming to view all tiles")--; con_text:align(fltk.FL_ALIGN_RIGHT) fltk:Fl_End();
tempfile = os.tmpname() if convert == "no" then b_browse:label("Browse (*.gif only)") b_browse:redraw() img_types = "*.{gif,GIF}" else -- these are some common image types...you can use the chooser to find others img_types = "*.{gif,GIF,jpg,JPG,jpeg,JPEG,png,PNG,bmp,BMP,pict,PICT,p?m,P?M,xwd,XWD}" end -- build the initial list of files os.execute("cd "..img_dir.." && ls "..img_types.." 2>/dev/null >"..tempfile) files:load(tempfile) if files:text(files.size) == "" then files:remove(files.size) end os.remove(tempfile) w:show() Fl:run();
|
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|