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

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

Pep-8-ification

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[f32d144]1"""
2Dialog to set ftol for Scipy
[2296316]3
[f32d144]4    ftol(float): Relative error desired in the sum of squares.
5"""
[2296316]6################################################################################
7#This software was developed by the University of Tennessee as part of the
8#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
[f32d144]9#project funded by the US National Science Foundation.
[2296316]10#
11#See the license text in license.txt
12#
13#copyright 2009, University of Tennessee
14################################################################################
15import wx
16import sys
[f32d144]17from sans.guiframe.events import StatusEvent
[2296316]18# default ftol
[f32d144]19F_TOL = 1.49012e-08
[2c6b224]20SANS_F_TOL = 5e-05
[2296316]21
22if sys.platform.count("win32") > 0:
[f32d144]23    PANEL_WIDTH = 270
[2c6b224]24    PANEL_HEIGHT = 265
[2296316]25    FONT_VARIANT = 0
26else:
27    PANEL_WIDTH = 285
[2c6b224]28    PANEL_HEIGHT = 265
[2296316]29    FONT_VARIANT = 1
30   
[f32d144]31   
[2296316]32class ChangeFtol(wx.Dialog):
33    """
34    Dialog to select ftol
35    """
[2c6b224]36    def __init__(self, parent, base, id=-1, title="FTolerance"):
[f32d144]37        wx.Dialog.__init__(self, parent, id, title,
[2296316]38                           size=(PANEL_WIDTH, PANEL_HEIGHT))
39        # parent
[2c6b224]40        self.parent = base
[2296316]41        # default ftol
[2c6b224]42        self.ftol = SANS_F_TOL
[f32d144]43        # font size
[2296316]44        self.SetWindowVariant(variant=FONT_VARIANT)
45        # build layout
46        panel = wx.Panel(self, -1)
47        vbox = wx.BoxSizer(wx.VERTICAL)
[2c6b224]48        wx.StaticBox(panel, -1, 'FTol selection (Leastsq)', (5, 6),
[f32d144]49                      (PANEL_WIDTH * 0.9, PANEL_HEIGHT * 0.7))
50        default_bt = wx.RadioButton(panel, -1, 'SansView Default (5e-05)',
51                                    (15, 30),
[2296316]52                                    style=wx.RB_GROUP)
53        default_bt.SetValue(True)
[2c6b224]54        default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[f32d144]55        sci_default_bt = wx.RadioButton(panel, -1,
[2c6b224]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))
[2296316]60        high_bt.SetValue(False)
61        high_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]62        mid_bt = wx.RadioButton(panel, -1, '1e-05', (15, 105))
[2296316]63        mid_bt.SetValue(False)
64        mid_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]65        low_bt = wx.RadioButton(panel, -1, '1e-04', (15, 130))
[2296316]66        low_bt.SetValue(False)
67        low_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]68        self.custom_bt = wx.RadioButton(panel, -1, 'Custom', (15, 155))
[2296316]69        self.custom_bt.SetValue(False)
70        self.custom_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]71        self.custombox = wx.TextCtrl(panel, -1, '', (95, 155))
[2296316]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)
[2c6b224]81
[2296316]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()
[f32d144]90        # get float value
[2c6b224]91        if selection.count('SansView') > 0:
[f32d144]92            ftol = SANS_F_TOL
93            self.custombox.Disable()
[2c6b224]94        elif selection.count('Scipy') > 0:
[f32d144]95            ftol = F_TOL
96            self.custombox.Disable()
[2296316]97        elif selection == 'Custom':
[f32d144]98            ftol = F_TOL
[2296316]99            self.custombox.Enable(True)
100        else:
[f32d144]101            ftol = float(selection)
[2296316]102            self.custombox.Disable()
[f32d144]103        self.ftol = ftol
[2296316]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
[f32d144]121            self.parent.set_ftol(self.ftol)
[2c6b224]122            msg = "The ftol (LeastSq) is set to %s." % self.ftol
[2296316]123        else:
[f32d144]124            msg = "Error in the selection... No changes in ftol."
[2296316]125        # post event for info
[f32d144]126        wx.PostEvent(self.parent.parent,
127                    StatusEvent(status=msg, info='warning'))
[2296316]128   
129        self.Destroy()
Note: See TracBrowser for help on using the repository browser.