""" Drive GrassBrowser for OssimApp GRASS->Browser Menu entry.

You might need to start ossim with the PYTHONPATH environment
variable set to make sure several modules are in the module search path.


Copyright (C) 2001 ImageLinks Inc. 
This file is part of OSSIM, 
created by Intevation GmbH for the Ossim Grass Bridge.

 OSSIM 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.

 This software 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. 

 You should have received a copy of the GNU General Public License
 along with this software. If not, write to the Free Software 
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-
 1307, USA.

 See the GPL in the COPYING.GPL file for more details.

 Author: Bernhard Reiter <bernhard@intevation.de>
"""

import sys

# FIXME this is a hack to get the possible paths to ossim.py and ossimgui.py 
# in here
sys.path.append("../../../util/pymod")
# and the path to our modules
sys.path.append(".")
print sys.path


from wxPython.wx import *
import ossim
import ossimgui

import BrowseFrame

#---------------------------------------------------------------------------

win=None

def subframeclosing(evt):
    global win
    print "GrassBrowseWindow is going to close down."
    win.Destroy()
    if win.okay:
        print "A cell or imagery group was selected:"
        print win.gisdbase, win.location, win.mapset, win.cellname
        print "Try to open Ossim Window with it..."
        o=ossimgui.OssimFrame()
        i=ossim.ImageHandlerRegistry_open(win.cellname)
        o.openImageHandler(i)

    else:
        print "No Grass cell selected"
    

def addourFrame(frame):
    global win
    win = BrowseFrame.create(None,1)
    EVT_CLOSE(win, subframeclosing)
    win.progname="grassbrowse"
    frame.otherWin = win
    win.Show(true)


def main():
    ossimframe=ossimgui.GetMainWxFrame()
#    print str(ossimframe)
    ossimframe.SetStatusText("yeah,yeah")
    parent=ossimframe.GetParent()
#    print str(parent)

    addourFrame(ossimframe)


# even when called directly from ossim, we are __main__ :)
if __name__=="__main__":
    main()
