source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ 00b76931

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 00b76931 was 16d7079, checked in by Jae Cho <jhjcho@…>, 14 years ago

Changed SLD unit for more user friendly

  • Property mode set to 100644
File size: 6.5 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 Theory1D
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 = 570
22    PANEL_SIZE = 475
23    FONT_VARIANT = 0
24else:
25    _STATICBOX_WIDTH = 610
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 = Theory1D(data_plot.x, data_plot.y, data_plot.dy)
71            self.newplot.name = 'SLD'
72            self.plotpanel.add_image(self.newplot) 
73            self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF , 
74                                                max(data_plot.y) + _Y_OFF)
75            self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF, 
76                                                max(data_plot.x) + _X_OFF)
77            #self.Centre()
78            self.Layout()
79
80    def _set_dy_data(self): 
81        """
82        make fake dy data
83       
84        :return dy:
85        """
86        # set dy as zero
87        dy = [0 for y in self.data.y]
88        return dy     
89
90    def _set_y_data(self): 
91        """
92        make y data unit Mega times
93       
94        :return y_value:
95        """
96        # changes the unit
97        y_value = [yvalue * 1e+006 for yvalue in self.data.y]
98       
99        return y_value     
100   
101    def _setup_layout(self):
102        """
103        Set up the layout
104        """
105        # panel sizer
106        sizer = wx.BoxSizer(wx.VERTICAL)
107        sizer.Add(self.plotpanel, -1, wx.LEFT|wx.RIGHT, 5)
108        sizer.Add((0, 10))
109        #-----Button------------1
110        id = wx.NewId()
111        button_reset = wx.Button(self, id, "Close")
112        button_reset.SetToolTipString("Close...")
113        button_reset.Bind(wx.EVT_BUTTON, self._close, 
114                          id=button_reset.GetId()) 
115        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
116        sizer.Add((0, 10))
117        self.SetSizerAndFit(sizer)
118        self.Centre()
119        self.Show(True)
120        button_reset.SetFocus()
121       
122    def _close(self, event):
123        """
124        Close the dialog
125        """
126        self.Close(True)
127
128
129   
130
131class SLDplotpanel(PlotPanel):
132    """
133    Panel
134    """
135    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
136                  **kwargs):
137        """
138        """
139        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
140                           color=color, dpi=dpi, 
141                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
142
143        # Keep track of the parent Frame
144        self.parent = parent
145        # Internal list of plottable names (because graph
146        # doesn't have a dictionary of handles for the plottables)
147        self.plots = {}
148        self.graph = Graph()
149        self.axes_label = []
150        for idx in range(0, len(axes)):
151            self.axes_label.append(axes[idx])
152       
153    def add_image(self, plot):
154        """
155        Add image(Theory1D)
156        """
157        self.plots[plot.name] = plot
158        #init graph
159        #self.gaph = Graph()
160        #add plot
161        self.graph.add(plot)
162        #add axes
163        x1_label = self.axes_label[0]
164        self.graph.xaxis('\\rm{%s} '% x1_label, 'A')
165        self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
166        #draw
167        self.graph.render(self)
168        self.subplot.figure.canvas.draw_idle()
169               
170        # For latter scale changes
171        self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A')
172        self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
173       
174    def on_set_focus(self, event):
175        """
176        send to the parenet the current panel on focus
177       
178        """
179        #Not implemented
180        pass
181
182    def on_kill_focus(self, event):
183        """
184        reset the panel color
185       
186        """
187        #Not implemented
188        pass
189   
190       
191       
192class ViewerFrame(wx.Frame):
193    """
194    Add comment
195    """
196    def __init__(self, parent, id, title):
197        """
198        comment
199        :param parent: parent panel/container
200        """
201        # Initialize the Frame object
202        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
203                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
204        # Panel for 1D plot
205        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
206
207class ViewApp(wx.App):
208    def OnInit(self):
209        frame = ViewerFrame(None, -1, 'testView')   
210        frame.Show(True)
211        self.SetTopWindow(frame)
212       
213        return True
214               
215if __name__ == "__main__": 
216    app = ViewApp(0)
217    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.