set images as button icon (multiple images and buttons)

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
pajito
Posts: 30
Joined: Thu Apr 13, 2017 8:08 pm

set images as button icon (multiple images and buttons)

Post by pajito » Sat Jun 03, 2017 1:19 pm

Hi everybody

currently I am tring to create a media player using Livecode and CasparCG. I have almsot eveything done except of some minor details.
I choose the folder I want to use.
I list all my media files to a list.
I choose the file from the list and it plays.

Now my problem is how to create snapshots(icons) of those media files. I thought to set a space in my app, put multiple buttons or rectangles, then set the icon of x button to the id of the image chosen. But it takes lot of time, plus you have to do it each and every time you select a new folder. What I really want to do is, to set icons of buttons or rectangles to the fileneame of my list.
....if this is possible

Thanks in advance
Pajito

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: set images as button icon (multiple images and buttons)

Post by richmond62 » Sat Jun 03, 2017 5:24 pm

I am having a problem understanding what you mean by

"create snapshots(icons) of those media files"

as they probably all look the same:
music-icon.png
music-icon.png (3.59 KiB) Viewed 5549 times
can you explain a bit more?

pajito
Posts: 30
Joined: Thu Apr 13, 2017 8:08 pm

Re: set images as button icon (multiple images and buttons)

Post by pajito » Sat Jun 03, 2017 8:39 pm

richmond62 wrote:I am having a problem understanding what you mean by

"create snapshots(icons) of those media files"

as they probably all look the same:
music-icon.png
can you explain a bit more?

Hi
I am really sorry about that. So I have a programm. I need to import some pictures from a folder and set them as icons to buttons. Not manually.
If you nees any further explanation please do not hesitate.

Regards
Pajito

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: set images as button icon (multiple images and buttons)

Post by richmond62 » Sat Jun 03, 2017 8:55 pm

Hope this helps:
PAI.png
Using Pictures as Icons.livecode.zip
Here's the stack.
(92.11 KiB) Downloaded 258 times

pajito
Posts: 30
Joined: Thu Apr 13, 2017 8:08 pm

Re: set images as button icon (multiple images and buttons)

Post by pajito » Sat Jun 03, 2017 10:52 pm

richmond62 wrote:Hope this helps:
PAI.png
Using Pictures as Icons.livecode.zip
Hi again

unfortunatelly no, my problem is that I need to load multiple pictures and set them to muliple buttons.
I want to thank you anyway, probably your code will help me later building the app.

thanks again

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: set images as button icon (multiple images and buttons)

Post by richmond62 » Sun Jun 04, 2017 9:22 am

The underlying principles of what you want to do are contained within my stack.

Import your multiple pictures; assign predetermined names to them as they are imported (P1, P2, P3 . . . .).

Create new buttons on the fly as the pictures are imported, set each image as an icon to each button.

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: set images as button icon (multiple images and buttons)

Post by jiml » Sun Jun 04, 2017 9:12 pm

a space in my app, put multiple buttons or rectangles, then set the icon of x button to the id of the image chosen. But it takes lot of time, plus you have to do it each and every time you select a new folder. What I really want to do is, to set icons of buttons or rectangles to the fileneame of my list.
Or
  • Use Object > New Control > Image to create a new blank image.
    Assign it a name as Richmond suggested, e.g. 'P1'
    Set its lockloc to true.
    Edit > Duplicate Objects to create your grid of images. You can use the arrow keys to reposition.
    Increment the name of each new image, e.g. 'P2', 'P3', etc.
Populate the images when a folder is chosen.
The code below assumes you have already gotten the list of image files in the selected folder and put it into a variable called imageList.
And that you have set the default folder to the selected folder.

Code: Select all

on populateImageGrid
   lock screen
   repeat with x = 1 to 15 (or however many images you have made in the grid)
     set the filename of image ('P' & x) to line x of imageList[/indent]
   end repeat
   unlock screen
end populateImageGrid
The lock screen should speed up the populating since the screen is not redrawn until all the images have been set.
It is also smart if the image files in the folder are already the correct thumbnail size for the grid, so that LiveCode doesn't need to resize them.
Of course, if different folders have different numbers of images you will want to make sure your grid contains the maximum number of possible images.
If a folder has less images than the maximum you will want to set the filename of any extra images in the grid to empty and perhaps hide them as well.

Jim Lambert

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: set images as button icon (multiple images and buttons)

Post by jiml » Sun Jun 04, 2017 9:14 pm

ignore that [/indent]

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”