source: sasview/theoryview/perspectives/theory/profile_dialog.py @ f118fe2f

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 f118fe2f was a1b2471, checked in by Jae Cho <jhjcho@…>, 14 years ago

added sld plot for onion model and etc…

  • Property mode set to 100644
File size: 5.2 KB
Line 
1import wx
2import sys
3
4import copy,numpy
5from danse.common.plottools.PlotPanel import PlotPanel
6from danse.common.plottools.plottables import Graph
7from sans.guiframe.dataFitting import Theory1D
8import pylab
9
10DEFAULT_CMAP= pylab.cm.jet
11
12_BOX_WIDTH = 76
13_STATICBOX_WIDTH = 400
14_SCALE = 1e-6
15
16#SLD panel size
17if sys.platform.count("win32")>0:
18    _STATICBOX_WIDTH = 380
19    PANEL_SIZE = 420
20    FONT_VARIANT = 0
21else:
22    _STATICBOX_WIDTH = 410
23    PANEL_SIZE = 450
24    FONT_VARIANT = 1
25   
26
27           
28class SLDPanel(wx.Dialog):
29    """
30    Provides the SLD profile plot panel.
31    """
32    ## Internal nickname for the window, used by the AUI manager
33    window_name = "SLD Profile"
34    ## Name to appear on the window title bar
35    window_caption = "SLD Profile"
36    ## Flag to tell the AUI manager to put this panel in the center pane
37    CENTER_PANE = True
38    def __init__(self, parent=None,base=None,data =None, id = -1, *args, **kwds):
39        kwds["style"] =  wx.DEFAULT_DIALOG_STYLE
40        kwds["size"] = wx.Size(_STATICBOX_WIDTH*2,PANEL_SIZE) 
41        wx.Dialog.__init__(self, parent, id = id,  *args, **kwds)
42        if data != None:
43           
44            #Font size
45            kwds =[]
46            self.SetWindowVariant(variant=FONT_VARIANT)
47
48            self.SetTitle("Scattering Length Density Profile")
49            self.parent = base
50            self.data = data
51            self.str = self.data.__str__()
52
53            ## when 2 data have the same id override the 1 st plotted
54            self.name = self.data.name
55           
56            # Panel for 2D plot
57            self.plotpanel    = SLDplotpanel(self, -1, style=wx.TRANSPARENT_WINDOW)
58            self.cmap = DEFAULT_CMAP
59            ## Create Artist and bind it
60            self.subplot = self.plotpanel.subplot
61
62            self._setup_layout()
63            self.newplot=Theory1D(self.data.x,self.data.y)
64            self.newplot.name = 'SLD'
65            self.plotpanel.add_image(self.newplot) 
66
67            self.Centre()
68            self.Layout()
69           
70   
71    def _setup_layout(self):
72        """
73        Set up the layout
74        """
75        #  panel
76        sizer = wx.GridBagSizer(14,14)
77       
78        sizer.Add(self.plotpanel,(0, 0), (13, 13), wx.EXPAND | wx.LEFT| wx.RIGHT, 15)
79
80        #-----Button------------1
81        id = wx.NewId()
82        button_reset = wx.Button(self, id, "Close")
83        button_reset.SetToolTipString("Close...")
84        button_reset.Bind(wx.EVT_BUTTON, self._close, id = button_reset.GetId()) 
85        sizer.Add(button_reset, (13, 12), flag=wx.RIGHT | wx.BOTTOM, border=15)
86
87        sizer.AddGrowableCol(2)
88        sizer.AddGrowableRow(3)
89        self.SetSizerAndFit(sizer)
90        button_reset.SetFocus()
91        self.Centre()
92        self.Show(True)
93
94    def _close(self, event):
95        """
96        Close the dialog
97        """
98       
99        self.Close(True)
100
101    def _draw_model(self,event):
102        """
103         on_close, update the model2d plot
104        """
105        pass
106
107           
108class SLDplotpanel(PlotPanel):
109    """
110    Panel
111    """
112    def __init__(self, parent, id = -1, color = None, dpi = None, **kwargs):
113        """
114        """
115        PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs)
116        # Keep track of the parent Frame
117        self.parent = parent
118        # Internal list of plottable names (because graph
119        # doesn't have a dictionary of handles for the plottables)
120        self.plots = {}
121        self.graph = Graph()
122
123
124         
125    def add_image(self, plot):
126        """
127        Add image(Theory1D)
128        """
129        self.plots[plot.name] = plot
130        #init graph
131        self.gaph = Graph()
132        #add plot
133        self.graph.add(plot)
134        #add axes
135        self.graph.xaxis('\\rm{Radius} ', '\\AA')
136        self.graph.yaxis('\\rm{SLD} ', '\\AA^{-2}')
137
138
139        #draw
140        self.graph.render(self)
141        self.subplot.figure.canvas.draw_idle()
142       
143    def onContextMenu(self, event):
144        """
145        Default context menu for a plot panel
146       
147        """
148        pass
149   
150    def on_set_focus(self, event):
151        """
152        send to the parenet the current panel on focus
153       
154        """
155        #Not implemented
156        pass
157
158    def on_kill_focus(self, event):
159        """
160        reset the panel color
161       
162        """
163        #Not implemented
164        pass
165
166
167class ViewerFrame(wx.Frame):
168    """
169    Add comment
170    """
171    def __init__(self, parent, id, title):
172        """
173        comment
174        :param parent: parent panel/container
175        """
176        # Initialize the Frame object
177        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850))
178       
179        # Panel for 1D plot
180        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
181
182class ViewApp(wx.App):
183    def OnInit(self):
184        frame = ViewerFrame(None, -1, 'testView')   
185        frame.Show(True)
186        self.SetTopWindow(frame)
187       
188        return True
189               
190if __name__ == "__main__": 
191    app = ViewApp(0)
192    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.