Changeset 7975f2b in sasview for sansview/perspectives/fitting/basepage.py
- Timestamp:
- Dec 13, 2009 4:48:11 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- fe9c19b4
- Parents:
- 7ab35154
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
redd166b r7975f2b 7 7 import math 8 8 import string 9 from sans.guiframe.utils import format_number,check_float 10 from sans.guicomm.events import StatusEvent 9 from sans.guiframe.utils import format_number,check_float,check_value 10 from sans.guicomm.events import StatusEvent 11 11 import pagestate 12 12 from pagestate import PageState … … 163 163 kill_focus_callback = None, set_focus_callback = None, 164 164 mouse_up_callback = None, text_enter_callback = None): 165 165 166 166 wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) 167 167 … … 208 208 if start==end: 209 209 control.SetSelection(-1,-1) 210 210 211 211 212 212 def onContextMenu(self, event): … … 455 455 #TODO: total hack - fix this 456 456 self.state.model= self.model.clone() 457 #if not hasattr(self.model, "_persistency_dict"): 457 458 458 self.model._persistency_dict = {} 459 459 self.model._persistency_dict[p] = [self.values, self.weights] … … 499 499 500 500 self.state.model.name= self.model.name 501 #if not hasattr(self.model, "_persistency_dict"):502 #self.model._persistency_dict = {}503 #self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict)504 501 505 502 #Remember fit engine_type for fit panel … … 508 505 if self.manager !=None: 509 506 self.manager._on_change_engine(engine=self.engine_type) 510 #self.engine_type = self.manager._return_engine_type()511 507 512 508 self.state.engine_type = self.engine_type … … 820 816 self.model.set_dispersion(item, disp_model) 821 817 822 #self.model._persistency_dict = {}823 818 self.model._persistency_dict[item] = [state.values, state.weights] 824 819 … … 925 920 use : _check_value_enter 926 921 """ 922 # Flag to register when a parameter has changed. 923 is_modified = False 927 924 #self._undo.Enable(True) 928 925 if self.model !=None: 929 # Flag to register when a parameter has changed.930 is_modified = False931 926 try: 932 927 is_modified =self._check_value_enter( self.fittable_param ,is_modified) … … 940 935 # If qmin and qmax have been modified, update qmin and qmax and 941 936 # set the is_modified flag to True 942 from sans.guiframe.utils import check_value943 937 if check_value( self.qmin, self.qmax): 944 if float(self.qmin.GetValue()) != self.qmin_x: 945 self.qmin_x = float(self.qmin.GetValue()) 938 tempmin = float(self.qmin.GetValue()) 939 if tempmin != self.qmin_x: 940 self.qmin_x = tempmin 946 941 is_modified = True 947 if float(self.qmax.GetValue()) != self.qmax_x: 948 self.qmax_x = float(self.qmax.GetValue()) 942 tempmax = float(self.qmax.GetValue()) 943 if tempmax != self.qmax_x: 944 self.qmax_x = tempmax 949 945 is_modified = True 950 946 self.fitrange = True … … 953 949 if self.npts != None: 954 950 if check_float(self.npts): 955 if float(self.npts.GetValue()) != self.num_points: 956 self.num_points = float(self.npts.GetValue()) 951 temp_npts = float(self.npts.GetValue()) 952 if temp_npts != self.num_points: 953 self.num_points = temp_npts 957 954 is_modified = True 958 955 else: … … 965 962 self.state_change= True 966 963 self._draw_model() 967 self.Layout() 968 self.Refresh() 969 964 self._sleep4sec() 965 self.Layout() 966 self.Refresh() 967 return is_modified 968 970 969 def _update_paramv_on_fit(self): 971 970 """ 972 971 make sure that update param values just before the fitting 973 972 """ 974 from sans.guiframe.utils import check_value975 973 #flag for qmin qmax check values 976 974 flag =False … … 985 983 986 984 # If qmin and qmax have been modified, update qmin and qmax and 985 # Here we should check whether the boundaries have been modified. 986 # If qmin and qmax have been modified, update qmin and qmax and 987 # set the is_modified flag to True 987 988 if check_value( self.qmin, self.qmax): 988 if float(self.qmin.GetValue()) != self.qmin_x: 989 self.qmin_x = float(self.qmin.GetValue()) 990 991 if float(self.qmax.GetValue()) != self.qmax_x: 992 self.qmax_x = float(self.qmax.GetValue()) 989 tempmin = float(self.qmin.GetValue()) 990 if tempmin != self.qmin_x: 991 self.qmin_x = tempmin 992 tempmax = float(self.qmax.GetValue()) 993 if tempmax != self.qmax_x: 994 self.qmax_x = tempmax 993 995 flag = True 994 995 if self.npts != None: 996 if check_float(self.npts): 997 if float(self.npts.GetValue()) != self.num_points: 998 self.num_points = float(self.npts.GetValue()) 996 else: 997 flag = False 999 998 else: 999 flag = False 1000 1000 msg= "Cannot Fit :Must select a model!!! " 1001 1001 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) … … 1231 1231 if self.enable_smearer.GetValue(): 1232 1232 temp_smear= self.smearer 1233 1234 1233 self.manager.draw_model(self.model, data=self.data, 1235 1234 smearer= temp_smear, … … 1400 1399 1401 1400 return 0 1401 1402 def _onparamEnter(self,event): 1403 """ 1404 when enter value on panel redraw model according to changed 1405 """ 1406 tcrtl= event.GetEventObject() 1407 1408 #Clear msg if previously shown. 1409 msg= "" 1410 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1411 1412 ## save current state 1413 self.save_current_state() 1414 if event !=None: 1415 #self._undo.Enable(True) 1416 event = PageInfoEvent(page = self) 1417 wx.PostEvent(self.parent, event) 1418 1419 if check_float(tcrtl): 1420 1421 self._onparamEnter_helper() 1422 event.Skip() 1423 else: 1424 msg= "Cannot Plot :Must enter a number!!! " 1425 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1426 event.Skip() 1427 return 1402 1428 1403 1429 … … 1447 1473 self.disp_list =self.model.getDispParamList() 1448 1474 self.state.disp_list = self.disp_list 1449 #self.sizer4_4.Layout() 1450 self.Layout() 1451 #self.SetScrollbars(20,20,25,65) 1452 #self.Refresh() 1453 1454 1455 1456 def _onparamEnter(self,event): 1457 """ 1458 when enter value on panel redraw model according to changed 1459 """ 1460 1461 tcrtl= event.GetEventObject() 1462 1463 #Clear msg if previously shown. 1464 msg= "" 1465 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1466 1467 ## save current state 1468 self.save_current_state() 1469 if event !=None: 1470 #self._undo.Enable(True) 1471 event = PageInfoEvent(page = self) 1472 wx.PostEvent(self.parent, event) 1475 self.Layout() 1476 1473 1477 1474 if check_float(tcrtl):1475 1476 self._onparamEnter_helper()1477 1478 else:1479 msg= "Cannot Plot :Must enter a number!!! "1480 wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))1481 return1482 1483 1484 1478 def _check_value_enter(self, list, modified): 1485 1479 """ … … 1491 1485 if len(list)==0: 1492 1486 return is_modified 1493 1494 1487 for item in list: 1495 1488 #skip angle parameters for 1D … … 1504 1497 param_min= None 1505 1498 param_max= None 1506 1499 1507 1500 ## check minimun value 1508 1501 if item[5]!= None and item[5]!= "": 1509 1502 if item[5].GetValue().lstrip().rstrip()!="": 1510 1503 try: 1504 1511 1505 param_min = float(item[5].GetValue()) 1506 if check_value(item[2],item[5]): 1507 if numpy.isfinite(param_min): 1508 item[2].SetValue(format_number(param_min)) 1509 item[2].SetBackgroundColour(wx.WHITE) 1512 1510 except: 1513 1511 msg = "Wrong Fit parameter range entered " … … 1516 1514 is_modified = True 1517 1515 ## check maximum value 1518 if item[6]!= None and item[ 5]!= "":1516 if item[6]!= None and item[6]!= "": 1519 1517 if item[6].GetValue().lstrip().rstrip()!="": 1520 try: 1518 try: 1521 1519 param_max = float(item[6].GetValue()) 1520 if check_value(item[6],item[2]): 1521 if numpy.isfinite(param_max): 1522 item[2].SetValue(format_number(param_max)) 1523 item[2].SetBackgroundColour(wx.WHITE) 1522 1524 except: 1523 1525 msg = "Wrong Fit parameter range entered " … … 1525 1527 raise ValueError, msg 1526 1528 is_modified = True 1527 from sans.guiframe.utils import check_value1529 1528 1530 1529 1531 if param_min != None and param_max !=None: … … 1532 1534 msg+= "name %s of model %s "%(name, self.model.name) 1533 1535 wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) 1534 1536 1535 1537 if name in self.model.details.keys(): 1536 if param_min != self.model.details[name][1] or param_max != self.model.details[name][2]:1537 1538 self.model.details[name][1:3]= param_min,param_max 1538 1539 is_modified = True 1539 1540 1540 1541 else: 1541 self.model.details [name] = ["",param_min,param_max]1542 is_modified = True1543 1542 self.model.details [name] = ["",param_min,param_max] 1543 is_modified = True 1544 1544 1545 value= float(item[2].GetValue()) 1545 1546 1546 1547 # If the value of the parameter has changed, 1547 1548 # +update the model and set the is_modified flag 1548 if value != self.model.getParam(name) :1549 if value != self.model.getParam(name) and numpy.isfinite(value): 1549 1550 self.model.setParam(name,value) 1550 1551 is_modified = True … … 1645 1646 self.save_current_state() 1646 1647 self.sizer4_4.Clear(True) 1647 #self.sizer4_4.Layout()1648 #self.sizer4.Layout()1649 1648 self.Layout() 1650 #self.Refresh() 1651 #self.SetScrollbars(20,20,25,65) 1649 1652 1650 return 1653 1651 if (len(self.disp_cb_dict)>0) : … … 1663 1661 1664 1662 pass 1665 # Redraw the model 1666 #self._draw_model() 1663 1667 1664 ## save state into 1668 1665 self.save_current_state() 1669 #self.sizer4_4.Layout() 1670 #self.sizer4.Layout() 1671 self.Layout() 1672 #self.SetScrollbars(20,20,25,65) 1666 self.Layout() 1673 1667 self.Refresh() 1674 1675 1668 1676 1669 1677 1670 def _on_select_Disp(self,event): … … 1683 1676 name = self.disp_box.GetValue() 1684 1677 dispersity= self.disp_box.GetClientData(n) 1685 1686 1678 self.disp_name = name 1687 1679 … … 1698 1690 wx.PostEvent(self.parent, event) 1699 1691 1700 #self.sizer4_4.Layout() 1701 #self.sizer4.Layout() 1702 #self.Layout() 1692 self.sizer4_4.Layout() 1693 self.sizer4.Layout() 1703 1694 self.SetScrollbars(20,20,25,65) 1704 #self.Refresh()1705 1695 1706 1696 def _set_sizer_arraydispersion(self): … … 1747 1737 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() 1748 1738 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) 1749 #wx.EVT_RADIOBUTTON(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle)1750 1739 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1751 1740 … … 1757 1746 if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): 1758 1747 self.disp_cb_dict[p].Hide() 1759 #self.disp_cb_dict[p].Disable()1760 1748 else: 1761 1749 self.disp_cb_dict[p].Show(True) 1762 #self.disp_cb_dict[p].Enable()1763 1750 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) 1764 #wx.EVT_RADIOBUTTON(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle)1765 1751 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1766 1752 … … 1769 1755 iy +=1 1770 1756 self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1771 #self.sizer4_4.Layout()1772 #self.sizer4.Layout()1773 1757 self.Layout() 1774 #self.SetScrollbars(20,20,25,65)1775 ## save state into1776 1758 1777 1759 self.state.orientation_params =[] … … 1815 1797 boxsizer1 = box_sizer 1816 1798 1817 self.qmin = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER)1799 self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER) 1818 1800 self.qmin.SetValue(str(self.qmin_x)) 1819 1801 self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 1820 #self.qmin.Bind(wx.EVT_SET_FOCUS, self.onSetFocus)1821 #self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)1822 #self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)1823 1802 1824 self.qmax = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER)1803 self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER) 1825 1804 self.qmax.SetValue(str(self.qmax_x)) 1826 1805 self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 1827 #self.qmax.Bind(wx.EVT_SET_FOCUS, self.onSetFocus)1828 #self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)1829 #self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)1830 1806 1831 1807 id = wx.NewId() 1832 1808 self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) 1809 1833 1810 self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) 1834 1811 self.reset_qrange.SetToolTipString("Reset Q range to the default values") … … 1857 1834 self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 1858 1835 self.sizer5.Layout() 1859 #self.Layout() 1860 #self.SetScrollbars(20,20,25,65) 1861 1836 1862 1837 1863 1838 def _fill_save_sizer(self): … … 1887 1862 self.sizer6.Layout() 1888 1863 self.SetScrollbars(20,20,25,65) 1889 1864 1865 def _lay_out(self): 1866 """ 1867 returns self.Layout 1868 Note: Mac seems to like this better when self.Layout is called after fitting. 1869 """ 1870 self._sleep4sec() 1871 self.Layout() 1872 self._sleep4sec() 1873 return 1874 1875 def _sleep4sec(self): 1876 """ 1877 sleep for 0.5 sec only on Mac 1878 """ 1879 if ON_MAC == True: 1880 time.sleep(0.5) 1881 1890 1882 def on_reset_clicked(self,event): 1891 1883 """ … … 1907 1899 self.num_points = _NPTS_DEFAULT 1908 1900 self.state.npts = self.num_points 1909 1901 1902 1910 1903 self.state.qmin = self.qmin_x 1911 1904 self.state.qmax = self.qmax_x
Note: See TracChangeset
for help on using the changeset viewer.