I need a lead on icns manipulation

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

I need a lead on icns manipulation

Post by doobox » Thu May 26, 2011 8:15 pm

Hi there,

Well things are going pretty well considering i have only been using the software for two days.
But at this point in my app dev, i could use a lead.

So far my app has successfully got the folders i want into a scroll list.
Upon clicking a list line the next scroll list populates with the icon files in the folder clicked.

The next step in the flow is to click on an icon file in the second populated list, and
have it display the icon file as a preview image image.
I imagine this would involve, breaking into the icon file in some way and retrieving one of the images in there.

I could use a lead into functions or plugins that may do that.
Kind Regards
Gary

https://www.doobox.co.uk

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need a lead on icns manipulation

Post by bn » Thu May 26, 2011 8:53 pm

Hi doobox,

you actually mean icns as in MacOSX icns, the image format that holds different resolutions of images used by the system to display icons for e.g. files of a specific type?

Could you elaborate what your are actully doing. Icns are not directly accessible from Livecode.

Or am I misunderstanding what you want?

Kind regards

Bernd

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: I need a lead on icns manipulation

Post by doobox » Thu May 26, 2011 9:18 pm

bn wrote:Hi doobox,

you actually mean icns as in MacOSX icns, the image format that holds different resolutions of images used by the system to display icons for e.g. files of a specific type?

Could you elaborate what your are actully doing. Icns are not directly accessible from Livecode.

Or am I misunderstanding what you want?

Kind regards

Bernd
Hi Bernd,

That's correct.

So i have now filtered out the MacOSX icns file and populated a list with the file.
And from that line in the list which holds the icns file, i wish to be able to click the line and display a preview of the icon
somewhere else on the card.

I was hoping i could pull out one of the images and use it.

Kind regards Gary
(must sort a signature here :-))
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: I need a lead on icns manipulation

Post by doobox » Thu May 26, 2011 9:41 pm

It was kind of obvious that this was not going to display the image, but for clarity i just proceeded with the code on click of the icon stored in the list line:

Code: Select all

on mouseUp

   local  theicon
   
   put the value of the clickLine into theicon
   
   put theicon into image"image" 
end mouseUp
But as this is not yet a single image of course it wont display and renders a blank image container.
Kind Regards
Gary

https://www.doobox.co.uk

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need a lead on icns manipulation

Post by bn » Thu May 26, 2011 11:05 pm

Hi Garry,

Livecode can not display icns natively.

You would have to pull some tricks. Applescript for example.

I append a stack that collects all the icns files on a disk (via shell) and the you can click on it to open the icns file in Preview. Unfortunately Preview is not scriptable.

I look a little further if I can find additional ways and import it into Livecode.

Kind regards

Bernd
Attachments
getShellIcns.rev.zip
(1.66 KiB) Downloaded 203 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need a lead on icns manipulation

Post by bn » Thu May 26, 2011 11:44 pm

Hi Gary,

Therry Judd has made a stack that you drop a file on and it retrieves the icon of the document/app.

it is here from the use-list.

http://runtime-revolution.278305.n4.nab ... 40606.html

The technique to load the stack is to

Code: Select all

go url "http://deblah.com/rev/MacIconToFile_demo.rev"
copy above to the message box and hit return. The stack will then load directly into Livecode. Tested the link, is still active.
Unfortunately the stack does not work with all documents, just some work. But Terry uses applescript and Image Events, so you may adapt that to your needs. Since you already know the path you would mostly need the transformation of the icns file to a png. And don't have to figure out the path to the icns.

Then there was a discussion here in the forum:
http://forums.runrev.com/viewtopic.php? ... 23&start=0
that dealt with icns. You might want to have a look at that too.

Kind regards

Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need a lead on icns manipulation

Post by bn » Fri May 27, 2011 12:59 am

Hi Gary,

here is a stack I adapted from Terry Judd's solution combined with a shell search for all icns files.

After you did the shell search and hilite a line in the field (click on it) then you click the "use image events to display image" button and you get the image into Livecode. This uses a temporary file "test.png" on the desktop to save the image to. You can also choose the size of the image, 64, 128 or 256 pixel square.

Since you have the file pathes already you should have no problems to adapt this stack/scripts to your needs

Works very well MacOSX 10.6.7, should also work with older versions at least 10.4 (not tested)


KInd regards

Bernd
Attachments
getShellIcns III.livecode.zip
(46.99 KiB) Downloaded 218 times

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: I need a lead on icns manipulation

Post by doobox » Fri May 27, 2011 1:28 am

Thank's guys,

That stack as far as i can see spends most of the code, finding the icon file and putting a copy of the file in another known location.
I already have the icon in a variable by the time i want to turn it into an image.

The bit that converts the file to an image that can be displayed is here:

Code: Select all

FUNCTION createFileFromIcon pSourceIconPath, pDestFilePath, pIconSize, pReturnImageData
   IF not (there is a file pDestFilePath) THEN
      put empty into url ("file:"&pDestFilePath)
      IF not (there is a file pDestFilePath) THEN
         return "Error: couldn't create output file" 
      END IF
   END IF
   put revMacFromUnixPath(pSourceIconPath) into pSourceIconPath
   put revMacFromUnixPath(pDestFilePath) into pDestFilePath
   put "tell application 'Image Events'" &cr&\
   "launch" &cr&\
   "set theIcon to open file '[[pSourceIconPath]]'" &cr&\
   "scale theIcon to size [[pIconSize]]" &cr&\
   "save theIcon as PNG in file '[[pDestFilePath]]' without icon" &cr&\
   "close theIcon" &cr&\
   "end tell" into tScript
   put merge(tScript) into tScript
   replace "'" WITH quote in tScript
   do tScript as AppleScript
   put revUnixFromMacPath(pDestFilePath) into pDestFilePath
   IF pReturnImageData THEN
      IF there is a file pDestFilePath THEN
         put url ("binfile:"&pDestFilePath) into tImageData
         return tImageData
      ELSE
         return "Error: couldn't create output file"
      END IF
   ELSE
      return the result
   END IF
END createFileFromIcon
I am not yet experienced enough to quickly work out what is live code and what is not here.
I will be studying this in great detail though, it looks to be the way forward for me.

Kind regards Gary
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: I need a lead on icns manipulation

Post by doobox » Fri May 27, 2011 1:37 am

Hang on a mo...!
This is running an apple script, telling it to launch an application 'Image Events'"

Code: Select all

put "tell application 'Image Events'" &cr&\
   "launch" &cr&\
Is this a default osx application...?
Kind Regards
Gary

https://www.doobox.co.uk

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: I need a lead on icns manipulation

Post by bn » Fri May 27, 2011 8:10 am

Hi Gary,

yes, the applescript calls the application "image events". Image event is kind of part of applecript. It is a faceless app that you can control with apple script. It is just there to handle images. No need to install it, it is on all Macs.


I just wonder why you dont download the stack I uploaded. This reuploaded one is all set up for you to test:
getShellIcns III.livecode.zip
(46.99 KiB) Downloaded 206 times

I upload it here inline to be more visible

And here is a screenshot:
getIconsScreenShot.png
getIconsScreenShot.png (82.17 KiB) Viewed 6450 times
Kind regards

Bernd

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: I need a lead on icns manipulation

Post by doobox » Fri May 27, 2011 9:34 pm

Thank's Bernd,
That looks like just the ticket :-)

I think the link in the earlier thread was dead.
Any way thank a lot, i will delve in there and see what i can utilize.

Kind regards Gary
Kind Regards
Gary

https://www.doobox.co.uk

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”