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 = 570 |
---|
18 | PANEL_SIZE = 475 |
---|
19 | FONT_VARIANT = 0 |
---|
20 | else: |
---|
21 | _STATICBOX_WIDTH = 610 |
---|
22 | PANEL_SIZE = 500 |
---|
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,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 | |
---|
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, |
---|
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 | |
---|
192 | class 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 | |
---|
208 | class 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 | |
---|
216 | if __name__ == "__main__": |
---|
217 | app = ViewApp(0) |
---|
218 | app.MainLoop() |
---|