source: sasview/guiframe/local_perspectives/plotting/profile_dialog.py @ 519c693

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

redesign the dialog sizer for better fit on MAC and PC platforms

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