source: sasview/guiframe/data_manager.py @ 1b3a5a9

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 1b3a5a9 was 6db811e, checked in by Gervaise Alina <gervyh@…>, 14 years ago

add data loading panel

  • Property mode set to 100644
File size: 4.4 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
19 
20class 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     
50    def set_auto_plot(self, flag=False):
51        """
52        When flag is true the data is plotted automatically
53        """
54        self._auto_set_data = flag
55       
56    def set_auto_set_data(self, flag=False):
57        """
58        When flag is true the data is send to the current perspective
59        automatically
60        """
61        self._auto_set_data = flag
62       
63    def get_message(self):
64        """
65        return message
66        """
67        return self.message
68   
69    def get_by_id(self, id_list=None):
70        """
71        get a list of data given a list of id
72        """
73        self._selected_data = {}
74        for id in id_list:
75            if id in self.stored_data:
76                self._selected_data[id] = self.stored_data[id]
77        return self._selected_data
78   
79    def append_theory(self, data_id, theory):
80        """
81        """
82        print "append theory", self.stored_data, data_id
83        if data_id in self.stored_data:
84            data_state = self.stored_data[data_id]
85            data_state.set_theory(theory)
86           
87    def delete_data(self, data_id, theory_id, delete_all):
88        """
89        """
90        if data_id in self.stored_data:
91            del self.stored_data[data_id]
92        if data_id in self._selected_data:
93            del self._selected_data
94           
95    def delete_by_id(self, id_list=None):
96        """
97        save data and path
98        """
99        for id in id_list:
100            if id in self.stored_data:
101                del self.stored_data[id]
102            if id  in self._selected_data:
103                del self._selected_data[id]
104   
105    def get_by_name(self, name_list=None):
106        """
107        return a list of data given a list of data names
108        """
109        self._selected_data = {}
110        for selected_name in name_list:
111            for id, data_state in self.stored_data.iteritems():
112                if data_state.data.name == selected_name:
113                    self._selected_data[id] = data_state
114        return self._selected_data
115   
116    def delete_by_name(self, name_list=None):
117        """
118        save data and path
119        """
120        for selected_name in name_list:
121            for id, data_state in self.stored_data.iteritems():
122                if data_state.data.name == selected_name:
123                    del self._selected_data[id]
124                    del self.stored_data[data.id]
125
126    def get_selected_data(self):
127        """
128        Send list of selected data
129        """
130        return self._selected_data
131   
132    def get_all_data(self):
133        """
134        return list of all available data
135        """
136        return self.stored_data
137   
138
139       
Note: See TracBrowser for help on using the repository browser.