source: sasview/fittingview/src/sans/perspectives/fitting/ftol_dialog.py @ ac2b835

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 ac2b835 was f32d144, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Pep-8-ification

  • Property mode set to 100644
File size: 4.6 KB
Line 
1"""
2Dialog to set ftol for Scipy
3
4    ftol(float): Relative error desired in the sum of squares.
5"""
6################################################################################
7#This software was developed by the University of Tennessee as part of the
8#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
9#project funded by the US National Science Foundation.
10#
11#See the license text in license.txt
12#
13#copyright 2009, University of Tennessee
14################################################################################
15import wx
16import sys
17from sans.guiframe.events import StatusEvent
18# default ftol
19F_TOL = 1.49012e-08
20SANS_F_TOL = 5e-05
21
22if sys.platform.count("win32") > 0:
23    PANEL_WIDTH = 270
24    PANEL_HEIGHT = 265
25    FONT_VARIANT = 0
26else:
27    PANEL_WIDTH = 285
28    PANEL_HEIGHT = 265
29    FONT_VARIANT = 1
30   
31   
32class ChangeFtol(wx.Dialog):
33    """
34    Dialog to select ftol
35    """
36    def __init__(self, parent, base, id=-1, title="FTolerance"):
37        wx.Dialog.__init__(self, parent, id, title,
38                           size=(PANEL_WIDTH, PANEL_HEIGHT))
39        # parent
40        self.parent = base
41        # default ftol
42        self.ftol = SANS_F_TOL
43        # font size
44        self.SetWindowVariant(variant=FONT_VARIANT)
45        # build layout
46        panel = wx.Panel(self, -1)
47        vbox = wx.BoxSizer(wx.VERTICAL)
48        wx.StaticBox(panel, -1, 'FTol selection (Leastsq)', (5, 6),
49                      (PANEL_WIDTH * 0.9, PANEL_HEIGHT * 0.7))
50        default_bt = wx.RadioButton(panel, -1, 'SansView Default (5e-05)',
51                                    (15, 30),
52                                    style=wx.RB_GROUP)
53        default_bt.SetValue(True)
54        default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
55        sci_default_bt = wx.RadioButton(panel, -1,
56                                    'Scipy Default (1.49012e-08)', (15, 55))
57        sci_default_bt.SetValue(False)
58        sci_default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
59        high_bt = wx.RadioButton(panel, -1, '1e-06', (15, 80))
60        high_bt.SetValue(False)
61        high_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
62        mid_bt = wx.RadioButton(panel, -1, '1e-05', (15, 105))
63        mid_bt.SetValue(False)
64        mid_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
65        low_bt = wx.RadioButton(panel, -1, '1e-04', (15, 130))
66        low_bt.SetValue(False)
67        low_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
68        self.custom_bt = wx.RadioButton(panel, -1, 'Custom', (15, 155))
69        self.custom_bt.SetValue(False)
70        self.custom_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
71        self.custombox = wx.TextCtrl(panel, -1, '', (95, 155))
72        self.custombox.Disable()
73        hbox = wx.BoxSizer(wx.HORIZONTAL)
74        okButton = wx.Button(self, -1, 'Set', size=(70, 30))
75        hbox.Add(okButton, 1, wx.RIGHT, 5)
76        okButton.Bind(wx.EVT_BUTTON, self.OnClose)
77        vbox.Add(panel)
78        vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
79        # set sizer
80        self.SetSizer(vbox)
81
82    def OnFtolSelection(self, event=None):
83        """
84        Changes the ftol on selection of the radio button
85        """
86        event.Skip()
87        # event object and selection
88        button = event.GetEventObject()
89        selection = button.GetLabel()
90        # get float value
91        if selection.count('SansView') > 0:
92            ftol = SANS_F_TOL
93            self.custombox.Disable()
94        elif selection.count('Scipy') > 0:
95            ftol = F_TOL
96            self.custombox.Disable()
97        elif selection == 'Custom':
98            ftol = F_TOL
99            self.custombox.Enable(True)
100        else:
101            ftol = float(selection)
102            self.custombox.Disable()
103        self.ftol = ftol
104       
105    def OnClose(self, event):
106        """
107        Close event
108        """
109        # clear event
110        event.Skip()
111        flag = True
112        # I case of the custom ftol
113        if self.custom_bt.GetValue():
114            try:
115                ftol = float(self.custombox.GetValue())
116                self.ftol = ftol
117            except:
118                flag = False
119        if flag:
120            # set ftol in fitting
121            self.parent.set_ftol(self.ftol)
122            msg = "The ftol (LeastSq) is set to %s." % self.ftol
123        else:
124            msg = "Error in the selection... No changes in ftol."
125        # post event for info
126        wx.PostEvent(self.parent.parent,
127                    StatusEvent(status=msg, info='warning'))
128   
129        self.Destroy()
Note: See TracBrowser for help on using the repository browser.