How to store pictures in a stack? - livecode

In Hypercard I can store pictures only on cards. In LiveCode it is possible to store a collection of pictures on the stack level. Is this correct? If yes, how do I load all the pictures in a folder into a stack? And how do I change the read script to only read all the references to pictures into the stack?

I think it's not possible to store images in a stack, but not on a card. For storing images on a card, you'll want the import command. It will place an image on the current (frontmost) card, for example:
answer file "select a picture"
if it <> "" then
import paint from file it
end if
To import several images from one folder, you can use the ask folder command, and use the defaultfoder and the files to get them all:
answer folder "select a folder"
if it <> "" then
set the defaultfolder to it
put the files into myListOfFiles
repeat for each line myFile in myListOfFiles
import paint from file myFile
end repeat
end if
Note that some OSes have hidden files that will show up in the files. To avoid them, you need to filter them out, for example on Mac OS X:
filter myListOfFiles without ".*"
Another way to avoid unwanted filetypes is to add a qualifier for files you want to include:
if char -4 to -1 of myFile is among the items of ".gif,.jpg,jpeg,.png,.bmp,.tif,tiff" then
import paint from file myFile
end if

It's not too hard to store images in a stack without placing them on a card. Do this:
Create a group on any card.
Import all your images into it.
In the Object menu, choose "Remove group".
This removes the group from the card but does not delete it. The group of images exists on no card but all your images are available. You can reference them normally, use them as icons, copy them to a card later, whatever you need. It's like having an invisible group on a card, only it isn't an object in the hierarchy. It receives no messages and isn't in the object layering.
This is how imported HyperCard stacks store their icon images, by the way. After an HC import you can find an unplaced group named "HC Icons" in the "Place group" menu item in the Object menu. It doesn't exist on any card, but all the imported buttons still show their icons.

You could store all the images in a folder in a stack with something like;
answer folder "Select the folder containing your images"
if it <> "" then
set the folder to it
put the files into tFiles
repeat for each line tFile in tFiles
set the uImages[tFile] of this stack to URL("binfile:" & tFile)
end repeat
end if
If you had an image object on your card called 'myImage', and one of the images in the folder was called 'car.png', you could then;
set the text of image "myImage" to the uImages["car.png"] of this stack
To retrieve the list of images stored in the stack, you can reference;
put the customKeys["uImages"] of this stack into tImageList
HTH :)

Related

Paraview: Create a state file in an external program

My c++ code outputs a number of vtu files and stl files. Each vtk file has a different mesh and a different number of fields. I want the user to be able to open those vtu files in Paraview together so that they are all on the same pipeline. Currently, the user has to open each vtu file separately or group select them together in the Open File dialog box and open them. But I want to give the user a better experience. I like the user to not worry about all the different but files and open just one "combined file". Is there a way to create one single file from all these vtu and stl files? Or create a single "reference" file that will reference those other vtu and STL files and the user has to open only the reference file?
If you have a way to get the list of file to load, you can create a python script alongside to your data, where you basically put:
from paraview.simple import *
# recover file list
# ...
for file in files:
OpenDataFile(file)
Then one can just load this script as a state in ParaView.

Import headshots via CSV

I have a sequence set up in my premiere project. It's a simple slide in from right (whilst fading in) of a headshot. Under the headshot is the name of the person (that follows the slide and fade in animation of the headshot) and I have to create a main sequence of 40 of these (each headshot sequence lasts around 3 seconds). That means manually placing the headshots (that are all the same size) and typing in the persons name for each one.
I am wondering if there is a way to automate this via a script in premiere pro that will read from a csv file the location of the headshot image and the name of the person and create it automatically for me?
I have tried looking around for such information but haven't had much success.
You can easily acheive this using Dataclay's Templater for Adobe After Effects. Even better than a CSV, you can use a cloud based Google Sheet and connect directly to that asset so you never have to deal with a file again.

Move files based on certain text in filename to specified folders in focused window

I've found similar requests but they don't quite fit my requirement. I've exhausted my searching and I've exhausted my limited skills.
Daily I create multiple new software projects creating the following folder structure:
"FOLDER 1" (root)
"Subfolder 1"
"subfolder 2" (inside subfolder 1).
Ive tried working with below but ideally i would like it to search for files with "quad bus" in the name and move those files.
tell application "Finder"
repeat with this_item in (selection of (folder of window 1))
move this_item to parent of parent of this_item
end repeat
end tell
I basically need to MOVE files added to subfolder 2 containing the word Quad Bus into the folder named to FOLDER 1.
The challenge I have is I can't specify the source and dest paths in the script so it would have to be a service that is run to execute the task in the focused or front finder window. Applescript seems to be the obvious choice but I've tried Python also.
The following Automator Service should get the basics for you, though I'm sure it could be improved. Open Automator, create a new Service, and set it up as shown in this image:
This uses two variables, which I called (with great creativity) ChosenFolder and DestinationFolder. You don't need to set values for them in Automator; values will be provided at runtime. Note that the fifth action (Get Value Of Variable) is set to ignore the input from the previous action. If you miss that break, Automator will throw an error, since it will add the destination folder into the list of items that need to be moved.

How to upload a photo to User Form using PATH and display on other computers?

I built a User Form where there is a post-select configuration that depending on choices shows an image and text results.
I uploaded the pictures from a cell where the image PATH is written to a picture box.
Image1.Picture = LoadPicture (Sheets ("XXX"). Cells (34, 5))
I have two problems:
The image is loaded upside down. I tried to find a ROTATE command, tried to make the image 180 degrees in a folder in advance, even tried to upload it to picture box directly one by one and the same problem. How can I make it rotate 180 degrees?
I sent the file to my co-workers and they were able to open the User Form, but when they clicked the SHOW button an error occurred that says the PATH was not found. I guess it is because the image is in a folder only on my computer. How can I put it in a shared folder and make PATH relevant to everyone (assuming there is a different USER for each computer)?
Regarding your first problem, there is a way of rotating images with vba code but it might be easier to just rotate it in advance so it gets displayed correctly. See this post for more info.
Your second problem can be solved in multiple ways, you could include the images in the workbook and load it from there, but if you don't like that, you can specify the path dynamically. Of course you have to provide your co workers with the image files aswell in this case. If the images are stored in the same folder as the excel file you can use
Application.ActiveWorkbook.Path
to dynamically find the path of the excel file, which would then also be the path of the image. You can also store the image in a subfolder in the folder of the excel file and create that path like this:
path=Application.ActiveWorkbook.Path & "\subfoldername"

select and copy files + directory [duplicate]

I am using Tkinter for building a GUI for a python script. I need a button which opens up a dialog box which allows me to select both files and directories.
Till now, I've come across
tkFileDialog.askdirectory(parent=root, title=dirtext1)
which allows just to select directories in the dialog box
and,
tkFileDialog.askopenfilename(parent=root, title=filetext)
which allows me to just select files. As of now, I access these dialog boxes using separate buttons, each of which calls one of these functions.
Is there anyway to select either a file or a folder using a single dialog box?
I don't think so. There is no built-in class to do it easily
Investigation
If you look at the tkFileDialog module's source code, both the Open and the Directory classes inherit from _Dialog, located in tkCommonDialog.
Good so far; these classes are simple and only extend two methods. _fixresult is a hook that filters based on your options (promising), and _fixoptions adds the right tcl parameters (like initial directory).
But when we get to the Dialog class (parent of _Dialog), we see that it calls a tcl command by a given name. The names built-in are "tk_getOpenFile" and "tk_chooseDirectory". We don't have a lot of python-level freedom of the command after this. If we go to see what other tcl scripts are avaliable, we are disappointed.
Looks like your options are
ttk::getOpenFile
ttk::getSaveFile
ttk::chooseDirectory
ttk::getAppendFile
Conclusion
Rats! Luckily, it should be quite easy for you to make your own dialog using listboxes, entry fields, button, (and other tk-builtins), and the os module.
Simple Alternative
From your comments, it looks like a viable simple work-around might be to use
directory = os.path.dirname(os.path.realpath(tkFileDialog.askopenfilename()))
They'll have to select a file, but the "Open" button will "return a path", in the sense that the path is computed from the file location
But I really want it!
If for some reason you really want this behaviour but don't want to remake the widget, you can call tcl scripts directly. It may be possible to copy the code from getOpenFile and provide more loose arguments that allow for selecting a more generic object. This isn't my speciality and seems like a really bad idea, but here is how you call tcl directly and here is where you can learn more about the underlying commands.
I've had a similar issue.
In the end, I used askopenfilenames() (plural) and split the path from the files. Then with a radiobutton, ask the user to choose if they want to process all the files in the directory, or just those they selected.
filetypes = [('All files', '*.*'), ('CSV files', '*.csv'),]
data_list = askopenfilenames(title='Select folder', filetypes=filetypes)
data_dir = data_list[0].rsplit('/', 1)[0]
I mention it because askopenfilenames() doesn't get suggested much, but is closer to selecting a folder, as can ctrl+A all files.

Resources