Example #1
0
 def __set_pure_state__(self, state):
     # Create and set the filter.
     children = [f for f in [self.filter] if f is not None]
     handle_children_state(children, [state.filter])
     self.filter = children[0]
     # Restore our state.
     super(Wrapper, self).__set_pure_state__(state)
Example #2
0
 def __set_pure_state__(self, state):
     # Do everything but our kids.
     set_state(self, state, ignore=['children'])
     # Setup children.
     handle_children_state(self.children, state.children)
     # Now setup the children.
     set_state(self, state, first=['children'], ignore=['*'])
Example #3
0
    def __set_pure_state__(self, state):
        # If we are already running, there is a problem since the
        # components will be started automatically in the module's
        # handle_components even though their state is not yet set call
        # so we disable it here and restart it later.
        running = self.running
        self.running = False

        # Remove the actor states since we don't want these unpickled.
        actor_st = state.pop('actor', None)
        contour_st = state.pop('contour', None)
        # Create and set the components.
        handle_children_state(self.components, state.components)
        components = self.components

        # Restore our state using set_state.
        state_pickler.set_state(self, state)

        # Now set our actor and component by finding the right one to get from
        # the state.
        if actor_st is not None:
            for cst, c in zip(state.components, components):
                actor = find_object_given_state(actor_st, cst, c)
                if actor is not None:
                    self.actor = actor
                    break
        if contour_st is not None:
            for cst, c in zip(state.components, components):
                contour = find_object_given_state(contour_st, cst, c)
                if contour is not None:
                    self.contour = contour
                    break
        # Now start all components if needed.
        self._start_components()
        self.running = running
Example #4
0
    def __set_pure_state__(self, state):
        # If we are already running, there is a problem since the
        # components will be started automatically in the module's
        # handle_components even though their state is not yet set call
        # so we disable it here and restart it later.
        running = self.running
        self.running = False

        # Remove the actor states since we don't want these unpickled.
        actor_st = state.pop('actor', None)
        contour_st = state.pop('contour', None)
        # Create and set the components.
        handle_children_state(self.components, state.components)
        components = self.components

        # Restore our state using set_state.
        state_pickler.set_state(self, state)

        # Now set our actor and component by finding the right one to get from
        # the state.
        if actor_st is not None:
            for cst, c in zip(state.components, components):
                actor = find_object_given_state(actor_st, cst, c)
                if actor is not None:
                    self.actor = actor
                    break
        if contour_st is not None:
            for cst, c in zip(state.components, components):
                contour = find_object_given_state(contour_st, cst, c)
                if contour is not None:
                    self.contour = contour
                    break
        # Now start all components if needed.
        self._start_components()
        self.running = running
Example #5
0
 def __set_pure_state__(self, state):
     # Do everything but our kids.
     set_state(self, state, ignore=['children'])
     # Setup children.
     handle_children_state(self.children, state.children)
     # Now setup the children.
     set_state(self, state, first=['children'], ignore=['*'])
     self.update()
Example #6
0
 def __set_pure_state__(self, state):
     # Create and set the filter.
     children = [f for f in [self.filter] if f is not None]
     handle_children_state(children, [state.filter])
     self.filter = children[0]
     self.update_pipeline()
     # Restore our state.
     super(UserDefined, self).__set_pure_state__(state)
Example #7
0
 def __set_pure_state__(self, state):
     # Use the saved path to initialize the file_list and timestep.
     fname = state.file_path.abs_pth
     if not isfile(fname):
         msg = 'Could not find file at %s\n'%fname
         msg += 'Please move the file there and try again.'
         raise IOError, msg
     
     self.initialize(fname)
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'file_path'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Example #8
0
    def __set_pure_state__(self, state):
        # Use the saved path to initialize the file_list and timestep.
        fname = state.file_path.abs_pth
        if not isfile(fname):
            msg = 'Could not find file at %s\n' % fname
            msg += 'Please move the file there and try again.'
            raise IOError, msg

        self.initialize(fname)
        # Now set the remaining state without touching the children.
        set_state(self, state, ignore=['children', 'file_path'])
        # Setup the children.
        handle_children_state(self.children, state.children)
        # Setup the children's state.
        set_state(self, state, first=['children'], ignore=['*'])
Example #9
0
 def __set_pure_state__(self, state):
     z = state.data
     if z is not None:
         d = gunzip_string(z)
         r = tvtk.DataSetReader(read_from_input_string=1, input_string=d)
         warn = r.global_warning_display
         r.global_warning_display = 0
         r.update()
         r.global_warning_display = warn
         self.data = r.output
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'data'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Example #10
0
 def __set_pure_state__(self, state):
     z = state.data
     if z is not None:
         d = gunzip_string(z)
         r = tvtk.DataSetReader(read_from_input_string=1,
                                input_string=d)
         warn = r.global_warning_display
         r.global_warning_display = 0
         r.update()
         r.global_warning_display = warn
         self.data = r.output
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'data'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Example #11
0
    def __set_pure_state__(self):
        # The reader has its own file_name which needs to be fixed.
        state.reader.file_name = state._file_path.abs_path
        # Now call the parent class to setup everything.
        # Use the saved path to initialize the file_list and timestep.
        fname = state._file_path.abs_pth
        if not isfile(fname):
            msg = 'Could not find file at %s\n' % fname
            msg += 'Please move the file there and try again.'
            raise IOError, msg

        self.initialize(fname)
        # Now set the remaining state without touching the children.
        set_state(self, state, ignore=['children', '_file_path'])
        # Setup the children
        handle_children_state(self.children, state.children)
        # Setup the children's state.
        set_state(self, state, first=['children'], ignore=['*'])
Example #12
0
 def __set_pure_state__(self, state):
     xyz_fn = state.xyz_file_path.abs_pth
     q_fn = state.q_file_path.abs_pth
     if not isfile(xyz_fn):
         msg = 'Could not find file at %s\n'%xyz_fn
         msg += 'Please move the file there and try again.'
         raise IOError, msg
     
     # Setup the reader state.
     set_state(self, state, first=['reader'], ignore=['*'])
     # Initialize the files.
     self.initialize(xyz_fn, q_fn, configure=False)
     # Now set the remaining state without touching the children.
     set_state(self, state, ignore=['children', 'xyz_file_path', 'q_file_path'])
     # Setup the children.
     handle_children_state(self.children, state.children)
     # Setup the children's state.
     set_state(self, state, first=['children'], ignore=['*'])
Example #13
0
    def __set_pure_state__(self, state):
        z = state.data
        if z:
            d = gunzip_string(z)
            m = re.search('(?<=Filename:)\w+', header)
            file_name = m.group(0)
            m = re.search('(?<=NX:)\w+', d)
            self.nx_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.ny_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.nz_redu = int(m.group(0))

            if not isfile(file_name):
                msg = 'Could not find file at %s\n' % file_name
                msg += 'Please move the file there and try again.'
                raise IOError, msg

            (step, modelname, metafilepath, filepath) = parsemodel(file_name)
            file_name = metafilepath

            self.filename = file_name

            #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
            f = tables.openFile(file_name, 'r')
            self.nx = int(f.root.input._v_attrs.nodex)
            self.ny = int(f.root.input._v_attrs.nodey)
            self.nz = int(f.root.input._v_attrs.nodez)

            #self.timesteps = int(f.root.time.nrows)

            f.close()
            self.data = self.citcomshdftougrid.initialize(
                self.filename, self.current_timestep, self.nx_redu,
                self.ny_redu, self.nz_redu)
            self.data_changed = True
            self._update_data()
            # Now set the remaining state without touching the children.
            set_state(self, state, ignore=['children', '_file_path'])
            # Setup the children.
            handle_children_state(self.children, state.children)
            # Setup the children's state.
            set_state(self, state, first=['children'], ignore=['*'])
Example #14
0
 def __set_pure_state__(self, state):
     self._unpickling = True
     # First create all the allowed widgets in the widget_list attr.
     handle_children_state(self.widget_list, state.widget_list)
     # Now set their state.
     set_state(self, state, first=['widget_list'], ignore=['*'])
     # Set the widget attr depending on value saved.
     m = [x.__class__.__name__ for x in self.widget_list]
     w_c_name = state.widget.__metadata__['class_name']
     w = self.widget = self.widget_list[m.index(w_c_name)]
     # Set the input.
     if len(self.inputs) > 0:
         w.input = self.inputs[0].outputs[0]
     # Fix for the point widget.
     if w_c_name == 'PointWidget':
         w.place_widget()
     # Set state of rest of the attributes ignoring the widget_list.
     set_state(self, state, ignore=['widget_list'])
     # Some widgets need some cajoling to get their setup right.
     w.update_traits()
     if w_c_name == 'PlaneWidget':
         w.origin = state.widget.origin
         w.normal = state.widget.normal
         w.update_placement()
         w.get_poly_data(self.poly_data)
     elif w_c_name == 'SphereWidget':
         # XXX: This hack is necessary because the sphere widget
         # does not update its poly data even when its ivars are
         # set (plus it does not have an update_placement method
         # which is a bug).  So we force this by creating a similar
         # sphere source and copy its output.
         s = tvtk.SphereSource(center=w.center,
                               radius=w.radius,
                               theta_resolution=w.theta_resolution,
                               phi_resolution=w.phi_resolution,
                               lat_long_tessellation=True)
         s.update()
         self.poly_data.shallow_copy(s.output)
     else:
         w.get_poly_data(self.poly_data)
     self._unpickling = False
     # Set the widgets trait so that the widget is rendered if needed.
     self.widgets = [w]
Example #15
0
 def __set_pure_state__(self, state):
     self._unpickling = True
     # First create all the allowed widgets in the widget_list attr.
     handle_children_state(self.widget_list, state.widget_list)
     # Now set their state.
     set_state(self, state, first=['widget_list'], ignore=['*'])
     # Set the widget attr depending on value saved.
     m = [x.__class__.__name__ for x in self.widget_list]
     w_c_name = state.widget.__metadata__['class_name']
     w = self.widget = self.widget_list[m.index(w_c_name)]
     # Set the input.
     if len(self.inputs) > 0:
         w.input = self.inputs[0].outputs[0]
     # Fix for the point widget.
     if w_c_name == 'PointWidget':
         w.place_widget()
     # Set state of rest of the attributes ignoring the widget_list.
     set_state(self, state, ignore=['widget_list'])
     # Some widgets need some cajoling to get their setup right.
     w.update_traits()
     if w_c_name == 'PlaneWidget':
         w.origin = state.widget.origin
         w.normal = state.widget.normal
         w.update_placement()
         w.get_poly_data(self.poly_data)
     elif w_c_name == 'SphereWidget':
         # XXX: This hack is necessary because the sphere widget
         # does not update its poly data even when its ivars are
         # set (plus it does not have an update_placement method
         # which is a bug).  So we force this by creating a similar
         # sphere source and copy its output.
         s = tvtk.SphereSource(center=w.center, radius=w.radius,
                               theta_resolution=w.theta_resolution,
                               phi_resolution=w.phi_resolution,
                               lat_long_tessellation=True)
         s.update()
         self.poly_data.shallow_copy(s.output)
     else:
         w.get_poly_data(self.poly_data)
     self._unpickling = False
     # Set the widgets trait so that the widget is rendered if needed.
     self.widgets = [w]
Example #16
0
    def __set_pure_state__(self, state):
        xyz_fn = state.xyz_file_path.abs_pth
        q_fn = state.q_file_path.abs_pth
        if not isfile(xyz_fn):
            msg = 'Could not find file at %s\n' % xyz_fn
            msg += 'Please move the file there and try again.'
            raise IOError, msg

        # Setup the reader state.
        set_state(self, state, first=['reader'], ignore=['*'])
        # Initialize the files.
        self.initialize(xyz_fn, q_fn, configure=False)
        # Now set the remaining state without touching the children.
        set_state(self,
                  state,
                  ignore=['children', 'xyz_file_path', 'q_file_path'])
        # Setup the children.
        handle_children_state(self.children, state.children)
        # Setup the children's state.
        set_state(self, state, first=['children'], ignore=['*'])
    def __set_pure_state__(self, state):
        z = state.data
        if z:
            d = gunzip_string(z)
            m = re.search('(?<=Filename:)\w+', header)
            file_name = m.group(0)
            m = re.search('(?<=NX:)\w+', d)
            self.nx_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.ny_redu = int(m.group(0))
            m = re.search('(?<=NX:)\w+', d)
            self.nz_redu = int(m.group(0))
        
            if not isfile(file_name):
                msg = 'Could not find file at %s\n'%file_name
                msg += 'Please move the file there and try again.'
                raise IOError, msg
            
            (step, modelname, metafilepath, filepath) = parsemodel(file_name)
            file_name = metafilepath
            
            self.filename = file_name
        
            #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
            f = tables.openFile(file_name,'r')
            self.nx = int(f.root.input._v_attrs.nodex)
            self.ny = int(f.root.input._v_attrs.nodey)
            self.nz = int(f.root.input._v_attrs.nodez)
        
            #self.timesteps = int(f.root.time.nrows)

            f.close()
            self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
            self.data_changed = True
            self._update_data()
            # Now set the remaining state without touching the children.
            set_state(self, state, ignore=['children', '_file_path'])
            # Setup the children.
            handle_children_state(self.children, state.children)
            # Setup the children's state.
            set_state(self, state, first=['children'], ignore=['*'])
Example #18
0
 def __set_pure_state__(self, state):
     if 'glyph_dict' in state:
         # Set their state.
         set_state(self, state, first=['glyph_dict'], ignore=['*'])
         ignore = ['glyph_dict']
     else:
         # Set the dict state using the persisted list.
         gd = self.glyph_dict
         gl = self.glyph_list
         handle_children_state(gl, state.glyph_list)
         for g, gs in zip(gl, state.glyph_list):
             name = camel2enthought(g.__class__.__name__)
             if name not in gd:
                 gd[name] = g
             # Set the glyph source's state.
             set_state(g, gs)
         ignore = ['glyph_list']
     g_name = state.glyph_source.__metadata__['class_name']
     name = camel2enthought(g_name)
     # Set the correct glyph_source.
     self.glyph_source = self.glyph_dict[name]
     set_state(self, state, ignore=ignore)
Example #19
0
 def __set_pure_state__(self, state):
     if 'glyph_dict' in state:
         # Set their state.
         set_state(self, state, first=['glyph_dict'], ignore=['*'])
         ignore = ['glyph_dict']
     else:
         # Set the dict state using the persisted list.
         gd = self.glyph_dict
         gl = self.glyph_list
         handle_children_state(gl, state.glyph_list)
         for g, gs in zip(gl, state.glyph_list):
             name = camel2enthought(g.__class__.__name__)
             if name not in gd:
                 gd[name] = g
             # Set the glyph source's state.
             set_state(g, gs)
         ignore = ['glyph_list']
     g_name = state.glyph_source.__metadata__['class_name']
     name = camel2enthought(g_name)
     # Set the correct glyph_source.
     self.glyph_source = self.glyph_dict[name]
     set_state(self, state, ignore=ignore)
Example #20
0
 def __set_pure_state__(self, state):
     handle_children_state(self.children, state.children)
     # Now set our complete state.  Doing the scene last ensures
     # that the camera view is set right.
     set_state(self, state, last=["scene"])
Example #21
0
 def __set_pure_state__(self, state):
     handle_children_state(self.children, state.children)
     # Now set our complete state.  Doing the scene last ensures
     # that the camera view is set right.
     set_state(self, state, last=['scene'])
Example #22
0
 def __set_pure_state__(self, state):
     handle_children_state(self.components, state.components)
     state_pickler.set_state(self, state)
     self.update_pipeline()
Example #23
0
 def __set_pure_state__(self, state):
     # Create and set the filters.
     handle_children_state(self.filters, state.filters)
     # Restore our state using the super class method.
     super(Collection, self).__set_pure_state__(state)
Example #24
0
 def __set_pure_state__(self, state):
     handle_children_state(self.components, state.components)
     state_pickler.set_state(self, state)
     self.update_pipeline()
Example #25
0
 def __set_pure_state__(self, state):
     # Create and set the filters.
     handle_children_state(self.filters, state.filters)
     # Restore our state using the super class method.
     super(Collection, self).__set_pure_state__(state)