#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2008 Martin Manns
# Distributed under the terms of the GNU General Public License

# --------------------------------------------------------------------
# pyspread 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 3 of the License, or
# (at your option) any later version.
#
# pyspread 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyspread.  If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------

"""
Cross-platform spreadsheet application.

See __init__.py for extensive docstring.

"""

import sys

import wx

# If pyspread is installed but run from a local dir the local libs are preferred
sys.path.insert(0, "..") 

from pyspread._interfaces import Commandlineparser
from pyspread._windows import MainWindow


def main():
    """Parses command line and starts pyspread"""
    
    # Get command line options and arguments
    cmdp = Commandlineparser()
    options, filename = cmdp.parse()
    
    if filename is None:
        dimensions = options.dimensions
    else:
        dimensions = (1, 1, 1) # Will be overridden anyways
    
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    
    main_window = MainWindow(None, dimensions=dimensions)
    
    if filename is not None:
        main_window.MainGrid.loadfile(filename)
    
    app.SetTopWindow(main_window)
    main_window.Show()
    app.MainLoop()

def __main__():
    """Compatibility hack"""
    
    pass

if __name__ == "__main__":
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

#    import cProfile
#    cProfile.run('main()')
    
    main()
