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

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

remove reference of guicomm

  • Property mode set to 100644
File size: 5.4 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,axes =['Radius'], id = -1, *args, **kwds):
42        kwds["style"] =  wx.DEFAULT_DIALOG_STYLE
43        kwds["size"] = wx.Size(_STATICBOX_WIDTH*1.5,PANEL_SIZE) 
44        wx.Dialog.__init__(self, parent, id = id,  *args, **kwds)
45        if data != None:
46           
47            #Font size
48            kwds =[]
49            self.SetWindowVariant(variant=FONT_VARIANT)
50
51            self.SetTitle("Scattering Length Density Profile")
52            self.parent = base
53            self.data = data
54            self.str = self.data.__str__()
55
56            ## when 2 data have the same id override the 1 st plotted
57            self.name = self.data.name
58           
59            # Panel for plot
60            self.plotpanel    = SLDplotpanel(self, axes, -1, style=wx.TRANSPARENT_WINDOW)
61            self.cmap = DEFAULT_CMAP
62            ## Create Artist and bind it
63            self.subplot = self.plotpanel.subplot
64
65            self._setup_layout()
66            data_plot = deepcopy(self.data)
67            self.newplot=Theory1D(data_plot.x,data_plot.y)
68            self.newplot.name = 'SLD'
69            self.plotpanel.add_image(self.newplot) 
70
71            self.Centre()
72            self.Layout()
73           
74   
75    def _setup_layout(self):
76        """
77        Set up the layout
78        """
79        #  panel
80        sizer = wx.GridBagSizer(14,14)
81       
82        sizer.Add(self.plotpanel,(0, 0), (13, 13), wx.EXPAND | wx.LEFT| wx.RIGHT, 1)
83
84        #-----Button------------1
85        id = wx.NewId()
86        button_reset = wx.Button(self, id, "Close")
87        button_reset.SetToolTipString("Close...")
88        button_reset.Bind(wx.EVT_BUTTON, self._close, id = button_reset.GetId()) 
89        sizer.Add(button_reset, (13, 12), flag=wx.RIGHT | wx.BOTTOM, border=15)
90
91        sizer.AddGrowableCol(2)
92        sizer.AddGrowableRow(3)
93        self.SetSizerAndFit(sizer)
94        button_reset.SetFocus()
95        self.Centre()
96        self.Show(True)
97
98    def _close(self, event):
99        """
100        Close the dialog
101        """
102       
103        self.Close(True)
104
105    def _draw_model(self,event):
106        """
107         on_close, update the model2d plot
108        """
109        pass
110
111           
112class SLDplotpanel(PlotPanel):
113    """
114    Panel
115    """
116    def __init__(self, parent,axes=[], id = -1, color = None, dpi = None, **kwargs):
117        """
118        """
119        PlotPanel.__init__(self, parent, id=id, 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
144
145        #draw
146        self.graph.render(self)
147        self.subplot.figure.canvas.draw_idle()
148       
149    def onContextMenu(self, event):
150        """
151        Default context menu for a plot panel
152       
153        """
154        pass
155   
156    def on_set_focus(self, event):
157        """
158        send to the parenet the current panel on focus
159       
160        """
161        #Not implemented
162        pass
163
164    def on_kill_focus(self, event):
165        """
166        reset the panel color
167       
168        """
169        #Not implemented
170        pass
171
172
173class ViewerFrame(wx.Frame):
174    """
175    Add comment
176    """
177    def __init__(self, parent, id, title):
178        """
179        comment
180        :param parent: parent panel/container
181        """
182        # Initialize the Frame object
183        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850))
184       
185        # Panel for 1D plot
186        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
187
188class ViewApp(wx.App):
189    def OnInit(self):
190        frame = ViewerFrame(None, -1, 'testView')   
191        frame.Show(True)
192        self.SetTopWindow(frame)
193       
194        return True
195               
196if __name__ == "__main__": 
197    app = ViewApp(0)
198    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.