Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (10) </ 1 2 3 [4] 5 6 7 8 9 ... >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: XPM Icon Viewer, murgaLua script< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Nov. 02 2007,06:00 QUOTE

I think something like that would probably start by removing most of what is in here, since much of the code is made to handle displaying the directory contents.

Unless you want to have it do what it does now but add stdin as a source for the initially-displayed image, I think  the tool you describe might be a very small and very fast script in comparison.  In fact, it might simply be a wrapper for existing DSL applications...sxpm for display (would remove the troubles of XPM files that murgaLua cannot read), sxpm/xpaint/beaver/vi/nano as various editor choices, and the fact that it would accept a file as a parameter means a file manager or drag-drop can be used instead of fl_dir_chooser.  An application like that could basically just be a menu.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Nov. 02 2007,15:40 QUOTE

Oh hey...this is easy now =o)
It's not complete, and the refresh is broken, but it only took about ten minutes to turn the browser into a smaller, faster drag-drop viewer.

I'll post later today after I do the refresh and run some tests.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Nov. 02 2007,18:39 QUOTE

I wasn't thinking of cutting your application way down. What I had in mind, was drag a folder to your app and it opens in that folder, drag an xpm to it and it opens the folder containing this xpm with that xpm displayed. And finally double click an xpm and it works the same as dnd of it. I would like DSLv4 to support both operating modes whenever possible. If you weren't going to do it, I was. But I would rather let you complete your project. Glad to hear that you are looking further into this and thus supporting DSL v4 DND operating mode. I will wait to see what you have. This will be a nice addition to DSL.
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Nov. 02 2007,21:17 QUOTE

I see where you're going. Well, I had already started a different script using basically just the image display from the old one as a base. It currently doesn't support directories at all, and in fact will give a warning message if you drag a folder onto it. It will allow you to drag an XPM file either to the app icon or onto the interface itself (that bit probably needs a decrease in the loop time to detect quick drags), or to browse for an XPM file. The double-click I assume would be controlled by the file manager.

I'll probably look into mashing the two scripts together in the future to see what I can make of them. I also will probably remove sxpm from the edit menu, since it's not an interactive app, and maybe use it elsewhere.

This is my first attempt at any sort of drag and drop, so it will need much testing and debugging.

Code Sample
#!/bin/murgaLua

-- XPM icon viewer
-- mikshaw 2007

dir="/usr/share/dfm/icons"
editor="xpaint"
--xpm_size=32

broken_xpm_data=[[
/* XPM */
static char *broken_image[] = {
/* columns rows colors chars-per-pixel */
"14 16 16 1",
"  c black",
". c #800000",
"X c #008000",
"o c #808000",
"O c navy",
"+ c #800080",
"@ c #008080",
"# c #C0C0C0",
"$ c #808080",
"% c red",
"& c green",
"* c None",
"= c blue",
"- c magenta",
"; c cyan",
": c gray100",
/* pixels */
"          $***",
" :::::::::$$**",
" :########$:$*",
" :###XX###$::$",
" :##X&X ##    ",
" :##XXX ####: ",
" :###  #####: ",
" :######=== :*",
" :#%####=;= :*",
" :#-%###==O***",
" :#--%##  **: ",
" :#---%#***#: ",
" :#   *****#: ",
" :##*****###: ",
" ::*****::::: ",
"  ******      "
};
]]
xpm_tempfile=os.tmpname()
xpm_write=io.open(xpm_tempfile,"w")
if xpm_write then
 xpm_write:write(broken_xpm_data)
 xpm_write:close()
 broken_xpm=fltk:Fl_XPM_Image(xpm_tempfile)
 os.remove(xpm_tempfile)
end

myname=fltk.fl_filename_name(arg[0])..": "
edvar=os.getenv("XPM_EDITOR")
if edvar then editor=edvar end

function find_stupid_space(infile)
 local data=io.open(infile)
 if data then
   local found=0
   for line in data:lines() do
     if string.find(line,"^%s") then found=1; break end
   end
   data:close()
   return found
 end
end

function get_image_data(image)
 local old_data=display:image()
 if old_data then old_data:uncache() end
 local image_data=fltk:Fl_XPM_Image(image)
 if image_data and find_stupid_space(image)==0 then
   display:image(image_data:copy(128,128)) --show it bigger!
 else
   display:image(broken_xpm)
 end
 current_file=image -- full path
 filename=fltk.fl_filename_name(image) -- filename only
 display:label(filename.."\n"..image_data:w().."x"..image_data:h().." | "..lfs.attributes(current_file).size.." bytes")
 display:redraw()
end

function menu_cb()
 local v=i_menu:value()
 if v==1 then menu_open_newfile()
 elseif v==2 and current_file then get_image_data(current_file)
 elseif v==3 then os.exit(0)
 elseif v>=4 and current_file then os.execute(i_menu:text().." "..current_file.." &")
 end
end

function menu_open_newfile()
 local filename=fltk.fl_file_chooser("XPM file...","*.xpm",dir)
 if filename then
   get_image_data(filename)
 end
end

function dnd_check()
 if Fl:event() == fltk.FL_DND_RELEASE then
   Fl:paste(w)
   Fl:wait()
   local dropped_file=Fl:event_text()
   if dropped_file then
     cut_stupid_space=string.gsub(dropped_file,"^%s*","")
     local new_file=string.gsub(cut_stupid_space,"^~",os.getenv("HOME"))
     open_file(new_file)
   end
 end
Fl:wait()
 timer:doWait(0.05)
end

function open_file(dfile)
if lfs.attributes(dfile).mode == "file" then
 local filename=io.open(dfile)
 if filename then
   local data=filename:read("*l")
   if string.find(data,"/%*%s*XPM%s*%*/") then
     filename:close()
     get_image_data(dfile)
   end
 else print(myname.."can't open "..dfile)
 end
else print(myname..dfile..": not a regular file")
end
end

ww=200; wh=200; mh=30
images={}; icon={}; butt={}
w=fltk:Fl_Window(ww,wh,"XPM Viewer")

file_items={"&Open","&Reload","&Quit"}
edit_items={"xpaint","sxpm","beaver","aterm -e vi"}
i_menu=fltk:Fl_Menu_Bar(0,0,ww,mh)
i_menu:callback(menu_cb)
i_menu:selection_color(fltk.FL_WHITE)
for i,v in ipairs(file_items) do i_menu:add("&File/"..v) end
for i,v in ipairs(edit_items) do i_menu:add("&Edit/"..v) end

timer=murgaLua.createFltkTimer()
display=fltk:Fl_Box(0,mh,ww,ww-mh) -- big image

if arg[1] then open_file(arg[1]) end
timer:callback(dnd_check)
timer:do_callback()
w:show()
Fl:run()


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Nov. 02 2007,21:53 QUOTE

I wasn't talking about murgaLua drag-n-drop but dfm drag-n-drop as is easily implemented by processing the command line arg(s) no matter what programming language is used. You seem to have both. Not sure how the Lua DND is supposed to work. It didn't for me.

But dragging an .xpm onto the Lua logo icon of your apps works as expected. Then it is a simple matter to associate your program name with *.xpm in .dfmext and you have the double click support.

Next you need to make or find a nifty icon for your app. We don't want to leave it a boring Lua logo.
Back to top
Profile PM WEB 
49 replies since Oct. 31 2007,17:49 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (10) </ 1 2 3 [4] 5 6 7 8 9 ... >/
reply to topic new topic new poll
Quick Reply: XPM Icon Viewer

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code