source: sasview/guiframe/data_manager.py @ cb463b4

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 cb463b4 was 4e9583c, checked in by Gervaise Alina <gervyh@…>, 14 years ago

reverse guiframe

  • Property mode set to 100644
File size: 4.8 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
15fake Data posts their data to data_manager . Data_manager  make these new data
16available for all other perspectives.
17"""
18
19class 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 get_data(self, data_list={}):
45        """
46        return
47        """
48        if not data_list:
49            return self.available_data.values()
50        for data, path in data_list:
51            if data.name not in self.available_data.keys():
52                self.available_data[data.name] = (data, path)
53        return self.available_data.values()
54   
55    def on_get_data(self, data_list, plot=False):
56        """
57        This method is a handler to an event sent by data_loader or theory
58        perspective. It gets a list of data object through that event
59        and stores that list into available_data dictionary. Only new data are
60        stored.
61       
62        param event: contains a list of data. The size of the list is >= 1
63        """
64        for data, path in data_list:
65            if data.name not in self.available_data.keys():
66                self.available_data[data.name] = (data, path)
67                if plot:
68                    self.data_to_plot[data.name] = (data, path)
69         
70        return self.get_sorted_list()
71   
72    def sort_data(self):
73        """
74        Get the dictionary of data and created a list of turple of data's name,
75                data's type(Data1D, Data2, Theory1D, Theory2D), data of
76                 modification etc.
77        In other words extra data from available_data dictionary and create
78        sorted_data_list.
79        """
80        self.sorted_data = {}
81        index = 1
82        for data, path in self.available_data.values():
83            self.sorted_data[index]= (data.name, data.__class__.__name__,
84                                      "created on...", path)
85            index += 1
86        return self.sorted_data.values() 
87   
88    def get_sorted_list(self):
89        """
90        Return a list of turple of data sorted
91        return: sorted_data_list .
92        """
93        return self.sort_data()
94       
95    def remove_data(self, data_name_list):
96        """
97        Remove data which names are in data_name_list from available_data and
98        sorted_data_list. Post an event to all perspectives(including plotting
99         perspective) to remove all reference of these data from themselves .
100       
101        param data_name_list: a list containing names of data to remove from
102        the whole application.
103        """
104        for data_name in data_name_list:
105            del self.available_data[data_name]
106            del self.data_to_plot[data_name]
107        return self.get_sorted_list()
108       
109    def post_data(self, data_name_list, perspective=None,plot=False):
110        """
111        Set data from available_data for with the name is in data_name_list
112        and post these data to the current active perspective
113        """
114        self.selected_data_list = []
115        for data_name in data_name_list:
116            self.selected_data_list.append(self.available_data[data_name])
117        self.parent.post_data(list_of_data=self.selected_data_list, 
118                              perspective=perspective,plot=plot)
119       
120    def get_selected_data(self):
121        """
122        """
123        return self.selected_data_list
124       
125       
Note: See TracBrowser for help on using the repository browser.