Exemplo n.º 1
0
def _quit(menuitem):
    global _rank
    if _rank != 0:
        ##        print "quitting back-end"
        ##        sys.stdout.flush()
        debug.fmsg()
        quit.quit()
Exemplo n.º 2
0
def _quit(menuitem):
    global _rank
    if _rank != 0:
        ##        print "quitting back-end"
        ##        sys.stdout.flush()
        debug.fmsg()
        quit.quit()
Exemplo n.º 3
0
def quitCmd(menuitem):
    from ooflib.common import quit
    quit.quit()
Exemplo n.º 4
0
Arquivo: oof.py Projeto: creuzige/OOF2
def front_end(no_interp=None):
    global startupfiles
    global gtk_options
    global randomseed
    ## From here on is the serial version.

    # When loading modules, use utils.OOFexec so that names are
    # imported into the oof environment, not the oof.run environment.
    if not (runtimeflags.text_mode or config.no_gui()):
        # The gtk import dance described below doesn't work when the program
        # has been packaged by cx_freeze.
        # TODO LATER: is checking frozen required for gtk2?
        frozen = hasattr(sys, 'frozen')
        if not frozen:
            import pygtk
            pygtk.require("2.0")
            import gtk
            msg = gtk.check_version(2, 6, 0)
            if msg:
                print msg
                sys.exit(3)

        import ooflib.common.IO.GUI.initialize
        # temporarily disable the engine, tutorials, orientationmap
        # for 3D development
        import ooflib.engine.IO.GUI.initialize
        import ooflib.image.IO.GUI.initialize
        if config.dimension() == 2:
            import ooflib.orientationmap.GUI.initialize
            import ooflib.tutorials.initialize
        if replaydelay is not None:
            from ooflib.common.IO.GUI import gtklogger
            gtklogger.set_delay(int(replaydelay))
    else:  # text mode
        import ooflib.common.initialize
        import ooflib.engine.initialize
        import ooflib.image.initialize
        if config.dimension() == 2:
            import ooflib.orientationmap.initialize
    import ooflib.EXTENSIONS.initialize

    # The random number generator must be seeded *after* the gui has
    # been started, because libfontconfig is using random numbers.  We
    # want the numbers to be the same in text and gui modes, so that
    # the test suite gets predictable answers.
    if debug.debug() or randomseed is not None:
        if randomseed is None:
            randomseed = 17
        random.seed(randomseed)
        crandom.rndmseed(randomseed)

    for module in startupimports:
        exec('import ' + module)

    if not (runtimeflags.text_mode or config.no_gui()):
        reporter.report("Welcome to OOF2 version %s!" % oofversion.version)
        ## The files to be loaded must be loaded *after* the GUI
        ## starts, but this routine doesn't regain control once it
        ## starts the GUI. So we have to install the file loader
        ## (loadStartUpFiles) as an idle callback, which will run on
        ## the main thread.  loadStartUpFiles just issues menu
        ## commands that load the files, and if it runs on the main
        ## thread those menu commands will run by Workers on
        ## subthreads, and won't be run sequentially.  So, instead of
        ## installing loadStartUpFiles as an idle callback, we install
        ## subthread.execute and have it call loadStartUpFiles, since
        ## workers on subthreads don't create additional subthreads to
        ## run their menu items.
        if startupfiles:
            # startupfiles won't be run until after the GUI starts.
            mainthread.run(subthread.execute_immortal,
                           (loadStartUpFiles, (startupfiles, )))
        if not no_interp:  # Default case, run on local thread.
            from ooflib.common.IO.GUI import oofGUI
            oofGUI.start()  # This call never returns.
            print "This line should never be printed.  rank =", _rank
        else:
            # TODO LATER: The gui and no_interp combination is
            # thinkable, but has problems.  You have to run the GUI on
            # a separate thread, but then exceptions show up as modal
            # dialog boxes in the GUI, and block the menu items which
            # raised them, causing a loss of control.  Also, the
            # current threading scheme requires that all gtk activity
            # happen on the main thread.
            print "GUI no_interp mode not implemented.  Sorry."
            raise NotImplementedError("GUI no_interp mode")

    else:  # text mode
        from ooflib.common import quit
        # Allow exceptions to propagate to the user if in batch mode
        # or not running an interpreter.  Otherwise, exceptions are
        # caught and reported to the user, but the program keeps
        # running.
        if runtimeflags.batch_mode or no_interp:
            from ooflib.common import worker
            worker.propagate_exceptions = True
        if startupfiles:
            loadStartUpFiles(startupfiles)
            if runtimeflags.batch_mode:
                # Batch mode runs startupfiles and quits immediately.
                quit.set_quiet()
                quit.quit()
                if sys.exc_info()[0] is not None:
                    sys.exit(1)
                sys.exit(0)
        # Format the banner for the current line width.
        if not quit.quiet():
            width = utils.screenwidth()
            wiggles = "//=*=\\\\=*="
            nwiggles = (width - 2) / len(wiggles)
            welcome = "Welcome to OOF2 version %s!" % oofversion.version
            nblanks = (width - len(welcome)) / 2
            banner = wiggles*nwiggles + "//\n\n" \
                     + " "*nblanks + welcome + "\n" + \
                     string.join(utils.format(banner1, width),"\n") + \
                     "\n\n" +  wiggles*nwiggles + "//\n" + \
                     string.join(utils.format(banner2, width), "\n")
        else:
            banner = ""

        if not no_interp:
            import code
            # Try to import readline, which allows command line
            # editing in text mode.  If it's not there, don't worry --
            # it's possible to live without it.  Some systems don't
            # seem to have it, although it's supposedly available on
            # all Unix systems.
            try:
                import readline
            except ImportError:
                pass
            # Start up the interpreter in the __main__ namespace.
            # This is the namespace that utils.OOFeval and OOFdefine
            # use.  It's not necessarily *this* namespace.
            interp = code.InteractiveConsole(sys.modules['__main__'].__dict__)
            interp.interact(banner)
Exemplo n.º 5
0
def front_end(no_interp=None):
    global startupfiles
    global gtk_options
    global randomseed
    ## From here on is the serial version.

    # VTK is started even in text mode to allow off-screen rendering,
    # interpretation of scripted mouse clicks, etc.
    from ooflib.SWIG.common.IO import vtkutils
    vtkutils.initialize_vtk()

    # When loading modules, use utils.OOFexec so that names are
    # imported into the oof environment, not the oof.run environment.
    if not (runtimeflags.text_mode or config.no_gui()):
        # The gtk import dance described below doesn't work when the program
        # has been packaged by cx_freeze.
        # TODO 3.1: is checking frozen required for gtk2?
        frozen = hasattr(sys, 'frozen')
        if not frozen:
            import pygtk
            pygtk.require("2.0")
            import gtk
            msg = gtk.check_version(2, 6, 0)
            if msg:
                print msg
                sys.exit(3)

        # The GUI initialization modules must be called before any
        # calls to mainthread.run(), because mainthread.run() is
        # redefined when mainthreadGUI.py is loaded (by
        # common/IO/GUI/initialize.py)
        import ooflib.common.IO.GUI.initialize
        import ooflib.engine.IO.GUI.initialize
        import ooflib.image.IO.GUI.initialize
        import ooflib.orientationmap.GUI.initialize
        import ooflib.tutorials.initialize

        if replaydelay is not None:
            from ooflib.common.IO.GUI import gtklogger
            gtklogger.set_delay(int(replaydelay))
    else:  # text mode
        # Load non-gui initialization modules.
        import ooflib.common.initialize
        import ooflib.engine.initialize
        import ooflib.image.initialize
        import ooflib.orientationmap.initialize

    import ooflib.EXTENSIONS.initialize

    # The random number generator must be seeded *after* the gui has
    # been started, because libfontconfig is using random numbers.  We
    # want the numbers to be the same in text and gui modes, so that
    # the test suite gets predictable answers.
    if debug.debug() or randomseed is not None:
        if randomseed is None:
            randomseed = 17
        random.seed(randomseed)
        crandom.rndmseed(randomseed)

    for module in startupimports:
        exec('import ' + module)

    if not (runtimeflags.text_mode or config.no_gui()):
        reporter.report("Welcome to %s version %s!" %
                        (program_name.upper(), oofversion.version))
        if not no_interp:  # Default case, run on local thread.
            from ooflib.common.IO.GUI import oofGUI
            oofGUI.start(files=startupfiles)  # This call never returns.
            print "This line should never be printed.  rank =", _rank
        else:
            # TODO 3.1: The gui and no_interp combination is
            # thinkable, but has problems.  You have to run the GUI on
            # a separate thread, but then exceptions show up as modal
            # dialog boxes in the GUI, and block the menu items which
            # raised them, causing a loss of control.  Also, the
            # current threading scheme requires that all gtk activity
            # happen on the main thread.
            print "GUI no_interp mode not implemented.  Sorry."
            raise NotImplementedError("GUI no_interp mode")

    else:  # text mode
        from ooflib.common import quit
        # Allow exceptions to propagate to the user if in batch mode
        # or not running an interpreter.  Otherwise, exceptions are
        # caught and reported to the user, but the program keeps
        # running.
        if runtimeflags.batch_mode or no_interp:
            from ooflib.common import worker
            worker.propagate_exceptions = True

        threadstate.textMode()
        lock.disableLocks()  # disables Locks, but not SLocks

        if startupfiles:
            loadStartUpFiles(startupfiles)
            if runtimeflags.batch_mode:
                # Batch mode runs startupfiles and quits immediately.
                quit.set_quiet()
                quit.quit()
                if sys.exc_info()[0] is not None:
                    sys.exit(1)
                sys.exit(0)
        # Format the banner for the current line width.
        if not quit.quiet():
            width = utils.screenwidth()
            wiggles = "//=*=\\\\=*="
            nwiggles = (width - 2) / len(wiggles)
            welcome = "Welcome to %s version %s!" % (program_name.upper(),
                                                     oofversion.version)
            nblanks = (width - len(welcome)) / 2
            banner = (
                wiggles * nwiggles + "//\n\n" + " " * nblanks + welcome +
                "\n" + string.join(
                    utils.format(banner1 % {'name': program_name.upper()},
                                 width), "\n") + "\n\n" + wiggles * nwiggles +
                "//\n" + string.join(
                    utils.format(banner2 % {'name': program_name.upper()},
                                 width), "\n"))
        else:
            banner = ""

        if not no_interp:
            import code
            # Try to import readline, which allows command line
            # editing in text mode.  If it's not there, don't worry --
            # it's possible to live without it.  Some systems don't
            # seem to have it, although it's supposedly available on
            # all Unix systems.
            try:
                import readline
            except ImportError:
                pass
            # Start up the interpreter in the __main__ namespace.
            # This is the namespace that utils.OOFeval and OOFdefine
            # use.  It's not necessarily *this* namespace.
            interp = code.InteractiveConsole(sys.modules['__main__'].__dict__)
            interp.interact(banner)
Exemplo n.º 6
0
def front_end(no_interp=None):
    global startupfiles
    global gtk_options
    global randomseed
    ## From here on is the serial version.
        
    # When loading modules, use utils.OOFexec so that names are
    # imported into the oof environment, not the oof.run environment.
    if not (runtimeflags.text_mode or config.no_gui()):
	# The gtk import dance described below doesn't work when the program
        # has been packaged by cx_freeze.
        # TODO LATER: is checking frozen required for gtk2?
        frozen = hasattr(sys, 'frozen')
	if not frozen:
            import pygtk
            pygtk.require("2.0")
            import gtk
            msg = gtk.check_version(2, 6, 0)
            if msg:
                print msg
                sys.exit(3)

        import ooflib.common.IO.GUI.initialize
        # temporarily disable the engine, tutorials, orientationmap
        # for 3D development
        import ooflib.engine.IO.GUI.initialize
        import ooflib.image.IO.GUI.initialize
        if config.dimension() == 2:
            import ooflib.orientationmap.GUI.initialize
            import ooflib.tutorials.initialize
        if replaydelay is not None:
            from ooflib.common.IO.GUI import gtklogger
            gtklogger.set_delay(int(replaydelay))
    else:                               # text mode
        import ooflib.common.initialize
        import ooflib.engine.initialize
        import ooflib.image.initialize
        if config.dimension() == 2:
            import ooflib.orientationmap.initialize
    import ooflib.EXTENSIONS.initialize

    # The random number generator must be seeded *after* the gui has
    # been started, because libfontconfig is using random numbers.  We
    # want the numbers to be the same in text and gui modes, so that
    # the test suite gets predictable answers.
    if debug.debug() or randomseed is not None:
        if randomseed is None:
            randomseed = 17
        random.seed(randomseed)
        crandom.rndmseed(randomseed)

    for module in startupimports:
        exec('import ' + module)

    if not (runtimeflags.text_mode or config.no_gui()):
        reporter.report("Welcome to OOF2 version %s!" % oofversion.version)
        ## The files to be loaded must be loaded *after* the GUI
        ## starts, but this routine doesn't regain control once it
        ## starts the GUI. So we have to install the file loader
        ## (loadStartUpFiles) as an idle callback, which will run on
        ## the main thread.  loadStartUpFiles just issues menu
        ## commands that load the files, and if it runs on the main
        ## thread those menu commands will run by Workers on
        ## subthreads, and won't be run sequentially.  So, instead of
        ## installing loadStartUpFiles as an idle callback, we install
        ## subthread.execute and have it call loadStartUpFiles, since
        ## workers on subthreads don't create additional subthreads to
        ## run their menu items.
        if startupfiles:
            # startupfiles won't be run until after the GUI starts.
            mainthread.run(subthread.execute_immortal,
                           (loadStartUpFiles, (startupfiles,)))
        if not no_interp: # Default case, run on local thread.
            from ooflib.common.IO.GUI import oofGUI
            oofGUI.start()      # This call never returns.
            print "This line should never be printed.  rank =", _rank
        else:
            # TODO LATER: The gui and no_interp combination is
            # thinkable, but has problems.  You have to run the GUI on
            # a separate thread, but then exceptions show up as modal
            # dialog boxes in the GUI, and block the menu items which
            # raised them, causing a loss of control.  Also, the
            # current threading scheme requires that all gtk activity
            # happen on the main thread.
            print "GUI no_interp mode not implemented.  Sorry."
            raise NotImplementedError("GUI no_interp mode")
            
    else:                               # text mode
        from ooflib.common import quit
        # Allow exceptions to propagate to the user if in batch mode
        # or not running an interpreter.  Otherwise, exceptions are
        # caught and reported to the user, but the program keeps
        # running.
        if runtimeflags.batch_mode or no_interp:
            from ooflib.common import worker
            worker.propagate_exceptions = True
        if startupfiles:
            loadStartUpFiles(startupfiles)
            if runtimeflags.batch_mode:
                # Batch mode runs startupfiles and quits immediately.
                quit.set_quiet()
                quit.quit()
                if sys.exc_info()[0] is not None:
                    sys.exit(1)
                sys.exit(0)
        # Format the banner for the current line width.
        if not quit.quiet():
            width = utils.screenwidth()
            wiggles = "//=*=\\\\=*="
            nwiggles = (width-2)/len(wiggles)
            welcome = "Welcome to OOF2 version %s!" % oofversion.version
            nblanks = (width - len(welcome))/2
            banner = wiggles*nwiggles + "//\n\n" \
                     + " "*nblanks + welcome + "\n" + \
                     string.join(utils.format(banner1, width),"\n") + \
                     "\n\n" +  wiggles*nwiggles + "//\n" + \
                     string.join(utils.format(banner2, width), "\n")
        else:
            banner = ""
            
        if not no_interp:
            import code
            # Try to import readline, which allows command line
            # editing in text mode.  If it's not there, don't worry --
            # it's possible to live without it.  Some systems don't
            # seem to have it, although it's supposedly available on
            # all Unix systems.
            try:
                import readline
            except ImportError:
                pass
            # Start up the interpreter in the __main__ namespace.
            # This is the namespace that utils.OOFeval and OOFdefine
            # use.  It's not necessarily *this* namespace.
            interp = code.InteractiveConsole(sys.modules['__main__'].__dict__)
            interp.interact(banner)