source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ 4c01978

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 4c01978 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
RevLine 
[16d7079]1"""
2SLD Profile Dialog for multifunctional models
3"""
[da9ac4e6]4import wx
5import sys
6from copy import deepcopy
7from danse.common.plottools.plottables import Graph
[a54e4be]8from Plotter1D import ModelPanel1D as PlotPanel
[da9ac4e6]9from sans.guiframe.dataFitting import Theory1D
10import pylab
11
[16d7079]12DEFAULT_CMAP = None#pylab.cm.jet
[da9ac4e6]13_BOX_WIDTH = 76
14_STATICBOX_WIDTH = 400
[16d7079]15# X Y offset on plot
16_X_OFF = 15
17_Y_OFF = 0.5
[da9ac4e6]18
19#SLD panel size
[519c693]20if sys.platform.count("win32") > 0:
[6996942]21    _STATICBOX_WIDTH = 570
[da9ac4e6]22    PANEL_SIZE = 475
23    FONT_VARIANT = 0
24else:
[519c693]25    _STATICBOX_WIDTH = 610
26    PANEL_SIZE = 500
[da9ac4e6]27    FONT_VARIANT = 1
28   
[a54e4be]29     
[da9ac4e6]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
[a54e4be]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)
[519c693]45
[da9ac4e6]46        if data != None:
47            #Font size
[a54e4be]48            kwds = []
[da9ac4e6]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
[a54e4be]57            self.plotpanel = SLDplotpanel(self, axes, -1, 
58                                             style=wx.TRANSPARENT_WINDOW)
[da9ac4e6]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()
[16d7079]67            # unit increase to M times for users
68            data_plot.y = self._set_y_data()
69           
[a54e4be]70            self.newplot = Theory1D(data_plot.x, data_plot.y, data_plot.dy)
[da9ac4e6]71            self.newplot.name = 'SLD'
72            self.plotpanel.add_image(self.newplot) 
[16d7079]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()
[da9ac4e6]78            self.Layout()
[519c693]79
[da9ac4e6]80    def _set_dy_data(self): 
81        """
82        make fake dy data
83       
84        :return dy:
85        """
86        # set dy as zero
[a54e4be]87        dy = [0 for y in self.data.y]
[da9ac4e6]88        return dy     
[16d7079]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     
[da9ac4e6]100   
101    def _setup_layout(self):
102        """
103        Set up the layout
104        """
[519c693]105        # panel sizer
106        sizer = wx.BoxSizer(wx.VERTICAL)
[a54e4be]107        sizer.Add(self.plotpanel, -1, wx.LEFT|wx.RIGHT, 5)
108        sizer.Add((0, 10))
[da9ac4e6]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, 
[a54e4be]114                          id=button_reset.GetId()) 
[519c693]115        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
[a54e4be]116        sizer.Add((0, 10))
[da9ac4e6]117        self.SetSizerAndFit(sizer)
118        self.Centre()
119        self.Show(True)
[519c693]120        button_reset.SetFocus()
121       
[da9ac4e6]122    def _close(self, event):
123        """
124        Close the dialog
125        """
126        self.Close(True)
127
128
129   
[a54e4be]130
[da9ac4e6]131class SLDplotpanel(PlotPanel):
132    """
133    Panel
134    """
[a54e4be]135    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
[da9ac4e6]136                  **kwargs):
137        """
138        """
[a54e4be]139        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
140                           color=color, dpi=dpi, 
141                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
[519c693]142
[da9ac4e6]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 = []
[519c693]150        for idx in range(0, len(axes)):
[da9ac4e6]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
[16d7079]159        #self.gaph = Graph()
[da9ac4e6]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')
[16d7079]165        self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
[da9ac4e6]166        #draw
167        self.graph.render(self)
168        self.subplot.figure.canvas.draw_idle()
[02879ea]169               
170        # For latter scale changes
171        self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A')
[16d7079]172        self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
173       
[da9ac4e6]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, 
[a54e4be]203                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
[da9ac4e6]204        # Panel for 1D plot
[a54e4be]205        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
[da9ac4e6]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.