Changeset ef26c83 in sasview for fittingview/src
- Timestamp:
- Apr 30, 2012 8:48:29 AM (13 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:
- 8df5faa
- Parents:
- ac2b835
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/basepage.py
rf992a06 ref26c83 5 5 import numpy 6 6 import time 7 import copy 7 import copy 8 8 import math 9 9 import string 10 10 from wx.lib.scrolledpanel import ScrolledPanel 11 11 from sans.guiframe.panel_base import PanelBase 12 from sans.guiframe.utils import format_number, check_float12 from sans.guiframe.utils import format_number, check_float 13 13 from sans.guiframe.events import PanelOnFocusEvent 14 14 from sans.guiframe.events import StatusEvent … … 22 22 from pagestate import PageState 23 23 24 (PageInfoEvent, EVT_PAGE_INFO) 25 (PreviousStateEvent, EVT_PREVIOUS_STATE) 26 (NextStateEvent, EVT_NEXT_STATE) 24 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 25 (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() 26 (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() 27 27 28 28 _BOX_WIDTH = 76 … … 30 30 _QMAX_DEFAULT = 0.5 31 31 _NPTS_DEFAULT = 50 32 #Control panel width 33 if sys.platform.count("win32") > 0:32 #Control panel width 33 if sys.platform.count("win32") > 0: 34 34 PANEL_WIDTH = 450 35 35 FONT_VARIANT = 0 … … 41 41 42 42 43 44 43 class BasicPage(ScrolledPanel, PanelBase): 45 44 """ 46 45 This class provide general structure of fitpanel page 47 46 """ 48 47 ## Internal name for the AUI manager 49 48 window_name = "Fit Page" 50 49 ## Title to appear on top of the window 51 50 window_caption = "Fit Page " 52 51 53 def __init__(self, parent, color='blue', **kwargs):52 def __init__(self, parent, color='blue', **kwargs): 54 53 """ 55 54 """ … … 57 56 PanelBase.__init__(self, parent) 58 57 self.SetupScrolling() 59 #Set window's font size 58 #Set window's font size 60 59 self.SetWindowVariant(variant=FONT_VARIANT) 61 60 … … 66 65 ## owner of the page (fitting plugin) 67 66 self.event_owner = None 68 67 ## current model 69 68 self.model = None 70 69 self.index_model = None … … 94 93 ## 2D smear accuracy default 95 94 self.smear2d_accuracy = 'Low' 96 ## slit smear: 95 ## slit smear: 97 96 self.dxl = None 98 97 self.dxw = None 99 ## pinhole smear 98 ## pinhole smear 100 99 self.dx_min = None 101 100 self.dx_max = None … … 110 109 self._disp_obj_dict = {} 111 110 ## selected parameters to apply dispersion 112 self.disp_cb_dict = {}111 self.disp_cb_dict = {} 113 112 ## smearer object 114 113 self.enable2D = False … … 152 151 self.number_saved_state = 0 153 152 ## dictionary of saved state 154 self.saved_states = {} 153 self.saved_states = {} 155 154 ## Create context menu for page 156 155 self.popUpMenu = wx.Menu() 157 156 158 157 id = wx.NewId() 159 self._keep = wx.MenuItem(self.popUpMenu, id,"Add bookmark",158 self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 160 159 " Keep the panel status to recall it later") 161 160 self.popUpMenu.AppendItem(self._keep) … … 167 166 168 167 ## Default locations 169 self._default_save_location = os.getcwd() 168 self._default_save_location = os.getcwd() 170 169 ## save initial state on context menu 171 170 #self.onSave(event=None) … … 177 176 ## create the basic structure of the panel with empty sizer 178 177 self.define_page_structure() 179 ## drawing Initial dispersion parameters sizer 178 ## drawing Initial dispersion parameters sizer 180 179 self.set_dispers_sizer() 181 180 … … 191 190 def create_default_data(self): 192 191 """ 193 Given the user selection, creates a 1D or 2D data 192 Given the user selection, creates a 1D or 2D data 194 193 Only when the page is on theory mode. 195 194 """ … … 206 205 self._manager.page_finder[self.uid].set_fit_data(data=[self.data]) 207 206 self.on_smear_helper(update=True) 208 self.state.enable_smearer =self.enable_smearer.GetValue()209 self.state.disable_smearer =self.disable_smearer.GetValue()207 self.state.enable_smearer = self.enable_smearer.GetValue() 208 self.state.disable_smearer = self.disable_smearer.GetValue() 210 209 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 211 210 self.state.slit_smearer = self.slit_smearer.GetValue() … … 213 212 def _create_default_1d_data(self): 214 213 """ 215 Create default data for fitting perspective 214 Create default data for fitting perspective 216 215 Only when the page is on theory mode. 217 216 :warning: This data is never plotted. 218 217 219 218 """ 220 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 219 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 221 220 num=self.npts_x, endpoint=True) 222 221 self.data = Data1D(x=x) 223 self.data.xaxis('\\rm{Q}', "A^{-1}")222 self.data.xaxis('\\rm{Q}', "A^{-1}") 224 223 self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 225 224 self.data.is_data = False 226 self.data.id = str(self.uid) + " data" 227 self.data.group_id = str(self.uid) + " Model1D" 225 self.data.id = str(self.uid) + " data" 226 self.data.group_id = str(self.uid) + " Model1D" 228 227 229 228 def _create_default_2d_data(self): … … 238 237 self.data.yaxis('\\rm{Q_{y}}', 'A^{-1}') 239 238 self.data.is_data = False 240 self.data.id = str(self.uid) + " data" 241 self.data.group_id = str(self.uid) + " Model2D" 242 ## Default values 243 self.data.detector.append(Detector()) 239 self.data.id = str(self.uid) + " data" 240 self.data.group_id = str(self.uid) + " Model2D" 241 ## Default values 242 self.data.detector.append(Detector()) 244 243 index = len(self.data.detector) - 1 245 self.data.detector[index].distance = 8000 # mm 246 self.data.source.wavelength = 6 # A244 self.data.detector[index].distance = 8000 # mm 245 self.data.source.wavelength = 6 # A 247 246 self.data.detector[index].pixel_size.x = 5 # mm 248 247 self.data.detector[index].pixel_size.y = 5 # mm … … 250 249 self.data.detector[index].beam_center.y = qmax 251 250 ## create x_bins and y_bins of the model 2D 252 pixel_width_x = self.data.detector[index].pixel_size.x253 pixel_width_y = self.data.detector[index].pixel_size.y254 center_x = self.data.detector[index].beam_center.x/pixel_width_x255 center_y = self.data.detector[index].beam_center.y/pixel_width_y256 # theory default: assume the beam 251 #pixel_width_x = self.data.detector[index].pixel_size.x 252 #pixel_width_y = self.data.detector[index].pixel_size.y 253 #center_x = self.data.detector[index].beam_center.x/pixel_width_x 254 #center_y = self.data.detector[index].beam_center.y/pixel_width_y 255 # theory default: assume the beam 257 256 #center is located at the center of sqr detector 258 xmax = qmax 257 xmax = qmax 259 258 xmin = -qmax 260 259 ymax = qmax … … 262 261 qstep = self.npts_x 263 262 264 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 263 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 265 264 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 266 265 ## use data info instead 267 266 new_x = numpy.tile(x, (len(y), 1)) 268 267 new_y = numpy.tile(y, (len(x), 1)) 269 new_y = new_y.swapaxes(0, 1)268 new_y = new_y.swapaxes(0, 1) 270 269 # all data reuire now in 1d array 271 270 qx_data = new_x.flatten() 272 271 qy_data = new_y.flatten() 273 q_data = numpy.sqrt(qx_data *qx_data + qy_data*qy_data)272 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 274 273 # set all True (standing for unmasked) as default 275 274 mask = numpy.ones(len(qx_data), dtype=bool) 276 275 # calculate the range of qx and qy: this way, 277 276 # it is a little more independent 278 x_size = xmax - xmin279 y_size = ymax - ymin277 #x_size = xmax - xmin 278 #y_size = ymax - ymin 280 279 # store x and y bin centers in q space 281 x_bins 282 y_bins = y280 x_bins = x 281 y_bins = y 283 282 # bin size: x- & y-directions 284 xstep = x_size/len(x_bins-1)285 ystep = y_size/len(y_bins-1)283 #xstep = x_size / len(x_bins - 1) 284 #ystep = y_size / len(y_bins - 1) 286 285 287 286 self.data.source = Source() 288 287 self.data.data = numpy.ones(len(mask)) 289 288 self.data.err_data = numpy.ones(len(mask)) 290 self.data.qx_data = qx_data 291 self.data.qy_data = qy_data 292 self.data.q_data = q_data 293 self.data.mask = mask 294 self.data.x_bins = x_bins 295 self.data.y_bins = y_bins 289 self.data.qx_data = qx_data 290 self.data.qy_data = qy_data 291 self.data.q_data = q_data 292 self.data.mask = mask 293 self.data.x_bins = x_bins 294 self.data.y_bins = y_bins 296 295 # max and min taking account of the bin sizes 297 self.data.xmin = xmin 296 self.data.xmin = xmin 298 297 self.data.xmax = xmax 299 self.data.ymin = ymin 300 self.data.ymax = ymax 298 self.data.ymin = ymin 299 self.data.ymax = ymax 301 300 302 301 def on_set_focus(self, event): … … 314 313 if self._manager.menu1 != None: 315 314 chain_menu = self._manager.menu1.FindItemById(\ 316 315 self._manager.id_reset_flag) 317 316 chain_menu.Enable(self.batch_on) 318 317 sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 319 318 flag = self.data.is_data\ 320 and (self.model !=None)319 and (self.model != None) 321 320 sim_menu.Enable(not self.batch_on and flag) 322 321 batch_menu = self._manager.menu1.FindItemById(self._manager.id_batchfit) 323 batch_menu.Enable(self.batch_on and flag) 322 batch_menu.Enable(self.batch_on and flag) 324 323 325 324 class ModelTextCtrl(wx.TextCtrl): … … 340 339 _on_set_focus_callback = None 341 340 342 def __init__(self, parent, id=-1, 343 value=wx.EmptyString, 344 pos=wx.DefaultPosition, 341 def __init__(self, parent, id=-1, 342 value=wx.EmptyString, 343 pos=wx.DefaultPosition, 345 344 size=wx.DefaultSize, 346 style=0, 345 style=0, 347 346 validator=wx.DefaultValidator, 348 347 name=wx.TextCtrlNameStr, … … 350 349 set_focus_callback=None, 351 350 mouse_up_callback=None, 352 text_enter_callback =None):351 text_enter_callback=None): 353 352 354 353 wx.TextCtrl.__init__(self, parent, id, value, pos, … … 360 359 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 361 360 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ 362 if kill_focus_callback is None else kill_focus_callback) 361 if kill_focus_callback is None else kill_focus_callback) 363 362 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ 364 363 if text_enter_callback is None else text_enter_callback) 365 if not ON_MAC 366 self.Bind(wx.EVT_LEFT_UP, 364 if not ON_MAC: 365 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ 367 366 if mouse_up_callback is None else mouse_up_callback) 368 367 … … 379 378 return self._on_set_focus_callback(event) 380 379 381 382 383 380 def _highlight_text(self, event): 384 381 """ … … 390 387 # Make sure the mouse event is available to other listeners 391 388 event.Skip() 392 control 389 control = event.GetEventObject() 393 390 if self.full_selection: 394 391 self.full_selection = False 395 392 # Check that we have a TextCtrl 396 393 if issubclass(control.__class__, wx.TextCtrl): 397 # Check whether text has been selected, 394 # Check whether text has been selected, 398 395 # if not, select the whole string 399 396 (start, end) = control.GetSelection() 400 if start ==end:401 control.SetSelection(-1, -1)397 if start == end: 398 control.SetSelection(-1, -1) 402 399 403 def _silent_kill_focus(self, event):400 def _silent_kill_focus(self, event): 404 401 """ 405 402 Save the state of the page … … 413 410 set some page important information at once 414 411 """ 415 ##window_name412 ##window_name 416 413 self.window_name = page_info.window_name 417 414 ##window_caption 418 415 self.window_caption = page_info.window_caption 419 416 ## manager is the fitting plugin 420 self._manager = page_info.manager417 self._manager = page_info.manager 421 418 ## owner of the page (fitting plugin) 422 self.event_owner = page_info.event_owner423 419 self.event_owner = page_info.event_owner 420 ## current model 424 421 self.model = page_info.model 425 422 ## data … … 430 427 self.populate_box(dict=self.model_list_box) 431 428 432 def onContextMenu(self, event): 429 def onContextMenu(self, event): 433 430 """ 434 431 Retrieve the state selected state … … 440 437 pos = self.ScreenToClient(pos) 441 438 442 self.PopupMenu(self.popUpMenu, pos) 439 self.PopupMenu(self.popUpMenu, pos) 443 440 444 445 441 def onUndo(self, event): 446 442 """ 447 443 Cancel the previous action 448 444 """ 449 event = PreviousStateEvent(page =self)445 event = PreviousStateEvent(page=self) 450 446 wx.PostEvent(self.parent, event) 451 447 452 448 def onRedo(self, event): 453 449 """ 454 Restore the previous action cancelled 455 """ 456 event = NextStateEvent(page= 450 Restore the previous action cancelled 451 """ 452 event = NextStateEvent(page=self) 457 453 wx.PostEvent(self.parent, event) 458 454 … … 461 457 Create empty sizer for a panel 462 458 """ 463 self.vbox 459 self.vbox = wx.BoxSizer(wx.VERTICAL) 464 460 self.sizer0 = wx.BoxSizer(wx.VERTICAL) 465 461 self.sizer1 = wx.BoxSizer(wx.VERTICAL) … … 470 466 self.sizer6 = wx.BoxSizer(wx.VERTICAL) 471 467 472 self.sizer0.SetMinSize((PANEL_WIDTH, -1))473 self.sizer1.SetMinSize((PANEL_WIDTH, -1))474 self.sizer2.SetMinSize((PANEL_WIDTH, -1))475 self.sizer3.SetMinSize((PANEL_WIDTH, -1))476 self.sizer4.SetMinSize((PANEL_WIDTH, -1))477 self.sizer5.SetMinSize((PANEL_WIDTH, -1))478 self.sizer6.SetMinSize((PANEL_WIDTH, -1))468 self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 469 self.sizer1.SetMinSize((PANEL_WIDTH, -1)) 470 self.sizer2.SetMinSize((PANEL_WIDTH, -1)) 471 self.sizer3.SetMinSize((PANEL_WIDTH, -1)) 472 self.sizer4.SetMinSize((PANEL_WIDTH, -1)) 473 self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 474 self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 479 475 480 476 self.vbox.Add(self.sizer0) … … 491 487 """ 492 488 self.vbox.Layout() 493 self.vbox.Fit(self) 489 self.vbox.Fit(self) 494 490 self.SetSizer(self.vbox) 495 491 self.Centre() 496 492 497 def set_owner(self, owner):498 """ 493 def set_owner(self, owner): 494 """ 499 495 set owner of fitpage 500 496 … … 502 498 503 499 """ 504 self.event_owner = owner 500 self.event_owner = owner 505 501 self.state.event_owner = owner 506 502 … … 512 508 def get_data(self): 513 509 """ 514 return the current data 515 """ 516 return self.data 510 return the current data 511 """ 512 return self.data 517 513 518 514 def get_data_list(self): 519 515 """ 520 return the current data 521 """ 522 return self.data_list 516 return the current data 517 """ 518 return self.data_list 523 519 524 520 def set_manager(self, manager): … … 529 525 530 526 """ 531 self._manager = manager 527 self._manager = manager 532 528 self.state.manager = manager 533 529 … … 543 539 self.initialize_combox() 544 540 545 def initialize_combox(self): 546 """ 547 put default value in the combobox 541 def initialize_combox(self): 542 """ 543 put default value in the combobox 548 544 """ 549 545 ## fill combox box … … 568 564 self.text2.Show() 569 565 self.structurebox.Enable() 570 self.text2.Enable() 566 self.text2.Enable() 571 567 572 568 def set_dispers_sizer(self): … … 575 571 """ 576 572 self.sizer4.Clear(True) 577 name ="Polydispersity and Orientational Distribution"578 box_description = wx.StaticBox(self, -1,name)573 name = "Polydispersity and Orientational Distribution" 574 box_description = wx.StaticBox(self, -1, name) 579 575 box_description.SetForegroundColour(wx.BLUE) 580 576 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 585 581 # best size for MAC and PC 586 582 if ON_MAC: 587 size_q = (30, 20) 583 size_q = (30, 20) 588 584 else: 589 size_q = (20, 15) 590 self.disp_help_bt = wx.Button(self, wx.NewId(),'?',591 style =wx.BU_EXACTFIT,585 size_q = (20, 15) 586 self.disp_help_bt = wx.Button(self, wx.NewId(), '?', 587 style=wx.BU_EXACTFIT, 592 588 size=size_q) 593 self.disp_help_bt.Bind(wx.EVT_BUTTON, 594 self.on_pd_help_clicked, id=self.disp_help_bt.GetId())595 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 589 self.disp_help_bt.Bind(wx.EVT_BUTTON, 590 self.on_pd_help_clicked, id=self.disp_help_bt.GetId()) 591 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 596 592 597 593 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, … … 602 598 self.disable_disp.SetValue(True) 603 599 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) 604 sizer_dispersion.Add((20, 20))605 name =""#Polydispersity and \nOrientational Distribution "606 sizer_dispersion.Add(wx.StaticText(self, -1,name))607 sizer_dispersion.Add(self.enable_disp 608 sizer_dispersion.Add((20, 20))609 sizer_dispersion.Add(self.disable_disp 610 sizer_dispersion.Add((25, 20))600 sizer_dispersion.Add((20, 20)) 601 name = "" # Polydispersity and \nOrientational Distribution " 602 sizer_dispersion.Add(wx.StaticText(self, -1, name)) 603 sizer_dispersion.Add(self.enable_disp) 604 sizer_dispersion.Add((20, 20)) 605 sizer_dispersion.Add(self.disable_disp) 606 sizer_dispersion.Add((25, 20)) 611 607 sizer_dispersion.Add(self.disp_help_bt) 612 608 613 ## fill a sizer for dispersion 614 boxsizer1.Add( sizer_dispersion,0, 615 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) 616 #boxsizer1.Add( (10,10) ) 617 #boxsizer1.Add( sizer_select_dispers ) 618 self.sizer4_4 = wx.GridBagSizer(6,5) 619 620 boxsizer1.Add( self.sizer4_4 ) 609 ## fill a sizer for dispersion 610 boxsizer1.Add(sizer_dispersion, 0, 611 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 612 border=5) 613 self.sizer4_4 = wx.GridBagSizer(6, 5) 614 615 boxsizer1.Add(self.sizer4_4) 621 616 #----------------------------------------------------- 622 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)617 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 623 618 self.sizer4_4.Layout() 624 619 self.sizer4.Layout() … … 627 622 self.Refresh() 628 623 ## saving the state of enable dispersity button 629 self.state.enable_disp = self.enable_disp.GetValue()630 self.state.disable_disp = self.disable_disp.GetValue()624 self.state.enable_disp = self.enable_disp.GetValue() 625 self.state.disable_disp = self.disable_disp.GetValue() 631 626 self.SetupScrolling() 632 633 627 634 628 def onResetModel(self, event): … … 637 631 """ 638 632 menu = event.GetEventObject() 639 ## post help message for the selected model 633 ## post help message for the selected model 640 634 msg = menu.GetHelpString(event.GetId()) 641 msg += " reloaded"635 msg += " reloaded" 642 636 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 643 637 self.Show(False) … … 650 644 ## reset state of checkbox,textcrtl and regular parameters value 651 645 652 self.reset_page(previous_state) 646 self.reset_page(previous_state) 653 647 self.state.m_name = self.m_name 654 648 self.Show(True) … … 657 651 """ 658 652 Report the current fit results 659 """ 653 """ 660 654 # Get plot image from plotpanel 661 655 images, canvases = self.get_images() … … 663 657 self.state.report(images, canvases) 664 658 665 666 def on_save(self, event): 659 def on_save(self, event): 667 660 """ 668 661 Save the current state into file 669 """ 662 """ 670 663 self.save_current_state() 671 664 new_state = self.state.clone() 672 665 # Ask the user the location of the file to write to. 673 666 path = None 674 if self.parent != 667 if self.parent != None: 675 668 self._default_save_location = \ 676 669 self.parent.parent._default_save_location … … 691 684 #the manager write the state into file 692 685 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 693 return new_state 686 return new_state 694 687 695 688 def on_copy(self, event): … … 702 695 wx.CallAfter(self.get_copy) 703 696 704 # messages depending on the flag705 #self._copy_info(None)706 707 697 def on_paste(self, event): 708 698 """ … … 711 701 if event != None: 712 702 event.Skip() 713 # It seems MAC needs wxCallAfter for the setvalues 714 # for multiple textctrl items, otherwise it tends to crash once a while .703 # It seems MAC needs wxCallAfter for the setvalues 704 # for multiple textctrl items, otherwise it tends to crash once a while 715 705 wx.CallAfter(self.get_paste) 716 706 # messages depending on the flag … … 735 725 infor = "error" 736 726 # inform msg to wx 737 wx.PostEvent( self.parent.parent,738 StatusEvent(status=msg, info=infor))727 wx.PostEvent(self.parent.parent, 728 StatusEvent(status=msg, info=infor)) 739 729 740 730 def _get_time_stamp(self): … … 742 732 return time and date stings 743 733 """ 744 # date and time 745 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 746 current_time= str(hour)+":"+str(minute)+":"+str(second) 747 current_date= str( month)+"/"+str(day)+"/"+str(year) 734 # date and time 735 year, month, day, hour, minute, second, tda, ty, tm_isdst \ 736 = time.localtime() 737 current_time = str(hour) + ":" + str(minute) + ":" + str(second) 738 current_date = str(month) + "/" + str(day) + "/" + str(year) 748 739 return current_time, current_date 749 740 … … 752 743 save history of the data and model 753 744 """ 754 if self.model ==None:755 msg ="Can not bookmark; Please select Data and Model first..."745 if self.model == None: 746 msg = "Can not bookmark; Please select Data and Model first..." 756 747 wx.MessageBox(msg, 'Info') 757 return 748 return 758 749 self.save_current_state() 759 750 new_state = self.state.clone() … … 761 752 self.number_saved_state += 1 762 753 current_time, current_date = self._get_time_stamp() 763 #name= self.model.name+"[%g]"%self.number_saved_state 764 name = "Fitting: %g]" % self.number_saved_state 765 name += self.model.__class__.__name__ 754 #name= self.model.name+"[%g]"%self.number_saved_state 755 name = "Fitting: %g]" % self.number_saved_state 756 name += self.model.__class__.__name__ 766 757 name += "bookmarked at %s on %s" % (current_time, current_date) 767 self.saved_states[name] = new_state758 self.saved_states[name] = new_state 768 759 769 760 ## Add item in the context menu 770 msg = "Model saved at %s on %s"%(current_time, current_date)771 ## post help message for the selected model772 msg += " Saved! right click on this page to retrieve this model"773 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))761 msg = "Model saved at %s on %s" % (current_time, current_date) 762 ## post help message for the selected model 763 msg += " Saved! right click on this page to retrieve this model" 764 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 774 765 775 766 id = wx.NewId() 776 self.popUpMenu.Append(id, name,str(msg))767 self.popUpMenu.Append(id, name, str(msg)) 777 768 wx.EVT_MENU(self, id, self.onResetModel) 778 wx.PostEvent(self.parent.parent, 779 AppendBookmarkEvent(title=name, 780 hint=str(msg), handler=self._back_to_bookmark)) 781 def _back_to_bookmark(self, event): 769 wx.PostEvent(self.parent.parent, 770 AppendBookmarkEvent(title=name, 771 hint=str(msg), 772 handler=self._back_to_bookmark)) 773 774 def _back_to_bookmark(self, event): 782 775 """ 783 776 Back to bookmark … … 786 779 self.onResetModel(event) 787 780 self._draw_model() 788 #self.save_current_state()789 790 781 791 782 def old_on_bookmark(self, event): … … 793 784 save history of the data and model 794 785 """ 795 if self.model ==None:796 msg ="Can not bookmark; Please select Data and Model first..."786 if self.model == None: 787 msg = "Can not bookmark; Please select Data and Model first..." 797 788 wx.MessageBox(msg, 'Info') 798 return 799 if hasattr(self, "enable_disp"):789 return 790 if hasattr(self, "enable_disp"): 800 791 self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) 801 792 if hasattr(self, "disp_box"): 802 793 self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) 803 794 804 self.state.model.name = self.model.name795 self.state.model.name = self.model.name 805 796 806 797 #Remember fit engine_type for fit panel 807 if self.engine_type == None: 798 if self.engine_type == None: 808 799 self.engine_type = "scipy" 809 if self._manager != None:800 if self._manager != None: 810 801 self._manager._on_change_engine(engine=self.engine_type) 811 802 … … 818 809 ##Add model state on context menu 819 810 self.number_saved_state += 1 820 #name= self.model.name+"[%g]"%self.number_saved_state 821 name= self.model.__class__.__name__+"[%g]"%self.number_saved_state 822 self.saved_states[name]= new_state 811 name = self.model.__class__.__name__ + "[%g]" % self.number_saved_state 812 self.saved_states[name] = new_state 823 813 824 814 ## Add item in the context menu 825 815 826 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 827 my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " 828 date= str( month)+"|"+str(day)+"|"+str(year) 829 msg= "Model saved at %s on %s"%(my_time, date) 830 ## post help message for the selected model 831 msg +=" Saved! right click on this page to retrieve this model" 832 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 816 year, month, day, hour, minute, second, tda, ty, tm_isdst \ 817 = time.localtime() 818 my_time = str(hour) + " : " + str(minute) + " : " + str(second) + " " 819 date = str(month) + "|" + str(day) + "|" + str(year) 820 msg = "Model saved at %s on %s" % (my_time, date) 821 ## post help message for the selected model 822 msg += " Saved! right click on this page to retrieve this model" 823 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 833 824 834 825 id = wx.NewId() 835 self.popUpMenu.Append(id, name,str(msg))826 self.popUpMenu.Append(id, name, str(msg)) 836 827 wx.EVT_MENU(self, id, self.onResetModel) 837 828 838 829 def onSetFocus(self, evt): 839 830 """ 840 highlight the current textcrtl and hide the error text control shown 831 highlight the current textcrtl and hide the error text control shown 841 832 after fitting 842 833 """ … … 851 842 """ 852 843 try: 853 if path ==None:854 wx.PostEvent(self.parent.parent, StatusEvent(status=\855 " Selected Distribution was not loaded: %s"%path))844 if path == None: 845 wx.PostEvent(self.parent.parent, 846 StatusEvent(status=" Selected Distribution was not loaded: %s" % path)) 856 847 return None, None 857 848 input_f = open(path, 'r') … … 860 851 861 852 angles = [] 862 weights =[]853 weights = [] 863 854 for line in lines: 864 855 toks = line.split() … … 873 864 return numpy.array(angles), numpy.array(weights) 874 865 except: 875 raise 866 raise 876 867 877 868 def createMemento(self): … … 880 871 """ 881 872 return self.state.clone() 882 883 873 884 874 def save_current_state(self): … … 888 878 self.state.engine_type = copy.deepcopy(self.engine_type) 889 879 ## save model option 890 if self.model != None:891 self.disp_list = self.model.getDispParamList()892 self.state.disp_list = copy.deepcopy(self.disp_list)880 if self.model != None: 881 self.disp_list = self.model.getDispParamList() 882 self.state.disp_list = copy.deepcopy(self.disp_list) 893 883 self.state.model = self.model.clone() 894 884 #save radiobutton state for model selection … … 898 888 self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 899 889 #model combobox 900 self.state.structurebox = self.structurebox.GetLabel() #.GetSelection()901 self.state.formfactorbox = self.formfactorbox.GetLabel() #.GetSelection()890 self.state.structurebox = self.structurebox.GetLabel() 891 self.state.formfactorbox = self.formfactorbox.GetLabel() 902 892 903 893 self.state.enable2D = copy.deepcopy(self.enable2D) 904 self.state.values = copy.deepcopy(self.values)905 self.state.weights = copy.deepcopy( 906 ## save data 907 self.state.data = copy.deepcopy(self.data)894 self.state.values = copy.deepcopy(self.values) 895 self.state.weights = copy.deepcopy(self.weights) 896 ## save data 897 self.state.data = copy.deepcopy(self.data) 908 898 self.state.qmax_x = self.qmax_x 909 899 self.state.qmin_x = self.qmin_x … … 914 904 self.state.dq_l = self.dq_l 915 905 self.state.dq_r = self.dq_r 916 if hasattr(self, "enable_disp"):917 self.state.enable_disp = self.enable_disp.GetValue()906 if hasattr(self, "enable_disp"): 907 self.state.enable_disp = self.enable_disp.GetValue() 918 908 self.state.disable_disp = self.disable_disp.GetValue() 919 909 920 910 self.state.smearer = copy.deepcopy(self.current_smearer) 921 if hasattr(self, "enable_smearer"):911 if hasattr(self, "enable_smearer"): 922 912 self.state.enable_smearer = \ 923 913 copy.deepcopy(self.enable_smearer.GetValue()) … … 927 917 self.state.pinhole_smearer = \ 928 918 copy.deepcopy(self.pinhole_smearer.GetValue()) 929 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 919 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 930 920 931 if len(self._disp_obj_dict)>0: 932 for k , v in self._disp_obj_dict.iteritems(): 933 self.state._disp_obj_dict[k]= v 934 935 921 if len(self._disp_obj_dict) > 0: 922 for k, v in self._disp_obj_dict.iteritems(): 923 self.state._disp_obj_dict[k] = v 924 936 925 self.state.values = copy.deepcopy(self.values) 937 926 self.state.weights = copy.deepcopy(self.weights) … … 946 935 self.state.str_parameters = [] 947 936 948 949 937 ## save checkbutton state and txtcrtl values 950 self._copy_parameters_state(self.str_parameters, 938 self._copy_parameters_state(self.str_parameters, 951 939 self.state.str_parameters) 952 940 self._copy_parameters_state(self.orientation_params, … … 967 955 """ 968 956 ## save model option 969 if self.model != None:970 self.disp_list = self.model.getDispParamList()971 self.state.disp_list = copy.deepcopy(self.disp_list)957 if self.model != None: 958 self.disp_list = self.model.getDispParamList() 959 self.state.disp_list = copy.deepcopy(self.disp_list) 972 960 self.state.model = self.model.clone() 973 961 if hasattr(self, "engine_type"): … … 975 963 976 964 self.state.enable2D = copy.deepcopy(self.enable2D) 977 self.state.values = copy.deepcopy(self.values)978 self.state.weights = copy.deepcopy( 979 ## save data 980 self.state.data = copy.deepcopy(self.data)981 982 if hasattr(self, "enable_disp"):983 self.state.enable_disp = self.enable_disp.GetValue()965 self.state.values = copy.deepcopy(self.values) 966 self.state.weights = copy.deepcopy(self.weights) 967 ## save data 968 self.state.data = copy.deepcopy(self.data) 969 970 if hasattr(self, "enable_disp"): 971 self.state.enable_disp = self.enable_disp.GetValue() 984 972 self.state.disable_disp = self.disable_disp.GetValue() 985 973 986 974 self.state.smearer = copy.deepcopy(self.current_smearer) 987 if hasattr(self, "enable_smearer"):975 if hasattr(self, "enable_smearer"): 988 976 self.state.enable_smearer = \ 989 977 copy.deepcopy(self.enable_smearer.GetValue()) … … 993 981 self.state.pinhole_smearer = \ 994 982 copy.deepcopy(self.pinhole_smearer.GetValue()) 995 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 983 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 996 984 self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) 997 985 self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) 998 986 self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 999 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 1000 if hasattr(self, "disp_box"):987 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 988 if hasattr(self, "disp_box"): 1001 989 self.state.disp_box = self.disp_box.GetCurrentSelection() 1002 990 … … 1004 992 for k, v in self.disp_cb_dict.iteritems(): 1005 993 1006 if v == None 994 if v == None: 1007 995 self.state.disp_cb_dict[k] = v 1008 996 else: … … 1013 1001 1014 1002 if len(self._disp_obj_dict) > 0: 1015 for k , v in self._disp_obj_dict.iteritems(): 1016 1003 for k, v in self._disp_obj_dict.iteritems(): 1017 1004 self.state._disp_obj_dict[k] = v 1018 1005 1019 1020 1006 self.state.values = copy.deepcopy(self.values) 1021 1007 self.state.weights = copy.deepcopy(self.weights) … … 1034 1020 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1035 1021 1036 1037 def check_invalid_panel(self): 1022 def check_invalid_panel(self): 1038 1023 """ 1039 1024 check if the user can already perform some action with this panel 1040 """ 1041 flag = False 1025 """ 1042 1026 if self.data is None: 1043 1027 self.disable_smearer.SetValue(True) … … 1055 1039 1056 1040 ## set the state of the radio box 1057 self.shape_rbutton.SetValue(state.shape_rbutton 1041 self.shape_rbutton.SetValue(state.shape_rbutton) 1058 1042 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 1059 1043 self.struct_rbutton.SetValue(state.struct_rbutton) … … 1092 1076 self.multifactorbox.SetSelection(state.multi_factor) 1093 1077 1094 1078 ## reset state of checkbox,textcrtl and regular parameters value 1095 1079 self._reset_parameters_state(self.orientation_params_disp, 1096 1080 state.orientation_params_disp) … … 1099 1083 self._reset_parameters_state(self.str_parameters, 1100 1084 state.str_parameters) 1101 self._reset_parameters_state(self.parameters, state.parameters)1102 ## display dispersion info layer1085 self._reset_parameters_state(self.parameters, state.parameters) 1086 ## display dispersion info layer 1103 1087 self.enable_disp.SetValue(state.enable_disp) 1104 1088 self.disable_disp.SetValue(state.disable_disp) 1105 1089 1106 1090 if hasattr(self, "disp_box"): 1107 1108 self.disp_box.SetSelection(state.disp_box) 1109 n= self.disp_box.GetCurrentSelection() 1110 dispersity= self.disp_box.GetClientData(n) 1111 name = dispersity.__name__ 1091 self.disp_box.SetSelection(state.disp_box) 1092 n = self.disp_box.GetCurrentSelection() 1093 dispersity = self.disp_box.GetClientData(n) 1094 name = dispersity.__name__ 1112 1095 1113 1096 self._set_dipers_Param(event=None) … … 1117 1100 for item in self.disp_cb_dict.keys(): 1118 1101 1119 if hasattr(self.disp_cb_dict[item], "SetValue") 1102 if hasattr(self.disp_cb_dict[item], "SetValue"): 1120 1103 self.disp_cb_dict[item].SetValue(\ 1121 1104 state.disp_cb_dict[item]) … … 1123 1106 from sans.models.dispersion_models import ArrayDispersion 1124 1107 disp_model = ArrayDispersion() 1125 if hasattr(state, "values")and\1108 if hasattr(state, "values") and \ 1126 1109 self.disp_cb_dict[item].GetValue() == True: 1127 if len(state.values) >0:1128 self.values =state.values1129 self.weights =state.weights1110 if len(state.values) > 0: 1111 self.values = state.values 1112 self.weights = state.weights 1130 1113 disp_model.set_weights(self.values, 1131 1114 state.weights) 1132 1115 else: 1133 1116 self._reset_dispersity() 1134 1117 1135 1118 self._disp_obj_dict[item] = disp_model 1136 # Set the new model as the dispersion object 1119 # Set the new model as the dispersion object 1137 1120 #for the selected parameter 1138 1121 self.model.set_dispersion(item, disp_model) … … 1145 1128 for item in keys: 1146 1129 if item in self.disp_list and \ 1147 not self.model.details.has_key(item):1130 not item in self.model.details: 1148 1131 self.model.details[item] = ["", None, None] 1149 for k, v in self.state.disp_cb_dict.iteritems():1150 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1132 for k, v in self.state.disp_cb_dict.iteritems(): 1133 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1151 1134 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1152 1135 ## smearing info restore 1153 1136 if hasattr(self, "enable_smearer"): 1154 ## set smearing value whether or not the data 1137 ## set smearing value whether or not the data 1155 1138 #contain the smearing info 1156 1139 self.enable_smearer.SetValue(state.enable_smearer) 1157 1140 self.disable_smearer.SetValue(state.disable_smearer) 1158 self.onSmear(event=None) 1141 self.onSmear(event=None) 1159 1142 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1160 1143 self.slit_smearer.SetValue(state.slit_smearer) … … 1166 1149 1167 1150 ## we have two more options for smearing 1168 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 1169 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 1151 if self.pinhole_smearer.GetValue(): 1152 self.onPinholeSmear(event=None) 1153 elif self.slit_smearer.GetValue(): 1154 self.onSlitSmear(event=None) 1170 1155 1171 1156 ## reset state of checkbox,textcrtl and dispersity parameters value 1172 self._reset_parameters_state(self.fittable_param, state.fittable_param)1173 self._reset_parameters_state(self.fixed_param, state.fixed_param)1157 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1158 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1174 1159 1175 1160 ## draw the model with previous parameters value 1176 1161 self._onparamEnter_helper() 1177 self.select_param(event=None) 1162 self.select_param(event=None) 1178 1163 #Save state_fit 1179 1164 self.save_current_state_fit() … … 1191 1176 """ 1192 1177 if state == None: 1193 #self._undo.Enable(False) 1194 return 1178 return 1195 1179 # set data, etc. from the state 1196 1180 # reset page between theory and fitting from bookmarking … … 1200 1184 data = state.data 1201 1185 1202 #if data != None:1203 1204 1186 if data == None: 1205 1187 data_min = state.qmin … … 1207 1189 self.qmin_x = data_min 1208 1190 self.qmax_x = data_max 1209 #self.minimum_q.SetValue(str(data_min))1210 #self.maximum_q.SetValue(str(data_max))1211 1191 self.qmin.SetValue(str(data_min)) 1212 1192 self.qmax.SetValue(str(data_max)) … … 1218 1198 self.set_data(data) 1219 1199 1220 self.enable2D = state.enable2D1200 self.enable2D = state.enable2D 1221 1201 self.engine_type = state.engine_type 1222 1202 … … 1225 1205 1226 1206 ## set the state of the radio box 1227 self.shape_rbutton.SetValue(state.shape_rbutton 1207 self.shape_rbutton.SetValue(state.shape_rbutton) 1228 1208 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 1229 1209 self.struct_rbutton.SetValue(state.struct_rbutton) … … 1239 1219 formfactor_pos = 0 1240 1220 for ind_form in range(self.formfactorbox.GetCount()): 1241 if self.formfactorbox.GetString(ind_form).count(state.formfactorcombobox) >0:1221 if self.formfactorbox.GetString(ind_form).count(state.formfactorcombobox) > 0: 1242 1222 formfactor_pos = int(ind_form) 1243 1223 break … … 1251 1231 structfactor_pos = 0 1252 1232 for ind_struct in range(self.structurebox.GetCount()): 1253 if self.structurebox.GetString(ind_struct).count(state.structurecombobox) >0:1233 if self.structurebox.GetString(ind_struct).count(state.structurecombobox) > 0: 1254 1234 structfactor_pos = int(ind_struct) 1255 1235 break … … 1262 1242 #reset the fitting engine type 1263 1243 self.engine_type = state.engine_type 1264 #draw the pnael according to the new model parameter 1244 #draw the pnael according to the new model parameter 1265 1245 self._on_select_model(event=None) 1266 1246 … … 1273 1253 # else: 1274 1254 1275 if self._manager != None and self.engine_type != None:1255 if self._manager != None and self.engine_type != None: 1276 1256 self._manager._on_change_engine(engine=self.engine_type) 1277 1257 ## set the select all check box to the a given state … … 1285 1265 self._reset_parameters_state(self.str_parameters, 1286 1266 state.str_parameters) 1287 self._reset_parameters_state(self.parameters, state.parameters)1288 ## display dispersion info layer1267 self._reset_parameters_state(self.parameters, state.parameters) 1268 ## display dispersion info layer 1289 1269 self.enable_disp.SetValue(state.enable_disp) 1290 1270 self.disable_disp.SetValue(state.disable_disp) … … 1294 1274 self._set_dipers_Param(event=None) 1295 1275 self._reset_page_disp_helper(state) 1296 ##plotting range restore 1276 ##plotting range restore 1297 1277 self._reset_plotting_range(state) 1298 1278 ## smearing info restore 1299 1279 if hasattr(self, "enable_smearer"): 1300 ## set smearing value whether or not the data 1280 ## set smearing value whether or not the data 1301 1281 #contain the smearing info 1302 1282 self.enable_smearer.SetValue(state.enable_smearer) 1303 1283 self.disable_smearer.SetValue(state.disable_smearer) 1304 self.onSmear(event=None) 1284 self.onSmear(event=None) 1305 1285 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1306 1286 self.slit_smearer.SetValue(state.slit_smearer) … … 1318 1298 1319 1299 ## we have two more options for smearing 1320 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 1321 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 1300 if self.pinhole_smearer.GetValue(): 1301 self.onPinholeSmear(event=None) 1302 elif self.slit_smearer.GetValue(): 1303 self.onSlitSmear(event=None) 1322 1304 1323 1305 ## reset state of checkbox,textcrtl and dispersity parameters value 1324 self._reset_parameters_state(self.fittable_param, state.fittable_param)1325 self._reset_parameters_state(self.fixed_param, state.fixed_param)1306 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1307 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1326 1308 1327 1309 ## draw the model with previous parameters value … … 1333 1315 1334 1316 ## set the value of the current state to the state given as parameter 1335 self.state = state.clone() 1317 self.state = state.clone() 1336 1318 self.state.m_name = self.m_name 1337 1319 … … 1343 1325 for item in keys: 1344 1326 if item in self.disp_list and \ 1345 not self.model.details.has_key(item):1327 not item in self.model.details: 1346 1328 self.model.details[item] = ["", None, None] 1347 1329 #for k,v in self.state.disp_cb_dict.iteritems(): 1348 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1330 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1349 1331 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1350 1332 self.values = copy.deepcopy(state.values) … … 1355 1337 # it will be sent as a string here, then converted to model object. 1356 1338 if disp.__class__.__name__ == 'str': 1357 com_str 1339 com_str = "from sans.models.dispersion_models " 1358 1340 com_str += "import %s as disp_func" 1359 1341 exec com_str % disp … … 1362 1344 disp_model = disp 1363 1345 1364 self._disp_obj_dict[key] = disp_model 1346 self._disp_obj_dict[key] = disp_model 1365 1347 param_name = key.split('.')[0] 1366 1348 # Try to set dispersion only when available 1367 # for eg., pass the orient. angles for 1D Cal 1349 # for eg., pass the orient. angles for 1D Cal 1368 1350 try: 1369 1351 self.model.set_dispersion(param_name, disp_model) … … 1376 1358 if list[1] == key and list[7] != None: 1377 1359 list[7].SetSelection(selection) 1378 # For the array disp_model, set the values and weights 1360 # For the array disp_model, set the values and weights 1379 1361 if selection == 1: 1380 disp_model.set_weights(self.values[key], 1381 self.weights[key])1362 disp_model.set_weights(self.values[key], 1363 self.weights[key]) 1382 1364 try: 1383 1365 # Diables all fittable params for array … … 1401 1383 # Make sure the check box updated when all checked 1402 1384 if self.cb1.GetValue(): 1403 self.select_all_param(None) 1385 self.select_all_param(None) 1404 1386 1405 1387 def _selectDlg(self): … … 1407 1389 open a dialog file to selected the customized dispersity 1408 1390 """ 1409 import os 1410 if self.parent != None: 1391 if self.parent != None: 1411 1392 self._default_save_location = \ 1412 1393 self.parent.parent._default_save_location 1413 1394 dlg = wx.FileDialog(self, "Choose a weight file", 1414 self._default_save_location , "",1395 self._default_save_location, "", 1415 1396 "*.*", wx.OPEN) 1416 1397 path = None … … 1436 1417 Reset the plotting range to a given state 1437 1418 """ 1438 # if self.check_invalid_panel():1439 # return1440 1419 self.qmin.SetValue(str(state.qmin)) 1441 self.qmax.SetValue(str(state.qmax)) 1420 self.qmax.SetValue(str(state.qmax)) 1442 1421 1443 1422 def _save_typeOfmodel(self): … … 1449 1428 self.state.struct_rbutton = self.struct_rbutton.GetValue() 1450 1429 self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1451 self.state.structurebox = self.structurebox.GetLabel()#.GetCurrentSelection()1452 self.state.formfactorbox = self.formfactorbox.GetLabel() #.GetCurrentSelection()1430 self.state.structurebox = self.structurebox.GetLabel() 1431 self.state.formfactorbox = self.formfactorbox.GetLabel() 1453 1432 1454 #self._undo.Enable(True)1455 1433 ## post state to fit panel 1456 event = PageInfoEvent(page =self)1434 event = PageInfoEvent(page=self) 1457 1435 wx.PostEvent(self.parent, event) 1458 1436 1459 def _save_plotting_range(self 1460 """ 1461 save the state of plotting range 1437 def _save_plotting_range(self): 1438 """ 1439 save the state of plotting range 1462 1440 """ 1463 1441 self.state.qmin = self.qmin_x 1464 self.state.qmax = self.qmax_x 1442 self.state.qmax = self.qmax_x 1465 1443 self.state.npts = self.npts_x 1466 1444 1467 1445 def _onparamEnter_helper(self): 1468 1446 """ 1469 check if values entered by the user are changed and valid to replot 1447 check if values entered by the user are changed and valid to replot 1470 1448 model 1471 1449 """ 1472 # Flag to register when a parameter has changed. 1450 # Flag to register when a parameter has changed. 1473 1451 is_modified = False 1474 1452 self.fitrange = True … … 1478 1456 if self.data.__class__.__name__ == "Data2D": 1479 1457 is_2Ddata = True 1480 if self.model != None:1458 if self.model != None: 1481 1459 try: 1482 1460 is_modified = self._check_value_enter(self.fittable_param, … … 1485 1463 is_modified) 1486 1464 is_modified = self._check_value_enter(self.parameters, 1487 is_modified) 1465 is_modified) 1488 1466 except: 1489 1467 pass 1490 1468 1491 1469 # Here we should check whether the boundaries have been modified. 1492 # If qmin and qmax have been modified, update qmin and qmax and 1470 # If qmin and qmax have been modified, update qmin and qmax and 1493 1471 # set the is_modified flag to True 1494 1472 if self._validate_qrange(self.qmin, self.qmax): … … 1503 1481 1504 1482 if is_2Ddata: 1505 # set mask 1483 # set mask 1506 1484 is_modified = self._validate_Npts() 1507 1485 1508 1486 else: 1509 self.fitrange = False 1487 self.fitrange = False 1510 1488 1511 1489 if not self.data.is_data: … … 1515 1493 if not self.fitrange: 1516 1494 #self.btFit.Disable() 1517 if is_2Ddata: self.btEditMask.Disable() 1495 if is_2Ddata: 1496 self.btEditMask.Disable() 1518 1497 else: 1519 #self.btFit.Enable(True) 1520 if is_2Ddata and self.data.is_data and not self.batch_on: 1498 if is_2Ddata and self.data.is_data and not self.batch_on: 1521 1499 self.btEditMask.Enable(True) 1522 1500 if is_modified and self.fitrange: 1523 #if self.data == None:1524 1501 # Theory case: need to get npts value to draw 1525 1502 self.npts_x = float(self.Npts_total.GetValue()) 1526 1503 self.create_default_data() 1527 self.state_change = True1528 self._draw_model() 1504 self.state_change = True 1505 self._draw_model() 1529 1506 self.Refresh() 1530 1507 return is_modified … … 1544 1521 ##So make sure that update param values on_Fit. 1545 1522 #self._undo.Enable(True) 1546 if self.model != None:1523 if self.model != None: 1547 1524 if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 1548 1525 if not self.data.is_data: 1549 1526 self._manager.page_finder[self.uid].set_fit_data(data=\ 1550 [self.data])1527 [self.data]) 1551 1528 ##Check the values 1552 self._check_value_enter( self.fittable_param ,is_modified)1553 self._check_value_enter( self.fixed_param ,is_modified)1554 self._check_value_enter( self.parameters ,is_modified)1529 self._check_value_enter(self.fittable_param, is_modified) 1530 self._check_value_enter(self.fixed_param, is_modified) 1531 self._check_value_enter(self.parameters, is_modified) 1555 1532 1556 1533 # If qmin and qmax have been modified, update qmin and qmax and 1557 1534 # Here we should check whether the boundaries have been modified. 1558 1535 # If qmin and qmax have been modified, update qmin and qmax and 1559 1536 # set the is_modified flag to True … … 1567 1544 self.qmax_x = tempmax 1568 1545 if tempmax == tempmin: 1569 flag = False 1546 flag = False 1570 1547 temp_smearer = None 1571 1548 if not self.disable_smearer.GetValue(): 1572 temp_smearer = self.current_smearer1549 temp_smearer = self.current_smearer 1573 1550 if self.slit_smearer.GetValue(): 1574 1551 flag = self.update_slit_smear() … … 1579 1556 uid=self.uid, 1580 1557 fid=self.data.id, 1581 1582 1558 qmin=float(self.qmin_x), 1559 qmax=float(self.qmax_x), 1583 1560 enable_smearer=not self.disable_smearer.GetValue(), 1584 1561 draw=False) … … 1586 1563 self._manager.set_smearer(smearer=temp_smearer, 1587 1564 qmin=float(self.qmin_x), 1588 uid=self.uid, 1565 uid=self.uid, 1589 1566 fid=self.data.id, 1590 qmax=float(self.qmax_x),1567 qmax=float(self.qmax_x), 1591 1568 enable_smearer=not self.disable_smearer.GetValue(), 1592 1569 draw=False) 1593 1570 if self.data != None: 1594 index_data = ((self.qmin_x <= self.data.x) &\1571 index_data = ((self.qmin_x <= self.data.x) & \ 1595 1572 (self.data.x <= self.qmax_x)) 1596 val = str(len(self.data.x[index_data ==True]))1573 val = str(len(self.data.x[index_data == True])) 1597 1574 self.Npts_fit.SetValue(val) 1598 1575 else: … … 1605 1582 flag = True 1606 1583 if self._is_2D(): 1607 # only 2D case set mask 1584 # only 2D case set mask 1608 1585 flag = self._validate_Npts() 1609 1586 if not flag: 1610 1587 return flag 1611 else: flag = False 1612 else: 1588 else: 1589 flag = False 1590 else: 1613 1591 flag = False 1614 1592 1615 #For invalid q range, disable the mask editor and fit button, vs. 1593 #For invalid q range, disable the mask editor and fit button, vs. 1616 1594 if not self.fitrange: 1617 #self.btFit.Disable()1618 1595 if self._is_2D(): 1619 1596 self.btEditMask.Disable() 1620 1597 else: 1621 #self.btFit.Enable(True)1622 1598 if self._is_2D() and self.data.is_data and not self.batch_on: 1623 1599 self.btEditMask.Enable(True) … … 1633 1609 pass 1634 1610 1635 return flag 1611 return flag 1636 1612 1637 1613 def _is_modified(self, is_modified): … … 1647 1623 if len(statelist) == 0 or len(listtorestore) == 0: 1648 1624 return 1649 if len(statelist) != 1625 if len(statelist) != len(listtorestore): 1650 1626 return 1651 1627 … … 1654 1630 item_page_info = statelist[j] 1655 1631 ##change the state of the check box for simple parameters 1656 if item_page[0] !=None:1632 if item_page[0] != None: 1657 1633 item_page[0].SetValue(item_page_info[0]) 1658 if item_page[2] !=None:1634 if item_page[2] != None: 1659 1635 item_page[2].SetValue(item_page_info[2]) 1660 1636 if item_page[2].__class__.__name__ == "ComboBox": 1661 if self.model.fun_list.has_key(item_page_info[2]):1662 fun_val = self.model.fun_list[item_page_info[2]]1663 self.model.setParam(item_page_info[1],fun_val)1664 if item_page[3] !=None:1637 if item_page_info[2] in self.model.fun_list: 1638 fun_val = self.model.fun_list[item_page_info[2]] 1639 self.model.setParam(item_page_info[1], fun_val) 1640 if item_page[3] != None: 1665 1641 ## show or hide text +/- 1666 1642 if item_page_info[2]: … … 1668 1644 else: 1669 1645 item_page[3].Hide() 1670 if item_page[4] !=None:1646 if item_page[4] != None: 1671 1647 ## show of hide the text crtl for fitting error 1672 1648 if item_page_info[4][0]: … … 1675 1651 else: 1676 1652 item_page[3].Hide() 1677 if item_page[5] !=None:1653 if item_page[5] != None: 1678 1654 ## show of hide the text crtl for fitting error 1679 1655 item_page[5].Show(item_page_info[5][0]) 1680 1656 item_page[5].SetValue(item_page_info[5][1]) 1681 1657 1682 if item_page[6] !=None:1658 if item_page[6] != None: 1683 1659 ## show of hide the text crtl for fitting error 1684 1660 item_page[6].Show(item_page_info[6][0]) 1685 1661 item_page[6].SetValue(item_page_info[6][1]) 1686 1687 1662 1688 1663 def _reset_strparam_state(self, listtorestore, statelist): … … 1700 1675 ##change the state of the check box for simple parameters 1701 1676 1702 if item_page[0] != None: 1677 if item_page[0] != None: 1703 1678 item_page[0].SetValue(format_number(item_page_info[0], True)) 1704 1679 … … 1707 1682 value = item_page_info[2] 1708 1683 selection = value 1709 if self.model.fun_list.has_key(value):1684 if value in self.model.fun_list: 1710 1685 selection = self.model.fun_list[value] 1711 1686 item_page[2].SetValue(selection) … … 1714 1689 def _copy_parameters_state(self, listtocopy, statelist): 1715 1690 """ 1716 copy the state of button 1691 copy the state of button 1717 1692 1718 1693 :param listtocopy: the list of check button to copy … … 1720 1695 1721 1696 """ 1722 if len(listtocopy) ==0:1697 if len(listtocopy) == 0: 1723 1698 return 1724 1699 … … 1726 1701 1727 1702 checkbox_state = None 1728 if item[0] != None:1729 checkbox_state = item[0].GetValue()1703 if item[0] != None: 1704 checkbox_state = item[0].GetValue() 1730 1705 parameter_name = item[1] 1731 1706 parameter_value = None 1732 if item[2] !=None:1707 if item[2] != None: 1733 1708 parameter_value = item[2].GetValue() 1734 1709 static_text = None 1735 if item[3] !=None:1710 if item[3] != None: 1736 1711 static_text = item[3].IsShown() 1737 1712 error_value = None 1738 1713 error_state = None 1739 if item[4] != None:1714 if item[4] != None: 1740 1715 error_value = item[4].GetValue() 1741 1716 error_state = item[4].IsShown() … … 1743 1718 min_value = None 1744 1719 min_state = None 1745 if item[5] != None:1720 if item[5] != None: 1746 1721 min_value = item[5].GetValue() 1747 1722 min_state = item[5].IsShown() … … 1749 1724 max_value = None 1750 1725 max_state = None 1751 if item[6] != None:1726 if item[6] != None: 1752 1727 max_value = item[6].GetValue() 1753 1728 max_state = item[6].IsShown() 1754 unit =None1755 if item[7] !=None:1729 unit = None 1730 if item[7] != None: 1756 1731 unit = item[7].GetLabel() 1757 1732 1758 1733 statelist.append([checkbox_state, parameter_name, parameter_value, 1759 static_text ,[error_state, error_value],1760 1761 1734 static_text, [error_state, error_value], 1735 [min_state, min_value], 1736 [max_state, max_value], unit]) 1762 1737 1763 1738 def _set_model_sizer_selection(self, model): … … 1767 1742 if model == None: 1768 1743 return 1769 if hasattr(model ,"s_model"):1744 if hasattr(model, "s_model"): 1770 1745 1771 1746 class_name = model.s_model.__class__ … … 1775 1750 (class_name in self.model_list_box["Structure Factors"]): 1776 1751 self.structurebox.Show() 1777 self.text2.Show() 1752 self.text2.Show() 1778 1753 self.structurebox.Enable() 1779 1754 self.text2.Enable() … … 1782 1757 1783 1758 for i in range(len(items)): 1784 if items[i] == str(name):1759 if items[i] == str(name): 1785 1760 self.structurebox.SetSelection(i) 1786 1761 break 1787 1762 1788 if hasattr(model ,"p_model"):1763 if hasattr(model, "p_model"): 1789 1764 class_name = model.p_model.__class__ 1790 1765 name = model.p_model.name … … 1792 1767 1793 1768 for k, list in self.model_list_box.iteritems(): 1794 if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: 1769 if k in["P(Q)*S(Q)", "Shapes"] and \ 1770 class_name in self.model_list_box["Shapes"]: 1795 1771 self.shape_rbutton.SetValue(True) 1796 1772 ## fill the form factor list with new model 1797 self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) 1773 self._populate_box(self.formfactorbox, 1774 self.model_list_box["Shapes"]) 1798 1775 items = self.formfactorbox.GetItems() 1799 1776 ## set comboxbox to the selected item 1800 1777 for i in range(len(items)): 1801 if items[i] == str(name):1778 if items[i] == str(name): 1802 1779 self.formfactorbox.SetSelection(i) 1803 1780 break … … 1806 1783 self.shape_indep_rbutton.SetValue(True) 1807 1784 elif k == "Structure Factors": 1808 1809 elif 1785 self.struct_rbutton.SetValue(True) 1786 elif k == "Multi-Functions": 1810 1787 continue 1811 1788 else: … … 1818 1795 ## set comboxbox to the selected item 1819 1796 for i in range(len(items)): 1820 if items[i] == str(name):1797 if items[i] == str(name): 1821 1798 self.formfactorbox.SetSelection(i) 1822 1799 break 1823 1800 break 1824 1801 else: 1825 1826 1802 ## Select the model from the menu 1827 1803 class_name = model.__class__ … … 1830 1806 items = self.formfactorbox.GetItems() 1831 1807 1832 for k, list in self.model_list_box.iteritems(): 1833 if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: 1808 for k, list in self.model_list_box.iteritems(): 1809 if k in["P(Q)*S(Q)", "Shapes"] and \ 1810 class_name in self.model_list_box["Shapes"]: 1834 1811 if class_name in self.model_list_box["P(Q)*S(Q)"]: 1835 1812 self.structurebox.Show() … … 1847 1824 self.shape_rbutton.SetValue(True) 1848 1825 ## fill the form factor list with new model 1849 self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) 1826 self._populate_box(self.formfactorbox, 1827 self.model_list_box["Shapes"]) 1850 1828 items = self.formfactorbox.GetItems() 1851 1829 ## set comboxbox to the selected item 1852 1830 for i in range(len(items)): 1853 if items[i] == str(name):1831 if items[i] == str(name): 1854 1832 self.formfactorbox.SetSelection(i) 1855 1833 break … … 1859 1837 elif k == "Structure Factors": 1860 1838 self.struct_rbutton.SetValue(True) 1861 elif 1839 elif k == "Multi-Functions": 1862 1840 continue 1863 1841 else: … … 1866 1844 self.structurebox.SetSelection(0) 1867 1845 self.structurebox.Disable() 1868 self.text2.Disable() 1846 self.text2.Disable() 1869 1847 ## fill the form factor list with new model 1870 1848 self._populate_box(self.formfactorbox, list) … … 1872 1850 ## set comboxbox to the selected item 1873 1851 for i in range(len(items)): 1874 if items[i] == str(name):1852 if items[i] == str(name): 1875 1853 self.formfactorbox.SetSelection(i) 1876 1854 break … … 1897 1875 #if self.check_invalid_panel(): 1898 1876 # return 1899 if self.model != None:1900 temp_smear =None1877 if self.model != None: 1878 temp_smear = None 1901 1879 if hasattr(self, "enable_smearer"): 1902 1880 if not self.disable_smearer.GetValue(): 1903 temp_smear = self.current_smearer1881 temp_smear = self.current_smearer 1904 1882 # compute weight for the current data 1905 1883 from .utils import get_weight … … 1908 1886 toggle_mode_on = self.model_view.IsEnabled() 1909 1887 is_2d = self._is_2D() 1910 self._manager.draw_model(self.model, 1888 self._manager.draw_model(self.model, 1911 1889 data=self.data, 1912 smearer= 1913 qmin=float(self.qmin_x), 1890 smearer=temp_smear, 1891 qmin=float(self.qmin_x), 1914 1892 qmax=float(self.qmax_x), 1915 1893 page_id=self.uid, 1916 toggle_mode_on=toggle_mode_on, 1917 state =self.state,1894 toggle_mode_on=toggle_mode_on, 1895 state=self.state, 1918 1896 enable2D=is_2d, 1919 1897 update_chisqr=update_chisqr, … … 1921 1899 weight=weight) 1922 1900 1923 1924 1901 def _on_show_sld(self, event=None): 1925 1902 """ … … 1927 1904 """ 1928 1905 # get profile data 1929 x, y=self.model.getProfile()1906 x, y = self.model.getProfile() 1930 1907 1931 1908 from danse.common.plottools import Data1D … … 1933 1910 from sans.guiframe.local_perspectives.plotting.profile_dialog \ 1934 1911 import SLDPanel 1935 sld_data = Data1D(x, y)1912 sld_data = Data1D(x, y) 1936 1913 sld_data.name = 'SLD' 1937 1914 sld_data.axes = self.sld_axes 1938 self.panel = SLDPanel(self, data=sld_data, axes =self.sld_axes,id=-1)1939 self.panel.ShowModal() 1940 1941 def _set_multfactor_combobox(self, multiplicity=10): 1915 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 1916 self.panel.ShowModal() 1917 1918 def _set_multfactor_combobox(self, multiplicity=10): 1942 1919 """ 1943 1920 Set comboBox for muitfactor of CoreMultiShellModel … … 1945 1922 """ 1946 1923 # build content of the combobox 1947 for idx in range(0,multiplicity): 1948 self.multifactorbox.Append(str(idx),int(idx)) 1949 #self.multifactorbox.SetSelection(1) 1924 for idx in range(0, multiplicity): 1925 self.multifactorbox.Append(str(idx), int(idx)) 1950 1926 self._hide_multfactor_combobox() 1951 1927 1952 def _show_multfactor_combobox(self): 1928 def _show_multfactor_combobox(self): 1953 1929 """ 1954 1930 Show the comboBox of muitfactor of CoreMultiShellModel 1955 """ 1931 """ 1956 1932 if not self.mutifactor_text.IsShown(): 1957 1933 self.mutifactor_text.Show(True) 1958 1934 self.mutifactor_text1.Show(True) 1959 1935 if not self.multifactorbox.IsShown(): 1960 self.multifactorbox.Show(True) 1936 self.multifactorbox.Show(True) 1961 1937 1962 def _hide_multfactor_combobox(self): 1938 def _hide_multfactor_combobox(self): 1963 1939 """ 1964 1940 Hide the comboBox of muitfactor of CoreMultiShellModel 1965 """ 1941 """ 1966 1942 if self.mutifactor_text.IsShown(): 1967 1943 self.mutifactor_text.Hide() 1968 1944 self.mutifactor_text1.Hide() 1969 1945 if self.multifactorbox.IsShown(): 1970 self.multifactorbox.Hide() 1971 1972 1946 self.multifactorbox.Hide() 1947 1973 1948 def _show_combox_helper(self): 1974 1949 """ … … 1980 1955 self.structurebox.Disable() 1981 1956 self.formfactorbox.Clear() 1982 self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) 1957 self._populate_box(self.formfactorbox, 1958 self.model_list_box["Shapes"]) 1983 1959 if self.shape_indep_rbutton.GetValue(): 1984 1960 ##fill the combobox with shape independent factor list … … 1986 1962 self.structurebox.Disable() 1987 1963 self.formfactorbox.Clear() 1988 self._populate_box( 1989 1964 self._populate_box(self.formfactorbox, 1965 self.model_list_box["Shape-Independent"]) 1990 1966 if self.struct_rbutton.GetValue(): 1991 1967 ##fill the combobox with structure factor list … … 1993 1969 self.structurebox.Disable() 1994 1970 self.formfactorbox.Clear() 1995 self._populate_box( 1996 1971 self._populate_box(self.formfactorbox, 1972 self.model_list_box["Structure Factors"]) 1997 1973 if self.plugin_rbutton.GetValue(): 1998 1974 ##fill the combobox with form factor list 1999 1975 self.structurebox.Disable() 2000 1976 self.formfactorbox.Clear() 2001 self._populate_box( 2002 1977 self._populate_box(self.formfactorbox, 1978 self.model_list_box["Customized Models"]) 2003 1979 2004 1980 def _show_combox(self, event=None): … … 2006 1982 Show combox box associate with type of model selected 2007 1983 """ 2008 #if self.check_invalid_panel():2009 # self.shape_rbutton.SetValue(True)2010 # return2011 1984 self.Show(False) 2012 1985 self._show_combox_helper() … … 2028 2001 mlist = [] 2029 2002 for models in list: 2030 model = models()2003 model = models() 2031 2004 name = model.__class__.__name__ 2032 if models.__name__ !="NoStructure":2005 if models.__name__ != "NoStructure": 2033 2006 if hasattr(model, "name"): 2034 2007 name = model.name 2035 mlist.append( (name, models))2008 mlist.append((name, models)) 2036 2009 2037 2010 # Sort the models 2038 2011 mlist_sorted = mlist 2039 2012 for item in mlist_sorted: 2040 combobox.Append(item[0], item[1])2013 combobox.Append(item[0], item[1]) 2041 2014 return 0 2042 2015 … … 2066 2039 else: 2067 2040 tcrtl.SetBackgroundColour("pink") 2068 msg = "Model Error:wrong value entered 2041 msg = "Model Error:wrong value entered: %s" % sys.exc_value 2069 2042 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2070 return 2043 return 2071 2044 except: 2072 2045 tcrtl.SetBackgroundColour("pink") 2073 msg = "Model Error:wrong value entered 2046 msg = "Model Error:wrong value entered: %s" % sys.exc_value 2074 2047 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2075 return 2048 return 2076 2049 #Check if # of points for theory model are valid(>0). 2077 2050 if self.npts != None: 2078 2051 if check_float(self.npts): 2079 2052 temp_npts = float(self.npts.GetValue()) 2080 if temp_npts != 2053 if temp_npts != self.num_points: 2081 2054 self.num_points = temp_npts 2082 2055 is_modified = True … … 2085 2058 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2086 2059 else: 2087 tcrtl.SetBackgroundColour("pink") 2088 msg = "Model Error:wrong value entered!!!" 2089 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2090 #self._undo.Enable(True) 2060 tcrtl.SetBackgroundColour("pink") 2061 msg = "Model Error:wrong value entered!!!" 2062 wx.PostEvent(self.parent, StatusEvent(status=msg)) 2091 2063 self.save_current_state() 2092 2064 event = PageInfoEvent(page=self) … … 2103 2075 """ 2104 2076 2105 tcrtl = event.GetEventObject()2077 tcrtl = event.GetEventObject() 2106 2078 #Clear msg if previously shown. 2107 msg = ""2108 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))2079 msg = "" 2080 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2109 2081 # Flag to register when a parameter has changed. 2110 2082 is_modified = False 2111 if tcrtl.GetValue().lstrip().rstrip() !="":2083 if tcrtl.GetValue().lstrip().rstrip() != "": 2112 2084 try: 2113 2085 value = float(tcrtl.GetValue()) … … 2124 2096 else: 2125 2097 tcrtl.SetBackgroundColour("pink") 2126 msg = "Model Error:wrong value entered : %s"% sys.exc_value2127 wx.PostEvent(self._manager.parent, StatusEvent(status = msg))2128 return 2098 msg = "Model Error:wrong value entered: %s" % sys.exc_value 2099 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2100 return 2129 2101 except: 2130 2102 tcrtl.SetBackgroundColour("pink") 2131 msg = "Model Error:wrong value entered : %s"% sys.exc_value2132 wx.PostEvent(self._manager.parent, StatusEvent(status = msg))2133 return 2103 msg = "Model Error:wrong value entered: %s" % sys.exc_value 2104 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2105 return 2134 2106 #Check if # of points for theory model are valid(>0). 2135 if self.Npts_total.IsEditable() 2107 if self.Npts_total.IsEditable(): 2136 2108 if check_float(self.Npts_total): 2137 2109 temp_npts = float(self.Npts_total.GetValue()) 2138 if temp_npts != 2110 if temp_npts != self.num_points: 2139 2111 self.num_points = temp_npts 2140 2112 is_modified = True 2141 2113 else: 2142 msg = "Cannot Plot :No npts in that Qrange!!! "2143 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))2114 msg = "Cannot Plot :No npts in that Qrange!!! " 2115 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2144 2116 else: 2145 tcrtl.SetBackgroundColour("pink") 2146 msg = "Model Error:wrong value entered!!!" 2147 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2148 #self._undo.Enable(True) 2117 tcrtl.SetBackgroundColour("pink") 2118 msg = "Model Error:wrong value entered!!!" 2119 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2149 2120 self.save_current_state() 2150 event = PageInfoEvent(page =self)2121 event = PageInfoEvent(page=self) 2151 2122 wx.PostEvent(self.parent, event) 2152 self.state_change = False2123 self.state_change = False 2153 2124 #Draw the model for a different range 2154 2125 self.create_default_data() 2155 2126 self._draw_model() 2156 2127 2157 def _on_select_model_helper(self): 2128 def _on_select_model_helper(self): 2158 2129 """ 2159 2130 call back for model selection … … 2161 2132 ## reset dictionary containing reference to dispersion 2162 2133 self._disp_obj_dict = {} 2163 self.disp_cb_dict = {}2134 self.disp_cb_dict = {} 2164 2135 self.temp_multi_functional = False 2165 2136 f_id = self.formfactorbox.GetCurrentSelection() … … 2171 2142 if not form_factor in self.model_list_box["multiplication"]: 2172 2143 self.structurebox.Hide() 2173 self.text2.Hide() 2144 self.text2.Hide() 2174 2145 self.structurebox.Disable() 2175 2146 self.structurebox.SetSelection(0) … … 2181 2152 self.text2.Enable() 2182 2153 2183 if form_factor != None: 2184 # set multifactor for Mutifunctional models 2154 if form_factor != None: 2155 # set multifactor for Mutifunctional models 2185 2156 if form_factor().__class__ in self.model_list_box["Multi-Functions"]: 2186 2157 m_id = self.multifactorbox.GetCurrentSelection() 2187 2158 multiplicity = form_factor().multiplicity_info[0] 2188 2159 self.multifactorbox.Clear() 2189 #self.mutifactor_text.SetLabel(form_factor().details[])2190 2160 self._set_multfactor_combobox(multiplicity) 2191 2161 self._show_multfactor_combobox() 2192 #ToDo: this info should be called directly from the model 2193 text = form_factor().multiplicity_info[1]#'No. of Shells: ' 2194 2195 #self.mutifactor_text.Clear() 2162 #ToDo: this info should be called directly from the model 2163 text = form_factor().multiplicity_info[1] # 'No. of Shells: ' 2164 2196 2165 self.mutifactor_text.SetLabel(text) 2197 if m_id > multiplicity - 1:2166 if m_id > multiplicity - 1: 2198 2167 # default value 2199 2168 m_id = 1 2200 2169 2201 2170 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2202 if self.multi_factor == None: self.multi_factor =0 2171 if self.multi_factor == None: 2172 self.multi_factor = 0 2203 2173 form_factor = form_factor(int(self.multi_factor)) 2204 2174 self.multifactorbox.SetSelection(m_id) … … 2223 2193 self._hide_multfactor_combobox() 2224 2194 self.show_sld_button.Hide() 2225 self.multi_factor = None 2195 self.multi_factor = None 2226 2196 2227 2197 s_id = self.structurebox.GetCurrentSelection() 2228 struct_factor = self.structurebox.GetClientData( s_id)2229 2230 if struct_factor != None:2198 struct_factor = self.structurebox.GetClientData(s_id) 2199 2200 if struct_factor != None: 2231 2201 from sans.models.MultiplicationModel import MultiplicationModel 2232 self.model = MultiplicationModel(form_factor,struct_factor())2202 self.model = MultiplicationModel(form_factor, struct_factor()) 2233 2203 # multifunctional form factor 2234 2204 if len(form_factor.non_fittable) > 0: … … 2236 2206 else: 2237 2207 if form_factor != None: 2238 self.model = form_factor2208 self.model = form_factor 2239 2209 else: 2240 2210 self.model = None … … 2242 2212 2243 2213 ## post state to fit panel 2244 self.state.parameters = []2245 self.state.model = self.model2214 self.state.parameters = [] 2215 self.state.model = self.model 2246 2216 self.state.qmin = self.qmin_x 2247 2217 self.state.multi_factor = self.multi_factor 2248 self.disp_list = self.model.getDispParamList()2218 self.disp_list = self.model.getDispParamList() 2249 2219 self.state.disp_list = self.disp_list 2250 2220 self.on_set_focus(None) 2251 self.Layout() 2221 self.Layout() 2252 2222 2253 2223 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): … … 2259 2229 :param qmax_ctrl: text control for Qmax 2260 2230 2261 :return: True is the Q range is value, False otherwise 2231 :return: True is the Q range is value, False otherwise 2262 2232 2263 2233 """ … … 2270 2240 qmax = float(qmax_ctrl.GetValue()) 2271 2241 if qmin < qmax: 2272 #Make sure to set both colours white. 2242 #Make sure to set both colours white. 2273 2243 qmin_ctrl.SetBackgroundColour(wx.WHITE) 2274 2244 qmin_ctrl.Refresh() … … 2280 2250 qmax_ctrl.SetBackgroundColour("pink") 2281 2251 qmax_ctrl.Refresh() 2282 msg = "Invalid Q range: Q min must be smaller than Q max"2283 wx.PostEvent(self.parent.parent, StatusEvent(status =msg))2252 msg = "Invalid Q range: Q min must be smaller than Q max" 2253 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2284 2254 return False 2285 2255 return True 2286 2256 2287 def _validate_Npts(self): 2257 def _validate_Npts(self): 2288 2258 """ 2289 2259 Validate the number of points for fitting is more than 10 points. … … 2297 2267 for data in self.data_list: 2298 2268 # q value from qx and qy 2299 radius = numpy.sqrt( data.qx_data * data.qx_data +2300 data.qy_data * data.qy_data 2269 radius = numpy.sqrt(data.qx_data * data.qx_data + 2270 data.qy_data * data.qy_data) 2301 2271 #get unmasked index 2302 2272 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2303 2273 (radius <= float(self.qmax.GetValue())) 2304 index_data = (index_data) & (data.mask) 2274 index_data = (index_data) & (data.mask) 2305 2275 index_data = (index_data) & (numpy.isfinite(data.data)) 2306 2276 … … 2311 2281 self.qmax.SetBackgroundColour("pink") 2312 2282 self.qmax.Refresh() 2313 msg = "Npts of Data Error :No or too little npts of %s."% data.name2314 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))2283 msg = "Npts of Data Error :No or too little npts of %s." % data.name 2284 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2315 2285 self.fitrange = False 2316 2286 flag = False 2317 2287 else: 2318 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2288 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2319 2289 self.fitrange = True 2320 2290 2321 2291 return flag 2322 2292 2323 def _validate_Npts_1D(self): 2293 def _validate_Npts_1D(self): 2324 2294 """ 2325 2295 Validate the number of points for fitting is more than 5 points. … … 2333 2303 for data in self.data_list: 2334 2304 # q value from qx and qy 2335 radius = data.x2305 radius = data.x 2336 2306 #get unmasked index 2337 2307 index_data = (float(self.qmin.GetValue()) <= radius) & \ … … 2345 2315 self.qmax.SetBackgroundColour("pink") 2346 2316 self.qmax.Refresh() 2347 msg = "Npts of Data Error :No or too little npts of %s."% data.name2348 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))2317 msg = "Npts of Data Error :No or too little npts of %s." % data.name 2318 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2349 2319 self.fitrange = False 2350 2320 flag = False 2351 2321 else: 2352 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2322 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2353 2323 self.fitrange = True 2354 2324 2355 2325 return flag 2356 2357 2358 2326 2359 2327 def _check_value_enter(self, list, modified): … … 2362 2330 :Note: each item of the list should be as follow: 2363 2331 item=[check button state, parameter's name, 2364 paramater's value, string="+/-", 2365 parameter's error of fit, 2366 parameter's minimum value, 2367 parrameter's maximum value , 2332 paramater's value, string="+/-", 2333 parameter's error of fit, 2334 parameter's minimum value, 2335 parrameter's maximum value , 2368 2336 parameter's units] 2369 """ 2370 is_modified = 2371 if len(list) ==0:2337 """ 2338 is_modified = modified 2339 if len(list) == 0: 2372 2340 return is_modified 2373 2341 for item in list: 2374 2342 #skip angle parameters for 1D 2375 if not self.enable2D: #self.data.__class__.__name__ !="Data2D":2343 if not self.enable2D: 2376 2344 if item in self.orientation_params: 2377 2345 continue … … 2379 2347 name = str(item[1]) 2380 2348 2381 if string.find(name, ".npts") ==-1 and \2382 string.find(name, ".nsigmas")==-1:2383 ## check model parameters range 2384 param_min = None2385 param_max = None2349 if string.find(name, ".npts") == -1 and \ 2350 string.find(name, ".nsigmas") == -1: 2351 ## check model parameters range 2352 param_min = None 2353 param_max = None 2386 2354 2387 2355 ## check minimun value 2388 if item[5] != None and item[5]!= "":2389 if item[5].GetValue().lstrip().rstrip() !="":2356 if item[5] != None and item[5] != "": 2357 if item[5].GetValue().lstrip().rstrip() != "": 2390 2358 try: 2391 2392 2359 param_min = float(item[5].GetValue()) 2393 if not self._validate_qrange(item[5], item[2]):2360 if not self._validate_qrange(item[5], item[2]): 2394 2361 if numpy.isfinite(param_min): 2395 2362 item[2].SetValue(format_number(param_min)) … … 2400 2367 except: 2401 2368 msg = "Wrong Fit parameter range entered " 2402 wx.PostEvent(self.parent.parent, 2403 StatusEvent(status =msg))2369 wx.PostEvent(self.parent.parent, 2370 StatusEvent(status=msg)) 2404 2371 raise ValueError, msg 2405 2372 is_modified = True 2406 2373 ## check maximum value 2407 if item[6] != None and item[6]!= "":2408 if item[6].GetValue().lstrip().rstrip() !="":2409 try: 2374 if item[6] != None and item[6] != "": 2375 if item[6].GetValue().lstrip().rstrip() != "": 2376 try: 2410 2377 param_max = float(item[6].GetValue()) 2411 if not self._validate_qrange(item[2], item[6]):2378 if not self._validate_qrange(item[2], item[6]): 2412 2379 if numpy.isfinite(param_max): 2413 item[2].SetValue(format_number(param_max)) 2380 item[2].SetValue(format_number(param_max)) 2414 2381 2415 2382 item[6].SetBackgroundColour(wx.WHITE) … … 2417 2384 except: 2418 2385 msg = "Wrong Fit parameter range entered " 2419 wx.PostEvent(self.parent.parent, 2420 StatusEvent(status =msg))2386 wx.PostEvent(self.parent.parent, 2387 StatusEvent(status=msg)) 2421 2388 raise ValueError, msg 2422 2389 is_modified = True 2423 2390 2424 2425 if param_min != None and param_max !=None: 2391 if param_min != None and param_max != None: 2426 2392 if not self._validate_qrange(item[5], item[6]): 2427 msg = "Wrong Fit range entered for parameter "2428 msg += "name %s of model %s "%(name, self.model.name)2429 wx.PostEvent(self.parent.parent, 2430 StatusEvent(status =msg))2393 msg = "Wrong Fit range entered for parameter " 2394 msg += "name %s of model %s " % (name, self.model.name) 2395 wx.PostEvent(self.parent.parent, 2396 StatusEvent(status=msg)) 2431 2397 2432 if name in self.model.details.keys(): 2398 if name in self.model.details.keys(): 2433 2399 self.model.details[name][1:3] = param_min, param_max 2434 2400 is_modified = True 2435 2436 2401 else: 2437 self.model.details [name] = ["", param_min, param_max]2402 self.model.details[name] = ["", param_min, param_max] 2438 2403 is_modified = True 2439 try: 2404 try: 2440 2405 # Check if the textctr is enabled 2441 2406 if item[2].IsEnabled(): 2442 value = float(item[2].GetValue())2407 value = float(item[2].GetValue()) 2443 2408 item[2].SetBackgroundColour("white") 2444 2409 # If the value of the parameter has changed, … … 2447 2412 numpy.isfinite(value): 2448 2413 self.model.setParam(name, value) 2449 2450 2414 except: 2451 2415 item[2].SetBackgroundColour("pink") 2452 2416 msg = "Wrong Fit parameter value entered " 2453 wx.PostEvent(self.parent.parent, StatusEvent(status =msg))2417 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2454 2418 2455 return is_modified 2456 2457 2419 return is_modified 2420 2458 2421 def _set_dipers_Param(self, event): 2459 2422 """ 2460 2423 respond to self.enable_disp and self.disable_disp radio box. 2461 The dispersity object is reset inside the model into Gaussian. 2462 When the user select yes , this method display a combo box for more selection2463 when the user selects No,the combo box disappears.2424 The dispersity object is reset inside the model into Gaussian. 2425 When the user select yes , this method display a combo box for 2426 more selection when the user selects No,the combo box disappears. 2464 2427 Redraw the model with the default dispersity (Gaussian) 2465 2428 """ 2466 #if self.check_invalid_panel():2467 # return2468 2429 ## On selction if no model exists. 2469 if self.model == None:2430 if self.model == None: 2470 2431 self.disable_disp.SetValue(True) 2471 msg ="Please select a Model first..."2432 msg = "Please select a Model first..." 2472 2433 wx.MessageBox(msg, 'Info') 2473 wx.PostEvent(self._manager.parent, StatusEvent(status=\2474 "Polydispersion: %s"%msg))2434 wx.PostEvent(self._manager.parent, 2435 StatusEvent(status="Polydispersion: %s" % msg)) 2475 2436 return 2476 2437 2477 2438 self._reset_dispersity() 2478 2439 2479 if self.model == None:2440 if self.model == None: 2480 2441 self.model_disp.Hide() 2481 2442 self.sizer4_4.Clear(True) … … 2485 2446 ## layout for model containing no dispersity parameters 2486 2447 2487 self.disp_list = self.model.getDispParamList()2448 self.disp_list = self.model.getDispParamList() 2488 2449 2489 if len(self.disp_list) ==0 and len(self.disp_cb_dict)==0:2490 self._layout_sizer_noDipers() 2450 if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 2451 self._layout_sizer_noDipers() 2491 2452 else: 2492 ## set gaussian sizer 2453 ## set gaussian sizer 2493 2454 self._on_select_Disp(event=None) 2494 2455 else: 2495 2456 self.sizer4_4.Clear(True) 2496 2457 2497 ## post state to fit panel 2458 ## post state to fit panel 2498 2459 self.save_current_state() 2499 if event !=None: 2500 #self._undo.Enable(True) 2501 event = PageInfoEvent(page = self) 2460 if event != None: 2461 event = PageInfoEvent(page=self) 2502 2462 wx.PostEvent(self.parent, event) 2503 2463 #draw the model with the current dispersity … … 2506 2466 self.sizer5.Layout() 2507 2467 self.Layout() 2508 self.Refresh() 2468 self.Refresh() 2509 2469 2510 2511 2470 def _layout_sizer_noDipers(self): 2512 2471 """ 2513 2472 Draw a sizer with no dispersity info 2514 2473 """ 2515 ix =02516 iy =12517 self.fittable_param =[]2518 self.fixed_param =[]2519 self.orientation_params_disp =[]2474 ix = 0 2475 iy = 1 2476 self.fittable_param = [] 2477 self.fixed_param = [] 2478 self.orientation_params_disp = [] 2520 2479 2521 2480 self.sizer4_4.Clear(True) 2522 2481 text = "No polydispersity available for this model" 2523 text = "No polydispersity available for this model"2524 2482 model_disp = wx.StaticText(self, -1, text) 2525 self.sizer4_4.Add(model_disp, ( iy, ix),(1,1),2526 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)2483 self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 2484 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 2527 2485 self.sizer4_4.Layout() 2528 2486 self.sizer4.Layout() … … 2532 2490 put gaussian dispersity into current model 2533 2491 """ 2534 if len(self.param_toFit) >0:2492 if len(self.param_toFit) > 0: 2535 2493 for item in self.fittable_param: 2536 2494 if item in self.param_toFit: … … 2541 2499 self.param_toFit.remove(item) 2542 2500 2543 self.fittable_param =[]2544 self.fixed_param =[]2545 self.orientation_params_disp =[]2546 self.values ={}2547 self.weights ={}2501 self.fittable_param = [] 2502 self.fixed_param = [] 2503 self.orientation_params_disp = [] 2504 self.values = {} 2505 self.weights = {} 2548 2506 2549 from sans.models.dispersion_models import GaussianDispersion , ArrayDispersion2550 if len(self.disp_cb_dict) ==0:2507 from sans.models.dispersion_models import GaussianDispersion 2508 if len(self.disp_cb_dict) == 0: 2551 2509 self.save_current_state() 2552 2510 self.sizer4_4.Clear(True) 2553 2511 self.Layout() 2554 2555 return 2556 if (len(self.disp_cb_dict)>0) : 2512 return 2513 if (len(self.disp_cb_dict) > 0): 2557 2514 for p in self.disp_cb_dict: 2558 # The parameter was un-selected. Go back to Gaussian model (with 0 pts) 2515 # The parameter was un-selected. 2516 # Go back to Gaussian model (with 0 pts) 2559 2517 disp_model = GaussianDispersion() 2560 2518 2561 2519 self._disp_obj_dict[p] = disp_model 2562 # Set the new model as the dispersion object for the selected parameter 2520 # Set the new model as the dispersion object 2521 # for the selected parameter 2563 2522 try: 2564 self.model.set_dispersion(p, disp_model)2523 self.model.set_dispersion(p, disp_model) 2565 2524 except: 2566 2525 … … 2569 2528 ## save state into 2570 2529 self.save_current_state() 2571 self.Layout() 2530 self.Layout() 2572 2531 self.Refresh() 2573 2532 2574 def _on_select_Disp(self, event):2533 def _on_select_Disp(self, event): 2575 2534 """ 2576 2535 allow selecting different dispersion … … 2580 2539 2581 2540 ## Redraw the model 2582 self._draw_model() 2541 self._draw_model() 2583 2542 #self._undo.Enable(True) 2584 event = PageInfoEvent(page =self)2543 event = PageInfoEvent(page=self) 2585 2544 wx.PostEvent(self.parent, event) 2586 2545 … … 2589 2548 self.SetupScrolling() 2590 2549 2591 def _on_disp_func(self, event=None): 2550 def _on_disp_func(self, event=None): 2592 2551 """ 2593 2552 Select a distribution function for the polydispersion 2594 2553 2595 :Param event: ComboBox event 2554 :Param event: ComboBox event 2596 2555 """ 2597 2556 # get ready for new event … … 2599 2558 event.Skip() 2600 2559 # Get event object 2601 disp_box = event.GetEventObject()2560 disp_box = event.GetEventObject() 2602 2561 2603 2562 # Try to select a Distr. function 2604 try: 2563 try: 2605 2564 disp_box.SetBackgroundColour("white") 2606 2565 selection = disp_box.GetCurrentSelection() 2607 2566 param_name = disp_box.Name.split('.')[0] 2608 2567 disp_name = disp_box.GetValue() 2609 dispersity = disp_box.GetClientData(selection)2568 dispersity = disp_box.GetClientData(selection) 2610 2569 2611 2570 #disp_model = GaussianDispersion() … … 2617 2576 # Check Disp. function whether or not it is 'array' 2618 2577 if disp_name.lower() == "array": 2619 value2 = ""2620 value3 = ""2578 value2 = "" 2579 value3 = "" 2621 2580 value1 = self._set_array_disp(name=name1, disp=disp_model) 2622 2581 else: … … 2625 2584 self._disp_obj_dict[name1] = disp_model 2626 2585 self.model.set_dispersion(param_name, disp_model) 2627 self.state._disp_obj_dict[name1] = disp_model2586 self.state._disp_obj_dict[name1] = disp_model 2628 2587 2629 value1 = str(format_number(self.model.getParam(name1), True))2630 value2 = str(format_number(self.model.getParam(name2)))2631 value3 = str(format_number(self.model.getParam(name3)))2588 value1 = str(format_number(self.model.getParam(name1), True)) 2589 value2 = str(format_number(self.model.getParam(name2))) 2590 value3 = str(format_number(self.model.getParam(name3))) 2632 2591 # Reset fittable polydispersin parameter value 2633 2592 for item in self.fittable_param: 2634 2635 item[2].SetValue(value1) 2593 if item[1] == name1: 2594 item[2].SetValue(value1) 2636 2595 item[5].SetValue("") 2637 2596 item[6].SetValue("") … … 2649 2608 item[2].Enable() 2650 2609 item[5].Enable() 2651 item[6].Enable() 2610 item[6].Enable() 2652 2611 break 2653 2612 # Reset fixed polydispersion params … … 2661 2620 item[2].Enable() 2662 2621 if item[1] == name3: 2663 item[2].SetValue(value3) 2622 item[2].SetValue(value3) 2664 2623 # Disable Nsigs for array 2665 2624 if disp_name.lower() == "array": … … 2674 2633 2675 2634 # update params 2676 self._update_paramv_on_fit() 2635 self._update_paramv_on_fit() 2677 2636 # draw 2678 2637 self._draw_model() … … 2686 2645 # Focus on Fit button so that users can see the pinky box 2687 2646 self.btFit.SetFocus() 2688 wx.PostEvent(self.parent.parent, 2647 wx.PostEvent(self.parent.parent, 2689 2648 StatusEvent(status=msg, info="error")) 2690 2691 2649 2692 2650 def _set_array_disp(self, name=None, disp=None): … … 2697 2655 :param disp: the polydisperion object 2698 2656 """ 2699 # The user wants this parameter to be averaged. 2657 # The user wants this parameter to be averaged. 2700 2658 # Pop up the file selection dialog. 2701 2659 path = self._selectDlg() … … 2713 2671 self._default_save_location 2714 2672 2715 basename 2716 values, weights = self.read_file(path)2673 basename = os.path.basename(path) 2674 values, weights = self.read_file(path) 2717 2675 2718 2676 # If any of the two arrays is empty, notify the user that we won't 2719 2677 # proceed 2720 if len(self.param_toFit) >0:2678 if len(self.param_toFit) > 0: 2721 2679 if name in self.param_toFit: 2722 2680 self.param_toFit.remove(name) … … 2724 2682 # Tell the user that we are about to apply the distribution 2725 2683 msg = "Applying loaded %s distribution: %s" % (name, path) 2726 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2684 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2727 2685 self._set_array_disp_model(name=name, disp=disp, 2728 2686 values=values, weights=weights) 2729 2687 return basename 2730 2688 2731 def _set_array_disp_model(self, name=None, disp=None, 2689 def _set_array_disp_model(self, name=None, disp=None, 2732 2690 values=[], weights=[]): 2733 2691 """ … … 2740 2698 self._disp_obj_dict[name] = disp 2741 2699 self.model.set_dispersion(name.split('.')[0], disp) 2742 self.state._disp_obj_dict[name] = disp2700 self.state._disp_obj_dict[name] = disp 2743 2701 self.values[name] = values 2744 2702 self.weights[name] = weights … … 2751 2709 self.state.weights = copy.deepcopy(self.weights) 2752 2710 2753 # Set the new model as the dispersion object for the 2711 # Set the new model as the dispersion object for the 2754 2712 #selected parameter 2755 2713 #self.model.set_dispersion(p, disp_model) 2756 # Store a reference to the weights in the model object 2714 # Store a reference to the weights in the model object 2757 2715 #so that 2758 2716 # it's not lost when we use the model within another thread. 2759 2717 #TODO: total hack - fix this 2760 self.state.model = self.model.clone()2718 self.state.model = self.model.clone() 2761 2719 self.model._persistency_dict[name.split('.')[0]] = \ 2762 2720 [values, weights] 2763 2721 self.state.model._persistency_dict[name.split('.')[0]] = \ 2764 [values, weights]2722 [values, weights] 2765 2723 2766 2767 def _del_array_values(self, name=None): 2724 def _del_array_values(self, name=None): 2768 2725 """ 2769 2726 Reset array dispersion 2770 2727 2771 :param name: name of the parameter for the dispersion to be set 2728 :param name: name of the parameter for the dispersion to be set 2772 2729 """ 2773 2730 # Try to delete values and weight of the names array dic if exists … … 2778 2735 del self.state.values[name] 2779 2736 del self.state.weights[name] 2780 del self.model._persistency_dict[name.split('.')[0]] 2737 del self.model._persistency_dict[name.split('.')[0]] 2781 2738 del self.state.model._persistency_dict[name.split('.')[0]] 2782 2739 except: … … 2792 2749 self._sleep4sec() 2793 2750 self.Layout() 2794 return 2751 return 2795 2752 2796 2753 def _sleep4sec(self): 2797 2754 """ 2798 2755 sleep for 1 sec only applied on Mac 2799 Note: This 1sec helps for Mac not to crash on self.:ayout after self._draw_model 2756 Note: This 1sec helps for Mac not to crash on self. 2757 Layout after self._draw_model 2800 2758 """ 2801 2759 if ON_MAC == True: 2802 2760 time.sleep(1) 2803 2761 2804 def _find_polyfunc_selection(self, disp_func =None):2805 """ 2806 FInd Comboox selection from disp_func 2762 def _find_polyfunc_selection(self, disp_func=None): 2763 """ 2764 FInd Comboox selection from disp_func 2807 2765 2808 2766 :param disp_function: dispersion distr. function 2809 2767 """ 2810 2768 # List of the poly_model name in the combobox 2811 list = ["RectangleDispersion", "ArrayDispersion", 2812 "LogNormalDispersion", "GaussianDispersion",2813 2769 list = ["RectangleDispersion", "ArrayDispersion", 2770 "LogNormalDispersion", "GaussianDispersion", 2771 "SchulzDispersion"] 2814 2772 2815 2773 # Find the selection … … 2818 2776 return selection 2819 2777 except: 2820 2778 return 3 2821 2779 2822 def on_reset_clicked(self, event):2780 def on_reset_clicked(self, event): 2823 2781 """ 2824 2782 On 'Reset' button for Q range clicked 2825 2783 """ 2826 2784 flag = True 2827 #if self.check_invalid_panel():2828 # return2829 2785 ##For 3 different cases: Data2D, Data1D, and theory 2830 2786 if self.model == None: 2831 msg ="Please select a model first..."2787 msg = "Please select a model first..." 2832 2788 wx.MessageBox(msg, 'Info') 2833 2789 flag = False … … 2835 2791 2836 2792 elif self.data.__class__.__name__ == "Data2D": 2837 data_min = 02838 x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax))2839 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax))2793 data_min = 0 2794 x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) 2795 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 2840 2796 self.qmin_x = data_min 2841 2797 self.qmax_x = math.sqrt(x*x + y*y) … … 2843 2799 # check smearing 2844 2800 if not self.disable_smearer.GetValue(): 2845 temp_smearer= self.current_smearer2846 # # set smearing value whether ornot the data contain the smearing info2801 ## set smearing value whether or 2802 # not the data contain the smearing info 2847 2803 if self.pinhole_smearer.GetValue(): 2848 2804 flag = self.update_pinhole_smear() … … 2853 2809 self.qmin_x = _QMIN_DEFAULT 2854 2810 self.qmax_x = _QMAX_DEFAULT 2855 self.num_points = _NPTS_DEFAULT 2811 self.num_points = _NPTS_DEFAULT 2856 2812 self.state.npts = self.num_points 2857 2813 … … 2861 2817 # check smearing 2862 2818 if not self.disable_smearer.GetValue(): 2863 temp_smearer= self.current_smearer2864 # # set smearing value whether ornot the data contain the smearing info2819 ## set smearing value whether or 2820 # not the data contain the smearing info 2865 2821 if self.slit_smearer.GetValue(): 2866 2822 flag = self.update_slit_smear() … … 2873 2829 2874 2830 if flag == False: 2875 msg = "Cannot Plot :Must enter a number!!! "2876 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))2831 msg = "Cannot Plot :Must enter a number!!! " 2832 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 2877 2833 else: 2878 2834 # set relative text ctrs. … … 2880 2836 self.qmax.SetValue(str(self.qmax_x)) 2881 2837 self.set_npts2fit() 2882 # At this point, some button and variables satatus (disabled?) should be checked 2883 # such as color that should be reset to white in case that it was pink. 2838 # At this point, some button and variables satatus (disabled?) 2839 # should be checked such as color that should be reset to 2840 # white in case that it was pink. 2884 2841 self._onparamEnter_helper() 2885 2842 … … 2890 2847 #reset the q range values 2891 2848 self._reset_plotting_range(self.state) 2892 #self.compute_chisqr(smearer=self.current_smearer)2893 #Re draw plot2894 2849 self._draw_model() 2895 2850 … … 2908 2863 # loops through the panels [dic] 2909 2864 for item1, item2 in gui_manager.plot_panels.iteritems(): 2910 data_title = self.data.group_id 2911 data_name = str(self.data.name).split(" [")[0] 2865 data_title = self.data.group_id 2912 2866 # try to get all plots belonging to this control panel 2913 try: 2914 title = '' 2915 # check titles (main plot) 2916 if hasattr(item2,"data2D"): 2917 title = item2.data2D.title 2918 # and data_names (model plot[2D], and residuals) 2919 if item2.group_id == data_title or \ 2867 try: 2868 if item2.group_id == data_title or \ 2920 2869 item2.group_id.count("res" + str(self.graph_id)) or \ 2921 2870 item2.group_id.count(str(self.uid)) > 0: 2922 #panel = gui_manager._mgr.GetPane(item2.window_name) 2923 # append to the list 2924 graphs.append(item2.figure) 2925 canvases.append(item2.canvas) 2926 except: 2927 # Not for control panels 2928 pass 2871 # append to the list 2872 graphs.append(item2.figure) 2873 canvases.append(item2.canvas) 2874 except: 2875 # Not for control panels 2876 pass 2929 2877 # return the list of graphs 2930 2878 return graphs, canvases 2931 2879 2932 def on_model_help_clicked(self, event):2880 def on_model_help_clicked(self, event): 2933 2881 """ 2934 2882 on 'More details' button … … 2939 2887 # Get models help model_function path 2940 2888 path = get_data_path(media='media') 2941 model_path = os.path.join(path, "model_functions.html")2889 model_path = os.path.join(path, "model_functions.html") 2942 2890 if self.model == None: 2943 2891 name = 'FuncHelp' 2944 2892 else: 2945 2893 name = self.formfactorbox.GetValue() 2946 #name = self.model.__class__.__name__ 2947 frame = HelpWindow(None, -1, pageToOpen=model_path) 2894 frame = HelpWindow(None, -1, pageToOpen=model_path) 2948 2895 if frame.rhelp.HasAnchor(name): 2949 2896 frame.Show(True) 2950 2897 frame.rhelp.ScrollToAnchor(name) 2951 2898 else: 2952 #msg= "Sorry, no information is available for this model" 2953 #wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 2954 if self.model != None: 2955 frame.Destroy() 2956 msg = 'Model description:\n' 2957 if str(self.model.description).rstrip().lstrip() == '': 2958 msg += "Sorry, no information is available for this model.\n" 2959 else: 2960 msg += self.model.description + '\n' 2961 info = "Info" 2962 wx.MessageBox(msg, info) 2963 else: 2964 frame.Show(True) 2899 if self.model != None: 2900 frame.Destroy() 2901 msg = 'Model description:\n' 2902 if str(self.model.description).rstrip().lstrip() == '': 2903 msg += "Sorry, no information is available for this model." 2904 else: 2905 msg += self.model.description + '\n' 2906 info = "Info" 2907 wx.MessageBox(msg, info) 2908 else: 2909 frame.Show(True) 2965 2910 2966 2911 def on_pd_help_clicked(self, event): … … 2969 2914 """ 2970 2915 from help_panel import HelpWindow 2971 import sans.models as models 2916 import sans.models as models 2972 2917 2973 2918 # Get models help model_function path 2974 2919 path = models.get_data_path(media='media') 2975 pd_path = os.path.join(path, "pd_help.html")2976 2977 frame = HelpWindow(None, -1, pageToOpen=pd_path)2920 pd_path = os.path.join(path, "pd_help.html") 2921 2922 frame = HelpWindow(None, -1, pageToOpen=pd_path) 2978 2923 frame.Show(True) 2979 2924 … … 2997 2942 Get copy params to clipboard 2998 2943 """ 2999 content = self.get_copy_params() 2944 content = self.get_copy_params() 3000 2945 flag = self.set_clipboard(content) 3001 self._copy_info(flag) 3002 return flag 3003 3004 def get_copy_params(self): 2946 self._copy_info(flag) 2947 return flag 2948 2949 def get_copy_params(self): 3005 2950 """ 3006 2951 Get the string copies of the param names and values in the tap 3007 """ 2952 """ 3008 2953 content = 'sansview_parameter_values:' 3009 # Do it if params exist 3010 if self.parameters != []:3011 3012 # go through the parameters 3013 string = self._get_copy_helper(self.parameters, 2954 # Do it if params exist 2955 if self.parameters != []: 2956 2957 # go through the parameters 2958 string = self._get_copy_helper(self.parameters, 3014 2959 self.orientation_params) 3015 2960 content += string 3016 2961 3017 2962 # go through the fittables 3018 string = self._get_copy_helper(self.fittable_param, 2963 string = self._get_copy_helper(self.fittable_param, 3019 2964 self.orientation_params_disp) 3020 2965 content += string 3021 2966 3022 2967 # go through the fixed params 3023 string = self._get_copy_helper(self.fixed_param, 2968 string = self._get_copy_helper(self.fixed_param, 3024 2969 self.orientation_params_disp) 3025 2970 content += string 3026 2971 3027 2972 # go through the str params 3028 string = self._get_copy_helper(self.str_parameters, 2973 string = self._get_copy_helper(self.str_parameters, 3029 2974 self.orientation_params) 3030 2975 content += string … … 3033 2978 return False 3034 2979 3035 def set_clipboard(self, content=None): 2980 def set_clipboard(self, content=None): 3036 2981 """ 3037 2982 Put the string to the clipboard 3038 """ 2983 """ 3039 2984 if not content: 3040 2985 return False … … 3055 3000 content = '' 3056 3001 # go through the str params 3057 for item in param: 3002 for item in param: 3058 3003 # copy only the params shown 3059 3004 if not item[2].IsShown(): … … 3100 3045 except: 3101 3046 pass 3102 #if disfunc.count('array') == 0: 3103 content += name + ',' + str(check) + ',' + value + disfunc + ':' 3047 content += name + ',' + str(check) + ',' + value + disfunc + ':' 3104 3048 3105 3049 return content 3106 3050 3107 def get_clipboard(self): 3051 def get_clipboard(self): 3108 3052 """ 3109 3053 Get strings in the clipboard 3110 3054 """ 3111 text = "" 3112 # Get text from the clip board 3055 text = "" 3056 # Get text from the clip board 3113 3057 if wx.TheClipboard.Open(): 3114 3058 if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): … … 3131 3075 return flag 3132 3076 3133 def get_paste_params(self, text=''): 3077 def get_paste_params(self, text=''): 3134 3078 """ 3135 3079 Get the string copies of the param names and values in the tap 3136 """ 3137 context = {} 3138 # put the text into dictionary 3080 """ 3081 context = {} 3082 # put the text into dictionary 3139 3083 lines = text.split(':') 3140 3084 if lines[0] != 'sansview_parameter_values': … … 3154 3098 context[name].append(poly_func) 3155 3099 try: 3156 # take the vals and weights for array 3100 # take the vals and weights for array 3157 3101 array_values = item[4].split(' ') 3158 3102 array_weights = item[5].split(' ') … … 3168 3112 context[name].append(poly_func) 3169 3113 3170 # Do it if params exist 3114 # Do it if params exist 3171 3115 if self.parameters != []: 3172 # go through the parameters 3173 self._get_paste_helper(self.parameters, 3116 # go through the parameters 3117 self._get_paste_helper(self.parameters, 3174 3118 self.orientation_params, context) 3175 3119 3176 3120 # go through the fittables 3177 self._get_paste_helper(self.fittable_param, 3178 self.orientation_params_disp, 3121 self._get_paste_helper(self.fittable_param, 3122 self.orientation_params_disp, 3179 3123 context) 3180 3124 3181 3125 # go through the fixed params 3182 self._get_paste_helper(self.fixed_param, 3126 self._get_paste_helper(self.fixed_param, 3183 3127 self.orientation_params_disp, context) 3184 3128 3185 3129 # go through the str params 3186 self._get_paste_helper(self.str_parameters, 3130 self._get_paste_helper(self.str_parameters, 3187 3131 self.orientation_params, context) 3188 3132 … … 3196 3140 : param param: parameters 3197 3141 : param orient_param: oritational params 3198 : param content: dictionary [ name, value: name1.value1,...] 3142 : param content: dictionary [ name, value: name1.value1,...] 3199 3143 """ 3200 3144 # go through the str params 3201 for item in param: 3145 for item in param: 3202 3146 # 2D 3203 3147 if self.data.__class__.__name__ == "Data2D": … … 3218 3162 item[2].Enable(False) 3219 3163 if item[2].__class__.__name__ == "ComboBox": 3220 if self.model.fun_list.has_key(content[name][1]):3164 if content[name][1] in self.model.fun_list: 3221 3165 fun_val = self.model.fun_list[content[name][1]] 3222 3166 self.model.setParam(name, fun_val) … … 3239 3183 if name in content.keys(): 3240 3184 check = content[name][0] 3241 # Avoid changing combox content which needs special care3185 # Avoid changing combox content 3242 3186 value = content[name][1:] 3243 3187 pd = value[0] … … 3254 3198 item[2].Enable(False) 3255 3199 if item[2].__class__.__name__ == "ComboBox": 3256 if self.model.fun_list.has_key(value[0]):3200 if value[0] in self.model.fun_list: 3257 3201 fun_val = self.model.fun_list[value[0]] 3258 3202 self.model.setParam(name, fun_val) 3259 3203 # save state 3260 #self._copy_parameters_state(self.str_parameters,3261 # self.state.str_parameters)3262 3204 self._paste_poly_help(item, value) 3263 3205 if check == 'True': … … 3294 3236 if len(pd_vals) == len(pd_weights): 3295 3237 self._set_disp_array_cb(item=item) 3296 self._set_array_disp_model(name=name, 3238 self._set_array_disp_model(name=name, 3297 3239 disp=disp_model, 3298 values=pd_vals, 3240 values=pd_vals, 3299 3241 weights=pd_weights) 3300 3242 is_array = True 3301 3243 except: 3302 pass 3244 pass 3303 3245 if not is_array: 3304 3246 self._disp_obj_dict[name] = disp_model 3305 self.model.set_dispersion(name, 3247 self.model.set_dispersion(name, 3306 3248 disp_model) 3307 3249 self.state._disp_obj_dict[name] = \ … … 3309 3251 self.model.set_dispersion(param_name, disp_model) 3310 3252 self.state.values = self.values 3311 self.state.weights = self.weights 3253 self.state.weights = self.weights 3312 3254 self.model._persistency_dict[param_name] = \ 3313 [self.state.values, 3255 [self.state.values, 3314 3256 self.state.weights] 3315 3257 3316 3258 except: 3317 print "Error in BasePage._paste_poly_help: %s" % sys.exc_value 3259 print "Error in BasePage._paste_poly_help: %s" % sys.exc_value 3318 3260 3319 3261 def _set_disp_array_cb(self, item): … … 3338 3280 print "BasicPage.update_pinhole_smear was called: skipping" 3339 3281 return 3340 3341
Note: See TracChangeset
for help on using the changeset viewer.