Esempio n. 1
0
    def PinnedModify(self):
        import os, random
        from ooflib.SWIG.common import crandom
        OOF.Graphics_1.Toolbox.Select_Node.Rectangle(
            skeleton="skeltest:skelextra",
            points=[Point(9.75, 7.25), Point(10.25, 12.75)],
            ctrl=0,
            shift=0)
        OOF.Skeleton.PinNodes.Pin_Node_Selection(skeleton="skeltest:skelextra")

        random.seed(17)
        crandom.rndmseed(17)
        OOF.Skeleton.Modify(skeleton="skeltest:skelextra",
                            modifier=SnapNodes(
                                targets=SnapAll(),
                                criterion=AverageEnergy(alpha=0.75)))
        OOF.File.Save.Skeleton(filename="skeleton_pinned_test",
                               mode="w",
                               format="ascii",
                               skeleton="skeltest:skelextra")
        OOF.Skeleton.Delete(skeleton="skeltest:skelextra")
        OOF.File.Load.Data(filename="skeleton_pinned_test")
        OOF.File.Load.Data(
            filename=reference_file("skeleton_data", "snapnodes_pinned"))
        sk1 = skeletoncontext.skeletonContexts["skeltest:skelextra"].getObject(
        )
        sk2 = skeletoncontext.skeletonContexts["skelcomp:skelextra"].getObject(
        )
        self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
        os.remove("skeleton_pinned_test")
        OOF.Skeleton.Delete(skeleton="skeltest:skelextra")
Esempio n. 2
0
    def doModify(self, registration, startfile, compfile, kwargs):
        import os, random
        from ooflib.SWIG.common import crandom

        # Loaded skeleton must be named "modtest".
        OOF.File.Load.Data(filename=reference_file("skeleton_data", startfile))
        mod = registration(**kwargs)
        random.seed(17)
        crandom.rndmseed(17)
        OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
        skelc = skeletoncontext.skeletonContexts["skeltest:modtest"]
        self.assert_(skelc.getObject().sanity_check())
        # Saving and reloading the Skeleton guarantees that node
        # indices match up with the reference skeleton.  Nodes are
        # re-indexed when a skeleton is saved.
        OOF.File.Save.Skeleton(filename="skeleton_mod_test", mode="w", format="ascii", skeleton="skeltest:modtest")
        OOF.Skeleton.Delete(skeleton="skeltest:modtest")
        OOF.File.Load.Data(filename="skeleton_mod_test")
        # Saved skeleton is named "skelcomp:reference".
        OOF.File.Load.Data(filename=reference_file("skeleton_data", compfile))
        sk1 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
        sk2 = skeletoncontext.skeletonContexts["skelcomp:reference"].getObject()
        # Tolerance is 1.0e-13, 100x double-precision noise.
        self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
        os.remove("skeleton_mod_test")
        OOF.Skeleton.Delete(skeleton="skeltest:modtest")
        OOF.Skeleton.Delete(skeleton="skelcomp:reference")
        OOF.Microstructure.Delete(microstructure="skelcomp")
Esempio n. 3
0
def generate():
    from ooflib.SWIG.common import crandom
    from ooflib.engine import skeletonmodifier
    from ooflib.engine import skeletonnode
    from ooflib.engine import skeletonelement
    from ooflib.engine import skeletonsegment
    for r in skeletonmodifier.SkeletonModifier.registry:
        try:
            mods = skel_modify_args[r.name()]
        except KeyError:
            print "No data for skeleton modifier %s." % r.name()
        else:
            # Saved skeleton must be named "modtest".
            for (startfile, destfile, kwargs) in mods:
                OOF.File.Load.Data(
                    filename=os.path.join("skeleton_data", startfile))
                mod = r(**kwargs)
                random.seed(17)
                crandom.rndmseed(17)
                OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
                OOF.Microstructure.Rename(microstructure="skeltest",
                                          name="skelcomp")
                OOF.Skeleton.Rename(skeleton="skelcomp:modtest",
                                    name="reference")
                OOF.File.Save.Skeleton(filename="skel_" + destfile,
                                       mode="w",
                                       format="ascii",
                                       skeleton="skelcomp:reference")
                OOF.Microstructure.Delete(microstructure="skelcomp")
Esempio n. 4
0
def generate():
    from ooflib.SWIG.common import crandom
    from ooflib.engine import skeletonmodifier
    from ooflib.engine import skeletonnode
    from ooflib.engine import skeletonelement
    from ooflib.engine import skeletonsegment
    for r in skeletonmodifier.SkeletonModifier.registry:
        try:
            mods = skel_modify_args[r.name()]
        except KeyError:
            print "No data for skeleton modifier %s." % r.name()
        else:
            # Saved skeleton must be named "modtest".
            for (startfile, destfile, kwargs) in mods:
                OOF.File.Load.Data(
                    filename=os.path.join("skeleton_data", startfile))
                mod = r(**kwargs)
                random.seed(17)
                crandom.rndmseed(17)
                OOF.Skeleton.Modify(skeleton="skeltest:modtest",
                                    modifier=mod)
                OOF.Microstructure.Rename(microstructure="skeltest",
                                          name="skelcomp")
                OOF.Skeleton.Rename(skeleton="skelcomp:modtest",
                                    name="reference")
                OOF.File.Save.Skeleton(filename="skel_"+destfile,
                                       mode="w", format="ascii",
                                       skeleton="skelcomp:reference")
                OOF.Microstructure.Delete(microstructure="skelcomp")
Esempio n. 5
0
    def PinnedModify(self):
        import os, random
        from ooflib.SWIG.common import crandom
        OOF.Graphics_1.Toolbox.Select_Node.Rectangle(
            skeleton="skeltest:skelextra",
            points=[Point(9.75,7.25), Point(10.25,12.75)],
            ctrl=0, shift=0)
        OOF.Skeleton.PinNodes.Pin_Node_Selection(
            skeleton="skeltest:skelextra")

        random.seed(17)
        crandom.rndmseed(17)
        OOF.Skeleton.Modify(
            skeleton="skeltest:skelextra",
            modifier=SnapNodes(targets=SnapAll(),
                               criterion=AverageEnergy(alpha=0.75)))
        OOF.File.Save.Skeleton(filename="skeleton_pinned_test",
                               mode="w", format="ascii",
                               skeleton="skeltest:skelextra")
        OOF.Skeleton.Delete(skeleton="skeltest:skelextra")
        OOF.File.Load.Data(filename="skeleton_pinned_test")
        OOF.File.Load.Data(filename=reference_file("skeleton_data",
                                                   "snapnodes_pinned"))
        sk1 = skeletoncontext.skeletonContexts[
            "skeltest:skelextra"].getObject()
        sk2 = skeletoncontext.skeletonContexts[
            "skelcomp:skelextra"].getObject()
        self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
        os.remove("skeleton_pinned_test")
        OOF.Skeleton.Delete(skeleton="skeltest:skelextra")
Esempio n. 6
0
    def Bufferbug(self):
        import os, random
        from ooflib.SWIG.common import crandom

        random.seed(17)
        crandom.rndmseed(17)

        OOF.Skeleton.Modify(
            skeleton='triangle:skeleton',
            modifier=Anneal(targets=AllNodes(),
                            criterion=AverageEnergy(alpha=0.94999999999999996),
                            T=0.0,
                            delta=1.0,
                            iteration=FixedIteration(iterations=20)))
        OOF.Skeleton.Modify(skeleton='triangle:skeleton',
                            modifier=SwapEdges(targets=AllElements(),
                                               criterion=AverageEnergy(
                                                   alpha=0.93650800000000001)))
        OOF.File.Save.Skeleton(filename="skeleton_bufferbug_test",
                               mode='w',
                               format='ascii',
                               skeleton='triangle:skeleton')
        self.assert_(
            fp_file_compare(
                "skeleton_bufferbug_test",
                os.path.join("skeleton_data", "skeleton_bufferbug_ref"),
                1.e-10))
        os.remove("skeleton_bufferbug_test")
Esempio n. 7
0
    def Bufferbug(self):
        import os,random
        from ooflib.SWIG.common import crandom

        random.seed(17)
        crandom.rndmseed(17)
        
        OOF.Skeleton.Modify(skeleton='triangle:skeleton', 
                            modifier=Anneal(
                targets=AllNodes(),
                criterion=AverageEnergy(
                    alpha=0.94999999999999996),
                T=0.0,delta=1.0,
                iteration=FixedIteration(
                    iterations=20)))
        OOF.Skeleton.Modify(skeleton='triangle:skeleton', 
                            modifier=SwapEdges(
                targets=AllElements(),
                criterion=AverageEnergy(alpha=0.93650800000000001)))
        OOF.File.Save.Skeleton(filename="skeleton_bufferbug_test", 
                               mode='w', 
                               format='ascii', 
                               skeleton='triangle:skeleton')
        self.assert_(
            fp_file_compare(
                "skeleton_bufferbug_test",
                os.path.join("skeleton_data", "skeleton_bufferbug_ref"),
                1.e-10))
        os.remove("skeleton_bufferbug_test")
Esempio n. 8
0
 def doModify(self, registration, startfile, compfile, kwargs):
     import os, random
     from ooflib.SWIG.common import crandom
     # Loaded skeleton must be named "modtest".
     OOF.File.Load.Data(filename=reference_file("skeleton_data", startfile))
     mod = registration(**kwargs)
     random.seed(17)
     crandom.rndmseed(17)
     OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
     skelc = skeletoncontext.skeletonContexts["skeltest:modtest"]
     self.assert_(skelc.getObject().sanity_check())
     # Saving and reloading the Skeleton guarantees that node
     # indices match up with the reference skeleton.  Nodes are
     # re-indexed when a skeleton is saved.
     OOF.File.Save.Skeleton(filename="skeleton_mod_test",
                            mode="w",
                            format="ascii",
                            skeleton="skeltest:modtest")
     OOF.Skeleton.Delete(skeleton="skeltest:modtest")
     OOF.File.Load.Data(filename="skeleton_mod_test")
     # Saved skeleton is named "skelcomp:reference".
     OOF.File.Load.Data(filename=reference_file("skeleton_data", compfile))
     sk1 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     sk2 = skeletoncontext.skeletonContexts["skelcomp:reference"].getObject(
     )
     # Tolerance is 1.0e-13, 100x double-precision noise.
     self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
     os.remove("skeleton_mod_test")
     OOF.Skeleton.Delete(skeleton="skeltest:modtest")
     OOF.Skeleton.Delete(skeleton="skelcomp:reference")
     OOF.Microstructure.Delete(microstructure="skelcomp")
Esempio n. 9
0
 def doModify(self, registration, startfile, compfile, kwargs):
     import os, random
     from ooflib.SWIG.common import crandom
     OOF.File.Load.Data(filename=reference_file("skeleton_data",
                                                "periodic_mods", startfile))
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     mod = registration(**kwargs)
     random.seed(17)
     crandom.rndmseed(17)
     OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     self.assert_(sk0.sanity_check())
     fname = reference_file("skeleton_data", "periodic_mods", compfile)
     if generate and not os.path.exists(fname):
         # Save the new Skeleton under a different name
         OOF.Microstructure.Rename(microstructure="skeltest",
                                   name="reference")
         OOF.File.Save.Skeleton(filename=fname,
                                mode="w",
                                format="ascii",
                                skeleton="reference:modtest")
         # Change the name back, so that tearDown won't complain.
         OOF.Microstructure.Rename(microstructure="reference",
                                   name="skeltest")
     else:
         # Saving and reloading the Skeleton guarantees that node
         # indices match up with the reference skeleton.  Nodes are
         # re-indexed when a skeleton is saved.
         OOF.File.Save.Skeleton(filename="skeleton_mod_test",
                                mode="w",
                                format="ascii",
                                skeleton="skeltest:modtest")
         OOF.Microstructure.Delete(microstructure="skeltest")
         OOF.File.Load.Data(filename="skeleton_mod_test")
         # Load the reference Skeleton.
         OOF.File.Load.Data(filename=fname)
         # Compare the two Skeletons
         sk1 = skeletoncontext.skeletonContexts[
             "skeltest:modtest"].getObject()
         sk2 = skeletoncontext.skeletonContexts[
             "reference:modtest"].getObject()
         # Tolerance is 1.0e-13, 100x double-precision noise.
         self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
         os.remove("skeleton_mod_test")
         OOF.Microstructure.Delete(microstructure="reference")
Esempio n. 10
0
 def doModify(self, registration, startfile, compfile, kwargs):
     import os, random
     from ooflib.SWIG.common import crandom
     OOF.File.Load.Data(
         filename=reference_file("skeleton_data","periodic_mods", startfile))
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     mod = registration(**kwargs)
     random.seed(17)
     crandom.rndmseed(17)
     OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     self.assert_(sk0.sanity_check())
     fname = reference_file("skeleton_data", "periodic_mods", compfile)
     if generate and not os.path.exists(fname):
         # Save the new Skeleton under a different name
         OOF.Microstructure.Rename(microstructure="skeltest",
                                   name="reference")
         OOF.File.Save.Skeleton(filename=fname, mode="w", format="ascii",
                                skeleton="reference:modtest")
         # Change the name back, so that tearDown won't complain.
         OOF.Microstructure.Rename(microstructure="reference",
                                   name="skeltest")
     else:
         # Saving and reloading the Skeleton guarantees that node
         # indices match up with the reference skeleton.  Nodes are
         # re-indexed when a skeleton is saved.
         OOF.File.Save.Skeleton(
             filename="skeleton_mod_test",
             mode="w", format="ascii",
             skeleton="skeltest:modtest")
         OOF.Microstructure.Delete(microstructure="skeltest")
         OOF.File.Load.Data(filename="skeleton_mod_test")
         # Load the reference Skeleton.
         OOF.File.Load.Data(filename=fname)
         # Compare the two Skeletons
         sk1 = skeletoncontext.skeletonContexts[
             "skeltest:modtest"].getObject()
         sk2 = skeletoncontext.skeletonContexts[
             "reference:modtest"].getObject()
         # Tolerance is 1.0e-13, 100x double-precision noise.
         self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
         os.remove("skeleton_mod_test")
         OOF.Microstructure.Delete(microstructure="reference")
Esempio n. 11
0
    def Modify(self):
        import filecmp, os, random
        from ooflib.SWIG.common import crandom
        from ooflib.image import oofimage3d
        global image_modify_args
        menuitem = OOF.Image.Modify
        for m in menuitem.items:
            try:
                test_list = image_modify_args[m.name]
            except KeyError:
                print "No test data for image modifier ", m.name
            else:
                for (datafilename, argdict) in test_list:
                    argdict['image']="imagemod_test:slice*.tif"
                    OOF.Microstructure.Create_From_ImageFile(
                        filename=os.path.join("ms_data","5color","slice*.tif"),
                        microstructure_name="imagemod_test",
                        height=automatic, width=automatic, depth=automatic)
                    random.seed(17)
                    crandom.rndmseed(17)
                    m.callWithArgdict(argdict)

##                     OOF.File.Save.Image(
##                         filename=os.path.join("image_data", datafilename[:-1]+"%i"),
##                         image="imagemod_test:slice*.tif")

                    OOF.Microstructure.Create_From_ImageFile(
                        filename=os.path.join("image_data", datafilename),
                        microstructure_name="comparison",
                        height=automatic, width=automatic, depth=automatic)
                    im1 = oofimage3d.imageContexts[
                        "imagemod_test:slice*.tif"].getObject()
                    im2 = oofimage3d.imageContexts[
                        "comparison:"+datafilename].getObject()
                    # Tolerance is 1./65535., which is the level of
                    # "quantization noise" for 16-bit color channels.
                    self.assert_(im1.compare(im2, 1./65535.))
                    
                    OOF.Microstructure.Delete(
                        microstructure="comparison")
                    OOF.Microstructure.Delete(
                        microstructure="imagemod_test")
Esempio n. 12
0
 def RandomNumbers(self):
     # Check to be sure that the random numbers are reproducible
     # from machine to machine when the generator has been seeded.
     # If they're not reproducible, many of the subsequent tests
     # will fail.
     from ooflib.SWIG.common import crandom
     crandom.rndmseed(17)
     r = [crandom.irndm() for x in range(10)]
     expected = [
         1227918265, 3978157, 263514239, 1969574147, 1833982879, 488658959,
         231688945, 1043863911, 1421669753, 1942003127
     ]
     self.assertEqual(r, expected)
     crandom.rndmseed(17)
     r = [crandom.irndm() for x in range(10)]
     expected = [
         1227918265, 3978157, 263514239, 1969574147, 1833982879, 488658959,
         231688945, 1043863911, 1421669753, 1942003127
     ]
     self.assertEqual(r, expected)
     crandom.rndmseed(137)
     r = [crandom.irndm() for x in range(10)]
     expected = [
         171676246, 1227563367, 950914861, 1789575326, 941409949, 491970794,
         2006468446, 837991916, 696662892, 1224152791
     ]
     self.assertEqual(r, expected)
Esempio n. 13
0
    def Modify(self):
        import filecmp, os, random
        from ooflib.SWIG.common import crandom
        from ooflib.SWIG.image import oofimage

        global image_modify_args
        menuitem = OOF.Image.Modify
        for m in menuitem.items:
            try:
                test_list = image_modify_args[m.name]
            except KeyError:
                print >> sys.stderr, "No test data for image modifier ", m.name
            else:
                for (datafilename, argdict) in test_list:
                    argdict["image"] = "imagemod_test:image_test.ppm"
                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", "image_test.ppm"),
                        microstructure_name="imagemod_test",
                        height=automatic,
                        width=automatic,
                    )
                    random.seed(17)
                    crandom.rndmseed(17)
                    m.callWithArgdict(argdict)

                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", datafilename),
                        microstructure_name="comparison",
                        height=automatic,
                        width=automatic,
                    )
                    im1 = imagecontext.imageContexts["imagemod_test:image_test.ppm"].getObject()
                    im2 = imagecontext.imageContexts["comparison:" + datafilename].getObject()
                    # Tolerance is 1./65535., which is the level of
                    # "quantization noise" for 16-bit color channels.
                    self.assert_(im1.compare(im2, 1.0 / 65535.0))

                    OOF.Microstructure.Delete(microstructure="comparison")
                    OOF.Microstructure.Delete(microstructure="imagemod_test")
Esempio n. 14
0
    def Modify(self):
        import filecmp, os, random
        from ooflib.SWIG.common import crandom
        from ooflib.SWIG.image import oofimage
        global image_modify_args
        menuitem = OOF.Image.Modify
        for m in menuitem.items:
            try:
                test_list = image_modify_args[m.name]
            except KeyError:
                print >> sys.stderr, "No test data for image modifier ", m.name
            else:
                for (datafilename, argdict) in test_list:
                    argdict['image'] = "imagemod_test:image_test.ppm"
                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data",
                                                "image_test.ppm"),
                        microstructure_name="imagemod_test",
                        height=automatic,
                        width=automatic)
                    random.seed(17)
                    crandom.rndmseed(17)
                    m.callWithArgdict(argdict)

                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", datafilename),
                        microstructure_name="comparison",
                        height=automatic,
                        width=automatic)
                    im1 = imagecontext.imageContexts[
                        "imagemod_test:image_test.ppm"].getObject()
                    im2 = imagecontext.imageContexts["comparison:" +
                                                     datafilename].getObject()
                    # Tolerance is 1./65535., which is the level of
                    # "quantization noise" for 16-bit color channels.
                    self.assert_(im1.compare(im2, 1. / 65535.))

                    OOF.Microstructure.Delete(microstructure="comparison")
                    OOF.Microstructure.Delete(microstructure="imagemod_test")
Esempio n. 15
0
 def RandomNumbers(self):
     # Check to be sure that the random numbers are reproducible
     # from machine to machine when the generator has been seeded.
     # If they'r e not reproducible, many of the subsequent tests
     # will fail.
     from ooflib.SWIG.common import crandom
     crandom.rndmseed(17)
     r = [crandom.irndm() for x in range(10)]
     expected = [1227918265, 3978157, 263514239, 1969574147, 1833982879,
                 488658959, 231688945, 1043863911, 1421669753, 1942003127]
     self.assertEqual(r, expected)
     crandom.rndmseed(17)
     r = [crandom.irndm() for x in range(10)]
     expected = [1227918265, 3978157, 263514239, 1969574147, 1833982879,
                 488658959, 231688945, 1043863911, 1421669753, 1942003127]
     self.assertEqual(r, expected)
     crandom.rndmseed(137)
     r = [crandom.irndm() for x in range(10)]
     expected = [171676246, 1227563367, 950914861, 1789575326, 941409949,
                 491970794, 2006468446, 837991916, 696662892, 1224152791]
     self.assertEqual(r, expected)
Esempio n. 16
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)
Esempio n. 17
0
def _randomseed(menuitem, seed):
    random.seed(seed)
    crandom.rndmseed(seed)
Esempio n. 18
0
File: oof.py Progetto: 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)
Esempio n. 19
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)