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 |
---|
15 | fake Data posts their data to data_manager . Data_manager make these new data |
---|
16 | available for all other perspectives. |
---|
17 | """ |
---|
18 | |
---|
19 | class DataManager(object): |
---|
20 | """ |
---|
21 | Manage a list of data |
---|
22 | """ |
---|
23 | def __init__(self, parent): |
---|
24 | """ |
---|
25 | Initialize the class. This class is binded with event sent by |
---|
26 | sans.guiframe.data_loader, sans.perspective.theoryview.theory |
---|
27 | to collected data created and loaded data. |
---|
28 | |
---|
29 | |
---|
30 | attribute:: available_data is dictionary of data |
---|
31 | attribute:: data_to_plot dictionary of data to plot automatically |
---|
32 | attribute:: sorted_data is a list of tuples containing data's name, |
---|
33 | data's type(Data1D, Data2, Theory1D, Theory2D), data of |
---|
34 | modification etc. |
---|
35 | :param parent: is the class that instantiates this object. |
---|
36 | for sansview :parent is gui_manager |
---|
37 | """ |
---|
38 | self.available_data = {} |
---|
39 | self.sorted_data = {} |
---|
40 | self.selected_data_list = [] |
---|
41 | #gui manager |
---|
42 | self.parent = parent |
---|
43 | |
---|
44 | def on_get_data(self, data_list, plot=False): |
---|
45 | """ |
---|
46 | This method is a handler to an event sent by data_loader or theory |
---|
47 | perspective. It gets a list of data object through that event |
---|
48 | and stores that list into available_data dictionary. Only new data are |
---|
49 | stored. |
---|
50 | |
---|
51 | param event: contains a list of data. The size of the list is >= 1 |
---|
52 | """ |
---|
53 | for data, path in data_list: |
---|
54 | if data.name not in self.available_data.keys(): |
---|
55 | self.available_data[data.name] = data, path |
---|
56 | if plot: |
---|
57 | self.data_to_plot[data.name] = data, path |
---|
58 | |
---|
59 | return self.get_sorted_list() |
---|
60 | |
---|
61 | def sort_data(self): |
---|
62 | """ |
---|
63 | Get the dictionary of data and created a list of turple of data's name, |
---|
64 | data's type(Data1D, Data2, Theory1D, Theory2D), data of |
---|
65 | modification etc. |
---|
66 | In other words extra data from available_data dictionary and create |
---|
67 | sorted_data_list. |
---|
68 | """ |
---|
69 | self.sorted_data = {} |
---|
70 | index = 1 |
---|
71 | for data, path in self.available_data.values(): |
---|
72 | self.sorted_data[index]= (data.name, data.__class__.__name__, |
---|
73 | "created on...", path) |
---|
74 | index += 1 |
---|
75 | return self.sorted_data.values() |
---|
76 | |
---|
77 | def get_sorted_list(self): |
---|
78 | """ |
---|
79 | Return a list of turple of data sorted |
---|
80 | return: sorted_data_list . |
---|
81 | """ |
---|
82 | return self.sort_data() |
---|
83 | |
---|
84 | def remove_data(self, data_name_list): |
---|
85 | """ |
---|
86 | Remove data which names are in data_name_list from available_data and |
---|
87 | sorted_data_list. Post an event to all perspectives(including plotting |
---|
88 | perspective) to remove all reference of these data from themselves . |
---|
89 | |
---|
90 | param data_name_list: a list containing names of data to remove from |
---|
91 | the whole application. |
---|
92 | """ |
---|
93 | for data_name in data_name_list: |
---|
94 | del self.available_data[data_name] |
---|
95 | del self.data_to_plot[data_name] |
---|
96 | return self.get_sorted_list() |
---|
97 | |
---|
98 | def post_data(self, data_name_list, perspective=None,plot=False): |
---|
99 | """ |
---|
100 | Set data from available_data for with the name is in data_name_list |
---|
101 | and post these data to the current active perspective |
---|
102 | """ |
---|
103 | self.selected_data_list = [] |
---|
104 | for data_name in data_name_list: |
---|
105 | self.selected_data_list.append(self.available_data[data_name]) |
---|
106 | self.parent.post_data(list_of_data=self.selected_data_list, |
---|
107 | perspective=perspective,plot=plot) |
---|
108 | |
---|
109 | def get_selected_data(self): |
---|
110 | """ |
---|
111 | """ |
---|
112 | return self.selected_data_list |
---|
113 | |
---|
114 | |
---|