#!/usr/bin/env python
#
###
# Application: pyFind
# File:        pyfind
# Description: Initial loader
# Copyright (c) 2001-2002   Andy Balcombe <kinematics _at_ ntlworld.com>
###
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""main pyFind app"""

#standard python modules
import sys
import getopt
import os
import gnome

#project imports
import pyFind
import pyFind.config

#parameters (do this before starting pyFind / gnome stuff)
try:
    lOpts, lArgs = getopt.getopt( sys.argv[1:],
                                    "",
                                    ["last", "devel","help","version"])
    sys.argv = sys.argv[:1]
    #print "sys.argv=",sys.argv
    #print "lOpts=",lOpts
    #print "lArgs=",lArgs
except getopt.error, msg:
    print msg
    sys.exit(2)

#check some params...
#display help message
if ("--help","") in lOpts:
    print "Usage: pyfind [OPTION] PATH"
    print "    PATH            path to search from"
    print " "
    print "    --last          load search settings from previous session"
    print "    --devel         load glade files from local directory (for development)"
    print "    --version       display version"
    print "    --help          display help"
    sys.exit(None)

#display version
if ("--version","") in lOpts:
    print pyFind.config.app_name + " " + pyFind.config.app_version
    print "Written by Andy Balcombe"
    print " "
    print "Copyright (C) 2001-2002 Andy Balcombe"
    print " "
    print "This is free software; see the source for copying conditions.  There is NO"
    print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
    sys.exit(None)

#set mode (production or development)
if ("--devel","") in lOpts:
    sMode = "development"
else:
    sMode = "production"

#set path
if len(lArgs) == 0:
    sPath = os.getcwd()
else:
    #path arg specified
    sPath = lArgs[0]
    
if ("--last","") in lOpts:
    sPath = ""
        
#set pyFind version before importing UI module
gnome.app_id = pyFind.config.app_name
gnome.app_version = pyFind.config.app_version

#import appMain window
from pyFind.appMain import *

#instantiate main GUI window class
app = appMain("pyfind.glade", "appMain", sMode)

#initialise pyFind
app.init_appMain( sPath )

#and... go...
gtk.mainloop()
