[da9ac4e6] | 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 |
---|
[519c693] | 16 | if sys.platform.count("win32") > 0: |
---|
[6996942] | 17 | _STATICBOX_WIDTH = 570 |
---|
[da9ac4e6] | 18 | PANEL_SIZE = 475 |
---|
| 19 | FONT_VARIANT = 0 |
---|
| 20 | else: |
---|
[519c693] | 21 | _STATICBOX_WIDTH = 610 |
---|
| 22 | PANEL_SIZE = 500 |
---|
[da9ac4e6] | 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 |
---|
[6996942] | 40 | kwds["size"] = wx.Size(_STATICBOX_WIDTH,PANEL_SIZE) |
---|
[da9ac4e6] | 41 | wx.Dialog.__init__(self, parent, id = id, *args, **kwds) |
---|
[519c693] | 42 | |
---|
[da9ac4e6] | 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, |
---|
[519c693] | 59 | style = wx.TRANSPARENT_WINDOW) |
---|
[da9ac4e6] | 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() |
---|
[519c693] | 74 | |
---|
[da9ac4e6] | 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 | """ |
---|
[519c693] | 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)) |
---|
[da9ac4e6] | 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()) |
---|
[519c693] | 100 | sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) |
---|
| 101 | sizer.Add((0,10)) |
---|
| 102 | |
---|
[da9ac4e6] | 103 | self.SetSizerAndFit(sizer) |
---|
[519c693] | 104 | |
---|
[da9ac4e6] | 105 | self.Centre() |
---|
| 106 | self.Show(True) |
---|
[519c693] | 107 | button_reset.SetFocus() |
---|
| 108 | |
---|
[da9ac4e6] | 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 | """ |
---|
[519c693] | 138 | def __init__(self, parent,axes = [], id = -1, color = None, dpi = None, |
---|
[da9ac4e6] | 139 | **kwargs): |
---|
| 140 | """ |
---|
| 141 | """ |
---|
[519c693] | 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 | |
---|
[da9ac4e6] | 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 = [] |
---|
[519c693] | 153 | for idx in range(0, len(axes)): |
---|
[da9ac4e6] | 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, |
---|
[519c693] | 203 | wx.Size(_STATICBOX_WIDTH,PANEL_SIZE)) |
---|
[da9ac4e6] | 204 | |
---|
| 205 | # Panel for 1D plot |
---|
[519c693] | 206 | self.plotpanel = SLDplotpanel(self, -1, style = wx.RAISED_BORDER) |
---|
[da9ac4e6] | 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() |
---|