1 | import wx |
---|
2 | import sys |
---|
3 | |
---|
4 | from copy import deepcopy |
---|
5 | from danse.common.plottools.plottables import Graph |
---|
6 | from sans.guiframe.dataFitting import Theory1D |
---|
7 | import pylab |
---|
8 | |
---|
9 | DEFAULT_CMAP= pylab.cm.jet |
---|
10 | |
---|
11 | _BOX_WIDTH = 76 |
---|
12 | _STATICBOX_WIDTH = 400 |
---|
13 | _SCALE = 1e-6 |
---|
14 | |
---|
15 | #SLD panel size |
---|
16 | if sys.platform.count("win32")>0: |
---|
17 | _STATICBOX_WIDTH = 380 |
---|
18 | PANEL_SIZE = 475 |
---|
19 | FONT_VARIANT = 0 |
---|
20 | else: |
---|
21 | _STATICBOX_WIDTH = 410 |
---|
22 | PANEL_SIZE = 505 |
---|
23 | FONT_VARIANT = 1 |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | class 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*1.5,PANEL_SIZE) |
---|
41 | wx.Dialog.__init__(self, parent, id = id, *args, **kwds) |
---|
42 | if data != None: |
---|
43 | |
---|
44 | #Font size |
---|
45 | kwds =[] |
---|
46 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
47 | |
---|
48 | self.SetTitle("Scattering Length Density Profile") |
---|
49 | self.parent = base |
---|
50 | self.data = data |
---|
51 | self.str = self.data.__str__() |
---|
52 | |
---|
53 | ## when 2 data have the same id override the 1 st plotted |
---|
54 | self.name = self.data.name |
---|
55 | |
---|
56 | # Panel for plot |
---|
57 | self.plotpanel = SLDplotpanel(self, axes, -1, |
---|
58 | style=wx.TRANSPARENT_WINDOW) |
---|
59 | self.cmap = DEFAULT_CMAP |
---|
60 | ## Create Artist and bind it |
---|
61 | self.subplot = self.plotpanel.subplot |
---|
62 | # layout |
---|
63 | self._setup_layout() |
---|
64 | # plot |
---|
65 | data_plot = deepcopy(self.data) |
---|
66 | data_plot.dy = self._set_dy_data() |
---|
67 | self.newplot=Theory1D(data_plot.x,data_plot.y,data_plot.dy) |
---|
68 | self.newplot.name = 'SLD' |
---|
69 | self.plotpanel.add_image(self.newplot) |
---|
70 | |
---|
71 | self.Centre() |
---|
72 | self.Layout() |
---|
73 | |
---|
74 | def _set_dy_data(self): |
---|
75 | """ |
---|
76 | make fake dy data |
---|
77 | |
---|
78 | :return dy: |
---|
79 | """ |
---|
80 | # set dy as zero |
---|
81 | dy = [ 0 for y in self.data.y] |
---|
82 | return dy |
---|
83 | |
---|
84 | def _setup_layout(self): |
---|
85 | """ |
---|
86 | Set up the layout |
---|
87 | """ |
---|
88 | # panel |
---|
89 | sizer = wx.GridBagSizer(14,14) |
---|
90 | |
---|
91 | sizer.Add(self.plotpanel,(0, 0), (13, 13), |
---|
92 | wx.EXPAND | wx.LEFT| wx.RIGHT, 1) |
---|
93 | |
---|
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, (13, 12), flag=wx.RIGHT | wx.BOTTOM, border=15) |
---|
101 | |
---|
102 | sizer.AddGrowableCol(2) |
---|
103 | sizer.AddGrowableRow(3) |
---|
104 | self.SetSizerAndFit(sizer) |
---|
105 | button_reset.SetFocus() |
---|
106 | self.Centre() |
---|
107 | self.Show(True) |
---|
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 | |
---|
133 | from Plotter1D import ModelPanel1D as PlotPanel |
---|
134 | class 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, **kwargs) |
---|
144 | # Keep track of the parent Frame |
---|
145 | self.parent = parent |
---|
146 | # Internal list of plottable names (because graph |
---|
147 | # doesn't have a dictionary of handles for the plottables) |
---|
148 | self.plots = {} |
---|
149 | self.graph = Graph() |
---|
150 | self.axes_label = [] |
---|
151 | for idx in range(0,len(axes)): |
---|
152 | self.axes_label.append(axes[idx]) |
---|
153 | |
---|
154 | def add_image(self, plot): |
---|
155 | """ |
---|
156 | Add image(Theory1D) |
---|
157 | """ |
---|
158 | self.plots[plot.name] = plot |
---|
159 | #init graph |
---|
160 | self.gaph = Graph() |
---|
161 | #add plot |
---|
162 | self.graph.add(plot) |
---|
163 | #add axes |
---|
164 | x1_label = self.axes_label[0] |
---|
165 | self.graph.xaxis('\\rm{%s} '% x1_label, 'A') |
---|
166 | self.graph.yaxis('\\rm{SLD} ', 'A^{-2}') |
---|
167 | |
---|
168 | #draw |
---|
169 | self.graph.render(self) |
---|
170 | self.subplot.figure.canvas.draw_idle() |
---|
171 | |
---|
172 | def on_set_focus(self, event): |
---|
173 | """ |
---|
174 | send to the parenet the current panel on focus |
---|
175 | |
---|
176 | """ |
---|
177 | #Not implemented |
---|
178 | pass |
---|
179 | |
---|
180 | def on_kill_focus(self, event): |
---|
181 | """ |
---|
182 | reset the panel color |
---|
183 | |
---|
184 | """ |
---|
185 | #Not implemented |
---|
186 | pass |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | class ViewerFrame(wx.Frame): |
---|
191 | """ |
---|
192 | Add comment |
---|
193 | """ |
---|
194 | def __init__(self, parent, id, title): |
---|
195 | """ |
---|
196 | comment |
---|
197 | :param parent: parent panel/container |
---|
198 | """ |
---|
199 | # Initialize the Frame object |
---|
200 | wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, |
---|
201 | wx.Size(950,850)) |
---|
202 | |
---|
203 | # Panel for 1D plot |
---|
204 | self.plotpanel = SLDplotpanel(self, -1, style=wx.RAISED_BORDER) |
---|
205 | |
---|
206 | class ViewApp(wx.App): |
---|
207 | def OnInit(self): |
---|
208 | frame = ViewerFrame(None, -1, 'testView') |
---|
209 | frame.Show(True) |
---|
210 | self.SetTopWindow(frame) |
---|
211 | |
---|
212 | return True |
---|
213 | |
---|
214 | if __name__ == "__main__": |
---|
215 | app = ViewApp(0) |
---|
216 | app.MainLoop() |
---|