source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ 247873a

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 247873a was accbb1b, checked in by Jae Cho <jhjcho@…>, 13 years ago

profile dialog bug fixes

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