Ignore:
Timestamp:
Sep 27, 2016 8:30:51 AM (8 years ago)
Author:
smk78
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:
6c382da
Parents:
e925f61 (diff), a0373d5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/SasView/sasview

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    ree4b3cb ra0373d5  
    1717from wx.lib.scrolledpanel import ScrolledPanel 
    1818 
    19 import sasmodels.sasview_model 
     19from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 
     20 
    2021from sas.sasgui.guiframe.panel_base import PanelBase 
    21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList 
     22from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 
    2223from sas.sasgui.guiframe.events import PanelOnFocusEvent 
    2324from sas.sasgui.guiframe.events import StatusEvent 
     
    626627        self.disp_help_bt.Bind(wx.EVT_BUTTON, self.on_pd_help_clicked, 
    627628                               id=self.disp_help_bt.GetId()) 
    628         self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 
     629        self.disp_help_bt.SetToolTipString("Help for polydispersion.") 
    629630 
    630631        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
     
    11231124                                                    state.disp_cb_dict[item]) 
    11241125                        # Create the dispersion objects 
    1125                         from sas.models.dispersion_models import ArrayDispersion 
    1126                         disp_model = ArrayDispersion() 
     1126                        disp_model = POLYDISPERSITY_MODELS['array']() 
    11271127                        if hasattr(state, "values") and \ 
    11281128                                 self.disp_cb_dict[item].GetValue() == True: 
     
    22812281                continue 
    22822282 
    2283             name = str(item[1]) 
    2284             if name.endswith(".npts") or name.endswith(".nsigmas"): 
     2283            value_ctrl = item[2] 
     2284            if not value_ctrl.IsEnabled(): 
     2285                # ArrayDispersion disables PD, Min, Max, Npts, Nsigs 
    22852286                continue 
    22862287 
    2287             # Check that min, max and value are floats 
    2288             value_ctrl, min_ctrl, max_ctrl = item[2], item[5], item[6] 
    2289             min_str = min_ctrl.GetValue().strip() 
    2290             max_str = max_ctrl.GetValue().strip() 
     2288            name = item[1] 
    22912289            value_str = value_ctrl.GetValue().strip() 
    2292             validity = check_float(value_ctrl) 
    2293             if min_str != "": 
    2294                 validity = validity and check_float(min_ctrl) 
    2295             if max_str != "": 
    2296                 validity = validity and check_float(max_ctrl) 
    2297             if not validity: 
    2298                 continue 
    2299  
    2300             # Check that min is less than max 
    2301             low = -numpy.inf if min_str == "" else float(min_str) 
    2302             high = numpy.inf if max_str == "" else float(max_str) 
    2303             if high < low: 
    2304                 min_ctrl.SetBackgroundColour("pink") 
    2305                 min_ctrl.Refresh() 
    2306                 max_ctrl.SetBackgroundColour("pink") 
    2307                 max_ctrl.Refresh() 
    2308                 #msg = "Invalid fit range for %s: min must be smaller than max"%name 
    2309                 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    2310                 continue 
    2311  
    2312             # Force value between min and max 
    2313             value = float(value_str) 
    2314             if value < low: 
    2315                 value = low 
    2316                 value_ctrl.SetValue(format_number(value)) 
    2317             elif value > high: 
    2318                 value = high 
    2319                 value_ctrl.SetValue(format_number(value)) 
     2290            if name.endswith(".npts"): 
     2291                validity = check_int(value_ctrl) 
     2292                if not validity: 
     2293                    continue 
     2294                value = int(value_str) 
     2295 
     2296            elif name.endswith(".nsigmas"): 
     2297                validity = check_float(value_ctrl) 
     2298                if not validity: 
     2299                    continue 
     2300                value = float(value_str) 
     2301 
     2302            else:  # value or polydispersity 
     2303 
     2304                # Check that min, max and value are floats 
     2305                min_ctrl, max_ctrl = item[5], item[6] 
     2306                min_str = min_ctrl.GetValue().strip() 
     2307                max_str = max_ctrl.GetValue().strip() 
     2308                validity = check_float(value_ctrl) 
     2309                if min_str != "": 
     2310                    validity = validity and check_float(min_ctrl) 
     2311                if max_str != "": 
     2312                    validity = validity and check_float(max_ctrl) 
     2313                if not validity: 
     2314                    continue 
     2315 
     2316                # Check that min is less than max 
     2317                low = -numpy.inf if min_str == "" else float(min_str) 
     2318                high = numpy.inf if max_str == "" else float(max_str) 
     2319                if high < low: 
     2320                    min_ctrl.SetBackgroundColour("pink") 
     2321                    min_ctrl.Refresh() 
     2322                    max_ctrl.SetBackgroundColour("pink") 
     2323                    max_ctrl.Refresh() 
     2324                    #msg = "Invalid fit range for %s: min must be smaller than max"%name 
     2325                    #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     2326                    continue 
     2327 
     2328                # Force value between min and max 
     2329                value = float(value_str) 
     2330                if value < low: 
     2331                    value = low 
     2332                    value_ctrl.SetValue(format_number(value)) 
     2333                elif value > high: 
     2334                    value = high 
     2335                    value_ctrl.SetValue(format_number(value)) 
     2336 
     2337                if name not in self.model.details.keys(): 
     2338                    self.model.details[name] = ["", None, None] 
     2339                old_low, old_high = self.model.details[name][1:3] 
     2340                if old_low != low or old_high != high: 
     2341                    # The configuration has changed but it won't change the 
     2342                    # computed curve so no need to set is_modified to True 
     2343                    #is_modified = True 
     2344                    self.model.details[name][1:3] = low, high 
    23202345 
    23212346            # Update value in model if it has changed 
     
    23232348                self.model.setParam(name, value) 
    23242349                is_modified = True 
    2325  
    2326             if name not in self.model.details.keys(): 
    2327                 self.model.details[name] = ["", None, None] 
    2328             old_low, old_high = self.model.details[name][1:3] 
    2329             if old_low != low or old_high != high: 
    2330                 # The configuration has changed but it won't change the 
    2331                 # computed curve so no need to set is_modified to True 
    2332                 #is_modified = True 
    2333                 self.model.details[name][1:3] = low, high 
    23342350 
    23352351        return is_modified 
     
    26872703        :param disp_function: dispersion distr. function 
    26882704        """ 
    2689         # List of the poly_model name in the combobox 
    2690         list = ["RectangleDispersion", "ArrayDispersion", 
    2691                 "LogNormalDispersion", "GaussianDispersion", 
    2692                 "SchulzDispersion"] 
    2693  
    26942705        # Find the selection 
    2695         try: 
    2696             selection = list.index(disp_func.__class__.__name__) 
    2697             return selection 
    2698         except: 
    2699             return 3 
     2706        if disp_func is not None: 
     2707            try: 
     2708                return POLYDISPERSITY_MODELS.values().index(disp_func.__class__) 
     2709            except ValueError: 
     2710                pass  # Fall through to default class 
     2711        return POLYDISPERSITY_MODELS.keys().index('gaussian') 
    27002712 
    27012713    def on_reset_clicked(self, event): 
Note: See TracChangeset for help on using the changeset viewer.