Exemple #1
0
def main():

    # -------------------------------------
    # initialize file names
    # -------------------------------------
    anEmlFile = None
    anEssFile = None

    # -------------------------------------
    # gets options
    # -------------------------------------
    try:
        opts , args = getopt.getopt( sys.argv[1:] , 'he:f:',
                                         ["help", "exec=", "file="])
    except:
        usage()
        sys.exit(1)

    # -------------------------------------
    # checks argument
    # -------------------------------------
    for anOption, anArg in opts:

        # prints help message
        if anOption in ( "-h", '--help' ):
            usage()
            sys.exit(0)
        # executes script file (.ess)
        if anOption in ( "-e", '--exec'):
            anEssFile = anArg

        # load model file (.eml)
        if anOption in ( "-f", '--file' ):
            anEmlFile = anArg
            
    # -------------------------------------
    # prohibits to use -e and -f options 
    # -------------------------------------
    if anEmlFile != None and anEssFile != None:
        usage()
        sys.exit(0)

    # -------------------------------------
    # creates an instance of GtkSession and 
    # creates MainWindow instance
    # -------------------------------------
    aSession = GtkSessionMonitor()

    # -------------------------------------
    # executes options
    # -------------------------------------
    # load model file (.eml)
    if anEmlFile != None:

        # check EML File
        if os.path.isfile( anEmlFile ):
            pass
        else:
            aMessage = " Error ! [%s] No such file. \n" %anEmlFile
            aSession.message( aMessage )
            sys.exit(1)

        # print message 
        aSession.message("%s is loaded.\n" %anEmlFile )

        # load model
        try:
            aSession.loadModel( anEmlFile )
        except:
        
            aSession.message(' can\'t load [%s]' %anEmlFile)
            anErrorMessage = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) )
            aSession.message("-----------")
            aSession.message(anErrorMessage)
            aSession.message("-----------")

    # executes script file (.ess)
    elif anEssFile != None:

        # check ESS File
        if os.path.isfile( anEssFile ):
            pass
        else:
            aMessage = " Error ! [%s] No such file. \n" %anEssFile
            aSession.message( aMessage )
            sys.exit(1)

        # print message on MainWindow
        aSession.message("%s is being loaded and executed.\n" %anEssFile )
        gobject.timeout_add( 1, loadScript, [ aSession, anEssFile ] )

    aMainWindow = aSession.openWindow('MainWindow')
    aSession.updateWindows()


    # -------------------------------------
    # calls gtk.main()
    # -------------------------------------

    aSession.GUI_interact()