1 | """ |
---|
2 | Corfunc perspective |
---|
3 | """ |
---|
4 | import wx |
---|
5 | import sys |
---|
6 | import logging |
---|
7 | from sas.sasgui.guiframe.plugin_base import PluginBase |
---|
8 | from sas.sasgui.guiframe.gui_manager import MDIFrame |
---|
9 | from sas.sasgui.guiframe.events import StatusEvent |
---|
10 | from sas.sasgui.guiframe.events import NewPlotEvent |
---|
11 | from sas.sasgui.guiframe.gui_style import GUIFRAME_ID |
---|
12 | from sas.sasgui.perspectives.corfunc.corfunc_panel import CorfuncPanel |
---|
13 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
14 | from sas.sasgui.perspectives.pr.pr_widgets import DataDialog |
---|
15 | |
---|
16 | |
---|
17 | GROUP_ID_IQ_DATA = r"$I_{obs}(q)$" |
---|
18 | IQ_DATA_LABEL = r"$I_{obs}(q)$" |
---|
19 | |
---|
20 | |
---|
21 | class 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 | if len(data_list) == 1: |
---|
56 | data = data_list[0] |
---|
57 | else: |
---|
58 | data_1d_list = [] |
---|
59 | data_2d_list = [] |
---|
60 | err_msg = "" |
---|
61 | |
---|
62 | for data in data_list: |
---|
63 | if data is not None: |
---|
64 | if issubclass(data.__class__, Data1D): |
---|
65 | data_1d_list.append(data) |
---|
66 | else: |
---|
67 | err_msg += "{} type {} \n".format(str(data.name), |
---|
68 | str(data.__class__)) |
---|
69 | data_2d_list.append(data) |
---|
70 | if len(data_2d_list) > 0: |
---|
71 | msg = "Corfunc doesn't support the following data types:\n" |
---|
72 | msg += err_msg |
---|
73 | if len(data_1d_list) == 0: |
---|
74 | msg += "No data recieved" |
---|
75 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
76 | info='error')) |
---|
77 | return |
---|
78 | elif len(data_list) > 1: |
---|
79 | msg = "Corfunc does not allow multiple data\n" |
---|
80 | msg += "Please select one.\n" |
---|
81 | dlg = DataDialog(data_list=data_1d_list, text=msg) |
---|
82 | if dlg.ShowModal() == wx.ID_OK: |
---|
83 | data = dlg.get_data() |
---|
84 | else: |
---|
85 | data = None |
---|
86 | dlg.Destroy() |
---|
87 | |
---|
88 | if data is None: |
---|
89 | msg += "Corfunc recieved no data\n" |
---|
90 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
91 | info='error')) |
---|
92 | return |
---|
93 | if issubclass(data.__class__, Data1D): |
---|
94 | try: |
---|
95 | wx.PostEvent(self.parent, NewPlotEvent(action='remove', |
---|
96 | group_id=GROUP_ID_IQ_DATA, |
---|
97 | id=self.data_id)) |
---|
98 | self.data_id = data.id |
---|
99 | self.corfunc_panel._set_data(data) |
---|
100 | except: |
---|
101 | msg = "Corfunc set_data: " + str(sys.exc_value) |
---|
102 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
103 | info='error')) |
---|
104 | |
---|
105 | def show_data(self, path=None, data=None, reset=False): |
---|
106 | """ |
---|
107 | Show data read from a file |
---|
108 | |
---|
109 | :param path: The path to the file |
---|
110 | :param data: The data to plot (Data1D) |
---|
111 | :param reset: If True, all other plottables will be cleared |
---|
112 | """ |
---|
113 | if data.dy is not None: |
---|
114 | new_plot = Data1D(data.x, data.y, dy=data.dy) |
---|
115 | else: |
---|
116 | new_plot = Data1D(data.x, data.y) |
---|
117 | new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM |
---|
118 | new_plot.name = IQ_DATA_LABEL |
---|
119 | new_plot.xaxis("\\rm{Q}", 'A^{-1}') |
---|
120 | new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") |
---|
121 | new_plot.interactive = True |
---|
122 | new_plot.group_id = GROUP_ID_IQ_DATA |
---|
123 | new_plot.id = self.data_id |
---|
124 | new_plot.title = "I(q)" |
---|
125 | wx.PostEvent(self.parent, |
---|
126 | NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) |
---|