[a1b2471] | 1 | import wx |
---|
| 2 | import sys |
---|
| 3 | |
---|
[fb59ed9] | 4 | from copy import deepcopy |
---|
[a1b2471] | 5 | from danse.common.plottools.PlotPanel import PlotPanel |
---|
| 6 | from danse.common.plottools.plottables import Graph |
---|
| 7 | from sans.guiframe.dataFitting import Theory1D |
---|
| 8 | import pylab |
---|
| 9 | |
---|
| 10 | DEFAULT_CMAP= pylab.cm.jet |
---|
| 11 | |
---|
| 12 | _BOX_WIDTH = 76 |
---|
| 13 | _STATICBOX_WIDTH = 400 |
---|
| 14 | _SCALE = 1e-6 |
---|
| 15 | |
---|
| 16 | #SLD panel size |
---|
| 17 | if sys.platform.count("win32")>0: |
---|
| 18 | _STATICBOX_WIDTH = 380 |
---|
[fb59ed9] | 19 | PANEL_SIZE = 475 |
---|
[a1b2471] | 20 | FONT_VARIANT = 0 |
---|
| 21 | else: |
---|
| 22 | _STATICBOX_WIDTH = 410 |
---|
[fb59ed9] | 23 | PANEL_SIZE = 505 |
---|
[a1b2471] | 24 | FONT_VARIANT = 1 |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | class 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 |
---|
[fb59ed9] | 38 | def __init__(self, parent=None,base=None,data =None,axes =['Radius'], id = -1, *args, **kwds): |
---|
[a1b2471] | 39 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
[fb59ed9] | 40 | kwds["size"] = wx.Size(_STATICBOX_WIDTH*1.5,PANEL_SIZE) |
---|
[a1b2471] | 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 | |
---|
[fb59ed9] | 56 | # Panel for plot |
---|
| 57 | self.plotpanel = SLDplotpanel(self, axes, -1, style=wx.TRANSPARENT_WINDOW) |
---|
[a1b2471] | 58 | self.cmap = DEFAULT_CMAP |
---|
| 59 | ## Create Artist and bind it |
---|
| 60 | self.subplot = self.plotpanel.subplot |
---|
| 61 | |
---|
| 62 | self._setup_layout() |
---|
[fb59ed9] | 63 | data_plot = deepcopy(self.data) |
---|
| 64 | self.newplot=Theory1D(data_plot.x,data_plot.y) |
---|
[a1b2471] | 65 | self.newplot.name = 'SLD' |
---|
| 66 | self.plotpanel.add_image(self.newplot) |
---|
| 67 | |
---|
| 68 | self.Centre() |
---|
| 69 | self.Layout() |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | def _setup_layout(self): |
---|
| 73 | """ |
---|
| 74 | Set up the layout |
---|
| 75 | """ |
---|
| 76 | # panel |
---|
| 77 | sizer = wx.GridBagSizer(14,14) |
---|
| 78 | |
---|
[fb59ed9] | 79 | sizer.Add(self.plotpanel,(0, 0), (13, 13), wx.EXPAND | wx.LEFT| wx.RIGHT, 1) |
---|
[a1b2471] | 80 | |
---|
| 81 | #-----Button------------1 |
---|
| 82 | id = wx.NewId() |
---|
| 83 | button_reset = wx.Button(self, id, "Close") |
---|
| 84 | button_reset.SetToolTipString("Close...") |
---|
| 85 | button_reset.Bind(wx.EVT_BUTTON, self._close, id = button_reset.GetId()) |
---|
| 86 | sizer.Add(button_reset, (13, 12), flag=wx.RIGHT | wx.BOTTOM, border=15) |
---|
| 87 | |
---|
| 88 | sizer.AddGrowableCol(2) |
---|
| 89 | sizer.AddGrowableRow(3) |
---|
| 90 | self.SetSizerAndFit(sizer) |
---|
| 91 | button_reset.SetFocus() |
---|
| 92 | self.Centre() |
---|
| 93 | self.Show(True) |
---|
| 94 | |
---|
| 95 | def _close(self, event): |
---|
| 96 | """ |
---|
| 97 | Close the dialog |
---|
| 98 | """ |
---|
| 99 | |
---|
| 100 | self.Close(True) |
---|
| 101 | |
---|
| 102 | def _draw_model(self,event): |
---|
| 103 | """ |
---|
| 104 | on_close, update the model2d plot |
---|
| 105 | """ |
---|
| 106 | pass |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | class SLDplotpanel(PlotPanel): |
---|
| 110 | """ |
---|
| 111 | Panel |
---|
| 112 | """ |
---|
[fb59ed9] | 113 | def __init__(self, parent,axes=[], id = -1, color = None, dpi = None, **kwargs): |
---|
[a1b2471] | 114 | """ |
---|
| 115 | """ |
---|
| 116 | PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs) |
---|
| 117 | # Keep track of the parent Frame |
---|
| 118 | self.parent = parent |
---|
| 119 | # Internal list of plottable names (because graph |
---|
| 120 | # doesn't have a dictionary of handles for the plottables) |
---|
| 121 | self.plots = {} |
---|
| 122 | self.graph = Graph() |
---|
[fb59ed9] | 123 | self.axes_label = [] |
---|
| 124 | for idx in range(0,len(axes)): |
---|
| 125 | self.axes_label.append(axes[idx]) |
---|
[a1b2471] | 126 | |
---|
| 127 | def add_image(self, plot): |
---|
| 128 | """ |
---|
| 129 | Add image(Theory1D) |
---|
| 130 | """ |
---|
| 131 | self.plots[plot.name] = plot |
---|
| 132 | #init graph |
---|
| 133 | self.gaph = Graph() |
---|
| 134 | #add plot |
---|
| 135 | self.graph.add(plot) |
---|
| 136 | #add axes |
---|
[fb59ed9] | 137 | x1_label = self.axes_label[0] |
---|
| 138 | self.graph.xaxis('\\rm{%s} '% x1_label, '\\AA') |
---|
[a1b2471] | 139 | self.graph.yaxis('\\rm{SLD} ', '\\AA^{-2}') |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | #draw |
---|
| 143 | self.graph.render(self) |
---|
| 144 | self.subplot.figure.canvas.draw_idle() |
---|
| 145 | |
---|
| 146 | def onContextMenu(self, event): |
---|
| 147 | """ |
---|
| 148 | Default context menu for a plot panel |
---|
| 149 | |
---|
| 150 | """ |
---|
| 151 | pass |
---|
| 152 | |
---|
| 153 | def on_set_focus(self, event): |
---|
| 154 | """ |
---|
| 155 | send to the parenet the current panel on focus |
---|
| 156 | |
---|
| 157 | """ |
---|
| 158 | #Not implemented |
---|
| 159 | pass |
---|
| 160 | |
---|
| 161 | def on_kill_focus(self, event): |
---|
| 162 | """ |
---|
| 163 | reset the panel color |
---|
| 164 | |
---|
| 165 | """ |
---|
| 166 | #Not implemented |
---|
| 167 | pass |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | class ViewerFrame(wx.Frame): |
---|
| 171 | """ |
---|
| 172 | Add comment |
---|
| 173 | """ |
---|
| 174 | def __init__(self, parent, id, title): |
---|
| 175 | """ |
---|
| 176 | comment |
---|
| 177 | :param parent: parent panel/container |
---|
| 178 | """ |
---|
| 179 | # Initialize the Frame object |
---|
| 180 | wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850)) |
---|
| 181 | |
---|
| 182 | # Panel for 1D plot |
---|
| 183 | self.plotpanel = SLDplotpanel(self, -1, style=wx.RAISED_BORDER) |
---|
| 184 | |
---|
| 185 | class ViewApp(wx.App): |
---|
| 186 | def OnInit(self): |
---|
| 187 | frame = ViewerFrame(None, -1, 'testView') |
---|
| 188 | frame.Show(True) |
---|
| 189 | self.SetTopWindow(frame) |
---|
| 190 | |
---|
| 191 | return True |
---|
| 192 | |
---|
| 193 | if __name__ == "__main__": |
---|
| 194 | app = ViewApp(0) |
---|
| 195 | app.MainLoop() |
---|