#@ String(visibility="MESSAGE", value="") Title
#@ File[] (label="Images/Image folder for which to look for the template", style="both") ListFiles
'''
FIJI macro
This script prompts a window to get the list of image to process
Folder can also be given in this case all images of the foler are processed
The only limitation currently is that all target images (where the search is done) must have the same size
Then it calls the GUI of the matching method and performs the match on the list of images
'''
import os
from ij import IJ
from MatchTemplate_Module import Run, Config

# Generate GUI for keypoint method...
Cancel = Config() 

# Process search on list of images
if Cancel:
	message = "Template matching was cancelled"
	print message
	IJ.log(message)
	
else:# Ok was pressed in the SI gui
	for item in ListPath:
		Path = item.getPath()
		
		# item is a directory, we process all files in this directory
		if os.path.isdir(Path):
			SubListPath = os.listdir(Path)
			
			for filename in SubListPath:
				filepath = os.path.join(Path,filename)
				
				if os.path.isdir(filepath): # this is a subfolder
					continue # skip the entry
				else:
					Run(filepath,False)
					
			
		# item is a file
		else: 
			Run(Path, False) # False = dont write the JobFile