source: sasview/src/sas/sasgui/perspectives/corfunc/corfunc.py @ 2196f102

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2196f102 was 2196f102, checked in by lewis, 8 years ago

Fix error shown when unsuported data loaded

  • Property mode set to 100644
File size: 4.7 KB
Line 
1"""
2    Corfunc perspective
3"""
4import wx
5import sys
6import logging
7from sas.sasgui.guiframe.plugin_base import PluginBase
8from sas.sasgui.guiframe.gui_manager import MDIFrame
9from sas.sasgui.guiframe.events import StatusEvent
10from sas.sasgui.guiframe.events import NewPlotEvent
11from sas.sasgui.guiframe.gui_style import GUIFRAME_ID
12from sas.sasgui.perspectives.corfunc.corfunc_panel import CorfuncPanel
13from sas.sasgui.guiframe.dataFitting import Data1D
14from sas.sasgui.perspectives.pr.pr_widgets import DataDialog
15
16
17GROUP_ID_IQ_DATA = r"$I_{obs}(q)$"
18IQ_DATA_LABEL = r"$I_{obs}(q)$"
19
20
21class Plugin(PluginBase):
22    """
23    This class defines the interface for a plugin class for a correlation
24    function perspective
25    """
26
27    def __init__(self):
28        PluginBase.__init__(self, name="Correlation Function")
29        logging.info("Correlation function plug-in started")
30        self._always_active = True
31
32    def get_panels(self, parent):
33        """
34        Define the GUI panels
35        """
36        self.parent = parent
37        self.frame = MDIFrame(self.parent, None, 'None', (100,200))
38        self.data_id = IQ_DATA_LABEL
39        self.corfunc_panel = CorfuncPanel(parent=self.frame)
40        self.frame.set_panel(self.corfunc_panel)
41        self.corfunc_panel.set_manager(self)
42        self.perspective.append(self.corfunc_panel.window_name)
43
44        return [self.corfunc_panel]
45
46    def set_data(self, data_list=None):
47        """
48        Load the data that's been selected
49
50        :param data_list: The data to load in
51        """
52        if data_list is None:
53            data_list = []
54        if len(data_list) >= 1:
55            msg = ""
56            if len(data_list) == 1:
57                data = data_list[0]
58            else:
59                data_1d_list = []
60                data_2d_list = []
61                err_msg = ""
62
63                for data in data_list:
64                    if data is not None:
65                        if issubclass(data.__class__, Data1D):
66                            data_1d_list.append(data)
67                        else:
68                            err_msg += "{} type {} \n".format(str(data.name),
69                                str(data.__class__))
70                            data_2d_list.append(data)
71                if len(data_2d_list) > 0:
72                    msg = "Corfunc doesn't support the following data types:\n"
73                    msg += err_msg
74                if len(data_1d_list) == 0:
75                    msg += "No data recieved"
76                    wx.PostEvent(self.parent, StatusEvent(status=msg,
77                                                info='error'))
78                    return
79                elif len(data_list) > 1:
80                    msg = "Corfunc does not allow multiple data\n"
81                    msg += "Please select one.\n"
82                    dlg = DataDialog(data_list=data_1d_list, text=msg)
83                    if dlg.ShowModal() == wx.ID_OK:
84                        data = dlg.get_data()
85                    else:
86                        data = None
87                    dlg.Destroy()
88
89            if data is None:
90                msg += "Corfunc recieved no data\n"
91                wx.PostEvent(self.parent, StatusEvent(status=msg,
92                                            info='error'))
93                return
94            if issubclass(data.__class__, Data1D):
95                try:
96                    wx.PostEvent(self.parent, NewPlotEvent(action='remove',
97                                                group_id=GROUP_ID_IQ_DATA,
98                                                id=self.data_id))
99                    self.data_id = data.id
100                    self.corfunc_panel._set_data(data)
101                except:
102                    msg = "Corfunc set_data: " + str(sys.exc_value)
103                    wx.PostEvent(self.parent, StatusEvent(status=msg,
104                        info='error'))
105
106    def show_data(self, path=None, data=None, reset=False):
107        """
108        Show data read from a file
109
110        :param path: The path to the file
111        :param data: The data to plot (Data1D)
112        :param reset: If True, all other plottables will be cleared
113        """
114        if data.dy is not None:
115            new_plot = Data1D(data.x, data.y, dy=data.dy)
116        else:
117            new_plot = Data1D(data.x, data.y)
118        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM
119        new_plot.name = IQ_DATA_LABEL
120        new_plot.xaxis("\\rm{Q}", 'A^{-1}')
121        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")
122        new_plot.interactive = True
123        new_plot.group_id = GROUP_ID_IQ_DATA
124        new_plot.id = self.data_id
125        new_plot.title = "I(q)"
126        new_plot.xtransform = 'x'
127        new_plot.ytransform = 'y'
128        wx.PostEvent(self.parent,
129                     NewPlotEvent(plot=new_plot, title="I(q)", reset=reset))
Note: See TracBrowser for help on using the repository browser.