#!/usr/bin/env /home/beams/BCDA/bin/python
import tkFileDialog
import sys
import os
import string
import Tkinter

def findconfig(file,path):
	try: 
		f = open('yca.config','r')
		file = f.readline()
		path = f.readline()
		f.close()
		if os.path.isfile(file):
		  os.system("yca "+file)
		else:
		  print 'Error: ',file,' not found!!!'
	except IOError:
		print 'No configuration file found!'
		return -1,"",""
	else:
		return 1,file,path

def main():

	found=-1
	file=""
	path=""
        root = Tkinter.Tk()
	root.title('runyca: python yo.py')
        if len(sys.argv) < 2:
	   found,file,path = findconfig(file,path)
	   print found,file,path
	   fname = "*.mda"
	   while (string.strip(fname) != ""):
		p1 = string.split(string.strip(path),'\n')
		f1 = string.split(string.strip(file),'\n')
		fname = tkFileDialog.askopenfilename(initialdir=p1[0],initialfile=f1[0])
#                fname = tkFileDialog.Open().show()
		if string.strip(fname) != "":
		   os.system("yca "+fname)

		(path,file) = os.path.split(fname)



        elif sys.argv[1] == '?' or sys.argv[1] == "help" or sys.argv[1][:2] == "-h":
                print "usage: %s [filename [maxdim [verbose]]]" % sys.argv[0]
                print "   maxdim defaults to 2; verbose defaults to 1"
                return()
        else:
                fname = sys.argv[1]

if __name__ == "__main__":
#  	found,file,path = findconfig(file,path)
#	if found == -1: 
		main()
