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

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 7e3d422 was 7e3d422, checked in by Gervaise Alina <gervyh@…>, 13 years ago

update profile_dialog

  • Property mode set to 100644
File size: 7.9 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
10from sans.guiframe.gui_style import GUIFRAME_ID
11import pylab
12
13DEFAULT_CMAP = None#pylab.cm.jet
14_BOX_WIDTH = 76
15_STATICBOX_WIDTH = 400
16# X Y offset on plot
17_X_OFF = 15
18_Y_OFF = 0.5
19
20#SLD panel size
21if sys.platform.count("win32") > 0:
22    _STATICBOX_WIDTH = 563
23    PANEL_SIZE = 425
24    FONT_VARIANT = 0
25else:
26    _STATICBOX_WIDTH = 605
27    PANEL_SIZE = 500
28    FONT_VARIANT = 1
29   
30     
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
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)
46
47        if data != None:
48            #Font size
49            kwds = []
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
58            self.plotpanel = SLDplotpanel(self, axes, -1, 
59                                             style=wx.TRANSPARENT_WINDOW)
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()
68            # unit increase to M times for users
69            data_plot.y = self._set_y_data()
70           
71            self.newplot = Data1D(data_plot.x, data_plot.y, data_plot.dy)
72            self.new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM
73            self.newplot.dy = None
74            self.newplot.name = 'SLD'
75            self.plotpanel.add_image(self.newplot) 
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()
81            self.Layout()
82
83    def _set_dy_data(self): 
84        """
85        make fake dy data
86       
87        :return dy:
88        """
89        # set dy as zero
90        dy = [0 for y in self.data.y]
91        return dy     
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     
103   
104    def _setup_layout(self):
105        """
106        Set up the layout
107        """
108        # panel sizer
109        sizer = wx.BoxSizer(wx.VERTICAL)
110        sizer.Add(self.plotpanel, 0, wx.LEFT|wx.RIGHT, 5)
111        sizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5)
112        sizer.Add((0, 5))
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, 
118                          id=button_reset.GetId()) 
119        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
120        sizer.Add((0, 10))
121        self.SetSizerAndFit(sizer)
122        self.Centre()
123        self.Show(True)
124        button_reset.SetFocus()
125       
126    def _close(self, event):
127        """
128        Close the dialog
129        """
130        self.Close(True)
131
132    def _draw_model(self, event):
133        """
134         on_close, update the model2d plot
135        """
136        pass
137
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
162       
163    def set_plot_unfocus(self):
164        """
165        Set_plot unfocus
166        """
167        # NOt implemented
168        pass
169
170   
171   
172class SLDplotpanel(PlotPanel):
173    """
174    Panel
175    """
176    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
177                  **kwargs):
178        """
179        """
180        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
181                           color=color, dpi=dpi, 
182                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
183
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 = []
191        for idx in range(0, len(axes)):
192            self.axes_label.append(axes[idx])
193       
194    def add_image(self, plot):
195        """
196        Add image(Theory1D)
197        """
198        self.plots[plot.name] = plot
199        self.plots[plot.name].is_data = False
200        #init graph
201        #self.gaph = Graph()
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')
207        self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
208        #draw
209        self.graph.render(self)
210        self.subplot.figure.canvas.draw_idle()
211               
212        # For latter scale changes
213        self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A')
214        self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
215       
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   
232    def _add_more_tool(self):
233        """
234        Not implemented
235        """
236        pass 
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, 
249                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
250        # Panel for 1D plot
251        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
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.