source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/profile_dialog.py @ 4467d62

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 4467d62 was 4467d62, checked in by Jae Cho <jhjcho@…>, 12 years ago

profile sld dataifo fixs

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