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

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 acf536e 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
RevLine 
[f53444be]1
2
3
[a1b2471]4import wx
5import sys
[f53444be]6import pylab
[fb59ed9]7from copy import deepcopy
[a1b2471]8from danse.common.plottools.PlotPanel import PlotPanel
9from danse.common.plottools.plottables import Graph
10from sans.guiframe.dataFitting import Theory1D
11
[f53444be]12
13DEFAULT_CMAP = pylab.cm.jet
[a1b2471]14
15_BOX_WIDTH = 76
16_STATICBOX_WIDTH = 400
17_SCALE = 1e-6
18
19#SLD panel size
[f53444be]20if sys.platform.count("win32") > 0:
[a1b2471]21    _STATICBOX_WIDTH = 380
[fb59ed9]22    PANEL_SIZE = 475
[a1b2471]23    FONT_VARIANT = 0
24else:
25    _STATICBOX_WIDTH = 410
[fb59ed9]26    PANEL_SIZE = 505
[a1b2471]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
[b5181f6]41    def __init__(self, parent=None, base=None ,data=None,
42                 axes =['Radius'], id = -1, *args, **kwds):
[a1b2471]43        kwds["style"] =  wx.DEFAULT_DIALOG_STYLE
[b5181f6]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:
[a1b2471]48            #Font size
[b5181f6]49            kwds = []
[a1b2471]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
[fb59ed9]57            # Panel for plot
[b5181f6]58            self.plotpanel = SLDplotpanel(self, axes, -1, 
59                                             style=wx.TRANSPARENT_WINDOW)
[a1b2471]60            self.cmap = DEFAULT_CMAP
61            ## Create Artist and bind it
62            self.subplot = self.plotpanel.subplot
63            self._setup_layout()
[fb59ed9]64            data_plot = deepcopy(self.data)
65            self.newplot=Theory1D(data_plot.x,data_plot.y)
[a1b2471]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       
[b5181f6]78        sizer.Add(self.plotpanel,(0, 0), (13, 13), 
79                  wx.EXPAND|wx.LEFT| wx.RIGHT, 1)
[a1b2471]80
81        #-----Button------------1
82        id = wx.NewId()
83        button_reset = wx.Button(self, id, "Close")
84        button_reset.SetToolTipString("Close...")
[b5181f6]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)
[a1b2471]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    """
[b5181f6]114    def __init__(self, parent, axes=[], id=-1, color=None,
115                  dpi=None, **kwargs):
[a1b2471]116        """
117        """
[b5181f6]118        PlotPanel.__init__(self, parent, id=id, 
119                           color=color, dpi=dpi, **kwargs)
[a1b2471]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()
[fb59ed9]126        self.axes_label = []
127        for idx in range(0,len(axes)):
128            self.axes_label.append(axes[idx])
[a1b2471]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
[fb59ed9]140        x1_label = self.axes_label[0]
[b5181f6]141        self.graph.xaxis('\\rm{%s} ' % x1_label, '\\AA')
[a1b2471]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
[b5181f6]181        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
182                           wx.Size(950, 850))
[a1b2471]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.