Beispiel #1
0
    def pickle_load(self, fn, set_vars=True, additional_vars=[]):
        """
        Load the pickled world in file fn.
        additional_vars is a dictionary to be populated with the
        loaded variables.
        """
        import cPickle as pickle
        try:
            world, variables = pickle.load(open(fn, 'rb'))
            world = world._pickle_finalize()
            variables = box2d.pickle_fix(world, variables, 'load')
        except Exception as s:
            print 'Error while loading world: ', s
            return

        self.world = world

        if set_vars:
            # reset the additional saved variables:
            for var, value in variables.items():
                if hasattr(self, var):
                    setattr(self, var, value)
                else:
                    print 'Unknown property %s=%s' % (var, value)

        print 'Loaded from %s' % fn

        return variables
Beispiel #2
0
    def pickle_load(self, fn, set_vars=True, additional_vars=[]):
        """
        Load the pickled world in file fn.
        additional_vars is a dictionary to be populated with the
        loaded variables.
        """
        import pickle as pickle
        try:
            world, variables = pickle.load(open(fn, 'rb'))
            world = world._pickle_finalize()
            variables = box2d.pickle_fix(world, variables, 'load')
        except Exception as s:
            print('Error while loading world: ', s)
            return

        self.world = world

        if set_vars:
            # reset the additional saved variables:
            for var, value in list(variables.items()):
                if hasattr(self, var):
                    setattr(self, var, value)
                else:
                    print('Unknown property %s=%s' % (var, value))

        print('Loaded from %s' % fn)

        return variables
Beispiel #3
0
 def pickle_load(self, fn, set_vars=True, additional_vars=[]):
     """
     Load the pickled world in file fn.
     additional_vars is a dictionary to be populated with the
     loaded variables.
     """
     import cPickle as pickle
     try:
         world, variables = pickle.load(open(fn, 'rb'))
         world = world._pickle_finalize()
         variables  = box2d.pickle_fix(world, variables, 'load')
     except Exception, s:
         print 'Error while loading world: ', s
         return
Beispiel #4
0
    def pickle_save(self, fn, additional_vars={}):
        import cPickle as pickle
        self.add.remove_mouseJoint()
    
        if not additional_vars and hasattr(self, '_pickle_vars'):
            additional_vars=dict((var, getattr(self, var)) for var in self._pickle_vars)

        save_values = [self.world, box2d.pickle_fix(self.world, additional_vars, 'save')]

        try:
            pickle.dump(save_values, open(fn, 'wb'))
        except Exception, s:
            print 'Pickling failed: ', s
            return
 def pickle_load(self, fn, set_vars=True, additional_vars=[]):
     """
     Load the pickled world in file fn.
     additional_vars is a dictionary to be populated with the
     loaded variables.
     """
     import cPickle as pickle
     try:
         world, variables = pickle.load(open(fn, 'rb'))
         world = world._pickle_finalize()
         variables  = box2d.pickle_fix(world, variables, 'load')
     except Exception, s:
         print 'Error while loading world: ', s
         return
Beispiel #6
0
    def pickle_save(self, fn, additional_vars={}):
        import cPickle as pickle
        self.add.remove_mouseJoint()
    
        if not additional_vars and hasattr(self, '_pickle_vars'):
            additional_vars=dict((var, getattr(self, var)) for var in self._pickle_vars)

        save_values = [self.world, box2d.pickle_fix(self.world, additional_vars, 'save')]

        try:
            pickle.dump(save_values, open(fn, 'wb'))
        except Exception, s:
            print 'Pickling failed: ', s
            return
    def pickle_save(self, fn, additional_vars={}):
        import cPickle as pickle

        if self.mouseJoint:
            self.MouseUp(self.mouseWorld)  # remove a mouse joint if it exists

        if not additional_vars and hasattr(self, "_pickle_vars"):
            additional_vars = dict((var, getattr(self, var)) for var in self._pickle_vars)

        save_values = [self.world, box2d.pickle_fix(self.world, additional_vars, "save")]

        try:
            pickle.dump(save_values, open(fn, "wb"))
        except Exception, s:
            print "Pickling failed: ", s
            return