source: sasview/sansview/perspectives/fitting/ftol_dialog.py @ 309a1f0

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 309a1f0 was e7f70e8, checked in by Jae Cho <jhjcho@…>, 13 years ago

fixed ftol setting bug

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