
import os
if os.environ.has_key( "CCP4I2_TOP" ) :
   CCP4I2_TOP = os.environ[ "CCP4I2_TOP" ]
elif os.environ.has_key( "CCP4I2" ) :
   CCP4I2_TOP = os.environ[ "CCP4I2" ]
else:
   import sys
   target = os.path.join(os.path.realpath(sys.argv[0]),"..")
   abstarget = os.path.abspath(target)
   splittarget = abstarget.split()
   if splittarget.count('ccp4i2'):
     splittarget.reverse()
     up = splittarget.index('ccp4i2')
   while up>0:
     abstarget = os.path.dirname(abstarget)
     up = up -1
   CCP4I2_TOP = abstarget

if os.environ.has_key( "CCP4I2_TEST" ) :
   CCP4I2_TEST = os.environ[ "CCP4I2_TEST" ]

execfile(os.path.join(CCP4I2_TOP,'utils','startup.py'))
setupEnvironment(path=CCP4I2_TOP)
setupPythonpath(top=CCP4I2_TOP,mode='qtgui')
#setupPluginsPath(CCP4I2_TOP)

# CCP4Modules contains functions to access key parameters and modules
from core import CCP4Config
config = CCP4Config.DEFCONFIG()
config.set('developer',True)
config.set('qt',True)
config.set('graphical',True)

from core.CCP4Modules import *
myQTAPPLICATION = QTAPPLICATION()
pm = startProjectsManager()
print 'Using CCP4i2 from '+os.path.abspath(getCCP4I2Dir())
if not testForCCP4Environment(): print 'BEWARE: CCP4 environment not set'




