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

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

added new models

  • Property mode set to 100644
File size: 5.4 KB
Line 
1import wx
2import sys
3
4from copy import deepcopy
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 = 475
20    FONT_VARIANT = 0
21else:
22    _STATICBOX_WIDTH = 410
23    PANEL_SIZE = 505
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,axes =['Radius'], id = -1, *args, **kwds):
39        kwds["style"] =  wx.DEFAULT_DIALOG_STYLE
40        kwds["size"] = wx.Size(_STATICBOX_WIDTH*1.5,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 plot
57            self.plotpanel    = SLDplotpanel(self, axes, -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            data_plot = deepcopy(self.data)
64            self.newplot=Theory1D(data_plot.x,data_plot.y)
65            self.newplot.name = 'SLD'
66            self.plotpanel.add_image(self.newplot) 
67
68            self.Centre()
69            self.Layout()
70           
71   
72    def _setup_layout(self):
73        """
74        Set up the layout
75        """
76        #  panel
77        sizer = wx.GridBagSizer(14,14)
78       
79        sizer.Add(self.plotpanel,(0, 0), (13, 13), wx.EXPAND | wx.LEFT| wx.RIGHT, 1)
80
81        #-----Button------------1
82        id = wx.NewId()
83        button_reset = wx.Button(self, id, "Close")
84        button_reset.SetToolTipString("Close...")
85        button_reset.Bind(wx.EVT_BUTTON, self._close, id = button_reset.GetId()) 
86        sizer.Add(button_reset, (13, 12), flag=wx.RIGHT | wx.BOTTOM, border=15)
87
88        sizer.AddGrowableCol(2)
89        sizer.AddGrowableRow(3)
90        self.SetSizerAndFit(sizer)
91        button_reset.SetFocus()
92        self.Centre()
93        self.Show(True)
94
95    def _close(self, event):
96        """
97        Close the dialog
98        """
99       
100        self.Close(True)
101
102    def _draw_model(self,event):
103        """
104         on_close, update the model2d plot
105        """
106        pass
107
108           
109class SLDplotpanel(PlotPanel):
110    """
111    Panel
112    """
113    def __init__(self, parent,axes=[], id = -1, color = None, dpi = None, **kwargs):
114        """
115        """
116        PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs)
117        # Keep track of the parent Frame
118        self.parent = parent
119        # Internal list of plottable names (because graph
120        # doesn't have a dictionary of handles for the plottables)
121        self.plots = {}
122        self.graph = Graph()
123        self.axes_label = []
124        for idx in range(0,len(axes)):
125            self.axes_label.append(axes[idx])
126         
127    def add_image(self, plot):
128        """
129        Add image(Theory1D)
130        """
131        self.plots[plot.name] = plot
132        #init graph
133        self.gaph = Graph()
134        #add plot
135        self.graph.add(plot)
136        #add axes
137        x1_label = self.axes_label[0]
138        self.graph.xaxis('\\rm{%s} '% x1_label, '\\AA')
139        self.graph.yaxis('\\rm{SLD} ', '\\AA^{-2}')
140
141
142        #draw
143        self.graph.render(self)
144        self.subplot.figure.canvas.draw_idle()
145       
146    def onContextMenu(self, event):
147        """
148        Default context menu for a plot panel
149       
150        """
151        pass
152   
153    def on_set_focus(self, event):
154        """
155        send to the parenet the current panel on focus
156       
157        """
158        #Not implemented
159        pass
160
161    def on_kill_focus(self, event):
162        """
163        reset the panel color
164       
165        """
166        #Not implemented
167        pass
168
169
170class ViewerFrame(wx.Frame):
171    """
172    Add comment
173    """
174    def __init__(self, parent, id, title):
175        """
176        comment
177        :param parent: parent panel/container
178        """
179        # Initialize the Frame object
180        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850))
181       
182        # Panel for 1D plot
183        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
184
185class ViewApp(wx.App):
186    def OnInit(self):
187        frame = ViewerFrame(None, -1, 'testView')   
188        frame.Show(True)
189        self.SetTopWindow(frame)
190       
191        return True
192               
193if __name__ == "__main__": 
194    app = ViewApp(0)
195    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.