source: sasview/guitools/fitDialog.py @ 6cfe703

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 6cfe703 was 6cfe703, checked in by Gervaise Alina <gervyh@…>, 16 years ago

fixing X(2)

  • Property mode set to 100644
File size: 4.0 KB
Line 
1#!/usr/bin/python
2
3# fitDialog.py
4
5import wx
6from sans.guitools.PlotPanel import PlotPanel
7
8class LinearFit(wx.Dialog):
9    def __init__(self, parent, id, title):
10        wx.Dialog.__init__(self, parent, id, title, size=(500, 300))
11        """
12            for the fit window
13        """
14        self.parent = parent
15        panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)   
16        vbox  = wx.BoxSizer(wx.VERTICAL)
17        sizer = wx.GridBagSizer(5,0)
18        vbox.Add(panel, 1, wx.EXPAND | wx.ALL)
19 
20        self.tcA = wx.TextCtrl(panel, -1,style=wx.SIMPLE_BORDER)
21        self.tcErrA = wx.TextCtrl(panel, -1,style=wx.SIMPLE_BORDER)
22        self.tcB = wx.TextCtrl(panel, -1,style=wx.SIMPLE_BORDER)
23        self.tcErrB = wx.TextCtrl(panel, -1,style=wx.SIMPLE_BORDER)
24        self.tcChi = wx.TextCtrl(panel, -1,style=wx.SIMPLE_BORDER)
25        self.tcXmin = wx.TextCtrl(panel,-1,style=wx.SIMPLE_BORDER)
26        self.tcXmax = wx.TextCtrl(panel,-1,style=wx.SIMPLE_BORDER)
27        self.btFit =wx.Button(panel,-1,'Fit' )
28        btClose =wx.Button(panel, wx.ID_CANCEL,'Close' )
29       
30        ix = 1
31        iy = 1
32        sizer.Add(wx.StaticText(panel, -1, 'y = Ax +B'),(iy, ix))
33        ix = 1
34        iy += 2
35        sizer.Add(wx.StaticText(panel, -1, 'Param A'),(iy, ix))
36        ix += 1
37        sizer.Add(self.tcA, (iy, ix))
38        ix += 1
39        sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix))
40        ix += 1
41        sizer.Add(self.tcErrA, (iy, ix))
42        #self.tcErrA.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
43        iy += 1
44        ix = 1
45        sizer.Add(wx.StaticText(panel, -1, 'Param B'),(iy, ix))
46        ix += 1
47        sizer.Add(self.tcB, (iy, ix))
48        #self.tcB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
49        ix += 1
50        # sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix))
51        ix += 1
52        sizer.Add(self.tcErrB, (iy, ix))
53        self.tcErrB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
54        iy += 1
55        ix = 1
56        sizer.Add(wx.StaticText(panel, -1, 'Chi ^{2}'),(iy, ix))
57        ix += 1
58        sizer.Add(self.tcChi, (iy, ix))
59        #self.tcChi.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
60        iy += 1
61        ix = 1
62        sizer.Add(wx.StaticText(panel, -1, 'Xmin'),(iy, ix))
63        ix += 2
64        sizer.Add(wx.StaticText(panel, -1, 'Xmax'),(iy, ix))
65        iy += 1
66        ix = 1
67        sizer.Add(self.tcXmin, (iy, ix))
68        #self.tcXmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
69        ix += 2
70        sizer.Add(self.tcXmax, (iy, ix))
71        #self.tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
72        iy += 1
73        ix = 1
74        sizer.Add(self.btFit, (iy, ix))
75        self.tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onFit)
76        ix += 2
77        sizer.Add(btClose, (iy, ix))
78       
79        panel.SetSizer(sizer)
80        self.SetSizer(vbox)
81        self.Centre()
82    def _onFit(self ,event):
83         param_evt1 = PlotPanel.FunctionFitEvent(\
84            Xmin=self._checkVal(self.tcXmin.GetValue()),\
85            Xmax=self._checkVal(self.tcXmax.GetValue())                                     )
86         wx.PostEvent(self, param_evt1)
87   
88    def _onsetValues(self,cstA,cstB,errA,errB,Chi):
89       
90         self.tcA.SetValue(cstA)
91         self.tcB.SetValue(cstB)
92         self.tcErrA.SetValue(cstB)
93         self.tcErrB.SetValue(cstA)
94         self.tcChi.SetValue(Chi)
95    def _getXrange(self):
96        if self.tcXmin.GetValue() and self.tcXmax.GetValue():
97            return float(),float(self.tcXmax.GetValue())
98        else:
99            return None, None
100    def _checkVal(self,value):
101        """
102                Ensure that fields parameter contains a value
103                before sending to fit in Plotter1D
104        """
105        try:
106            param = float(value)
107        except:
108            param = None
109        return param
110if __name__ == "__main__": 
111    app = wx.App()
112    dialog=LinearFit(None, -1, 'Fitting')
113    dialog.ShowModal()
114    app.MainLoop()
115
116
Note: See TracBrowser for help on using the repository browser.