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

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 5eede4e was 9a3d433, checked in by Jae Cho <jhjcho@…>, 13 years ago

fix sld_plot error

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