source: sasview/theoryview/perspectives/theory/profile_dialog.py @ 16c415e

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 16c415e was b5181f6, checked in by Gervaise Alina <gervyh@…>, 14 years ago

correct for pylint score

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