Index: guiframe/custom_pstats.py
===================================================================
--- guiframe/custom_pstats.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
+++ guiframe/custom_pstats.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -0,0 +1,118 @@
+
+import cProfile, pstats, os
+def func_std_string(func_name): # match what old profile produced
+    if func_name[:2] == ('~', 0):
+        # special case for built-in functions
+        name = func_name[2]
+        if name.startswith('<') and name.endswith('>'):
+            return '{%s}' % name[1:-1]
+        else:
+            return name
+    else:
+        return "%s:%d(%s)" % func_name
+
+def f8(x):
+    return "%8.3f" % x
+
+class CustomPstats(pstats.Stats):
+    def __init__(self, *args, **kwds):
+        pstats.Stats.__init__(self, *args, **kwds)
+        
+    def write_stats(self, *amount):
+        msg = ''
+        for filename in self.files:
+            msg +=  str(filename) + '\n'
+        #if self.files: msg += str(self.stream) + '\n'
+        indent = ' ' * 8
+        for func in self.top_level:
+            msg +=   str(indent)+ str(func_get_function_name(func))+"\n"
+
+        msg += str(indent) + str(self.total_calls)+ "function calls" + '\n'
+        if self.total_calls != self.prim_calls:
+            msg +=  "(%d primitive calls)" % self.prim_calls + '\n'
+        msg +=  "in %.3f CPU seconds" % self.total_tt + '\n'
+        #msg +=  str(self.stream) + '\n'
+       
+        width = self.max_name_len
+        if self.fcn_list:
+            list = self.fcn_list[:]
+            temp_msg = "   Ordered by: " + self.sort_type + '\n'
+        else:
+            list = self.stats.keys()
+            temp_msg = "   Random listing order was used\n"
+
+        for selection in amount:
+            list, temp_msg = self.eval_print_amount(selection, list, temp_msg)
+
+        count = len(list)
+
+        if not list:
+            width, list = 0, list
+        else:
+            msg +=   str(temp_msg) + '\n'
+            if count < len(self.stats):
+                width = 0
+                for func in list:
+                    if  len(func_std_string(func)) > width:
+                        width = len(func_std_string(func))
+       
+            width, list = width+2, list
+        if list:
+            msg += '   ncalls  tottime  percall  cumtime  percall'
+            msg +=  ' filename:lineno(function)' + "\n"
+            for func in list:
+                cc, nc, tt, ct, callers = self.stats[func]
+                c = str(nc)
+                if nc != cc:
+                    c = c + '/' + str(cc)
+                msg +=  str( c.rjust(9)) 
+                msg +=  str(f8(tt)) 
+                if nc == 0:
+                    msg += str(' '*8) 
+                else:
+                    msg +=  str(f8(tt/nc)) 
+                msg += str(f8(ct)) 
+                if cc == 0:
+                    msg += str( ' '*80) 
+                else:
+                    msg += str(f8(ct/cc)) 
+                msg +=  " " + str(func_std_string(func)) + '\n'
+            msg += str(self.stream) + '\n'
+            #msg += str(self.stream) + '\n'
+        return self, msg
+            
+def profile( fn, name='profile.txt',*args, **kw):
+    import cProfile, pstats, os
+    global call_result
+    def call():
+        global call_result
+        call_result = fn(*args, **kw)
+    cProfile.runctx('call()', dict(call=call), {}, 'profile.txt')
+    stats = CustomPstats('profile.txt')
+    #sort by cumlative time
+    stats.sort_stats('time')
+    stats.print_stats(50)
+    """
+        filename = 'profile_cum_' + name
+        _, msg = stats.write_stats(50)
+        f = file(filename, 'wb')
+        f.write(msg)
+        f.close()
+        #sort by time
+        stats.sort_stats('time')
+        _, msg = stats.write_stats(50)
+        filename = 'profile_time_' + name
+        f = file(filename, 'wb')
+        f.write(msg)
+        f.close()
+        # sort by number of calls
+        stats.sort_stats('call')
+        _, msg = stats.write_stats(50)
+        filename = 'profile_call_' + name
+        f = file(filename, 'wb')
+        f.write(msg)
+        f.close()
+        os.unlink('profile.txt')
+    """
+    return call_result
+
Index: guiframe/data_manager.py
===================================================================
--- guiframe/data_manager.py	(revision 5c4b6743f7da312106d80c6bed8f5384071df146)
+++ guiframe/data_manager.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -17,4 +17,7 @@
 import logging
 import os
+import wx
+import copy 
+
 from sans.guiframe.data_state import DataState
 from sans.guiframe.utils import parse_name
@@ -23,5 +26,4 @@
 from sans.guiframe.dataFitting import Data2D
   
-import wx
 
 class DataManager(object):
@@ -42,4 +44,14 @@
         self.data_name_dict = {}
       
+    def __str__(self):
+        _str  = ""
+        _str += "No of states  is %s \n" % str(len(self.stored_data))
+        n_count = 0
+        for  value in self.stored_data.values():
+            n_count += 1 
+            _str += "State No %s \n"  % str(n_count)
+            _str += str(value) + "\n"
+        return _str
+        
     def create_gui_data(self, data, path=None):
         """
@@ -121,20 +133,21 @@
             else:
                 data_state = DataState(data)
+                data_state.id = wx.NewId()
                 self.stored_data[data.id] = data_state
             self._selected_data[data.id] = data_state
-      
-    def set_auto_plot(self, flag=False):
-        """
-        When flag is true the data is plotted automatically
-        """
-        self._auto_set_data = flag
-        
-    def set_auto_set_data(self, flag=False):
-        """
-        When flag is true the data is send to the current perspective
-        automatically
-        """
-        self._auto_set_data = flag
-        
+  
+        
+    def update_data(self, prev_data, new_data):
+        """
+        """
+        if prev_data.id not in self.stored_data.keys():
+            return {}
+        data_state = self.stored_data[prev_data.id] 
+        self.stored_data[new_data.id]  = data_state.clone()
+        self.stored_data[new_data.id].data = new_data
+        if prev_data.id in self.stored_data.keys():
+            del self.stored_data[prev_data.id] 
+        return prev_data.id, {new_data.id: self.stored_data[new_data.id]}
+    
     def get_message(self):
         """
@@ -153,18 +166,67 @@
         return self._selected_data
     
-    def append_theory(self, data_id, theory):
+    def append_theory(self, data_id, theory, state=None):
+        """
+        """
+        data_state = self.stored_data[data_id]
+        data_state.set_theory(theory_data=theory, 
+                              theory_state=state)
+        return {data_id: self.stored_data[data_id]}
+            
+    def freeze_theory(self, data_id, theory_id):
+        """
+        """
+        new_data_state = []
+        for d_id in data_id:
+            if d_id in self.stored_data:
+                data_state = self.stored_data[d_id]
+                theory_list = data_state.get_theory()
+                for t_id in theory_id:
+                    if t_id in theory_list.keys():
+                        theory = theory_list[t_id]
+                        new_theory = copy.deepcopy(theory)
+                        new_theory.id  = wx.NewId()
+                        data_state.append_theory(new_theory)
+                        theory_list.append(new_theory)
+                        new_data_state.append(data_state)
+                        msg = "Theory with ID %s " % str(theory_id)
+                        msg += "couldn't not be frozen" 
+                        raise ValueError, msg
+        return new_data_state
+                    
+            
+    def delete_data(self, data_id, theory_id=None, delete_all=False):
+        """
+        """
+        if data_id in self.stored_data.keys():
+            data_state = self.stored_data[data_id]
+            if data_state.data.name in self.data_name_dict:
+                del self.data_name_dict[data_state.data.name]
+            del self.stored_data[data_id]
+        if data_id in self._selected_data.keys():
+            data_state = self._selected_data[data_id]
+            if data_state.data.name in self.data_name_dict:
+                del self.data_name_dict[data_state.data.name]
+            del self._selected_data[data_id]
+        
+        self.delete_theory(self, data_id, theory_id)
+        if delete_all:
+            self._selected_data = {}
+            self.stored_data = {}
+            self.data_name_dict = {}
+            
+    def delete_theory(self, data_id, theory_id):
         """
         """
         if data_id in self.stored_data:
             data_state = self.stored_data[data_id]
-            data_state.set_theory(theory)
-            
-    def delete_data(self, data_id, theory_id, delete_all):
-        """
-        """
-        if data_id in self.stored_data:
-            del self.stored_data[data_id]
+            theory_list = data_state.get_theory()
+            if theory_id in theory_list.key():
+                del theory_list[theory_id]
         if data_id in self._selected_data:
-            del self._selected_data
+            data_state = self._selected_data[data_id]
+            theory_list = data_state.get_theory()
+            if theory_id in theory_list.key():
+                del theory_list[theory_id]
             
     def delete_by_id(self, id_list=None):
Index: guiframe/data_panel.py
===================================================================
--- guiframe/data_panel.py	(revision cc061c37128610b4318003ab4f78cccc3765de3c)
+++ guiframe/data_panel.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -59,6 +59,7 @@
         self.list_of_perspective = list_of_perspective
         self.list_rb_perspectives= []
-        self.list_cb_data =[]
-        self.list_cb_theory =[]
+        self.list_cb_data = {}
+        self.list_cb_theory = {}
+        
         self.owner = None
         self.do_layout()
@@ -181,5 +182,6 @@
         option = self.selection_cbox.GetString(pos)
         for item in self.list_cb_data:
-            data_id, data_class = self.tree_ctrl.GetItemPyData(item) 
+            data_ctrl, _, _ = item
+            data_id, data_class = self.tree_ctrl.GetItemPyData(dta_ctrl) 
             if option == 'Select all Data':
                 self.tree_ctrl.CheckItem(item, True) 
@@ -190,8 +192,8 @@
                     self.tree_ctrl.CheckItem(item, True) 
             elif option == 'Unselect all Data 1D':
-                if data_class in ['Data1D', 'Theory1D']:
+                if data_class == 'Data1D':
                     self.tree_ctrl.CheckItem(item, False) 
             elif option == 'Select all Data 1D':
-                if data_class == ['Data1D', 'Theory1D']:
+                if data_class == 'Data1D':
                     self.tree_ctrl.CheckItem(item, True) 
             elif option == 'Select all Data 2D':
@@ -223,4 +225,8 @@
         self.bt_plot.SetToolTipString("To trigger plotting")
         wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot)
+        
+        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze")
+        self.bt_freeze.SetToolTipString("To trigger freeze")
+        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze)
         
         self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data")
@@ -253,4 +259,8 @@
         ix = 0          
         iy += 1 
+        self.sizer3.Add(self.bt_freeze,( iy, ix),(1,1),  
+                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix = 0          
+        iy += 1 
         self.sizer3.Add(self.bt_remove,( iy, ix),(1,1),  
                              wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
@@ -317,90 +327,178 @@
         item = event.GetItem()
         name = self.tree_ctrl.GetItemText(item)
-  
+    
     def load_data_list(self, list):
         """
-        
+        add need data with its theory under the tree
         """
         if not list:
             return
         
-        for dstate in list.values():
+        for state_id, dstate in list.iteritems():
             data = dstate.get_data()
             if data is None:
-                data_name = str(data)
-                data_class = "unkonwn"
+                data_name = "Unkonwn"
+                data_class = "Unkonwn"
+                path = "Unkonwn"
+                process_list = []
+                data_id = "Unkonwn"
             else:
                 data_name = data.name
-            data_class = data.__class__.__name__
-            path = dstate.get_path() 
+                data_class = data.__class__.__name__
+                path = dstate.get_path() 
+                process_list = data.process
+                data_id = data.id
             theory_list = dstate.get_theory()
-            data_child = None
+            if state_id not in self.list_cb_data:
+                #new state
+                data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0,
+                                                   data_name, ct_type=1, 
+                                     data=(data_id, data_class, state_id))
+                data_c.Check(True)
+                d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
+                i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
+                                              'Type: %s' % data_class)
+                p_c_c = self.tree_ctrl.AppendItem(d_i_c,
+                                              'Path: %s' % str(path))
+                d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
+                
+                for process in process_list:
+                    i_t_c = self.tree_ctrl.AppendItem(d_p_c,
+                                                      process.__str__())
+                theory_child = self.tree_ctrl.AppendItem(data_c, "THEORIES")
+               
+                self.list_cb_data[state_id] = [data_c, 
+                                               d_i_c,
+                                               i_c_c,
+                                                p_c_c,
+                                                 d_p_c,
+                                                 theory_child]
+            else:
+                data_ctrl_list =  self.list_cb_data[state_id]
+                #This state is already display replace it contains
+                data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = data_ctrl_list
+                self.tree_ctrl.SetItemText(data_c, data_name) 
+                temp = (data_id, data_class, state_id)
+                self.tree_ctrl.SetItemPyData(data_c, temp) 
+                self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % data_class)
+                self.tree_ctrl.SetItemText(p_c_c, 'Path: %s' % str(path)) 
+                self.tree_ctrl.DeleteChildren(d_p_c) 
+                for process in process_list:
+                    i_t_c = self.tree_ctrl.AppendItem(d_p_c,
+                                                      process.__str__())
+            self.append_theory(state_id, theory_list)
+                  
+   
+    def append_theory(self, state_id, theory_list):
+        """
+        append theory object under data from a state of id = state_id
+        replace that theory if  already displayed
+        """
+        if not theory_list:
+            return 
+        if state_id not in self.list_cb_data.keys():
+            msg = "Invalid state ID : %s requested for theory" % str(state_id)
+            raise ValueError, msg
             
-            if theory_list:
-                for theory_id,theory in theory_list.iteritems():
-                    for item in self.list_cb_data:
-                        data_id, data_class = self.tree_ctrl.GetItemPyData(item) 
-                        if data_id == data.id:
-                            data_child = item
-                            for process in data.process:
-                                theory_child = self.tree_ctrl.FindItem(data_child,
-                                                                "CREATED DATA"),
-                                if theory is not None:
-                                    av_theory_child =self.tree_ctrl.AppendItem(theory_child,
-                                            theory.name,ct_type=1, 
-                                            data=(theory_id, theory))
-                                    self.list_cb_theory.append(av_theory_child)
-                                    av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child,
-                                                             'info')
-                                    for process in theory.process:
-                                        info_time_child = self.tree_ctrl.AppendItem(av_theory_child_info,
-                                                 process.__str__())
-                           
-                        break
-            if data_child is None:
-                data_child = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0,
-                                            data_name, ct_type=1, 
-                                            data=(data.id, data_class))
-                cb_data = self.tree_ctrl.GetFirstChild(self.tree_ctrl.root) 
-                item, id = cb_data
-                item.Check(True)
-                self.list_cb_data.append(item)                         
-                data_info_child =self.tree_ctrl.AppendItem(data_child, 'info')#,
-                                                            #wnd=data_info_txt)
-                info_class_child =self.tree_ctrl.AppendItem(data_info_child, 
-                                                            'Type: %s'%data_class)
-                path_class_child =self.tree_ctrl.AppendItem(data_info_child,
-                                                             'Path: %s'%str(path))
-                for process in data.process:
-                    info_time_child =self.tree_ctrl.AppendItem(data_info_child,process.__str__())
-                theory_child =self.tree_ctrl.AppendItem(data_child, "Available Theories")
-                
-                if  theory_list:
-                    theory = theory_list[len(theory_list)-1]
-                    if theory is not None:
-                        av_theory_child =self.tree_ctrl.AppendItem(theory_child,
-                                                    theory.name,ct_type=1)
-                        self.list_cb_theory.append(av_theory_child)
-                        av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child,
-                                                         'info')
-                        for process in theory.process:
-                            info_time_child =self.tree_ctrl.AppendItem(av_theory_child_info,
-                                             process.__str__())
-                   
+        item = self.list_cb_data[state_id]
+        data_c, _, _, _, _, theory_child = item
+        data_id, _, _ = self.tree_ctrl.GetItemPyData(data_c) 
+        
+        if data_id in self.list_cb_theory.keys():
+            #update current list of theory for this data
+            theory_list_ctrl = self.list_cb_theory[data_id]
+
+            for theory_id, item in theory_list.iteritems():
+                theory_data, _ = item
+                if theory_data is None:
+                    name = "Unknown"
+                    theory_class = "Unknown"
+                    theory_id = "Unknown"
+                    temp = (None, None, None)
+                else:
+                    name = theory_data.name
+                    theory_class = theory_data.__class__.__name__
+                    theory_id = theory_data.id
+                    temp = (theory_id, theory_class, state_id)
+                if theory_id not in theory_list_ctrl:
+                    #add new theory
+                    t_child = self.tree_ctrl.AppendItem(theory_child,
+                                                    name, ct_type=1, data=temp)
+                    t_i_c = self.tree_ctrl.AppendItem(t_child, 'Info')
+                    i_c_c = self.tree_ctrl.AppendItem(t_i_c, 
+                                                  'Type: %s' % theory_class)
+                    t_p_c = self.tree_ctrl.AppendItem(t_i_c, 'Process')
+                    
+                    for process in theory_data.process:
+                        i_t_c = self.tree_ctrl.AppendItem(t_p_c,
+                                                          process.__str__())
+                    theory_list_ctrl[theory_id] = [t_child, 
+                                                   i_c_c, 
+                                                   t_p_c]
+                else:
+                    #replace theory
+                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
+                    self.tree_ctrl.SetItemText(t_child, name) 
+                    self.tree_ctrl.SetItemPyData(t_child, temp) 
+                    self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % theory_class) 
+                    self.tree_ctrl.DeleteChildren(t_p_c) 
+                    for process in theory_data.process:
+                        i_t_c = self.tree_ctrl.AppendItem(t_p_c,
+                                                          process.__str__())
+              
+        else:
+            #data didn't have a theory associated it before
+            theory_list_ctrl = {}
+            for theory_id, item in theory_list.iteritems():
+                theory_data, _ = item
+                if theory_data is not None:
+                    theory_class = theory_data.__class__.__name__
+                    
+                    t_child = self.tree_ctrl.AppendItem(theory_child,
+                            theory_data.name, ct_type=1, 
+                            data=(theory_data.id, theory_class, state_id))
+                    t_i_c = self.tree_ctrl.AppendItem(t_child, 'Info')
+                    i_c_c = self.tree_ctrl.AppendItem(t_i_c, 
+                                                  'Type: %s' % theory_class)
+                    t_p_c = self.tree_ctrl.AppendItem(t_i_c, 'Process')
+                    
+                    for process in theory_data.process:
+                        i_t_c = self.tree_ctrl.AppendItem(t_p_c,
+                                                          process.__str__())
+            
+                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
+            self.list_cb_theory[data_id] = theory_list_ctrl
+            
+    
     def set_data_helper(self):
         """
         """
         data_to_plot = []
-        for item in self.list_cb_data:
+        for value in self.list_cb_data.values():
+            item, _, _, _, _, _ = value
             if item.IsChecked():
-               data_id, data_class = self.tree_ctrl.GetItemPyData(item) 
+               data_id, _, _ = self.tree_ctrl.GetItemPyData(item) 
                data_to_plot.append(data_id)
         theory_to_plot = []
-        for item in self.list_cb_theory:
-            if item.IsChecked():
-                data_id, data_class = self.tree_ctrl.GetItemPyData(item)
-                theory_to_plot.append(data_id)
+        for theory_dict in self.list_cb_theory.values():
+            for key, value in theory_dict.iteritems():
+                item, _, _ = value
+                if item.IsChecked():
+                    theory_id, _, _ = self.tree_ctrl.GetItemPyData(item)
+                    theory_to_plot.append(theory_id)
         return data_to_plot, theory_to_plot
     
+    def remove_by_id(self, id):
+        """
+        """
+        for item in self.list_cb_data.values():
+            data_c, _, _, _, _, theory_child = item
+            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
+            if id == data_id:
+                self.tree_ctrl.Delete(data_c)
+                del self.list_cb_data[state_id]
+                del self.list_cb_theory[data_id]
+                print "went here"
+      
     def on_remove(self, event):
         """
@@ -441,4 +539,10 @@
         self.post_helper(plot=True)
        
+    def on_freeze(self, event):
+        """
+        """
+        data_to_plot, theory_to_plot = self.set_data_helper()
+        self.parent.freeze(data_id=data_to_plot, theory_id=theory_to_plot)
+        
     def set_active_perspective(self, name):
         """
@@ -457,8 +561,9 @@
         """
         data_to_plot, theory_to_plot = self.set_data_helper()
-      
         if self.parent is not None:
             self.parent.get_data_from_panel(data_id=data_to_plot, plot=plot,
                                             append=append)
+            
+    
 
 
@@ -495,4 +600,6 @@
         """
         self.panel.layout_perspective(list_of_perspective=list_of_perspective)
+    
+    
         
     
@@ -512,6 +619,6 @@
     dstate = DataState(data=data)
     dstate.set_path(path=path)
-    dstate.set_theory(theory)
-    dstate.set_state(state)
+    dstate.set_theory(theory, state)
+  
     return dstate
 """'
@@ -528,17 +635,18 @@
         list_of_perspective = [('perspective2', False), ('perspective1', True)]
         data_list = {}
+        # state 1
         data = Data1D()
         data.name = "data1"
         data.id = 1
-        #data.append_process()
-        #process = data.process[len(data.process)-1]
-        #process.data = "07/01/2010"
+        data.append_empty_process()
+        process = data.process[len(data.process)-1]
+        process.data = "07/01/2010"
         theory = Theory1D()
         theory.id = 34
-        theory.pseudo_name = "theory1"
+        theory.name = "theory1"
         path = "path1"
         state = State()
         data_list['1']=set_data_state(data, path,theory, state)
-        
+        #state 2
         data = Data1D()
         data.name = "data2"
@@ -547,6 +655,6 @@
         theory.id = 78
         theory.name = "CoreShell 07/24/25"
-        theory.pseudo_name = "CoreShell"
         path = "path2"
+        #state3
         state = State()
         data_list['2']=set_data_state(data, path,theory, state)
@@ -556,23 +664,26 @@
         theory = Theory1D()
         theory.name = "CoreShell"
-        theory.pseudo_name = "CoreShell"
         theory.id = 4
-        #theory.append_process()
-        #process = theory.process[len(theory.process)-1]
-        #process.description = "this is my description"
+        theory.append_empty_process()
+        process = theory.process[len(theory.process)-1]
+        process.description = "this is my description"
         path = "path3"
-        #data.append_process()
-        #process = data.process[len(data.process)-1]
-        #process.data = "07/22/2010"
+        data.append_empty_process()
+        process = data.process[len(data.process)-1]
+        process.data = "07/22/2010"
         data_list['4']=set_data_state(data, path,theory, state)
-        
+        #state 4
+        temp_data_list = {}
+        data.name = "data5 erasing data2"
+        temp_data_list['4'] = set_data_state(data, path,theory, state)
+        #state 5
         data = Data2D()
         data.name = "data3"
         data.id = 5
-        #data.append_process()
-        #process = data.process[len(data.process)-1]
-        #process.data = "07/01/2010"
+        data.append_empty_process()
+        process = data.process[len(data.process)-1]
+        process.data = "07/01/2010"
         theory = Theory1D()
-        theory.pseudo_name = "Cylinder"
+        theory.name = "Cylinder"
         path = "path2"
         state = State()
@@ -580,15 +691,23 @@
         theory = Theory1D()
         theory.id = 6
-        theory.pseudo_name = "Sphere"
+        theory.name = "CoreShell"
         dstate.set_theory(theory)
-        data_list['3']=dstate
+        theory = Theory1D()
+        theory.id = 6
+        theory.name = "CoreShell replacing coreshell in data3"
+        dstate.set_theory(theory)
+        data_list['3'] = dstate
+        #state 6
+        data_list['6']=set_data_state(None, path,theory, state)
         
         window = DataFrame(list=data_list)
-        #window.load_data_list(list=data_list)
-        window.layout_perspective(list_of_perspective=list_of_perspective)
+        window.load_data_list(list=data_list)
+        #window.layout_perspective(list_of_perspective=list_of_perspective)
         window.Show(True)
+        window.load_data_list(list=temp_data_list)
     except:
         #raise
         print "error",sys.exc_value
+        
     app.MainLoop()  
     
Index: guiframe/data_state.py
===================================================================
--- guiframe/data_state.py	(revision 5c4b6743f7da312106d80c6bed8f5384071df146)
+++ guiframe/data_state.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -10,4 +10,6 @@
 """
 """
+import copy
+
 
 class DataState(object):
@@ -24,11 +26,52 @@
         self.path = None
         self.theory_list = {}
-        self.state_list = []
         self.message = ""
+        self.id = None
+        
+    def __str__(self):
+        _str  = ""
+        _str += "State with ID : %s \n" % str(self.id)
+        if self.data is not None:
+            _str += "Data name : %s \n" % str(self.data.name)
+            _str += "Data ID : %s \n" % str(self.data.id)
+        else:
+            _str += "Data: %s \n" % str(self.data)
+            
+        if self.theory_list:
+            _str += "Theories available: \n"
+            for id, item in self.theory_list.iteritems():
+                theory_data, theory_state = item
+                _str += "Theory name : %s \n" % str(theory_data.name)
+                _str += "Theory ID : %s \n" % str(id)
+        else:
+            for key , value in self.theory_list.iteritems():
+                theory_data, theory_state = value
+                _str += "Theory with ID : %s \n" % str(key)
+                _str += str(theory_data)
+                _str += str(theory_state)
+        return _str
+        
+    def clone(self):
+        obj = DataState(copy.deepcopy(self.data))
+        obj.parent = self.parent
+        obj.name = self.name 
+        obj.path = self.path 
+        obj.message = self.message
+        obj.id = self.id
+        for id, item in self.theory_list.iteritems():
+            theory_data, theory_state = item
+            state = None
+            if theory_state is not None:
+                state = theory_state.clone()
+            obj.theory_list[id] = [copy.deepcopy(theory_data), 
+                                   state]
+        return obj
         
     def set_name(self, name):
         self.name = name
+        
     def get_name(self):
         return self.name
+    
     def set_data(self, data):
         self.data = data
@@ -49,20 +92,11 @@
         return self.path
     
-    def set_theory(self, theory):
+    def set_theory(self, theory_data, theory_state=None):
         """
         """
-        self.theory_list[theory.id] = theory
+        self.theory_list[theory_data.id] = [theory_data, theory_state]
         
     def get_theory(self):
         return self.theory_list
-    
-    def set_state(self, state):
-        """
-        """
-        #self.theory_list.append(state)
-        return
-        
-    def get_state(self):
-        return self.state_list
     
     def get_message(self):
Index: guiframe/gui_manager.py
===================================================================
--- guiframe/gui_manager.py	(revision 9c169f4aa9d072ed72a3a963dca050225c148bba)
+++ guiframe/gui_manager.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -431,4 +431,40 @@
                                   Hide())        
       
+    def append_theory(self, data_id, theory, state=None):
+        """
+        """
+        data_state = self._data_manager.append_theory(data_id=data_id, 
+                                                      theory=theory,
+                                                      state=state)
+        self._data_panel.load_data_list(data_state)
+        
+    def update_data(self, prev_data, new_data):
+        """
+        """
+        prev_id, data_state = self._data_manager.update_data(prev_data=prev_data, 
+                                       new_data=new_data)
+        self._data_panel.remove_by_id(prev_id)
+        self._data_panel.load_data_list(data_state)
+       
+        
+    def freeze(self, data_id, theory_id):
+        """
+        """
+        data_state_list = self._data_manager.freeze_theory(data_id=data_id, 
+                                                theory_id=theory_id)
+        
+        self._data_panel.load_data_list(list=data_state_list)
+        for data_state in data_state_list:
+            theory_list = data_state.get_theory()
+            for new_plot in theory_list:
+                wx.PostEvent(self, NewplotEvent(plot=new_plot,
+                                             title=new_plot.title))
+        
+    def delete_data(self, data):
+        """
+        """
+        self._current_perspective.delete_data(data)
+        
+    
     def get_context_menu(self, plotpanel=None):
         """
@@ -1207,5 +1243,10 @@
             self.__gui_style = self.__gui_style & (~GUIFRAME.MANAGER_ON)
             self._data_panel_menu.SetText('Data Explorer ON')
- 
+    
+    def add_data_helper(self, data_list):
+        """
+        """
+        self._data_manager.add_data(data_list)
+        
     def add_data(self, data_list):
         """
@@ -1215,12 +1256,8 @@
         #send a list of available data to plotting plugin
         avalaible_data = []
+        theory_list = []
         if self._data_manager is not None:
             self._data_manager.add_data(data_list)
             avalaible_data = self._data_manager.get_all_data()
-        
-        # set data in the data panel
-        if self._data_panel is not None:
-            data_state = self._data_manager.get_selected_data()
-            self._data_panel.load_data_list(data_state)
         style = self.__gui_style & GUIFRAME.MANAGER_ON
         if style == GUIFRAME.MANAGER_ON:
@@ -1232,5 +1269,10 @@
             #automatically send that to the current perspective
             self.set_data(data_list)
-                
+       
+         # set data in the data panel
+        if self._data_panel is not None:
+            data_state = self._data_manager.get_selected_data()
+            self._data_panel.load_data_list(data_state)
+           
     def get_data_from_panel(self, data_id, plot=False,append=False):
         """
@@ -1290,13 +1332,5 @@
                                                   title=str(new_plot.title)))
             
-    def add_theory(self, data_id, theory):
-        """
-        """
-        self._data_manager.append_theory(data_id, theory)
-        style = self.__gui_style & GUIFRAME.MANAGER_ON
-        if style == GUIFRAME.MANAGER_ON:
-            if self._data_panel is not None:
-                data_state = self._data_manager.get_by_id([data_id])
-                self._data_panel.load_data_list(data_state)
+  
                 
     def remove_data(self, data_id, theory_id=None, delete_all=True):
Index: guiframe/local_perspectives/plotting/plotting.py
===================================================================
--- guiframe/local_perspectives/plotting/plotting.py	(revision 5c4b6743f7da312106d80c6bed8f5384071df146)
+++ guiframe/local_perspectives/plotting/plotting.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -76,7 +76,5 @@
         pass
     
-    #def _on_plot_event(self, event):
-    #     return profile(self.tested_on_plot_event, event)
-    
+  
     def _on_plot_event(self, event):
         """
@@ -165,18 +163,3 @@
             
         return
-
-def profile(fn, *args, **kw):
-    import cProfile, pstats, os
-    global call_result
-    def call():
-        global call_result
-        call_result = fn(*args, **kw)
-    cProfile.runctx('call()', dict(call=call), {}, 'profile.txt')
-    stats = pstats.Stats('profile.txt')
-    stats.sort_stats('time')
-    #stats.sort_stats('calls')
-    stats.print_stats()
-    #os.unlink('profile.out')
-    return call_result
-
    
Index: guiframe/panel_base.py
===================================================================
--- guiframe/panel_base.py	(revision 03314e7471e80689c0f7229fc1a95f0856155e0d)
+++ guiframe/panel_base.py	(revision c70eb7c2e177e54344c3d95752ddc8b7bccc0f1c)
@@ -46,4 +46,5 @@
         self._reset_flag = False
         self._has_changed = False
+        self.group_id = None
         
         self.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus)
