source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ 140fcbc8

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 140fcbc8 was 1c6389c, checked in by Jae Cho <jhjcho@…>, 13 years ago

passes add_more_too(): toolbar item

  • 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
[1c6389c]167
168   
[da9ac4e6]169   
170class SLDplotpanel(PlotPanel):
171    """
172    Panel
173    """
[a54e4be]174    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
[da9ac4e6]175                  **kwargs):
176        """
177        """
[a54e4be]178        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
179                           color=color, dpi=dpi, 
180                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
[519c693]181
[da9ac4e6]182        # Keep track of the parent Frame
183        self.parent = parent
184        # Internal list of plottable names (because graph
185        # doesn't have a dictionary of handles for the plottables)
186        self.plots = {}
187        self.graph = Graph()
188        self.axes_label = []
[519c693]189        for idx in range(0, len(axes)):
[da9ac4e6]190            self.axes_label.append(axes[idx])
191       
192    def add_image(self, plot):
193        """
194        Add image(Theory1D)
195        """
196        self.plots[plot.name] = plot
[accbb1b]197        self.plots[plot.name].is_data = False
[da9ac4e6]198        #init graph
[16d7079]199        #self.gaph = Graph()
[da9ac4e6]200        #add plot
201        self.graph.add(plot)
202        #add axes
203        x1_label = self.axes_label[0]
204        self.graph.xaxis('\\rm{%s} '% x1_label, 'A')
[16d7079]205        self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
[da9ac4e6]206        #draw
207        self.graph.render(self)
208        self.subplot.figure.canvas.draw_idle()
[02879ea]209               
210        # For latter scale changes
211        self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A')
[16d7079]212        self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}')
213       
[da9ac4e6]214    def on_set_focus(self, event):
215        """
216        send to the parenet the current panel on focus
217       
218        """
219        #Not implemented
220        pass
221
222    def on_kill_focus(self, event):
223        """
224        reset the panel color
225       
226        """
227        #Not implemented
228        pass
229   
[1c6389c]230    def _add_more_tool(self):
231        """
232        Not implemented
233        """
234        pass 
[da9ac4e6]235       
236class ViewerFrame(wx.Frame):
237    """
238    Add comment
239    """
240    def __init__(self, parent, id, title):
241        """
242        comment
243        :param parent: parent panel/container
244        """
245        # Initialize the Frame object
246        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
[a54e4be]247                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
[da9ac4e6]248        # Panel for 1D plot
[a54e4be]249        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
[da9ac4e6]250
251class ViewApp(wx.App):
252    def OnInit(self):
253        frame = ViewerFrame(None, -1, 'testView')   
254        frame.Show(True)
255        self.SetTopWindow(frame)
256       
257        return True
258               
259if __name__ == "__main__": 
260    app = ViewApp(0)
261    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.