source: sasview/guiframe/data_manager.py @ 064cfb9

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 064cfb9 was f444b20, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on guiframe loading

  • Property mode set to 100644
File size: 4.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"""
17
18import logging
19logging.basicConfig(level=logging.DEBUG,
20                    format='%(asctime)s %(levelname)s %(message)s',
21                    filename='sans_app.log',
22                    filemode='w')   
23 
24class DataManager(object):
25    """
26    Manage a list of data
27    """
28    def __init__(self):
29        """
30        Store opened path and data object created at the loading time
31        :param auto_plot: if True the datamanager sends data to plotting
32                            plugin.
33        :param auto_set_data: if True the datamanager sends to the current
34        perspective
35        """
36        self._selected_data = []
37        self.stored_data = {}
38        self.message = ""
39     
40    def add_data(self, data_list):
41        """
42        receive a list of
43        """
44        self._selected_data = []
45        for data in data_list:
46            if data.id  in self.stored_data:
47                msg = "Data manager already stores %s" % str(data.name)
48                msg += ""
49                logging.info(msg)
50            self._selected_data.append(data)
51            self.stored_data[id] = data
52           
53    def set_auto_plot(self, flag=False):
54        """
55        When flag is true the data is plotted automatically
56        """
57        self._auto_set_data = flag
58       
59    def set_auto_set_data(self, flag=False):
60        """
61        When flag is true the data is send to the current perspective
62        automatically
63        """
64        self._auto_set_data = flag
65       
66    def get_message(self):
67        """
68        return message
69        """
70        return self.message
71   
72    def get_by_id(self, id_list=None):
73        """
74        get a list of data given a list of id
75        """
76        self._selected_data = []
77        for id in id_list:
78            if id in self.stored_data:
79                self._selected_data.append(self.stored_data[id])
80        return self._selected_data
81   
82    def delete_by_id(self, id_list=None):
83        """
84        save data and path
85        """
86        for id in id_list:
87            if id in self.stored_data:
88                data = self.stored_data[id]
89                if data in self._selected_data:
90                    self._selected_data.remove(data)
91                del self.stored_data[id]
92   
93    def get_by_name(self, name_list=None):
94        """
95        return a list of data given a list of data names
96        """
97        self._selected_data = []
98        for selected_name in name_list:
99            for data in self.stored_data.values():
100                if data.name == selected_name:
101                    self._selected_data.append(data)
102        return self._selected_data
103   
104    def delete_by_name(self, name_list=None):
105        """
106        save data and path
107        """
108        for selected_name in name_list:
109            for data in self.stored_data.values():
110                if data.name == selected_name:
111                    if data in self._selected_data:
112                        self._selected_data.remove(data)
113                    if data.id in self.stored_data:
114                        del self.stored_data[data.id]
115
116    def get_selected_data(self):
117        """
118        Send list of selected data
119        """
120        return self._selected_data
121   
122    def get_all_data(self):
123        """
124        return list of all available data
125        """
126        return self.stored_data.values()
127   
128
129       
Note: See TracBrowser for help on using the repository browser.