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 | """ |
---|
11 | This module manages all data loaded into the application. Data_manager makes |
---|
12 | available all data loaded for the current perspective. |
---|
13 | |
---|
14 | All modules "creating Data" posts their data to data_manager . |
---|
15 | Data_manager make these new data available for all other perspectives. |
---|
16 | """ |
---|
17 | import logging |
---|
18 | from sans.guiframe.data_state import DataState |
---|
19 | |
---|
20 | class DataManager(object): |
---|
21 | """ |
---|
22 | Manage a list of data |
---|
23 | """ |
---|
24 | def __init__(self): |
---|
25 | """ |
---|
26 | Store opened path and data object created at the loading time |
---|
27 | :param auto_plot: if True the datamanager sends data to plotting |
---|
28 | plugin. |
---|
29 | :param auto_set_data: if True the datamanager sends to the current |
---|
30 | perspective |
---|
31 | """ |
---|
32 | self._selected_data = {} |
---|
33 | self.stored_data = {} |
---|
34 | self.message = "" |
---|
35 | |
---|
36 | def add_data(self, data_list): |
---|
37 | """ |
---|
38 | receive a list of |
---|
39 | """ |
---|
40 | self._selected_data = {} |
---|
41 | for data in data_list: |
---|
42 | if data.id in self.stored_data: |
---|
43 | msg = "Data manager already stores %s" % str(data.name) |
---|
44 | msg += "" |
---|
45 | logging.info(msg) |
---|
46 | data_state = DataState(data) |
---|
47 | self._selected_data[data.id] = data_state |
---|
48 | self.stored_data[data.id] = data_state |
---|
49 | print "datalist", self._selected_data |
---|
50 | |
---|
51 | def set_auto_plot(self, flag=False): |
---|
52 | """ |
---|
53 | When flag is true the data is plotted automatically |
---|
54 | """ |
---|
55 | self._auto_set_data = flag |
---|
56 | |
---|
57 | def set_auto_set_data(self, flag=False): |
---|
58 | """ |
---|
59 | When flag is true the data is send to the current perspective |
---|
60 | automatically |
---|
61 | """ |
---|
62 | self._auto_set_data = flag |
---|
63 | |
---|
64 | def get_message(self): |
---|
65 | """ |
---|
66 | return message |
---|
67 | """ |
---|
68 | return self.message |
---|
69 | |
---|
70 | def get_by_id(self, id_list=None): |
---|
71 | """ |
---|
72 | get a list of data given a list of id |
---|
73 | """ |
---|
74 | self._selected_data = {} |
---|
75 | for id in id_list: |
---|
76 | if id in self.stored_data: |
---|
77 | self._selected_data[id] = self.stored_data[id] |
---|
78 | return self._selected_data |
---|
79 | |
---|
80 | def delete_by_id(self, id_list=None): |
---|
81 | """ |
---|
82 | save data and path |
---|
83 | """ |
---|
84 | for id in id_list: |
---|
85 | if id in self.stored_data: |
---|
86 | del self.stored_data[id] |
---|
87 | if id in self._selected_data: |
---|
88 | del self._selected_data[id] |
---|
89 | |
---|
90 | def get_by_name(self, name_list=None): |
---|
91 | """ |
---|
92 | return a list of data given a list of data names |
---|
93 | """ |
---|
94 | self._selected_data = {} |
---|
95 | for selected_name in name_list: |
---|
96 | for id, data_state in self.stored_data.iteritems(): |
---|
97 | if data_state.data.name == selected_name: |
---|
98 | self._selected_data[id] = data_state |
---|
99 | return self._selected_data |
---|
100 | |
---|
101 | def delete_by_name(self, name_list=None): |
---|
102 | """ |
---|
103 | save data and path |
---|
104 | """ |
---|
105 | for selected_name in name_list: |
---|
106 | for id, data_state in self.stored_data.iteritems(): |
---|
107 | if data_state.data.name == selected_name: |
---|
108 | del self._selected_data[id] |
---|
109 | del self.stored_data[data.id] |
---|
110 | |
---|
111 | def get_selected_data(self): |
---|
112 | """ |
---|
113 | Send list of selected data |
---|
114 | """ |
---|
115 | return self._selected_data |
---|
116 | |
---|
117 | def get_all_data(self): |
---|
118 | """ |
---|
119 | return list of all available data |
---|
120 | """ |
---|
121 | return self.stored_data |
---|
122 | |
---|
123 | |
---|
124 | |
---|