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

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 c966e1c was 7625f49, checked in by Jae Cho <jhjcho@…>, 13 years ago

changed theory 1d to data1d

  • Property mode set to 100644
File size: 7.8 KB
Line 
1"""
2SLD Profile Dialog for multifunctional models
3"""
4import wx
5import sys
6from copy import deepcopy
7from danse.common.plottools.plottables import Graph
8from Plotter1D import ModelPanel1D as PlotPanel
9from sans.guiframe.dataFitting import Data1D
10import pylab
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 = "SLD Profile"
36    ## Name to appear on the window title bar
37    window_caption = "SLD 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            self.SetTitle("Scattering Length Density Profile")
51            self.parent = base
52            self.data = data
53            self.str = self.data.__str__()
54            ## when 2 data have the same id override the 1 st plotted
55            self.name = self.data.name
56            # Panel for plot
57            self.plotpanel = SLDplotpanel(self, axes, -1, 
58                                             style=wx.TRANSPARENT_WINDOW)
59            self.cmap = DEFAULT_CMAP
60            ## Create Artist and bind it
61            self.subplot = self.plotpanel.subplot
62            # layout
63            self._setup_layout()
64            # plot
65            data_plot = deepcopy(self.data)
66            data_plot.dy = self._set_dy_data()
67            # unit increase to M times for users
68            data_plot.y = self._set_y_data()
69           
70            self.newplot = Data1D(data_plot.x, data_plot.y, data_plot.dy)
71            self.newplot.dy = None
72            self.newplot.name = 'SLD'
73            self.newplot.symbol = 13
74            self.plotpanel.add_image(self.newplot) 
75            self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF , 
76                                                max(data_plot.y) + _Y_OFF)
77            self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF, 
78                                                max(data_plot.x) + _X_OFF)
79            #self.Centre()
80            self.Layout()
81
82    def _set_dy_data(self): 
83        """
84        make fake dy data
85       
86        :return dy:
87        """
88        # set dy as zero
89        dy = [0 for y in self.data.y]
90        return dy     
91
92    def _set_y_data(self): 
93        """
94        make y data unit Mega times
95       
96        :return y_value:
97        """
98        # changes the unit
99        y_value = [yvalue * 1e+006 for yvalue in self.data.y]
100       
101        return y_value     
102   
103    def _setup_layout(self):
104        """
105        Set up the layout
106        """
107        # panel sizer
108        sizer = wx.BoxSizer(wx.VERTICAL)
109        sizer.Add(self.plotpanel, 0, wx.LEFT|wx.RIGHT, 5)
110        sizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
111        sizer.Add((0, 5))
112        #-----Button------------1
113        id = wx.NewId()
114        button_reset = wx.Button(self, id, "Close")
115        button_reset.SetToolTipString("Close...")
116        button_reset.Bind(wx.EVT_BUTTON, self._close, 
117                          id=button_reset.GetId()) 
118        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
119        sizer.Add((0, 10))
120        self.SetSizerAndFit(sizer)
121        self.Centre()
122        self.Show(True)
123        button_reset.SetFocus()
124       
125    def _close(self, event):
126        """
127        Close the dialog
128        """
129        self.Close(True)
130
131    def _draw_model(self, event):
132        """
133         on_close, update the model2d plot
134        """
135        pass
136
137    def get_context_menu(self, graph=None):
138        """
139        When the context menu of a plot is rendered, the
140        get_context_menu method will be called to give you a
141        chance to add a menu item to the context menu.
142        :param graph: the Graph object to which we attach the context menu
143       
144        :return: a list of menu items with call-back function
145        """
146        return []
147   
148    def set_schedule_full_draw(self, panel=None, func=None):
149        """
150        Set_schedule for full draw
151        """
152        # Not implemented
153        pass
154   
155    def set_schedule(self, schedule=False):
156        """
157        Set schedule for redraw
158        """
159        # Not implemented
160        pass
161       
162    def set_plot_unfocus(self):
163        """
164        Set_plot unfocus
165        """
166        # NOt implemented
167        pass
168
169   
170   
171class SLDplotpanel(PlotPanel):
172    """
173    Panel
174    """
175    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
176                  **kwargs):
177        """
178        """
179        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
180                           color=color, dpi=dpi, 
181                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
182
183        # Keep track of the parent Frame
184        self.parent = parent
185        # Internal list of plottable names (because graph
186        # doesn't have a dictionary of handles for the plottables)
187        self.plots = {}
188        self.graph = Graph()
189        self.axes_label = []
190        for idx in range(0, len(axes)):
191            self.axes_label.append(axes[idx])
192       
193    def add_image(self, plot):
194        """
195        Add image(Data1D)
196        """
197        self.plots[plot.name] = plot
198        self.plots[plot.name].is_data = False
199        #init graph
200        #self.gaph = Graph()
201        #add plot
202        self.graph.add(plot)
203        #add axes
204        x1_label = self.axes_label[0]
205        self.graph.xaxis('\\rm{%s} '% x1_label, 'A')
206        self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
207        #draw
208        self.graph.render(self)
209        self.subplot.figure.canvas.draw_idle()
210               
211        # For latter scale changes
212        self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A')
213        self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
214       
215    def on_set_focus(self, event):
216        """
217        send to the parenet the current panel on focus
218       
219        """
220        #Not implemented
221        pass
222
223    def on_kill_focus(self, event):
224        """
225        reset the panel color
226       
227        """
228        #Not implemented
229        pass
230   
231    def _add_more_tool(self):
232        """
233        Not implemented
234        """
235        pass 
236       
237class ViewerFrame(wx.Frame):
238    """
239    Add comment
240    """
241    def __init__(self, parent, id, title):
242        """
243        comment
244        :param parent: parent panel/container
245        """
246        # Initialize the Frame object
247        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
248                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
249        # Panel for 1D plot
250        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
251
252class ViewApp(wx.App):
253    def OnInit(self):
254        frame = ViewerFrame(None, -1, 'testView')   
255        frame.Show(True)
256        self.SetTopWindow(frame)
257       
258        return True
259               
260if __name__ == "__main__": 
261    app = ViewApp(0)
262    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.