source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/profile_dialog.py @ 0c24e98

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

trying to fix sldprofile plot problem

  • Property mode set to 100644
File size: 9.7 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.plotpanel.resizing = False
85            self.plotpanel.canvas.set_resizing(self.plotpanel.resizing)
86            self.plotpanel.graph.render(self.plotpanel)
87
88    def _set_dy_data(self): 
89        """
90        make fake dy data
91       
92        :return dy:
93        """
94        # set dy as zero
95        dy = [0 for y in self.data.y]
96        return dy     
97
98    def _set_y_data(self): 
99        """
100        make y data unit Mega times
101       
102        :return y_value:
103        """
104        # changes the unit
105        y_value = [yvalue * 1e+006 for yvalue in self.data.y]
106       
107        return y_value     
108   
109    def _setup_layout(self):
110        """
111        Set up the layout
112        """
113        # panel sizer
114        sizer = wx.BoxSizer(wx.VERTICAL)
115        sizer.Add(self.plotpanel, 0, wx.LEFT|wx.RIGHT, 5)
116        sizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
117        sizer.Add((0, 5))
118        #-----Button------------1
119        id = wx.NewId()
120        button_reset = wx.Button(self, id, "Close")
121        button_reset.SetToolTipString("Close...")
122        button_reset.Bind(wx.EVT_BUTTON, self._close, 
123                          id=button_reset.GetId()) 
124        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
125        sizer.Add((0, 10))
126        self.SetSizerAndFit(sizer)
127        self.Centre()
128        self.Show(True)
129        button_reset.SetFocus()
130       
131    def _close(self, event):
132        """
133        Close the dialog
134        """
135        self.Close(True)
136
137    def _draw_model(self, event):
138        """
139         on_close, update the model2d plot
140        """
141        pass
142
143    def get_current_context_menu(self, graph=None):
144        """
145        When the context menu of a plot is rendered, the
146        get_context_menu method will be called to give you a
147        chance to add a menu item to the context menu.
148        :param graph: the Graph object to which we attach the context menu
149       
150        :return: a list of menu items with call-back function
151        """
152        return []
153   
154    def set_schedule_full_draw(self, panel=None, func=None):
155        """
156        Set_schedule for full draw
157        """
158        # Not implemented
159        pass
160   
161    def set_schedule(self, schedule=False):
162        """
163        Set schedule for redraw
164        """
165        # Not implemented
166        pass
167       
168    def set_plot_unfocus(self):
169        """
170        Set_plot unfocus
171        """
172        # NOt implemented
173        pass
174   
175    def on_change_caption(self, name, old_caption, new_caption):
176        """
177        """
178        self.parent.parent.parent.on_change_caption(name, old_caption, new_caption)
179   
180    def disable_app_menu(self, panel):
181        """
182        Disable menu bar
183        """
184        # Not implemented!
185        return
186   
187    def show_data1d(self, data, name):
188        """
189        Show data dialog
190        """   
191        self.parent.parent.parent.show_data1d(data, name)
192       
193class SLDplotpanel(PlotPanel):
194    """
195    Panel
196    """
197    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
198                  **kwargs):
199        """
200        """
201        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
202                           color=color, dpi=dpi, 
203                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
204
205        # Keep track of the parent Frame
206        self.parent = parent
207        self.window_name = "Scattering Length Density Profile"
208        self.window_caption = self.window_name
209        # Internal list of plottable names (because graph
210        # doesn't have a dictionary of handles for the plottables)
211        self.plots = {}
212        self.graph = Graph()
213        self.axes_label = []
214        for idx in range(0, len(axes)):
215            self.axes_label.append(axes[idx])
216        self.xaxis_label = ''
217        self.xaxis_unit = ''
218        self.yaxis_label = ''
219        self.yaxis_unit = ''
220        self.resizing = True
221       
222    def add_image(self, plot):
223        """
224        Add image(Theory1D)
225        """
226        self.plots[plot.id] = plot
227        self.plots[plot.id].is_data = True
228        #add plot
229        self.graph.add(plot)
230        #add axes
231        x1_label = self.axes_label[0]
232        self.xaxis_label = '\\rm{%s} '% x1_label
233        self.xaxis_unit = 'A'
234        self.graph.xaxis(self.xaxis_label, self.xaxis_unit)
235        self.yaxis_label = '\\rm{SLD} '
236        self.yaxis_unit = '10^{-6}A^{-2}'
237        self.graph.yaxis(self.yaxis_label, self.yaxis_unit)
238        #self.subplot.figure.canvas.draw_idle()
239        # For latter scale changes
240        self.plots[plot.id].xaxis('\\rm{%s} '% x1_label, 'A')
241        self.plots[plot.id].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
242        #draw
243        #self.graph.render(self)
244       
245    def on_set_focus(self, event):
246        """
247        send to the parenet the current panel on focus
248       
249        """
250        #Not implemented
251        pass
252
253    def on_kill_focus(self, event):
254        """
255        reset the panel color
256       
257        """
258        #Not implemented
259        pass
260   
261    def _add_more_tool(self):
262        """
263        Not implemented
264        """
265        pass 
266   
267    def onChangeCaption(self, event):
268        """
269        Not implemented
270        """
271        pass
272                           
273    def _onSave(self, evt):
274        """
275        Save a data set to a text file
276       
277        :param evt: Menu event
278       
279        """
280        menu = evt.GetEventObject()
281        id = evt.GetId()
282        self.set_selected_from_menu(menu, id)
283        data = self.plots[self.graph.selected_plottable]
284        default_name = data.label
285        if default_name.count('.') > 0:
286            default_name = default_name.split('.')[0]
287        default_name += "_out"
288        if self.parent != None:
289            # What an ancestor!
290            fit_panel = self.parent.parent.parent
291            fit_panel.parent.save_data1d(data, default_name)
292             
293class ViewerFrame(wx.Frame):
294    """
295    Add comment
296    """
297    def __init__(self, parent, id, title):
298        """
299        comment
300        :param parent: parent panel/container
301        """
302        # Initialize the Frame object
303        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
304                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
305        # Panel for 1D plot
306        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
307
308class ViewApp(wx.App):
309    def OnInit(self):
310        frame = ViewerFrame(None, -1, 'testView')   
311        frame.Show(True)
312        self.SetTopWindow(frame)
313       
314        return True
315               
316if __name__ == "__main__": 
317    app = ViewApp(0)
318    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.