source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ a54e4be

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

working on pylint

  • Property mode set to 100644
File size: 6.1 KB
Line 
1
2
3
4import wx
5import sys
6from copy import deepcopy
7from danse.common.plottools.plottables import Graph
8from Plotter1D import ModelPanel1D as PlotPanel
9from sans.guiframe.dataFitting import Theory1D
10import pylab
11
12DEFAULT_CMAP = pylab.cm.jet
13_BOX_WIDTH = 76
14_STATICBOX_WIDTH = 400
15_SCALE = 1e-6
16
17#SLD panel size
18if sys.platform.count("win32") > 0:
19    _STATICBOX_WIDTH = 570
20    PANEL_SIZE = 475
21    FONT_VARIANT = 0
22else:
23    _STATICBOX_WIDTH = 610
24    PANEL_SIZE = 500
25    FONT_VARIANT = 1
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'], 
39                 id=-1, *args, **kwds):
40        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
41        kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE) 
42        wx.Dialog.__init__(self, parent, id=id, *args, **kwds)
43
44        if data != None:
45            #Font size
46            kwds = []
47            self.SetWindowVariant(variant=FONT_VARIANT)
48            self.SetTitle("Scattering Length Density Profile")
49            self.parent = base
50            self.data = data
51            self.str = self.data.__str__()
52            ## when 2 data have the same id override the 1 st plotted
53            self.name = self.data.name
54            # Panel for plot
55            self.plotpanel = SLDplotpanel(self, axes, -1, 
56                                             style=wx.TRANSPARENT_WINDOW)
57            self.cmap = DEFAULT_CMAP
58            ## Create Artist and bind it
59            self.subplot = self.plotpanel.subplot
60            # layout
61            self._setup_layout()
62            # plot
63            data_plot = deepcopy(self.data)
64            data_plot.dy = self._set_dy_data()
65            self.newplot = Theory1D(data_plot.x, data_plot.y, data_plot.dy)
66            self.newplot.name = 'SLD'
67            self.plotpanel.add_image(self.newplot) 
68            self.Centre()
69            self.Layout()
70
71    def _set_dy_data(self): 
72        """
73        make fake dy data
74       
75        :return dy:
76        """
77        # set dy as zero
78        dy = [0 for y in self.data.y]
79        return dy     
80   
81    def _setup_layout(self):
82        """
83        Set up the layout
84        """
85        # panel sizer
86        sizer = wx.BoxSizer(wx.VERTICAL)
87        sizer.Add(self.plotpanel, -1, wx.LEFT|wx.RIGHT, 5)
88        sizer.Add((0, 10))
89        #-----Button------------1
90        id = wx.NewId()
91        button_reset = wx.Button(self, id, "Close")
92        button_reset.SetToolTipString("Close...")
93        button_reset.Bind(wx.EVT_BUTTON, self._close, 
94                          id=button_reset.GetId()) 
95        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
96        sizer.Add((0, 10))
97        self.SetSizerAndFit(sizer)
98        self.Centre()
99        self.Show(True)
100        button_reset.SetFocus()
101       
102    def _close(self, event):
103        """
104        Close the dialog
105        """
106        self.Close(True)
107
108    def _draw_model(self, event):
109        """
110         on_close, update the model2d plot
111        """
112        pass
113
114    def get_context_menu(self, graph=None):
115        """
116        When the context menu of a plot is rendered, the
117        get_context_menu method will be called to give you a
118        chance to add a menu item to the context menu.
119        :param graph: the Graph object to which we attach the context menu
120       
121        :return: a list of menu items with call-back function
122        """
123        return []
124   
125
126class SLDplotpanel(PlotPanel):
127    """
128    Panel
129    """
130    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None,
131                  **kwargs):
132        """
133        """
134        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
135                           color=color, dpi=dpi, 
136                           size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs)
137
138        # Keep track of the parent Frame
139        self.parent = parent
140        # Internal list of plottable names (because graph
141        # doesn't have a dictionary of handles for the plottables)
142        self.plots = {}
143        self.graph = Graph()
144        self.axes_label = []
145        for idx in range(0, len(axes)):
146            self.axes_label.append(axes[idx])
147       
148    def add_image(self, plot):
149        """
150        Add image(Theory1D)
151        """
152        self.plots[plot.name] = plot
153        #init graph
154        self.gaph = Graph()
155        #add plot
156        self.graph.add(plot)
157        #add axes
158        x1_label = self.axes_label[0]
159        self.graph.xaxis('\\rm{%s} '% x1_label, 'A')
160        self.graph.yaxis('\\rm{SLD} ', 'A^{-2}')
161        #draw
162        self.graph.render(self)
163        self.subplot.figure.canvas.draw_idle()
164
165    def on_set_focus(self, event):
166        """
167        send to the parenet the current panel on focus
168       
169        """
170        #Not implemented
171        pass
172
173    def on_kill_focus(self, event):
174        """
175        reset the panel color
176       
177        """
178        #Not implemented
179        pass
180   
181       
182       
183class ViewerFrame(wx.Frame):
184    """
185    Add comment
186    """
187    def __init__(self, parent, id, title):
188        """
189        comment
190        :param parent: parent panel/container
191        """
192        # Initialize the Frame object
193        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
194                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE))
195        # Panel for 1D plot
196        self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER)
197
198class ViewApp(wx.App):
199    def OnInit(self):
200        frame = ViewerFrame(None, -1, 'testView')   
201        frame.Show(True)
202        self.SetTopWindow(frame)
203       
204        return True
205               
206if __name__ == "__main__": 
207    app = ViewApp(0)
208    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.