Changeset 74755ff in sasview
- Timestamp:
- Jun 2, 2010 10:17:18 AM (14 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:
- 6c79243
- Parents:
- a45622a
- Location:
- theoryview
- Files:
-
- 59 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
theoryview/perspectives/theory/basepage.py
re071b1c r74755ff 30 30 class BasicPage(wx.ScrolledWindow): 31 31 """ 32 This class provide general structure of fitpanel page 32 This class provide general structure of fitpanel page 33 33 34 """ 34 35 ## Internal name for the AUI manager … … 154 155 class ModelTextCtrl(wx.TextCtrl): 155 156 """ 156 Text control for model and fit parameters. 157 Binds the appropriate events for user interactions. 158 Default callback methods can be overwritten on initialization 159 160 @param kill_focus_callback: callback method for EVT_KILL_FOCUS event 161 @param set_focus_callback: callback method for EVT_SET_FOCUS event 162 @param mouse_up_callback: callback method for EVT_LEFT_UP event 163 @param text_enter_callback: callback method for EVT_TEXT_ENTER event 157 Text control for model and fit parameters. 158 Binds the appropriate events for user interactions. 159 Default callback methods can be overwritten on initialization 160 161 :param kill_focus_callback: callback method for EVT_KILL_FOCUS event 162 :param set_focus_callback: callback method for EVT_SET_FOCUS event 163 :param mouse_up_callback: callback method for EVT_LEFT_UP event 164 :param text_enter_callback: callback method for EVT_TEXT_ENTER event 165 164 166 """ 165 167 ## Set to True when the mouse is clicked while the whole string is selected … … 189 191 def _on_set_focus(self, event): 190 192 """ 191 Catch when the text control is set in focus to highlight the whole 192 text if necessary 193 @param event: mouse event 193 Catch when the text control is set in focus to highlight the whole 194 text if necessary 195 196 :param event: mouse event 194 197 """ 195 198 … … 202 205 def _highlight_text(self, event): 203 206 """ 204 Highlight text of a TextCtrl only of no text has be selected 205 @param event: mouse event 207 Highlight text of a TextCtrl only of no text has be selected 208 209 :param event: mouse event 210 206 211 """ 207 212 # Make sure the mouse event is available to other listeners … … 218 223 control.SetSelection(-1,-1) 219 224 220 221 225 def onContextMenu(self, event): 222 226 """ 223 Retrieve the state selected state 224 """ 225 # Skipping the save state functionality for release 0.9.0 226 #return 227 227 Retrieve the state selected state 228 229 """ 228 230 pos = event.GetPosition() 229 231 pos = self.ScreenToClient(pos) 230 231 232 self.PopupMenu(self.popUpMenu, pos) 232 233 233 234 234 def onUndo(self, event): 235 235 """ 236 237 """238 #print "enable undo"236 Cancel the previous action 237 238 """ 239 239 event = PreviousStateEvent(page = self) 240 240 wx.PostEvent(self.parent, event) 241 242 241 243 242 def onRedo(self, event): 244 243 """ 245 Restore the previous action cancelled246 """247 #print "enable redo"244 Restore the previous action canceled 245 246 """ 248 247 event = NextStateEvent(page= self) 249 248 wx.PostEvent(self.parent, event) 250 251 249 252 250 def define_page_structure(self): 253 251 """ 254 Create empty sizer for a panel 252 Create empty sizer for a panel 253 255 254 """ 256 255 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 282 281 def set_layout(self): 283 282 """ 284 layout 283 layout 284 285 285 """ 286 286 self.vbox.Layout() 287 287 self.vbox.Fit(self) 288 288 self.SetSizer(self.vbox) 289 290 289 self.set_scroll() 291 290 self.Centre() 292 291 293 294 292 def set_scroll(self): 293 """ 294 """ 295 295 self.SetScrollbars(20,20,25,65) 296 296 self.Layout() 297 297 self.SetAutoLayout(True) 298 298 299 300 def set_owner(self,owner): 299 def set_owner(self, owner): 301 300 """ 302 303 301 set owner of fitpage 302 @param owner: the class responsible of plotting 304 303 """ 305 304 self.event_owner = owner … … 308 307 def set_manager(self, manager): 309 308 """ 310 set panel manager 311 @param manager: instance of plugin fitting 309 set panel manager 310 311 :param manager: instance of plugin fitting 312 312 """ 313 313 self.manager = manager … … 316 316 def populate_box(self, dict): 317 317 """ 318 Store list of model 319 @param dict: dictionary containing list of models 318 Store list of model 319 320 :param dict: dictionary containing list of models 321 320 322 """ 321 323 self.model_list_box = dict 322 324 self.state.model_list_box = self.model_list_box 323 325 324 325 326 326 def set_dispers_sizer(self): 327 327 """ 328 fill sizer containing dispersity info 328 fill sizer containing dispersity info 329 329 330 """ 330 331 self.sizer4.Clear(True) 331 name ="Polydispersity and Orientational Distribution"332 name = "Polydispersity and Orientational Distribution" 332 333 box_description= wx.StaticBox(self, -1,name) 333 334 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 336 337 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 337 338 338 339 339 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) 340 340 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) … … 392 392 def select_disp_angle(self, event): 393 393 """ 394 Event for when a user select a parameter to average over. 395 @param event: radiobutton event 394 Event for when a user select a parameter to average over. 395 396 :param event: radiobutton event 396 397 """ 397 398 self.values=[] … … 479 480 wx.PostEvent(self.parent, event) 480 481 481 482 482 def onResetModel(self, event): 483 483 """ 484 Reset model state 484 Reset model state 485 485 486 """ 486 487 ## post help message for the selected model … … 499 500 def onSave(self, event): 500 501 """ 501 save history of the data and model 502 save history of the data and model 503 502 504 """ 503 505 if self.model==None: … … 536 538 def onSetFocus(self, evt): 537 539 """ 538 539 540 540 highlight the current textcrtl and hide the error text control shown 541 after fitting 542 :Not implemented. 541 543 """ 542 544 return … … 544 546 def read_file(self, path): 545 547 """ 546 Read two columns file 547 @param path: the path to the file to read 548 Read two columns file 549 550 :param path: the path to the file to read 548 551 """ 549 552 try: … … 575 578 def createMemento(self): 576 579 """ 577 580 return the current state of the page 578 581 """ 579 582 return self.state.clone() … … 582 585 def save_current_state(self): 583 586 """ 584 Store current state 587 Store current state 588 585 589 """ 586 590 ## save model option … … 656 660 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 657 661 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 658 659 660 def save_current_state_fit(self): 661 """ 662 Store current state for fit_page 663 """ 664 ## save model option 665 if self.model!= None: 666 self.disp_list= self.model.getDispParamList() 667 self.state.disp_list= copy.deepcopy(self.disp_list) 668 self.state.model = self.model.clone() 669 #if hasattr(self,self.engine_type)> 0: 670 #self.state.engine_type = self.engine_type.clone() 671 self.state.enable2D = copy.deepcopy(self.enable2D) 672 self.state.values= copy.deepcopy(self.values) 673 self.state.weights = copy.deepcopy( self.weights) 674 ## save data 675 self.state.data= copy.deepcopy(self.data) 676 try: 677 n = self.disp_box.GetCurrentSelection() 678 dispersity= self.disp_box.GetClientData(n) 679 name= dispersity.__name__ 680 self.disp_name = name 681 if name == "GaussianDispersion" : 682 if hasattr(self,"cb1"): 683 self.state.cb1= self.cb1.GetValue() 684 685 except: 686 pass 687 688 if hasattr(self,"enable_disp"): 689 self.state.enable_disp= self.enable_disp.GetValue() 690 self.state.disable_disp = self.disable_disp.GetValue() 691 692 self.state.smearer = copy.deepcopy(self.smearer) 693 if hasattr(self,"enable_smearer"): 694 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 695 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 696 697 if hasattr(self,"disp_box"): 698 self.state.disp_box = self.disp_box.GetCurrentSelection() 699 700 if len(self.disp_cb_dict)>0: 701 for k , v in self.disp_cb_dict.iteritems(): 702 703 if v ==None : 704 self.state.disp_cb_dict[k]= v 705 else: 706 try: 707 self.state.disp_cb_dict[k]=v.GetValue() 708 except: 709 self.state.disp_cb_dict[k]= None 710 711 if len(self._disp_obj_dict)>0: 712 for k , v in self._disp_obj_dict.iteritems(): 713 714 self.state._disp_obj_dict[k]= v 715 716 717 self.state.values = copy.deepcopy(self.values) 718 self.state.weights = copy.deepcopy(self.weights) 719 720 ## save plotting range 721 self._save_plotting_range() 722 723 ## save checkbutton state and txtcrtl values 724 self._copy_parameters_state(self.orientation_params, 725 self.state.orientation_params) 726 self._copy_parameters_state(self.orientation_params_disp, 727 self.state.orientation_params_disp) 728 self._copy_parameters_state(self.parameters, self.state.parameters) 729 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 730 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 731 732 662 733 663 def reset_page_helper(self, state): 734 664 """ 735 Use page_state and change the state of existing page 736 @precondition: the page is already drawn or created 737 @postcondition: the state of the underlying data change as well as the 665 Use page_state and change the state of existing page 666 667 :precondition: the page is already drawn or created 668 669 :postcondition: the state of the underlying data change as well as the 738 670 state of the graphic interface 739 671 """ … … 765 697 self.structurebox.SetSelection(state.structurecombobox ) 766 698 self.formfactorbox.SetSelection(state.formfactorcombobox) 767 768 699 769 700 ## enable the view 2d button if this is a modelpage type … … 848 779 ## reset context menu items 849 780 self._reset_context_menu() 850 851 781 ## set the value of the current state to the state given as parameter 852 782 self.state = state.clone() … … 855 785 def _selectDlg(self): 856 786 """ 857 open a dialog file to selected the customized dispersity 787 open a dialog file to selected the customized dispersity 788 858 789 """ 859 790 import os … … 866 797 return path 867 798 868 869 799 def _reset_context_menu(self): 870 800 """ 871 reset the context menu 801 reset the context menu 802 872 803 """ 873 804 for name, state in self.state.saved_states.iteritems(): … … 881 812 def _reset_plotting_range(self, state): 882 813 """ 883 Reset the plotting range to a given state 814 Reset the plotting range to a given state 815 884 816 """ 885 817 self.qmin.SetValue(str(state.qmin)) … … 891 823 def _save_typeOfmodel(self): 892 824 """ 893 save radiobutton containing the type model that can be selected 825 save radiobutton containing the type model that can be selected 826 894 827 """ 895 828 self.state.shape_rbutton = self.shape_rbutton.GetValue() … … 908 841 def _save_plotting_range(self ): 909 842 """ 910 save the state of plotting range 843 save the state of plotting range 844 911 845 """ 912 846 self.state.qmin = self.qmin_x … … 918 852 def _onparamEnter_helper(self): 919 853 """ 920 check if values entered by the user are changed and valid to replot 921 model 922 use : _check_value_enter 854 check if values entered by the user are changed and valid to replot 855 model 856 use : _check_value_enter 857 923 858 """ 924 859 # Flag to register when a parameter has changed. … … 969 904 def _is_modified(self, is_modified): 970 905 """ 971 return to self._is_modified 906 return to self._is_modified 907 972 908 """ 973 909 return is_modified … … 975 911 def _reset_parameters_state(self, listtorestore,statelist): 976 912 """ 977 Reset the parameters at the given state 913 Reset the parameters at the given state 914 978 915 """ 979 916 if len(statelist)==0 or len(listtorestore)==0 : … … 1020 957 else: 1021 958 item_page[6].Hide() 1022 1023 959 1024 960 def _copy_parameters_state(self, listtocopy, statelist): 1025 961 """ 1026 copy the state of button 1027 @param listtocopy: the list of check button to copy 1028 @param statelist: list of state object to store the current state 962 copy the state of button 963 964 :param listtocopy: the list of widgets 's state to copy 965 :param statelist: container for the state of widgets that must be copied 966 1029 967 """ 1030 968 if len(listtocopy)==0: … … 1068 1006 [min_state,min_value],[max_state , max_value],unit]) 1069 1007 1070 1071 1072 1008 def _set_model_sizer_selection(self, model): 1073 1009 """ 1074 Display the sizer according to the type of the current model 1010 Display the sizer according to the type of the current model 1011 1075 1012 """ 1076 1013 if model ==None: … … 1181 1118 break 1182 1119 1183 1184 1120 def _draw_model(self): 1185 1121 """ 1186 Method to draw or refresh a plotted model. 1187 The method will use the data member from the model page 1188 to build a call to the fitting perspective manager. 1189 1190 [Note to coder: This way future changes will be done in only one place.] 1122 Method to draw or refresh a plotted model. 1123 The method will use the data member from the model page 1124 to build a call to the fitting perspective manager. 1125 1126 :Note to coder: This way future changes will be done in only one place. 1127 1191 1128 """ 1192 1129 if self.model !=None: … … 1203 1140 enable2D=self.enable2D) 1204 1141 1205 1206 1142 def _set_model_sizer(self,sizer, box_sizer, title="", object=None): 1207 1143 """ 1208 Use lists to fill a sizer for model info 1144 Use lists to fill a sizer for model info 1145 1209 1146 """ 1210 1147 … … 1304 1241 def _show_combox(self, event): 1305 1242 """ 1306 Show combox box associate with type of model selected 1243 Show combox box associate with type of model selected 1244 1307 1245 """ 1308 1246 ## Don't want to populate combo box again if the event comes from check box … … 1352 1290 def _populate_box(self, combobox, list): 1353 1291 """ 1354 fill combox box with dict item 1355 @param list: contains item to fill the combox 1292 fill combox box with dict item 1293 1294 :param list: contains item to fill the combox 1356 1295 item must model class 1357 1296 """ … … 1368 1307 def _onparamEnter(self,event): 1369 1308 """ 1370 when enter value on panel redraw model according to changed 1309 when enter value on panel redraw model according to changed 1310 1371 1311 """ 1372 1312 tcrtl= event.GetEventObject() … … 1395 1335 def _onQrangeEnter(self, event): 1396 1336 """ 1397 Check validity of value enter in the Q range field 1337 Check validity of value enter in the Q range field 1338 1398 1339 """ 1399 1340 … … 1454 1395 def _on_select_model_helper(self): 1455 1396 """ 1456 call back for model selection 1397 call back for model selection 1398 1457 1399 """ 1458 1400 ## reset dictionary containing reference to dispersion … … 1501 1443 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 1502 1444 """ 1503 Verify that the Q range controls have valid values 1504 and that Qmin < Qmax. 1505 1506 @param qmin_ctrl: text control for Qmin 1507 @param qmax_ctrl: text control for Qmax 1508 @return: True is the Q range is value, False otherwise 1445 Verify that the Q range controls have valid values 1446 and that Qmin < Qmax. 1447 1448 :param qmin_ctrl: text control for Qmin 1449 :param qmax_ctrl: text control for Qmax 1450 1451 :return: True is the Q range is value, False otherwise 1452 1509 1453 """ 1510 1454 qmin_validity = check_float(qmin_ctrl) … … 1533 1477 def _check_value_enter(self, list, modified): 1534 1478 """ 1535 @param list: model parameter and panel info 1536 each item of the list should be as follow: 1537 item=[cb state, name, value, "+/-", error of fit, min, max , units] 1479 :param list: model parameter and panel info 1480 each item of the list should be as follow: :: 1481 1482 item = [cb state, name, value, "+/-", error of fit, min, max , units] 1483 1538 1484 """ 1539 1485 is_modified = modified … … 1560 1506 1561 1507 return is_modified 1562 1563 1508 1564 1509 def _set_dipers_Param(self, event): 1565 1510 """ 1566 respond to self.enable_disp and self.disable_disp radio box. 1567 The dispersity object is reset inside the model into Gaussian. 1568 When the user select yes , this method display a combo box for more selection 1569 when the user selects No,the combo box disappears. 1570 Redraw the model with the default dispersity (Gaussian) 1511 respond to self.enable_disp and self.disable_disp radio box. 1512 The dispersity object is reset inside the model into Gaussian. 1513 When the user select yes , this method display a combo box for more selection 1514 when the user selects No,the combo box disappears. 1515 Redraw the model with the default dispersity (Gaussian) 1516 1571 1517 """ 1572 1518 … … 1613 1559 def _layout_sizer_noDipers(self): 1614 1560 """ 1615 Draw a sizer with no dispersity info 1561 Draw a sizer with no dispersity info 1562 1616 1563 """ 1617 1564 ix=0 … … 1633 1580 def _reset_dispersity(self): 1634 1581 """ 1635 put gaussian dispersity into current model 1582 put gaussian dispersity into current model 1583 1636 1584 """ 1637 1585 if len(self.param_toFit)>0: … … 1678 1626 def _on_select_Disp(self,event): 1679 1627 """ 1680 allow selecting different dispersion 1681 self.disp_list should change type later .now only gaussian 1628 allow selecting different dispersion 1629 self.disp_list should change type later .now only gaussian 1630 1682 1631 """ 1683 1632 n = self.disp_box.GetCurrentSelection() … … 1704 1653 def _set_sizer_arraydispersion(self): 1705 1654 """ 1706 draw sizer with array dispersity parameters 1655 draw sizer with array dispersity parameters 1656 1707 1657 """ 1708 1658 … … 1772 1722 1773 1723 ## save checkbutton state and txtcrtl values 1774 1775 1724 self._copy_parameters_state(self.orientation_params, 1776 1725 self.state.orientation_params) … … 1782 1731 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 1783 1732 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1784 1785 1733 1786 1734 ## post state to fit panel 1787 1735 event = PageInfoEvent(page = self) 1788 1736 wx.PostEvent(self.parent, event) 1789 1737 1790 1791 1792 1793 1794 1738 def _set_range_sizer(self, title, box_sizer=None, object1=None,object=None): 1795 1739 """ 1796 Fill the Q range sizer 1740 Fill the Q range sizer 1741 1797 1742 """ 1798 1743 self.sizer5.Clear(True) … … 1847 1792 self.sizer5.Layout() 1848 1793 1849 1850 1794 def _fill_save_sizer(self): 1851 1795 """ 1852 Draw the layout for saving option 1796 Draw the layout for saving option 1797 1853 1798 """ 1854 1799 # Skipping save state functionality for release 0.9.0 … … 1877 1822 def _lay_out(self): 1878 1823 """ 1879 returns self.Layout 1880 Note: Mac seems to like this better when self.Layout is called after fitting. 1824 returns self.Layout 1825 1826 :Note: Mac seems to like this better when self.Layout 1827 is called after fitting. 1828 1881 1829 """ 1882 1830 self._sleep4sec() … … 1887 1835 def _sleep4sec(self): 1888 1836 """ 1889 sleep for 1 sec only applied on Mac 1890 Note: This 1sec helps for Mac not to crash on self.:ayout after self._draw_model 1837 sleep for 1 sec only applied on Mac 1838 1839 :Note: This 1sec helps for Mac not to crash on 1840 self.layout after self._draw_model 1841 1891 1842 """ 1892 1843 if ON_MAC == True: … … 1895 1846 def on_reset_clicked(self,event): 1896 1847 """ 1897 #On 'Reset' button for Q range clicked 1848 On 'Reset' button for Q range clicked 1849 1898 1850 """ 1899 1851 ##For 3 different cases: Data2D, Data1D, and theory … … 1913 1865 self.state.npts = self.num_points 1914 1866 1915 1916 1867 self.state.qmin = self.qmin_x 1917 1868 self.state.qmax = self.qmax_x … … 1921 1872 #Re draw plot 1922 1873 self._draw_model() 1923 1924 -
theoryview/perspectives/theory/help_panel.py
r82789f1 r74755ff 4 4 from wx.lib.splitter import MultiSplitterWindow 5 5 import os 6 def help():7 """8 Provide general online help text9 Future work: extend this function to allow topic selection10 """11 info_txt = "The inversion approach is based on Moore, J. Appl. Cryst. (1980) 13, 168-175.\n\n"12 info_txt += "P(r) is set to be equal to an expansion of base functions of the type "13 info_txt += "phi_n(r) = 2*r*sin(pi*n*r/D_max). The coefficient of each base functions "14 info_txt += "in the expansion is found by performing a least square fit with the "15 info_txt += "following fit function:\n\n"16 info_txt += "chi**2 = sum_i[ I_meas(q_i) - I_th(q_i) ]**2/error**2 + Reg_term\n\n"17 info_txt += "where I_meas(q) is the measured scattering intensity and I_th(q) is "18 info_txt += "the prediction from the Fourier transform of the P(r) expansion. "19 info_txt += "The Reg_term term is a regularization term set to the second derivative "20 info_txt += "d**2P(r)/dr**2 integrated over r. It is used to produce a smooth P(r) output.\n\n"21 info_txt += "The following are user inputs:\n\n"22 info_txt += " - Number of terms: the number of base functions in the P(r) expansion.\n\n"23 info_txt += " - Regularization constant: a multiplicative constant to set the size of "24 info_txt += "the regularization term.\n\n"25 info_txt += " - Maximum distance: the maximum distance between any two points in the system.\n"26 27 return info_txt28 29 class HelpDialog(wx.Dialog):30 def __init__(self, parent, id):31 32 wx.Dialog.__init__(self, parent, id, size=(400, 420))33 self.SetTitle("P(r) help")34 35 6 36 vbox = wx.BoxSizer(wx.VERTICAL)37 38 explanation = help()39 40 label_explain = wx.StaticText(self, -1, explanation, size=(350,320))41 42 vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15)43 44 45 static_line = wx.StaticLine(self, -1)46 vbox.Add(static_line, 0, wx.EXPAND, 0)47 48 button_OK = wx.Button(self, wx.ID_OK, "OK")49 50 sizer_button = wx.BoxSizer(wx.HORIZONTAL)51 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)52 sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)53 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10)54 55 self.SetSizer(vbox)56 self.SetAutoLayout(True)57 58 self.Layout()59 self.Centre()60 7 61 8 class HelpWindow(wx.Frame): … … 63 10 wx.Frame.__init__(self, parent, id, title, size=(850, 500)) 64 11 """ 65 contains help info 12 Windows containing html documentation for theory application 13 66 14 """ 67 15 … … 135 83 def OnButtonClicked(self, event): 136 84 """ 137 Function to diplay html page related to the hyperlinktext selected 85 Function to diplay html page related to the hyperlinktext selected 86 138 87 """ 139 88 self.rhelp.LoadPage("media/modelfunction.html") … … 141 90 def OnLinkClicked(self, event): 142 91 """ 143 Function to diplay html page related to the hyperlinktext selected 92 Function to diplay html page related to the hyperlinktext selected 93 144 94 """ 145 95 link= event.GetLinkInfo().GetHref() 146 96 self.rhelp.LoadPage(link) 97 147 98 148 99 class ViewApp(wx.App): -
theoryview/perspectives/theory/model_panel.py
r1a94c36 r74755ff 18 18 class ModelPanel(BasicPage): 19 19 """ 20 FitPanel class contains fields allowing to display results when 21 fitting a model and one data 22 @note: For Fit to be performed the user should check at least 20 FitPanel class contains fields allowing to display results when 21 fitting a model and one data 22 23 :note: For Fit to be performed the user should check at least 23 24 one parameter on fit Panel window. 24 25 """ … … 32 33 BasicPage.__init__(self, parent, page_info , model_list_box) 33 34 """ 34 35 Initialization of the Panel 35 36 """ 36 37 self._fill_model_sizer( self.sizer1) … … 48 49 def _on_display_description(self, event): 49 50 """ 50 Show or Hide description 51 @param event: wx.EVT_RADIOBUTTON 51 Show or Hide description 52 53 :param event: wx.EVT_RADIOBUTTON 54 52 55 """ 53 56 self._on_display_description_helper() … … 58 61 def _on_display_description_helper(self): 59 62 """ 60 Show or Hide description 61 @param event: wx.EVT_RADIOBUTTON 63 Show or Hide description 64 65 :param event: wx.EVT_RADIOBUTTON 66 62 67 """ 63 68 ## Show description … … 79 84 def _fill_range_sizer(self): 80 85 """ 81 Fill the sizer containing the plotting range 82 add access to npts 86 Fill the sizer containing the plotting range 87 add access to npts 88 83 89 """ 84 90 ##The following 3 lines are for Mac. Let JHC know before modifying.. … … 100 106 def _on_select_model(self, event): 101 107 """ 102 call back for model selection 108 call back for model selection 109 103 110 """ 104 111 self._on_select_model_helper() … … 110 117 def _fill_model_sizer(self, sizer): 111 118 """ 112 fill sizer containing model info 119 fill sizer containing model info 120 113 121 """ 114 122 ##The following 3 lines are for Mac. Let JHC know before modifying.. … … 129 137 def _set_sizer_dispersion(self, dispersity): 130 138 """ 131 draw sizer with gaussian, log or schulz dispersity parameters 139 draw sizer with gaussian, log or schulz dispersity parameters 140 132 141 """ 133 142 self.fittable_param=[] … … 308 317 def _onModel2D(self, event): 309 318 """ 310 call manager to plot model in 2D 319 call manager to plot model in 2D 320 311 321 """ 312 322 # If the 2D display is not currently enabled, plot the model in 2D … … 356 366 def reset_page(self, state): 357 367 """ 358 reset the state 368 reset the state 369 359 370 """ 360 371 self.reset_page_helper(state) … … 363 374 def select_model(self, model): 364 375 """ 365 Select a new model 366 @param model: model object 376 Select a new model 377 378 :param model: model object 379 367 380 """ 368 381 self.model = model … … 390 403 def set_model_description(self,description,sizer): 391 404 """ 392 fill a sizer with description 393 @param description: of type string 394 @param sizer: wx.BoxSizer() 405 fill a sizer with description 406 407 :param description: of type string 408 :param sizer: wx.BoxSizer() 409 395 410 """ 396 411 … … 442 457 def on_button_clicked(self,event): 443 458 """ 444 #On 'More details' button459 On 'More details' button 445 460 """ 446 461 from help_panel import HelpWindow … … 459 474 wx.PostEvent(self.parent, StatusEvent(status = msg )) 460 475 461 462 463 476 def set_range(self, qmin_x, qmax_x, npts): 464 477 """ 465 Set the range for the plotted models 466 @param qmin: minimum Q 467 @param qmax: maximum Q 468 @param npts: number of Q bins 478 Set the range for the plotted models 479 480 :param qmin: minimum Q 481 :param qmax: maximum Q 482 :param npts: number of Q bins 483 469 484 """ 470 485 # Set the data members … … 472 487 self.qmax_x = qmax_x 473 488 self.num_points = npts 474 475 489 # Set the controls 476 490 #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) 477 478 491 self.qmin.SetValue(str(self.qmin_x)) 479 492 self.qmax.SetValue(str(self.qmax_x)) 480 493 self.npts.SetValue(format_number(self.num_points)) 481 494 482 483 495 def set_model_param_sizer(self, model): 484 496 """ 485 Build the panel from the model content 486 @param model: the model selected in combo box for fitting purpose 497 Build the panel from the model content 498 499 :param model: the model selected in combo box for fitting purpose 500 487 501 """ 488 502 self.sizer3.Clear(True) -
theoryview/perspectives/theory/model_thread.py
r64017a8 r74755ff 6 6 class Calc2D(CalcThread): 7 7 """ 8 Compute 2D model 9 This calculation assumes a 2-fold symmetry of the model 10 where points are computed for one half of the detector 11 and I(qx, qy) = I(-qx, -qy) is assumed. 8 Compute 2D model 9 This calculation assumes a 2-fold symmetry of the model 10 where points are computed for one half of the detector 11 and I(qx, qy) = I(-qx, -qy) is assumed. 12 12 13 """ 13 14 … … 34 35 def compute(self): 35 36 """ 36 Compute the data given a model function 37 Compute the data given a model function 38 37 39 """ 38 40 self.starttime = time.time() … … 105 107 qstep = self.qstep ) 106 108 107 108 109 110 109 class Calc1D(CalcThread): 111 """Compute 1D data""" 110 """ 111 Compute 1D data 112 113 """ 112 114 113 115 def __init__(self, x, model, … … 135 137 def compute(self): 136 138 """ 137 Compute model 1d value given qmin , qmax , x value 139 Compute model 1d value given qmin , qmax , x value 140 138 141 """ 139 142 … … 154 157 self.complete(x= self.x[index], y= output[index], 155 158 elapsed=elapsed, model= self.model, data=self.data) 156 157 158 159 """ 160 Example of use of Calc2D :: 161 159 162 class CalcCommandline: 163 160 164 def __init__(self, n=20000): 161 165 #print thread.get_ident() … … 163 167 164 168 model = CylinderModel() 165 166 167 169 print model.runXY([0.01, 0.02]) 168 170 … … 173 175 x = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 174 176 y = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 175 176 177 177 178 calc_thread_2D = Calc2D(x, y, None, model.clone(),-qmax, qmax,qstep, … … 196 197 CalcCommandline() 197 198 199 """ 200 -
theoryview/perspectives/theory/models.py
rce07fa8 r74755ff 1 #TODO: add comments to document this module 2 #TODO: clean-up the exception handling. 3 4 #TODO: clean-up the FractalAbsModel and PowerLawAbsModel menu items. Those 5 # model definitions do not belong here. They belong with the rest of the 6 # models. 7 1 2 """ 3 This module collects models from sans.models packages and orders theses models 4 by categories that GUI application understands and uses. 5 6 """ 8 7 import wx 9 8 import wx.lib.newevent … … 23 22 24 23 def log(message): 24 """ 25 """ 25 26 out = open("plugins.log", 'a') 26 27 out.write("%10g: %s\n" % (time.clock(), message)) … … 28 29 29 30 def findModels(): 31 """ 32 """ 30 33 log("looking for models in: %s/plugins" % os.getcwd()) 31 34 if os.path.isdir('plugins'): … … 35 38 def _check_plugin(model, name): 36 39 """ 37 Do some checking before model adding plugins in the list 38 @param model: class model to add into the plugin list 39 @param name:name of the module plugin 40 @return model: model if valid model or None if not valid 40 Do some checking before model adding plugins in the list 41 42 :param model: class model to add into the plugin list 43 :param name: name of the module plugin 44 45 :return model: model if valid model or None if not valid 46 41 47 """ 42 48 #Check is the plugin is of type Model1DPlugin … … 74 80 75 81 def _findModels(dir): 82 """ 83 """ 76 84 # List of plugin objects 77 85 plugins = [] … … 114 122 class ModelList(object): 115 123 """ 116 Contains dictionary of model and their type 124 Contains dictionary of model and their type 125 117 126 """ 118 127 def __init__(self): … … 121 130 def set_list(self, name, mylist): 122 131 """ 123 @param name: the type of the list 124 @param mylist: the list to add 132 133 :param name: the type of the list 134 :param mylist: the list to add 135 125 136 """ 126 137 if name not in self.mydict.keys(): … … 130 141 def get_list(self): 131 142 """ 132 143 return all the list stored in a dictionary object 133 144 """ 134 145 return self.mydict 135 146 136 147 class ModelManager: 148 """ 149 ModelManager collected model classes object of available into a 150 dictionary of models' names and models' classes. 151 152 """ 137 153 ## external dict for models 138 154 model_combobox = ModelList() … … 156 172 def _getModelList(self): 157 173 """ 158 List of models we want to make available by default 159 for this application 160 161 @return: the next free event ID following the new menu events 174 Fill up lists of models available by default 175 for the current application 176 177 :return: the next free event ID following the new menu events 178 162 179 """ 163 180 ## form factor … … 293 310 self.shape_indep_list.append(PorodModel ) 294 311 295 296 312 #FractalModel (a c-model)will be used. 297 313 #from sans.models.FractalAbsModel import FractalAbsModel … … 309 325 return 0 310 326 311 312 327 def get_model_list(self): 313 """ @ return dictionary of models for fitpanel use """ 328 """ 329 :return: dictionary of models for fitpanel use 330 331 """ 314 332 self._getModelList() 315 333 self.model_combobox.set_list("Shapes", self.shape_list) … … 319 337 self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor) 320 338 self.model_combobox.set_list("multiplication", self.multiplication_factor) 321 322 339 return self.model_combobox 323 324 325 326 327 328 340 -
theoryview/perspectives/theory/pagestate.py
r0277d084 r74755ff 5 5 class PageState(object): 6 6 """ 7 Contains info to reconstruct a page 7 Contains info to reconstruct a page 8 8 9 """ 9 10 def __init__(self, parent,model=None, data=None): 10 11 11 12 """ 12 Initialization of the Panel 13 Initialization of the Panel 14 13 15 """ 14 16 #TODO: remove this once the inheritence is cleaned up … … 96 98 97 99 def clone(self): 100 """ 101 """ 98 102 model=None 99 103 if self.model !=None: … … 154 158 155 159 def old__repr__(self): 156 """ output string for printing""" 160 """ 161 output string for printing 162 163 """ 157 164 rep = "\n\nState name: %s\n"%self.name 158 165 rep +="data : %s\n"% str(self.data) … … 198 205 rep += "maximum value : %s \n"%str(item[6][1]) 199 206 rep += "parameter unit: %s\n\n"%str(item[7]) 200 201 207 return rep 202 203 204 205 208 -
theoryview/perspectives/theory/theory.py
r2882fb5 r74755ff 20 20 class PlotInfo: 21 21 """ 22 store some plotting field 22 store some plotting field 23 23 24 """ 24 25 _xunit = 'A^{-1}' … … 33 34 class Plugin: 34 35 """ 35 This class defines the interface for a Plugin class 36 for calculator perspective 36 This class defines the interface for a Plugin class 37 for calculator perspective 38 37 39 """ 38 40 39 41 def __init__(self, standalone=True): 40 42 """ 41 Abstract class for gui_manager Plugins. 43 Abstract class for gui_manager Plugins. 44 42 45 """ 43 46 ## Plug-in name. It will appear on the application menu. … … 61 64 def populate_menu(self, id, owner): 62 65 """ 63 Create and return the list of application menu 64 items for the plug-in. 65 66 @param id: deprecated. Un-used. 67 @param parent: parent window 68 @return: plug-in menu 66 Create and return the list of application menu 67 items for the plug-in. 68 69 :param id: deprecated. Un-used. 70 :param parent: parent window 71 72 :return: plug-in menu 69 73 """ 70 74 return [] … … 72 76 def get_panels(self, parent): 73 77 """ 74 Create and return the list of wx.Panels for your plug-in. 75 Define the plug-in perspective. 76 77 Panels should inherit from DefaultPanel defined below, 78 or should present the same interface. They must define 79 "window_caption" and "window_name". 80 81 @param parent: parent window 82 @return: list of panels 78 Create and return the list of wx.Panels for your plug-in. 79 Define the plug-in perspective. 80 81 Panels should inherit from DefaultPanel defined below, 82 or should present the same interface. They must define 83 "window_caption" and "window_name". 84 85 :param parent: parent window 86 87 :return: list of panels 83 88 """ 84 89 ## Save a reference to the parent … … 88 93 model_list_box= self.menu_mng.get_model_list().get_list()) 89 94 self.model_panel.set_manager(self) 90 91 95 # If needed, add its name to the perspective list 92 96 self.perspective.append(self.model_panel.window_name) … … 97 101 def get_context_menu(self, graph=None): 98 102 """ 99 This method is optional. 100 101 When the context menu of a plot is rendered, the 102 get_context_menu method will be called to give you a 103 chance to add a menu item to the context menu. 104 105 A ref to a Graph object is passed so that you can 106 investigate the plot content and decide whether you 107 need to add items to the context menu. 108 109 This method returns a list of menu items. 110 Each item is itself a list defining the text to 111 appear in the menu, a tool-tip help text, and a 112 call-back method. 113 114 @param graph: the Graph object to which we attach the context menu 115 @return: a list of menu items with call-back function 103 This method is optional. 104 105 When the context menu of a plot is rendered, the 106 get_context_menu method will be called to give you a 107 chance to add a menu item to the context menu. 108 109 A ref to a Graph object is passed so that you can 110 investigate the plot content and decide whether you 111 need to add items to the context menu. 112 113 This method returns a list of menu items. 114 Each item is itself a list defining the text to 115 appear in the menu, a tool-tip help text, and a 116 call-back method. 117 118 :param graph: the Graph object to which we attach the context menu 119 120 :return: a list of menu items with call-back function 121 116 122 """ 117 123 return [] … … 119 125 def get_perspective(self): 120 126 """ 121 Get the list of panel names for this perspective 127 Get the list of panel names for this perspective 128 122 129 """ 123 130 return self.perspective … … 125 132 def on_perspective(self, event): 126 133 """ 127 Call back function for the perspective menu item. 128 We notify the parent window that the perspective 129 has changed. 130 @param event: menu event 134 Call back function for the perspective menu item. 135 We notify the parent window that the perspective 136 has changed. 137 138 :param event: menu event 139 131 140 """ 132 141 self.parent.set_perspective(self.perspective) … … 134 143 def post_init(self): 135 144 """ 136 Post initialization call back to close the loose ends 145 Post initialization call back to close the loose ends 146 137 147 """ 138 148 pass … … 142 152 qmin= DEFAULT_QMIN, qmax= DEFAULT_QMAX, qstep= DEFAULT_NPTS): 143 153 """ 144 Draw model. 145 @param model: the model to draw 146 @param name: the name of the model to draw 147 @param data: the data on which the model is based to be drawn 148 @param description: model's description 149 @param enable1D: if true enable drawing model 1D 150 @param enable2D: if true enable drawing model 2D 151 @param qmin: Range's minimum value to draw model 152 @param qmax: Range's maximum value to draw model 153 @param qstep: number of step to divide the x and y-axis 154 Draw model. 155 156 :param model: the model to draw 157 :param name: the name of the model to draw 158 :param data: the data on which the model is based to be drawn 159 :param description: model's description 160 :param enable1D: if true enable drawing model 1D 161 :param enable2D: if true enable drawing model 2D 162 :param qmin: Range's minimum value to draw model 163 :param qmax: Range's maximum value to draw model 164 :param qstep: number of step to divide the x and y-axis 154 165 155 166 """ … … 167 178 def _on_model_panel(self, evt): 168 179 """ 169 react to model selection on any combo box or model menu.plot the model 170 @param evt: wx.combobox event 180 react to model selection on any combo box or model menu.plot the model 181 182 :param evt: wx.combobox event 183 171 184 """ 172 185 model = evt.model … … 182 195 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 183 196 """ 184 draw model in 2D 185 @param model: instance of the model to draw 186 @param enable2D: when True allows to draw model 2D 187 @param qmin: the minimum value to draw model 2D 188 @param qmax: the maximum value to draw model 2D 189 @param qstep: the number of division of Qx and Qy of the model to draw 190 197 draw model in 2D 198 199 :param model: instance of the model to draw 200 :param enable2D: when True allows to draw model 2D 201 :param qmin: the minimum value to draw model 2D 202 :param qmax: the maximum value to draw model 2D 203 :param qstep: the number of division of Qx and Qy of the model to draw 204 191 205 """ 192 206 x= numpy.linspace(start= -1*qmax, … … 236 250 enable1D= True): 237 251 """ 238 Draw model 1D from loaded data1D 239 @param data: loaded data 240 @param model: the model to plot 252 Draw model 1D from loaded data1D 253 254 :param data: loaded data 255 :param model: the model to plot 256 241 257 """ 242 258 x= numpy.linspace(start= qmin, … … 281 297 def _update1D(self,x, output): 282 298 """ 283 Update the output of plotting model 1D 299 Update the output of plotting model 1D 300 284 301 """ 285 302 wx.PostEvent(self.parent, StatusEvent(status="Plot \ … … 287 304 self.ready_fit() 288 305 #self.calc_thread.ready(0.01) 289 290 306 291 307 def _fill_default_model2D(self, theory, qmax,qstep, qmin=None): 292 308 """ 293 fill Data2D with default value 294 @param theory: Data2D to fill 309 fill Data2D with default value 310 311 :param theory: Data2D to fill 312 295 313 """ 296 314 from DataLoader.data_info import Detector, Source … … 369 387 theory.ymin= ymin 370 388 theory.ymax= ymax 371 theory.group_id ="Model" 372 theory.id ="Model" 373 389 theory.group_id = "Model" 390 theory.id = "Model" 374 391 375 392 def _get_plotting_info(self, data=None): 376 393 """ 377 get plotting info from data if data !=None 378 else use some default 394 get plotting info from data if data !=None 395 else use some default 396 379 397 """ 380 398 my_info = PlotInfo() … … 397 415 return my_info 398 416 399 400 417 def _complete1D(self, x,y, elapsed,model,data=None): 401 418 """ 402 Complete plotting 1D data 419 Complete plotting 1D data 420 403 421 """ 404 422 … … 435 453 return 436 454 437 438 439 455 def _update2D(self, output,time=None): 440 456 """ 441 Update the output of plotting model 457 Update the output of plotting model 458 442 459 """ 443 460 wx.PostEvent(self.parent, StatusEvent(status="Plot \ … … 446 463 #self.calc_thread.ready(0.01) 447 464 448 449 465 def _complete2D(self, image,data, model, elapsed,qmin, qmax,qstep=DEFAULT_NPTS): 450 466 """ 451 Complete get the result of modelthread and create model 2D 452 that can be plot. 467 Complete get the result of modelthread and create model 2D 468 that can be plot. 469 453 470 """ 454 471 err_image = numpy.zeros(numpy.shape(image)) … … 484 501 msg = "Plot 2D complete !" 485 502 wx.PostEvent( self.parent, StatusEvent( status= msg , type="stop" )) 486 487 503
Note: See TracChangeset
for help on using the changeset viewer.