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 | ################################################################################ |
---|
11 | import wx |
---|
12 | import sys |
---|
13 | from sans.guiframe.events import StatusEvent |
---|
14 | # default ftol |
---|
15 | F_TOL = 1.49012e-08 |
---|
16 | |
---|
17 | if sys.platform.count("win32") > 0: |
---|
18 | PANEL_WIDTH = 270 |
---|
19 | PANEL_HEIGHT = 250 |
---|
20 | FONT_VARIANT = 0 |
---|
21 | else: |
---|
22 | PANEL_WIDTH = 285 |
---|
23 | PANEL_HEIGHT = 255 |
---|
24 | FONT_VARIANT = 1 |
---|
25 | |
---|
26 | """ |
---|
27 | Dialog to set ftol for Scipy |
---|
28 | |
---|
29 | ftol(float): Relative error desired in the sum of squares. |
---|
30 | """ |
---|
31 | class 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 |
---|
113 | self.parent.parent._manager.set_ftol(self.ftol) |
---|
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 |
---|
118 | wx.PostEvent( self.parent.parent._manager.parent, |
---|
119 | StatusEvent(status= msg, info='warning')) |
---|
120 | |
---|
121 | self.Destroy() |
---|
122 | |
---|