source: sasview/src/sas/sasgui/guiframe/local_perspectives/plotting/profile_dialog.py @ 1905128

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 1905128 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 9.5 KB
Line 
1"""
2SLD Profile Dialog for multifunctional models
3"""
4import wx
5import sys
6from copy import deepcopy
7from sas.sasgui.plottools.plottables import Graph
8from Plotter1D import ModelPanel1D as PlotPanel
9from sas.sasgui.guiframe.dataFitting import Data1D
10from sas.sasgui.guiframe.gui_style import GUIFRAME_ID
11
12DEFAULT_CMAP = None  #pylab.cm.jet
13_BOX_WIDTH = 76
14_STATICBOX_WIDTH = 400
15# X Y offset on plot
16_X_OFF = 15
17_Y_OFF = 0.5
18
19#SLD panel size
20if sys.platform.count("win32") > 0:
21    _STATICBOX_WIDTH = 563
22    PANEL_SIZE = 425
23    FONT_VARIANT = 0
24else:
25    _STATICBOX_WIDTH = 605
26    PANEL_SIZE = 500
27    FONT_VARIANT = 1
28
29
30class SLDPanel(wx.Dialog):
31    """
32    Provides the SLD profile plot panel.
33    """
34    ## Internal nickname for the window, used by the AUI manager
35    window_name = "Scattering Length Density Profile"
36    ## Name to appear on the window title bar
37    window_caption = "Scattering Length Density Profile"
38    ## Flag to tell the AUI manager to put this panel in the center pane
39    CENTER_PANE = True
40    def __init__(self, parent=None, base=None, data=None, axes=['Radius'],
41                 id=-1, *args, **kwds):
42        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
43        kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE)
44        wx.Dialog.__init__(self, parent, id=id, *args, **kwds)
45
46        if data != None:
47            #Font size
48            kwds = []
49            self.SetWindowVariant(variant=FONT_VARIANT)
50
51            self.SetTitle("Scattering Length Density Profile")
52            self.parent = parent
53            self._mgr = None
54            self.data = data
55            self.str = self.data.__str__()
56            ## when 2 data have the same id override the 1 st plotted
57            self.name = self.data.name
58            # Panel for plot
59            self.plotpanel = SLDplotpanel(self, axes, -1,
60                                          style=wx.TRANSPARENT_WINDOW)
61            self.cmap = DEFAULT_CMAP
62            ## Create Artist and bind it
63            self.subplot = self.plotpanel.subplot
64            # layout
65            self._setup_layout()
66
67            # plot
68            data_plot = deepcopy(self.data)
69            data_plot.dy = self._set_dy_data()
70            # unit increase to M times for users
71            data_plot.y = self._set_y_data()
72
73            self.newplot = Data1D(data_plot.x, data_plot.y, data_plot.dy)
74            self.newplot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM
75            self.newplot.dy = None
76            self.newplot.name = 'SLD'
77            self.newplot.is_data = False
78
79            self.newplot.id = self.newplot.name
80            self.plotpanel.add_image(self.newplot)
81
82            self.plotpanel.resizing = False
83            self.plotpanel.canvas.set_resizing(self.plotpanel.resizing)
84
85            self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF,
86                                            max(data_plot.y) + _Y_OFF)
87            self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF,
88                                            max(data_plot.x) + _X_OFF)
89            self.plotpanel.graph.render(self.plotpanel)
90            self.plotpanel.canvas.draw()
91
92    def _set_dy_data(self):
93        """
94        make fake dy data
95
96        :return dy:
97        """
98        # set dy as zero
99        dy = [0 for y in self.data.y]
100        return dy
101
102    def _set_y_data(self):
103        """
104        make y data unit Mega times
105
106        :return y_value:
107        """
108        # changes the unit
109        y_value = [yvalue * 1e+006 for yvalue in self.data.y]
110
111        return y_value
112
113    def _setup_layout(self):
114        """
115        Set up the layout
116        """
117        # panel sizer
118        sizer = wx.BoxSizer(wx.VERTICAL)
119        sizer.Add(self.plotpanel, 0, wx.LEFT | wx.RIGHT, 5)
120        sizer.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5)
121        sizer.Add((0, 5))
122        #-----Button------------1
123        button_reset = wx.Button(self, wx.NewId(), "Close")
124        button_reset.SetToolTipString("Close...")
125        button_reset.Bind(wx.EVT_BUTTON, self._close,
126                          id=button_reset.GetId())
127        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80)
128        sizer.Add((0, 10))
129        self.SetSizerAndFit(sizer)
130        self.Centre()
131        self.Show(True)
132        button_reset.SetFocus()
133
134    def _close(self, event):
135        """
136        Close the dialog
137        """
138        self.Close(True)
139
140    def _draw_model(self, event):
141        """
142         on_close, update the model2d plot
143        """
144        pass
145
146    def get_current_context_menu(self, graph=None):
147        """
148        When the context menu of a plot is rendered, the
149        get_context_menu method will be called to give you a
150        chance to add a menu item to the context menu.
151        :param graph: the Graph object to which we attach the context menu
152
153        :return: a list of menu items with call-back function
154        """
155        return []
156
157    def set_schedule_full_draw(self, panel=None, func=None):
158        """
159        Set_schedule for full draw
160        """
161        # Not implemented
162        pass
163
164    def set_schedule(self, schedule=False):
165        """
166        Set schedule for redraw
167        """
168        # Not implemented
169        pass
170
171    def set_plot_unfocus(self):
172        """
173        Set_plot unfocus
174        """
175        # NOt implemented
176        pass
177
178    def on_change_caption(self, name, old_caption, new_caption):
179        """
180        """
181        self.parent.parent.parent.on_change_caption(name, old_caption, new_caption)
182
183    def disable_app_menu(self, panel):
184        """
185        Disable menu bar
186        """
187        # Not implemented!
188        return
189
190    def show_data1d(self, data, name):
191        """
192        Show data dialog
193        """
194        self.parent._manager.parent.show_data1d(data, name)
195
196class SLDplotpanel(PlotPanel):
197    """
198    Panel
199    """
200    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None, **kwargs):
201        """
202        """
203        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y',
204                           color=color, dpi=dpi,
205                           size=(_STATICBOX_WIDTH, PANEL_SIZE - 100), **kwargs)
206
207        # Keep track of the parent Frame
208        self.parent = parent
209        self.window_name = "Scattering Length Density Profile"
210        self.window_caption = self.window_name
211        self.prevXtrans = "x"
212        self.prevYtrans = "y"
213        self.viewModel = "--"
214        # Internal list of plottable names (because graph
215        # doesn't have a dictionary of handles for the plottables)
216        self.plots = {}
217        self.graph = Graph()
218        self.axes_label = []
219        for idx in range(0, len(axes)):
220            self.axes_label.append(axes[idx])
221        self.xaxis_label = ''
222        self.xaxis_unit = ''
223        self.yaxis_label = ''
224        self.yaxis_unit = ''
225        self.resizing = True
226        self.xcolor = 'black'
227        self.ycolor = 'black'
228
229    def add_image(self, plot):
230        """
231        Add image(Theory1D)
232        """
233        self.plots[plot.id] = plot
234        self.plots[plot.id].is_data = True
235        #add plot
236        self.graph.add(plot)
237        #add axes
238        x1_label = self.axes_label[0]
239        self.xaxis_label = '\\rm{%s} ' % x1_label
240        self.xaxis_unit = 'A'
241        self.graph.xaxis(self.xaxis_label, self.xaxis_unit)
242        self.yaxis_label = '\\rm{SLD} '
243        self.yaxis_unit = '10^{-6}A^{-2}'
244        self.graph.yaxis(self.yaxis_label, self.yaxis_unit)
245        # For latter scale changes
246        self.plots[plot.id].xaxis('\\rm{%s} ' % x1_label, 'A')
247        self.plots[plot.id].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
248
249    def on_set_focus(self, event):
250        """
251        send to the parenet the current panel on focus
252
253        """
254        #Not implemented
255        pass
256
257    def on_kill_focus(self, event):
258        """
259        reset the panel color
260
261        """
262        #Not implemented
263        pass
264
265    def onChangeCaption(self, event):
266        """
267        Not implemented
268        """
269        pass
270
271    def _onSave(self, evt):
272        """
273        Save a data set to a text file
274
275        :param evt: Menu event
276
277        """
278        menu = evt.GetEventObject()
279        event_id = evt.GetId()
280        self.set_selected_from_menu(menu, event_id)
281        data = self.plots[self.graph.selected_plottable]
282        default_name = data.label
283        if default_name.count('.') > 0:
284            default_name = default_name.split('.')[0]
285        default_name += "_out"
286        if self.parent != None:
287            # What an ancestor!
288            fit_panel = self.parent.parent.parent
289            fit_panel._manager.parent.save_data1d(data, default_name)
290
291class ViewerFrame(wx.Frame):
292    """
293    Add comment
294    """
295    def __init__(self, parent, id, title):
296        """
297        comment
298        :param parent: parent panel/container
299        """
300        # Initialize the Frame object
301        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
302                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
303        # Panel for 1D plot
304        self.plotpanel = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
305
306class ViewApp(wx.App):
307    def OnInit(self):
308        frame = ViewerFrame(None, -1, 'testView')
309        frame.Show(True)
310        self.SetTopWindow(frame)
311
312        return True
313
314if __name__ == "__main__":
315    app = ViewApp(0)
316    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.