source: sasview/guiframe/data_manager.py @ 8cd029b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 8cd029b was 75fbd17, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on save state

  • Property mode set to 100644
File size: 5.1 KB
Line 
1################################################################################
2#This software was developed by the University of Tennessee as part of the
3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4#project funded by the US National Science Foundation.
5#
6#See the license text in license.txt
7#
8#copyright 2010, University of Tennessee
9################################################################################
10"""
11This module manages all data loaded into the application. Data_manager makes
12available all data loaded  for the current perspective.
13
14All modules "creating Data" posts their data to data_manager .
15Data_manager  make these new data available for all other perspectives.
16"""
17import logging
18from sans.guiframe.data_state import DataState
19from sans.guiframe.utils import parse_name
20 
21class DataManager(object):
22    """
23    Manage a list of data
24    """
25    def __init__(self):
26        """
27        Store opened path and data object created at the loading time
28        :param auto_plot: if True the datamanager sends data to plotting
29                            plugin.
30        :param auto_set_data: if True the datamanager sends to the current
31        perspective
32        """
33        self._selected_data = {}
34        self.stored_data = {}
35        self.message = ""
36        self.data_name_dict = {}
37     
38    def rename(self, name):
39        """
40        rename data
41        """
42        ## name of the data allow to differentiate data when plotted
43        name = parse_name(name=name, expression="_")
44       
45        max_char = name.find("[")
46        if max_char < 0:
47            max_char = len(name)
48        name = name[0:max_char]
49       
50        if name not in self.data_name_dict:
51            self.data_name_dict[name] = 0
52        else:
53            self.data_name_dict[name] += 1
54            name = name + " [" + str(self.data_name_dict[name]) + "]"
55        return name
56   
57    def add_data(self, data_list):
58        """
59        receive a list of
60        """
61        self._selected_data = {}
62        for data in data_list:
63            if data.id  in self.stored_data:
64                msg = "Data manager already stores %s" % str(data.name)
65                msg += ""
66                logging.info(msg)
67            data_state = DataState(data)
68            self._selected_data[data.id] = data_state
69            self.stored_data[data.id] = data_state
70     
71    def set_auto_plot(self, flag=False):
72        """
73        When flag is true the data is plotted automatically
74        """
75        self._auto_set_data = flag
76       
77    def set_auto_set_data(self, flag=False):
78        """
79        When flag is true the data is send to the current perspective
80        automatically
81        """
82        self._auto_set_data = flag
83       
84    def get_message(self):
85        """
86        return message
87        """
88        return self.message
89   
90    def get_by_id(self, id_list=None):
91        """
92        get a list of data given a list of id
93        """
94        self._selected_data = {}
95        for id in id_list:
96            if id in self.stored_data:
97                self._selected_data[id] = self.stored_data[id]
98        return self._selected_data
99   
100    def append_theory(self, data_id, theory):
101        """
102        """
103        print "append theory", self.stored_data, data_id
104        if data_id in self.stored_data:
105            data_state = self.stored_data[data_id]
106            data_state.set_theory(theory)
107           
108    def delete_data(self, data_id, theory_id, delete_all):
109        """
110        """
111        if data_id in self.stored_data:
112            del self.stored_data[data_id]
113        if data_id in self._selected_data:
114            del self._selected_data
115           
116    def delete_by_id(self, id_list=None):
117        """
118        save data and path
119        """
120        for id in id_list:
121            if id in self.stored_data:
122                del self.stored_data[id]
123            if id  in self._selected_data:
124                del self._selected_data[id]
125   
126    def get_by_name(self, name_list=None):
127        """
128        return a list of data given a list of data names
129        """
130        self._selected_data = {}
131        for selected_name in name_list:
132            for id, data_state in self.stored_data.iteritems():
133                if data_state.data.name == selected_name:
134                    self._selected_data[id] = data_state
135        return self._selected_data
136   
137    def delete_by_name(self, name_list=None):
138        """
139        save data and path
140        """
141        for selected_name in name_list:
142            for id, data_state in self.stored_data.iteritems():
143                if data_state.data.name == selected_name:
144                    del self._selected_data[id]
145                    del self.stored_data[data.id]
146
147    def get_selected_data(self):
148        """
149        Send list of selected data
150        """
151        return self._selected_data
152   
153    def get_all_data(self):
154        """
155        return list of all available data
156        """
157        return self.stored_data
158   
159
160       
Note: See TracBrowser for help on using the repository browser.