Changeset 02098e3 in sasview


Ignore:
Timestamp:
Dec 8, 2015 11:09:13 AM (8 years ago)
Author:
ajj
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:
50a77df
Parents:
12e5cc8 (diff), 1c2bf90 (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:

merging master to integration branch. hopefully successfully this time and with no weird line ending issues

Files:
6 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rf0d720b r02098e3  
    2424build 
    2525 
     26/setup.cfg 
     27 
    2628/dist 
    2729**/build 
     
    3032**/test/logs 
    3133*.pyc 
     34*.so 
    3235default_categories.json 
    3336 
     
    4346/docs/sphinx-docs/source/user/perspectives 
    4447 
    45 default_categories.json 
     48# test outputs 
     49/test/pr_inversion/test/test_output.txt 
     50/test/sasdataloader/test/plugins.zip 
     51/test/sasdataloader/test/test_log.txt 
     52 
  • sasview/README.txt

    r9533593 r40c69b3  
    255255 
    256256   2.2- Installing from source 
    257         - Get the code from GitHub at https://github.com/SasView/sasview.git 
    258           for this release version use: https://github.com/SasView/sasview/releases 
    259           - run 'python setup.py install' under the 'sasview-x.x.x' folder 
     257        - Get the source code 
     258          - to follow the current development version from source control use 
     259              git clone https://github.com/SasView/sasview.git 
     260              git clone https://github.com/bumps/bumps.git 
     261          - to install a specific version 
     262 
     263        - Build, install and run a specific release 
     264          - make sure the requirements below are already installed 
     265          - retrieve the source from https://github.com/SasView/sasview/releases 
     266          - open a command line window in the 'sasview-x.x.x' directory 
     267          - run 'python setup.py install' 
    260268          - run 'python sasview.py' under the 'sasview' folder. 
    261            
     269 
     270        - Build, install and run the current development version 
     271          - clone the source from git; also clone bumps, which is developed in parallel 
     272              git clone https://github.com/SasView/sasview.git 
     273              git clone https://github.com/bumps/bumps.git 
     274          - open a command line window in the 'sasview' directory 
     275          - run 'python setup.py build' 
     276          - run 'python run.py'; this runs from the source directories, so you 
     277            don't have to rebuild every time you make a change, unless you are 
     278            changing the C++ model files 
     279 
    262280        - The following modules are required (version numbers are what are used 
    263281          in the windows release build): 
  • sasview/sasview.py

    r78f75d02 r85130cb  
    6969 
    7070import wx 
     71 
    7172try: 
    7273    logging.info("Wx version: %s" % wx.__version__) 
    7374except: 
    7475    logging.error("Wx version: error reading version") 
     76 
     77import wxcruft 
     78wxcruft.call_later_fix() 
     79#wxcruft.trace_new_id() 
    7580 
    7681# The below will make sure that sasview application uses the matplotlib font 
  • sasview/setup_mac.py

    r49cd712 re8e3e38  
    121121VERSION = sasviewver.__version__ 
    122122APPNAME = "SasView "+VERSION 
    123 DMGNAME = "SasView-"+VERSION 
     123DMGNAME = "SasView-"+VERSION+"-MacOSX" 
    124124 
    125125APP = ['sasview.py'] 
  • src/sas/guiframe/gui_toolbar.py

    r79492222 r6f16e25  
    3636    Implement toolbar for guiframe 
    3737    """ 
     38    ID_BOOKMARK = wx.NewId() 
    3839    def __init__(self, parent,  *args, **kwds): 
    3940        Tbar.__init__(self, parent,  *args, **kwds) 
     
    133134        Add default items in bookmark menu 
    134135        """ 
    135         id = wx.NewId() 
    136         self._bookmark_menu.Append(id, 'Bookmark This Page State') 
     136        self._bookmark_menu.Append(self.ID_BOOKMARK, 'Bookmark This Page State') 
    137137        self._bookmark_menu.AppendSeparator() 
    138         wx.EVT_MENU(self, id, self.on_bookmark) 
     138        wx.EVT_MENU(self, self.ID_BOOKMARK, self.on_bookmark) 
    139139    
    140140    def on_bind_button(self): 
  • src/sas/guiframe/local_perspectives/plotting/Plotter1D.py

    r098f3d2 r6f16e25  
    1919from sas.guiframe.events import StatusEvent 
    2020from sas.guiframe.events import PanelOnFocusEvent 
    21 from sas.guiframe.utils import PanelMenu 
     21from sas.guiframe.utils import PanelMenu, IdList 
    2222from sas.guiframe.panel_base import PanelBase 
    2323from sas.guiframe.gui_style import GUIFRAME_ICON 
     
    3535    """return the key of dictionary dic given the value""" 
    3636    return [k for k, v in dic.iteritems() if v == val][0] 
    37  
    38  
    3937 
    4038class ModelPanel1D(PlotPanel, PanelBase): 
     
    5250    ## Group ID 
    5351    group_id = None 
     52    _menu_ids = IdList() 
    5453 
    5554    def __init__(self, parent, id=-1, color=None, 
     
    6867 
    6968        self._available_data = [] 
    70         self._menu_add_ids = [] 
    7169        self._symbol_labels = self.get_symbol_label() 
    7270        self._color_labels = self.get_color_label() 
     
    556554        self._slicerpop.set_plots(self.plots) 
    557555        self._slicerpop.set_graph(self.graph) 
     556        ids = iter(self._menu_ids) 
    558557        if not self.graph.selected_plottable in self.plots: 
    559558            # Various plot options 
    560             wx_id = wx.NewId() 
     559            wx_id = ids.next() 
    561560            self._slicerpop.Append(wx_id, '&Save Image', 'Save image as PNG') 
    562561            wx.EVT_MENU(self, wx_id, self.onSaveImage) 
    563             wx_id = wx.NewId() 
     562            wx_id = ids.next() 
    564563            self._slicerpop.Append(wx_id, '&Print Image', 'Print image ') 
    565564            wx.EVT_MENU(self, wx_id, self.onPrint) 
    566565 
    567             wx_id = wx.NewId() 
     566            wx_id = ids.next() 
    568567            self._slicerpop.Append(wx_id, '&Copy to Clipboard', 
    569568                                   'Copy to the clipboard') 
     
    582581                    continue 
    583582 
    584             wx_id = wx.NewId() 
     583            wx_id = ids.next() 
    585584            plot_menu.Append(wx_id, "&DataInfo", name) 
    586585            wx.EVT_MENU(self, wx_id, self. _onDataShow) 
    587             wx_id = wx.NewId() 
     586            wx_id = ids.next() 
    588587            plot_menu.Append(wx_id, "&Save Points as a File", name) 
    589588            wx.EVT_MENU(self, wx_id, self._onSave) 
     
    592591            # add menu of other plugins 
    593592            item_list = self.parent.get_current_context_menu(self) 
    594  
    595593            if (not item_list == None) and (not len(item_list) == 0): 
    596                 for item in item_list: 
     594                # Note: reusing menu ids in submenu.  This code works because 
     595                # IdItems is set up as a lazy iterator returning each id in 
     596                # sequence, creating new ids as needed so it never runs out. 
     597                # zip() is set up to stop when any iterator is empty, so it 
     598                # only asks for the number of ids in item_list. 
     599                for item, wx_id in zip(item_list, self._menu_ids): 
    597600 
    598601                    try: 
    599                         wx_id = wx.NewId() 
    600602                        plot_menu.Append(wx_id, item[0], name) 
    601603                        wx.EVT_MENU(self, wx_id, item[2]) 
     
    607609 
    608610            if self.parent.ClassName.count('wxDialog') == 0: 
    609                 wx_id = wx.NewId() 
     611                wx_id = ids.next() 
    610612                plot_menu.Append(wx_id, '&Linear Fit', name) 
    611613                wx.EVT_MENU(self, wx_id, self.onFitting) 
    612614                plot_menu.AppendSeparator() 
    613615 
    614                 wx_id = wx.NewId() 
     616                wx_id = ids.next() 
    615617                plot_menu.Append(wx_id, "Remove", name) 
    616618                wx.EVT_MENU(self, wx_id, self._onRemove) 
    617619                if not plot.is_data: 
    618                     wx_id = wx.NewId() 
     620                    wx_id = ids.next() 
    619621                    plot_menu.Append(wx_id, '&Freeze', name) 
    620622                    wx.EVT_MENU(self, wx_id, self.onFreeze) 
     
    622624 
    623625                if plot.is_data: 
    624                     wx_id = wx.NewId() 
     626                    wx_id = ids.next() 
    625627                    self.hide_menu = plot_menu.Append(wx_id, "Hide Error Bar", name) 
    626628 
     
    636638                    plot_menu.AppendSeparator() 
    637639 
    638                 wx_id = wx.NewId() 
     640                wx_id = ids.next() 
    639641                plot_menu.Append(wx_id, '&Modify Plot Property', name) 
    640642                wx.EVT_MENU(self, wx_id, self.createAppDialog) 
    641             wx_id = wx.NewId() 
     643            wx_id = ids.next() 
    642644            # plot_menu.SetTitle(name) 
    643645            self._slicerpop.AppendMenu(wx_id, '&%s' % name, plot_menu) 
     
    648650            loc_menu = wx.Menu() 
    649651            for label in self._loc_labels: 
    650                 wx_id = wx.NewId() 
     652                wx_id = ids.next() 
    651653                loc_menu.Append(wx_id, str(label), str(label)) 
    652654                wx.EVT_MENU(self, wx_id, self.onChangeLegendLoc) 
    653655 
    654             wx_id = wx.NewId() 
     656            wx_id = ids.next() 
    655657            self._slicerpop.Append(wx_id, '&Modify Graph Appearance', 
    656658                                   'Modify graph appearance') 
     
    660662 
    661663            if self.position != None: 
    662                 wx_id = wx.NewId() 
     664                wx_id = ids.next() 
    663665                self._slicerpop.Append(wx_id, '&Add Text') 
    664666                wx.EVT_MENU(self, wx_id, self._on_addtext) 
    665                 wx_id = wx.NewId() 
     667                wx_id = ids.next() 
    666668                self._slicerpop.Append(wx_id, '&Remove Text') 
    667669                wx.EVT_MENU(self, wx_id, self._on_removetext) 
    668670                self._slicerpop.AppendSeparator() 
    669             wx_id = wx.NewId() 
     671            wx_id = ids.next() 
    670672            self._slicerpop.Append(wx_id, '&Change Scale') 
    671673            wx.EVT_MENU(self, wx_id, self._onProperties) 
    672674            self._slicerpop.AppendSeparator() 
    673             wx_id = wx.NewId() 
     675            wx_id = ids.next() 
    674676            self._slicerpop.Append(wx_id, '&Reset Graph Range') 
    675677            wx.EVT_MENU(self, wx_id, self.onResetGraph) 
     
    677679            if self.parent.ClassName.count('wxDialog') == 0: 
    678680                self._slicerpop.AppendSeparator() 
    679                 wx_id = wx.NewId() 
     681                wx_id = ids.next() 
    680682                self._slicerpop.Append(wx_id, '&Window Title') 
    681683                wx.EVT_MENU(self, wx_id, self.onChangeCaption) 
  • src/sas/guiframe/local_perspectives/plotting/Plotter2D.py

    r098f3d2 r6f16e25  
    287287 
    288288        """ 
     289        ids = iter(self._menu_ids) 
    289290        slicerpop = PanelMenu() 
    290291        slicerpop.set_plots(self.plots) 
    291292        slicerpop.set_graph(self.graph) 
    292293 
    293         wx_id = wx.NewId() 
     294        wx_id = ids.next() 
    294295        slicerpop.Append(wx_id, '&Save Image') 
    295296        wx.EVT_MENU(self, wx_id, self.onSaveImage) 
    296297 
    297         wx_id = wx.NewId() 
     298        wx_id = ids.next() 
    298299        slicerpop.Append(wx_id, '&Print Image', 'Print image') 
    299300        wx.EVT_MENU(self, wx_id, self.onPrint) 
    300301 
    301         wx_id = wx.NewId() 
     302        wx_id = ids.next() 
    302303        slicerpop.Append(wx_id, '&Copy to Clipboard', 'Copy to the clipboard') 
    303304        wx.EVT_MENU(self, wx_id, self.OnCopyFigureMenu) 
     
    305306        # saving data 
    306307        plot = self.data2D 
    307         wx_id = wx.NewId() 
     308        wx_id = ids.next() 
    308309        slicerpop.Append(wx_id, "&Data Info") 
    309310        wx.EVT_MENU(self, wx_id, self._onDataShow) 
    310311 
    311         wx_id = wx.NewId() 
     312        wx_id = ids.next() 
    312313        slicerpop.Append(wx_id, "&Save as a File (DAT)") 
    313314        self.action_ids[str(wx_id)] = plot 
     
    320321                self.data2D.name.split(" ")[0] != 'Residuals': 
    321322                # The line above; Not for trunk 
    322                 for item in item_list: 
     323                # Note: reusing menu ids for the sub-menus.  See Plotter1D. 
     324                for item, wx_id in zip(item_list, self._menu_ids): 
    323325                    try: 
    324                         wx_id = wx.NewId() 
    325326                        slicerpop.Append(wx_id, item[0], item[1]) 
    326327                        wx.EVT_MENU(self, wx_id, item[2]) 
     
    331332                slicerpop.AppendSeparator() 
    332333 
    333             wx_id = wx.NewId() 
     334            wx_id = ids.next() 
    334335            slicerpop.Append(wx_id, '&Perform Circular Average') 
    335336            wx.EVT_MENU(self, wx_id, self.onCircular) \ 
    336337            # For Masked Data 
    337338            if not plot.mask.all(): 
    338                 wx_id = wx.NewId() 
     339                wx_id = ids.next() 
    339340                slicerpop.Append(wx_id, '&Masked Circular Average') 
    340341                wx.EVT_MENU(self, wx_id, self.onMaskedCircular) 
    341             wx_id = wx.NewId() 
     342            wx_id = ids.next() 
    342343            slicerpop.Append(wx_id, '&Sector [Q View]') 
    343344            wx.EVT_MENU(self, wx_id, self.onSectorQ) 
    344             wx_id = wx.NewId() 
     345            wx_id = ids.next() 
    345346            slicerpop.Append(wx_id, '&Annulus [Phi View ]') 
    346347            wx.EVT_MENU(self, wx_id, self.onSectorPhi) 
    347             wx_id = wx.NewId() 
     348            wx_id = ids.next() 
    348349            slicerpop.Append(wx_id, '&Box Sum') 
    349350            wx.EVT_MENU(self, wx_id, self.onBoxSum) 
    350             wx_id = wx.NewId() 
     351            wx_id = ids.next() 
    351352            slicerpop.Append(wx_id, '&Box Averaging in Qx') 
    352353            wx.EVT_MENU(self, wx_id, self.onBoxavgX) 
    353             wx_id = wx.NewId() 
     354            wx_id = ids.next() 
    354355            slicerpop.Append(wx_id, '&Box Averaging in Qy') 
    355356            wx.EVT_MENU(self, wx_id, self.onBoxavgY) 
    356357            if self.slicer != None: 
    357                 wx_id = wx.NewId() 
     358                wx_id = ids.next() 
    358359                slicerpop.Append(wx_id, '&Clear Slicer') 
    359360                wx.EVT_MENU(self, wx_id, self.onClearSlicer) 
    360361                if self.slicer.__class__.__name__ != "BoxSum": 
    361                     wx_id = wx.NewId() 
     362                    wx_id = ids.next() 
    362363                    slicerpop.Append(wx_id, '&Edit Slicer Parameters') 
    363364                    wx.EVT_MENU(self, wx_id, self._onEditSlicer) 
    364365            slicerpop.AppendSeparator() 
    365366 
    366         wx_id = wx.NewId() 
     367        wx_id = ids.next() 
    367368        slicerpop.Append(wx_id, '&Edit Graph Label', 'Edit Graph Label') 
    368369        wx.EVT_MENU(self, wx_id, self.onEditLabels) 
     
    371372        # ILL mod here 
    372373 
    373         wx_id = wx.NewId() 
     374        wx_id = ids.next() 
    374375        slicerpop.Append(wx_id, '&Modify graph appearance', 'Modify graph appearance') 
    375376        wx.EVT_MENU(self, wx_id, self.modifyGraphAppearance) 
    376377        slicerpop.AppendSeparator() 
    377378 
    378         wx_id = wx.NewId() 
     379        wx_id = ids.next() 
    379380        slicerpop.Append(wx_id, '&2D Color Map') 
    380381        wx.EVT_MENU(self, wx_id, self._onEditDetector) 
    381382        slicerpop.AppendSeparator() 
    382383 
    383         wx_id = wx.NewId() 
     384        wx_id = ids.next() 
    384385        slicerpop.Append(wx_id, '&Toggle Linear/Log Scale') 
    385386        wx.EVT_MENU(self, wx_id, self._onToggleScale) 
    386387 
    387388        slicerpop.AppendSeparator() 
    388         wx_id = wx.NewId() 
     389        wx_id = ids.next() 
    389390        slicerpop.Append(wx_id, '&Window Title') 
    390391        wx.EVT_MENU(self, wx_id, self.onChangeCaption) 
  • src/sas/guiframe/utils.py

    r79492222 r6f16e25  
    123123    return begin_flag, end_flag 
    124124 
     125class IdList: 
     126    """ 
     127    Create a list of wx ids that can be reused. 
     128 
     129    Ids for items need to be unique within their context.  In a dynamic 
     130    application where the number of ids needed different each time the 
     131    form is created, depending for example, on the number of items that 
     132    need to be shown in the context menu, you cannot preallocate the 
     133    ids that you are going to use for the form.  Instead, you can use 
     134    an IdList, which will reuse ids from context to context, adding new 
     135    ones if the new context requires more than a previous context. 
     136 
     137    IdList is set up as an iterator, which returns new ids forever 
     138    or until it runs out.  This makes it pretty useful for defining 
     139    menus:: 
     140 
     141        class Form(wx.Dialog): 
     142            _form_id_pool = IdList() 
     143            def __init__(self): 
     144                ... 
     145                menu = wx.Menu() 
     146                for item, wx_id in zip(menu_items, self._form_id_pool): 
     147                    name, description, callback = item 
     148                    menu.Append(wx_id, name, description) 
     149                    wx.EVT_MENU(self, wx_id, callback) 
     150                ... 
     151 
     152    It is a little unusual to use an iterator outside of a loop, but it is 
     153    supported. For example, when defining a form, your class definition 
     154    might look something like:: 
     155 
     156        class Form(wx.Dialog): 
     157            _form_id_pool = IdList() 
     158            def __init__(self, pairs, ...): 
     159                ids = iter(_form_id_pool) 
     160                ... 
     161                wx.StaticText(self, ids.next(), "Some key-value pairs") 
     162                for name, value in pairs: 
     163                    label = wx.StaticText(self, ids.next(), name) 
     164                    input = wx.TextCtrl(self, ids.next(), value=str(value)) 
     165                    ... 
     166                ... 
     167 
     168    If the dialog is really dynamic, and not defined all in one place, then 
     169    save the id list iterator as *self._ids = iter(_form_id_pool)* in the 
     170    constructor. 
     171 
     172    The wx documentation is not clear on whether ids need to be unique. 
     173    Clearly different dialogs can use the same ids, as this is done for the 
     174    standard button ids such as wx.ID_HELP.  Presumably each widget on the 
     175    form needs its own id, but whether these ids can match the ids of menu 
     176    items is not indicated, or whether different submenus need their own 
     177    ids.  Using different id lists for menu items and widgets is safest, 
     178    but probably not necessary.  And what about notebook tabs.  Do the 
     179    ids need to be unique across all tabs? 
     180    """ 
     181    def __init__(self): 
     182        self._ids = [] 
     183    def __iter__(self): 
     184        return _IdListIterator(self) 
     185    def __getitem__(self, index): 
     186        while index >= len(self._ids): 
     187            self._ids.append(wx.NewId()) 
     188        return self._ids[index] 
     189 
     190class _IdListIterator: 
     191    def __init__(self, id_list): 
     192        self.id_list = id_list 
     193        self.index = -1 
     194    def next(self): 
     195        self.index += 1 
     196        return self.id_list[self.index] 
     197 
  • src/sas/models/PeakGaussModel.py

    rac7be54 rd430ee8  
    33PeakGaussModel function as a BaseComponent model 
    44""" 
     5from __future__ import division 
    56 
    67from sas.models.BaseComponent import BaseComponent 
  • src/sas/models/resolution.py

    rbe0c318 r80ba1a2  
    1111MINIMUM_RESOLUTION = 1e-8 
    1212 
    13 class Resolution1D(object): 
     13 
     14# When extrapolating to -q, what is the minimum positive q relative to q_min 
     15# that we wish to calculate? 
     16MIN_Q_SCALE_FOR_NEGATIVE_Q_EXTRAPOLATION = 0.01 
     17 
     18class Resolution(object): 
    1419    """ 
    1520    Abstract base class defining a 1D resolution function. 
     
    3237 
    3338 
    34 class Perfect1D(Resolution1D): 
     39class Perfect1D(Resolution): 
    3540    """ 
    3641    Resolution function to use when there is no actual resolution smearing 
     
    4550 
    4651 
    47 class Pinhole1D(Resolution1D): 
     52class Pinhole1D(Resolution): 
    4853    r""" 
    4954    Pinhole aperture with q-dependent gaussian resolution. 
     
    7782 
    7883 
    79 class Slit1D(Resolution1D): 
     84class Slit1D(Resolution): 
    8085    """ 
    8186    Slit aperture with a complicated resolution function. 
     
    9297    The *weight_matrix* is computed by :func:`slit1d_resolution` 
    9398    """ 
    94     def __init__(self, q, width, height, q_calc=None): 
    95         # TODO: maybe issue warnings rather than raising errors 
    96         if not np.isscalar(width): 
    97             if np.any(np.diff(width) > 0.0): 
    98                 raise ValueError("Slit resolution requires fixed width slits") 
    99             width = width[0] 
    100         if not np.isscalar(height): 
    101             if np.any(np.diff(height) > 0.0): 
    102                 raise ValueError("Slit resolution requires fixed height slits") 
    103             height = height[0] 
    104  
     99    def __init__(self, q, width, height=0., q_calc=None): 
    105100        # Remember what width/height was used even though we won't need them 
    106101        # after the weight matrix is constructed 
    107102        self.width, self.height = width, height 
     103 
     104        # Allow independent resolution on each point even though it is not 
     105        # needed in practice. 
     106        if np.isscalar(width): 
     107            width = np.ones(len(q))*width 
     108        else: 
     109            width = np.asarray(width) 
     110        if np.isscalar(height): 
     111            height = np.ones(len(q))*height 
     112        else: 
     113            height = np.asarray(height) 
    108114 
    109115        self.q = q.flatten() 
     
    147153 
    148154 
    149 def slit_resolution(q_calc, q, width, height): 
     155def slit_resolution(q_calc, q, width, height, n_height=30): 
    150156    r""" 
    151157    Build a weight matrix to compute *I_s(q)* from *I(q_calc)*, given 
    152     $q_v$ = *width* and $q_h$ = *height*. 
    153  
    154     *width* and *height* are scalars since current instruments use the 
    155     same slit settings for all measurement points. 
     158    $q_\perp$ = *width* and $q_\parallel$ = *height*.  *n_height* is 
     159    is the number of steps to use in the integration over $q_\parallel$ 
     160    when both $q_\perp$ and $q_\parallel$ are non-zero. 
     161 
     162    Each $q$ can have an independent width and height value even though 
     163    current instruments use the same slit setting for all measured points. 
    156164 
    157165    If slit height is large relative to width, use: 
     
    159167    .. math:: 
    160168 
    161         I_s(q_o) = \frac{1}{\Delta q_v} 
    162             \int_0^{\Delta q_v} I(\sqrt{q_o^2 + u^2} du 
     169        I_s(q_i) = \frac{1}{\Delta q_\perp} 
     170            \int_0^{\Delta q_\perp} I(\sqrt{q_i^2 + q_\perp^2} dq_\perp 
    163171 
    164172    If slit width is large relative to height, use: 
     
    166174    .. math:: 
    167175 
    168         I_s(q_o) = \frac{1}{2 \Delta q_v} 
    169             \int_{-\Delta q_v}^{\Delta q_v} I(u) du 
    170     """ 
    171     if width == 0.0 and height == 0.0: 
    172         #print "condition zero" 
    173         return 1 
    174  
     176        I_s(q_i) = \frac{1}{2 \Delta q_\parallel} 
     177            \int_{-\Delta q_\parallel}^{\Delta q_\parallel} 
     178                I(|q_i + q_\parallel|) dq_\parallel 
     179 
     180    For a mixture of slit width and height use: 
     181 
     182    .. math:: 
     183 
     184        I_s(q_i) = \frac{1}{2 \Delta q_\parallel \Delta q_\perp} 
     185            \int_{-\Delta q_\parallel)^{\Delta q_parallel} 
     186            \int_0^[\Delta q_\perp} 
     187                I(\sqrt{(q_i + q_\parallel)^2 + q_\perp^2}) 
     188                dq_\perp dq_\parallel 
     189 
     190 
     191    Algorithm 
     192    --------- 
     193 
     194    We are using the mid-point integration rule to assign weights to each 
     195    element of a weight matrix $W$ so that 
     196 
     197    .. math:: 
     198 
     199        I_s(q) = W I(q_\text{calc}) 
     200 
     201    If *q_calc* is at the mid-point, we can infer the bin edges from the 
     202    pairwise averages of *q_calc*, adding the missing edges before 
     203    *q_calc[0]* and after *q_calc[-1]*. 
     204 
     205    For $q_\parallel = 0$, the smeared value can be computed numerically 
     206    using the $u$ substitution 
     207 
     208    .. math:: 
     209 
     210        u_j = \sqrt{q_j^2 - q^2} 
     211 
     212    This gives 
     213 
     214    .. math:: 
     215 
     216        I_s(q) \approx \sum_j I(u_j) \Delta u_j 
     217 
     218    where $I(u_j)$ is the value at the mid-point, and $\Delta u_j$ is the 
     219    difference between consecutive edges which have been first converted 
     220    to $u$.  Only $u_j \in [0, \Delta q_\perp]$ are used, which corresponds 
     221    to $q_j \in [q, \sqrt{q^2 + \Delta q_\perp}]$, so 
     222 
     223    .. math:: 
     224 
     225        W_{ij} = \frac{1}{\Delta q_\perp} \Delta u_j 
     226               = \frac{1}{\Delta q_\perp} 
     227                    \sqrt{q_{j+1}^2 - q_i^2} - \sqrt{q_j^2 - q_i^2} 
     228            \text{if} q_j \in [q_i, \sqrt{q_i^2 + q_\perp^2}] 
     229 
     230    where $I_s(q_i)$ is the theory function being computed and $q_j$ are the 
     231    mid-points between the calculated values in *q_calc*.  We tweak the 
     232    edges of the initial and final intervals so that they lie on integration 
     233    limits. 
     234 
     235    (To be precise, the transformed midpoint $u(q_j)$ is not necessarily the 
     236    midpoint of the edges $u((q_{j-1}+q_j)/2)$ and $u((q_j + q_{j+1})/2)$, 
     237    but it is at least in the interval, so the approximation is going to be 
     238    a little better than the left or right Riemann sum, and should be 
     239    good enough for our purposes.) 
     240 
     241    For $q_\perp = 0$, the $u$ substitution is simpler: 
     242 
     243    .. math:: 
     244 
     245        u_j = |q_j - q| 
     246 
     247    so 
     248 
     249    .. math:: 
     250 
     251        W_ij = \frac{1}{2 \Delta q_\parallel} \Delta u_j 
     252            = \frac{1}{2 \Delta q_\parallel} (q_{j+1} - q_j) 
     253            \text{if} q_j \in [q-\Delta q_\parallel, q+\Delta q_\parallel] 
     254 
     255    However, we need to support cases were $u_j < 0$, which means using 
     256    $2 (q_{j+1} - q_j)$ when $q_j \in [0, q_\parallel-q_i]$.  This is not 
     257    an issue for $q_i > q_\parallel$. 
     258 
     259    For bot $q_\perp > 0$ and $q_\parallel > 0$ we perform a 2 dimensional 
     260    integration with 
     261 
     262    .. math:: 
     263 
     264        u_jk = \sqrt{q_j^2 - (q + (k\Delta q_\parallel/L))^2} 
     265            \text{for} k = -L \ldots L 
     266 
     267    for $L$ = *n_height*.  This gives 
     268 
     269    .. math:: 
     270 
     271        W_{ij} = \frac{1}{2 \Delta q_\perp q_\parallel} 
     272            \sum_{k=-L}^L \Delta u_jk (\frac{\Delta q_\parallel}{2 L + 1} 
     273 
     274 
     275    """ 
     276    #np.set_printoptions(precision=6, linewidth=10000) 
     277 
     278    # The current algorithm is a midpoint rectangle rule. 
    175279    q_edges = bin_edges(q_calc) # Note: requires q > 0 
    176280    q_edges[q_edges<0.0] = 0.0 # clip edges below zero 
    177  
    178     #np.set_printoptions(linewidth=10000) 
    179     if width <= 100.0 * height or height == 0: 
    180         # The current algorithm is a midpoint rectangle rule.  In the test case, 
    181         # neither trapezoid nor Simpson's rule improved the accuracy. 
    182         #print "condition h", q_edges.shape, q.shape, q_calc.shape 
    183         weights = np.zeros((len(q), len(q_calc)), 'd') 
    184         for i, qi in enumerate(q): 
    185             weights[i, :] = np.diff(q_to_u(q_edges, qi)) 
    186         weights /= width 
    187         weights = weights.T 
    188     else: 
    189         #print "condition w" 
    190         # Make q_calc into a row vector, and q into a column vector 
    191         q, q_calc = q[None,:], q_calc[:,None] 
    192         in_x = (q_calc >= q-width) * (q_calc <= q+width) 
    193         weights = np.diff(q_edges)[:,None] * in_x 
    194  
     281    weights = np.zeros((len(q), len(q_calc)), 'd') 
     282 
     283    #print q_calc 
     284    for i, (qi, w, h) in enumerate(zip(q, width, height)): 
     285        if w == 0. and h == 0.: 
     286            # Perfect resolution, so return the theory value directly. 
     287            # Note: assumes that q is a subset of q_calc.  If qi need not be 
     288            # in q_calc, then we can do a weighted interpolation by looking 
     289            # up qi in q_calc, then weighting the result by the relative 
     290            # distance to the neighbouring points. 
     291            weights[i, :] = (q_calc == qi) 
     292        elif h == 0: 
     293            weights[i, :] = _q_perp_weights(q_edges, qi, w) 
     294        elif w == 0: 
     295            in_x = 1.0 * ((q_calc >= qi-h) & (q_calc <= qi+h)) 
     296            abs_x = 1.0*(q_calc < abs(qi - h)) if qi < h else 0. 
     297            #print qi - h, qi + h 
     298            #print in_x + abs_x 
     299            weights[i,:] = (in_x + abs_x) * np.diff(q_edges) / (2*h) 
     300        else: 
     301            L = n_height 
     302            for k in range(-L, L+1): 
     303                weights[i,:] += _q_perp_weights(q_edges, qi+k*h/L, w) 
     304            weights[i,:] /= 2*L + 1 
     305 
     306    return weights.T 
     307 
     308 
     309def _q_perp_weights(q_edges, qi, w): 
     310    # Convert bin edges from q to u 
     311    u_limit = np.sqrt(qi**2 + w**2) 
     312    u_edges = q_edges**2 - qi**2 
     313    u_edges[q_edges < abs(qi)] = 0. 
     314    u_edges[q_edges > u_limit] = u_limit**2 - qi**2 
     315    weights = np.diff(np.sqrt(u_edges))/w 
     316    #print "i, qi",i,qi,qi+width 
     317    #print q_calc 
     318    #print weights 
    195319    return weights 
    196320 
     
    212336    function. 
    213337    """ 
    214     height # keep lint happy 
    215     q_min, q_max = np.min(q), np.max(np.sqrt(q**2 + width**2)) 
     338    q_min, q_max = np.min(q-height), np.max(np.sqrt((q+height)**2 + width**2)) 
     339 
    216340    return geometric_extrapolation(q, q_min, q_max) 
    217341 
     
    233357        ]) 
    234358    return edges 
    235  
    236  
    237 def q_to_u(q, q0): 
    238     """ 
    239     Convert *q* values to *u* values for the integral computed at *q0*. 
    240     """ 
    241     # array([value])**2 - value**2 is not always zero 
    242     qpsq = q**2 - q0**2 
    243     qpsq[qpsq<0] = 0 
    244     return sqrt(qpsq) 
    245359 
    246360 
     
    275389    q = np.sort(q) 
    276390    if q_min < q[0]: 
    277         if q_min <= 0: q_min = q[0]/10 
     391        if q_min <= 0: q_min = q_min*MIN_Q_SCALE_FOR_NEGATIVE_Q_EXTRAPOLATION 
    278392        n_low = np.ceil((q[0]-q_min) / (q[1]-q[0])) if q[1]>q[0] else 15 
    279393        q_low = np.linspace(q_min, q[0], n_low+1)[:-1] 
     
    297411    *points_per_decade* sets the ratio between consecutive steps such 
    298412    that there will be $n$ points used for every factor of 10 increase 
    299     in $q$. 
     413    in *q*. 
    300414 
    301415    If *points_per_decade* is not given, it will be estimated as follows. 
     
    316430    Substituting: 
    317431 
    318     .. math:: 
    319  
    320432        n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n) 
    321             / (\log q_n - \log q_1) 
     433            / (\log q_n - log q_1) 
    322434    """ 
    323435    q = np.sort(q) 
     
    327439        log_delta_q = log(10.) / points_per_decade 
    328440    if q_min < q[0]: 
    329         if q_min < 0: q_min = q[0]/10 
     441        if q_min < 0: q_min = q[0]*MIN_Q_SCALE_FOR_NEGATIVE_Q_EXTRAPOLATION 
    330442        n_low = log_delta_q * (log(q[0])-log(q_min)) 
    331443        q_low  = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 
     
    359471 
    360472 
    361 def romberg_slit_1d(q, delta_qv, form, pars): 
     473def romberg_slit_1d(q, width, height, form, pars): 
    362474    """ 
    363475    Romberg integration for slit resolution. 
     
    366478    that make it slow to evaluate but give it good accuracy. 
    367479    """ 
    368     from scipy.integrate import romberg 
     480    from scipy.integrate import romberg, dblquad 
    369481 
    370482    if any(k not in form.info['defaults'] for k in pars.keys()): 
     
    374486                         (", ".join(sorted(extra)), ", ".join(sorted(keys)))) 
    375487 
    376     _fn = lambda u, q0: eval_form(sqrt(q0**2 + u**2), form, pars) 
    377     r = [romberg(_fn, 0, delta_qv[0], args=(qi,), 
    378                  divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    379          for qi in q] 
     488    if np.isscalar(width): 
     489        width = [width]*len(q) 
     490    if np.isscalar(height): 
     491        height = [height]*len(q) 
     492    _int_w = lambda w, qi: eval_form(sqrt(qi**2 + w**2), form, pars) 
     493    _int_h = lambda h, qi: eval_form(abs(qi+h), form, pars) 
     494    # If both width and height are defined, then it is too slow to use dblquad. 
     495    # Instead use trapz on a fixed grid, interpolated into the I(Q) for 
     496    # the extended Q range. 
     497    #_int_wh = lambda w, h, qi: eval_form(sqrt((qi+h)**2 + w**2), form, pars) 
     498    q_calc = slit_extend_q(q, np.asarray(width), np.asarray(height)) 
     499    Iq = eval_form(q_calc, form, pars) 
     500    result = np.empty(len(q)) 
     501    for i, (qi, w, h) in enumerate(zip(q, width, height)): 
     502        if h == 0.: 
     503            r = romberg(_int_w, 0, w, args=(qi,), 
     504                        divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     505            result[i] = r/w 
     506        elif w == 0.: 
     507            r = romberg(_int_h, -h, h, args=(qi,), 
     508                        divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     509            result[i] = r/(2*h) 
     510        else: 
     511            w_grid = np.linspace(0, w, 21)[None,:] 
     512            h_grid = np.linspace(-h, h, 23)[:,None] 
     513            u = sqrt((qi+h_grid)**2 + w_grid**2) 
     514            Iu = np.interp(u, q_calc, Iq) 
     515            #print np.trapz(Iu, w_grid, axis=1) 
     516            Is = np.trapz(np.trapz(Iu, w_grid, axis=1), h_grid[:,0]) 
     517            result[i] = Is / (2*h*w) 
     518            """ 
     519            r, err = dblquad(_int_wh, -h, h, lambda h: 0., lambda h: w, 
     520                             args=(qi,)) 
     521            result[i] = r/(w*2*h) 
     522            """ 
     523 
    380524    # r should be [float, ...], but it is [array([float]), array([float]),...] 
    381     return np.asarray(r).flatten()/delta_qv[0] 
     525    return result 
    382526 
    383527 
     
    520664 
    521665    def compare(self, q, output, answer, tolerance): 
    522         err = (output - answer)/answer 
    523         idx = abs(err) >= tolerance 
    524         problem = zip(q[idx], output[idx], answer[idx], err[idx]) 
    525         print "\n".join(str(v) for v in problem) 
     666        #err = (output - answer)/answer 
     667        #idx = abs(err) >= tolerance 
     668        #problem = zip(q[idx], output[idx], answer[idx], err[idx]) 
     669        #print "\n".join(str(v) for v in problem) 
    526670        np.testing.assert_allclose(output, answer, rtol=tolerance) 
    527671 
     
    609753        data = np.loadtxt(data_string.split('\n')).T 
    610754        q, delta_qv, _, answer = data 
    611         answer = romberg_slit_1d(q, delta_qv, self.model, pars) 
     755        answer = romberg_slit_1d(q, delta_qv, 0., self.model, pars) 
    612756        q_calc = slit_extend_q(interpolate(q, 2*np.pi/radius/20), 
    613                                delta_qv[0], delta_qv[0]) 
     757                               delta_qv[0], 0.) 
    614758        resolution = Slit1D(q, width=delta_qv, height=0, q_calc=q_calc) 
    615759        output = self.Iq_sphere(pars, resolution) 
     
    629773        form = load_model('ellipsoid', dtype='double') 
    630774        q = np.logspace(log10(4e-5),log10(2.5e-2), 68) 
    631         delta_qv = [0.117] 
    632         resolution = Slit1D(q, width=delta_qv, height=0) 
    633         answer = romberg_slit_1d(q, delta_qv, form, pars) 
     775        width, height = 0.117, 0. 
     776        resolution = Slit1D(q, width=width, height=height) 
     777        answer = romberg_slit_1d(q, width, height, form, pars) 
    634778        output = resolution.apply(eval_form(resolution.q_calc, form, pars)) 
    635779        # TODO: 10% is too much error; use better algorithm 
     780        #print np.max(abs(answer-output)/answer) 
    636781        self.compare(q, output, answer, 0.1) 
    637782 
     
    8601005 
    8611006def _eval_demo_1d(resolution, title): 
     1007    import sys 
    8621008    from sasmodels import core 
    863     from sasmodels.models import cylinder 
    864     ## or alternatively: 
    865     # cylinder = core.load_model_definition('cylinder') 
    866     model = core.load_model(cylinder) 
     1009    name = sys.argv[1] if len(sys.argv) > 1 else 'cylinder' 
     1010 
     1011    if name == 'cylinder': 
     1012        pars = {'length':210, 'radius':500} 
     1013    elif name == 'teubner_strey': 
     1014        pars = {'a2':0.003, 'c1':-1e4, 'c2':1e10, 'background':0.312643} 
     1015    elif name == 'sphere' or name == 'spherepy': 
     1016        pars = TEST_PARS_SLIT_SPHERE 
     1017    elif name == 'ellipsoid': 
     1018        pars = { 
     1019            'scale':0.05, 
     1020            'rpolar':500, 'requatorial':15000, 
     1021            'sld':6, 'solvent_sld': 1, 
     1022            } 
     1023    else: 
     1024        pars = {} 
     1025    defn = core.load_model_definition(name) 
     1026    model = core.load_model(defn) 
    8671027 
    8681028    kernel = core.make_kernel(model, [resolution.q_calc]) 
    869     theory = core.call_kernel(kernel, {'length':210, 'radius':500}) 
     1029    theory = core.call_kernel(kernel, pars) 
    8701030    Iq = resolution.apply(theory) 
     1031 
     1032    if isinstance(resolution, Slit1D): 
     1033        width, height = resolution.width, resolution.height 
     1034        Iq_romb = romberg_slit_1d(resolution.q, width, height, model, pars) 
     1035    else: 
     1036        dq = resolution.q_width 
     1037        Iq_romb = romberg_pinhole_1d(resolution.q, dq, model, pars) 
    8711038 
    8721039    import matplotlib.pyplot as plt 
    8731040    plt.loglog(resolution.q_calc, theory, label='unsmeared') 
    8741041    plt.loglog(resolution.q, Iq, label='smeared', hold=True) 
     1042    plt.loglog(resolution.q, Iq_romb, label='romberg smeared', hold=True) 
    8751043    plt.legend() 
    8761044    plt.title(title) 
     
    8791047 
    8801048def demo_pinhole_1d(): 
    881     q = np.logspace(-3, -1, 400) 
     1049    q = np.logspace(-4, np.log10(0.2), 400) 
    8821050    q_width = 0.1*q 
    8831051    resolution = Pinhole1D(q, q_width) 
     
    8851053 
    8861054def demo_slit_1d(): 
    887     q = np.logspace(-3, -1, 400) 
    888     qx_width = 0.005 
    889     qy_width = 0.0 
    890     resolution = Slit1D(q, qx_width, qy_width) 
    891     _eval_demo_1d(resolution, title="0.005 Qx Slit Resolution") 
     1055    q = np.logspace(-4, np.log10(0.2), 100) 
     1056    w = h = 0. 
     1057    #w = 0.000000277790 
     1058    w = 0.0277790 
     1059    #h = 0.00277790 
     1060    #h = 0.0277790 
     1061    resolution = Slit1D(q, w, h) 
     1062    _eval_demo_1d(resolution, title="(%g,%g) Slit Resolution"%(w,h)) 
    8921063 
    8931064def demo(): 
     
    8951066    plt.subplot(121) 
    8961067    demo_pinhole_1d() 
     1068    #plt.yscale('linear') 
    8971069    plt.subplot(122) 
    8981070    demo_slit_1d() 
     1071    #plt.yscale('linear') 
    8991072    plt.show() 
    9001073 
    9011074 
    9021075if __name__ == "__main__": 
    903     #demo() 
    904     main() 
     1076    demo() 
     1077    #main() 
  • src/sas/perspectives/fitting/basepage.py

    rf0d720b r02098e3  
    1515from wx.lib.scrolledpanel import ScrolledPanel 
    1616from sas.guiframe.panel_base import PanelBase 
    17 from sas.guiframe.utils import format_number, check_float 
     17from sas.guiframe.utils import format_number, check_float, IdList 
    1818from sas.guiframe.events import PanelOnFocusEvent 
    1919from sas.guiframe.events import StatusEvent 
     
    5757    ## Title to appear on top of the window 
    5858    window_caption = "Fit Page " 
    59      
     59 
     60    # These two buttons have specific IDs since they seem to be created more 
     61    # frequently than they need to.  In particular, set_dispers_sizer() is 
     62    # called by _on_select_model 
     63    ID_BOOKMARK = wx.NewId() 
     64    ID_DISPERSER_HELP = wx.NewId() 
     65    _id_pool = IdList() 
     66 
    6067    def __init__(self, parent, color='blue', **kwargs): 
    6168        """ 
     
    6673        #Set window's font size 
    6774        self.SetWindowVariant(variant=FONT_VARIANT) 
    68        
    6975        self.SetBackgroundColour(color) 
     76 
     77        self._ids = iter(self._id_pool) 
    7078        ## parent of the page 
    7179        self.parent = parent 
     
    126134        self.Npts_fit = None 
    127135        self.Npts_total = None 
    128         self.theory_qmin = None  
     136        self.theory_qmin = None 
    129137        self.theory_qmax = None 
    130138        self.theory_qmin_x = None 
     
    135143        self.sld_axes = None 
    136144        self.multi_factor = None 
    137         
     145 
    138146        self.disp_cb_dict = {} 
    139     
     147 
    140148        #self.state = PageState(parent=parent) 
    141149        ## dictionary containing list of models 
    142150        self.model_list_box = {} 
    143         
     151 
    144152        ## Data member to store the dispersion object created 
    145153        self._disp_obj_dict = {} 
     
    169177        self.disp_list = [] 
    170178        self.disp_name = "" 
    171          
     179 
    172180        ## list of orientation parameters 
    173181        self.orientation_params = [] 
    174182        self.orientation_params_disp = [] 
    175 #       Self.model should ALWAYS be None here.  It was set to none above in  
     183#       Self.model should ALWAYS be None here.  It was set to none above in 
    176184#       this long init setting.  no obvious function call in between setting 
    177 #       and this - commenting out on 4/8/2014 by PDB.  Remove once clear  
     185#       and this - commenting out on 4/8/2014 by PDB.  Remove once clear 
    178186#       it is pointless. 
    179187#        if self.model != None: 
     
    198206        ## Create context menu for page 
    199207        self.popUpMenu = wx.Menu() 
    200      
    201         id = wx.NewId() 
    202         self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 
     208 
     209        wx_id = self._ids.next() 
     210        self._keep = wx.MenuItem(self.popUpMenu, wx_id, "Add bookmark", 
    203211                                 " Keep the panel status to recall it later") 
    204212        self.popUpMenu.AppendItem(self._keep) 
     
    206214        self._set_bookmark_flag(False) 
    207215        self._set_save_flag(False) 
    208         wx.EVT_MENU(self, id, self.on_bookmark) 
     216        wx.EVT_MENU(self, wx_id, self.on_bookmark) 
    209217        self.popUpMenu.AppendSeparator() 
    210      
     218 
    211219        ## Default locations 
    212220        self._default_save_location = os.getcwd() 
     
    214222        #self.onSave(event=None) 
    215223        self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 
    216          
     224 
    217225        # bind key event 
    218226        self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 
    219          
     227 
    220228        ## create the basic structure of the panel with empty sizer 
    221229        self.define_page_structure() 
    222230        ## drawing Initial dispersion parameters sizer 
    223231        self.set_dispers_sizer() 
    224          
     232 
    225233        ## layout 
    226234        self.set_layout() 
    227      
     235 
    228236    def set_index_model(self, index): 
    229237        """ 
     
    231239        """ 
    232240        self.index_model = index 
    233          
     241 
    234242    def create_default_data(self): 
    235243        """ 
     
    248256                else: 
    249257                    self._create_default_1d_data() 
    250                          
     258 
    251259            if self.model != None: 
    252260                if not self.data.is_data: 
     
    258266            self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 
    259267            self.state.slit_smearer = self.slit_smearer.GetValue() 
    260          
     268 
    261269    def _create_default_1d_data(self): 
    262270        """ 
     
    264272        Only when the page is on theory mode. 
    265273        :warning: This data is never plotted. 
    266          
     274 
    267275        """ 
    268276        x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 
     
    274282        self.data.id = str(self.uid) + " data" 
    275283        self.data.group_id = str(self.uid) + " Model1D" 
    276           
     284 
    277285    def _create_log_1d_data(self): 
    278286        """ 
     
    280288        Only when the page is on theory mode. 
    281289        :warning: This data is never plotted. 
    282          
     290 
    283291        """ 
    284292        if self.qmin_x >= 1.e-10: 
    285293            qmin = numpy.log10(self.qmin_x) 
    286294        else: 
    287             qmin = -10.     
    288              
     295            qmin = -10. 
     296 
    289297        if self.qmax_x <= 1.e10: 
    290298            qmax = numpy.log10(self.qmax_x) 
    291299        else: 
    292             qmax = 10.  
    293                 
     300            qmax = 10. 
     301 
    294302        x = numpy.logspace(start=qmin, stop=qmax, 
    295303                           num=self.npts_x, endpoint=True, base=10.0) 
     
    300308        self.data.id = str(self.uid) + " data" 
    301309        self.data.group_id = str(self.uid) + " Model1D" 
    302        
     310 
    303311    def _create_default_2d_data(self): 
    304312        """ 
     
    358366        #xstep = x_size / len(x_bins - 1) 
    359367        #ystep = y_size / len(y_bins - 1) 
    360    
     368 
    361369        self.data.source = Source() 
    362370        self.data.data = numpy.ones(len(mask)) 
     
    381389            wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 
    382390            self.on_tap_focus() 
    383                 
     391 
    384392    def on_tap_focus(self): 
    385393        """ 
     
    397405                    self._manager.menu1.FindItemById(self._manager.id_batchfit) 
    398406            batch_menu.Enable(self.batch_on and flag) 
    399      
     407 
    400408    def set_page_info(self, page_info): 
    401409        """ 
    402410        set some page important information at once 
    403411        """ 
    404 #       THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED.  Started up program  
     412#       THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED.  Started up program 
    405413#       and started new fit window and PR and Invariant and a fit in fitting 
    406414#       but never entered this routine which should be an initialization 
    407 #       routine.  Leave for a while but probably something to clean up at  
     415#       routine.  Leave for a while but probably something to clean up at 
    408416#       some point? 
    409417# 
     
    426434        ## Data member to store the dispersion object created 
    427435        self.populate_box(model_dict=self.model_list_box) 
    428          
     436 
    429437    def onContextMenu(self, event): 
    430438        """ 
     
    433441        # Skipping the save state functionality for release 0.9.0 
    434442        #return 
    435      
     443 
    436444        pos = event.GetPosition() 
    437445        pos = self.ScreenToClient(pos) 
    438         
     446 
    439447        self.PopupMenu(self.popUpMenu, pos) 
    440        
     448 
    441449    def onUndo(self, event): 
    442450        """ 
     
    445453        event = PreviousStateEvent(page=self) 
    446454        wx.PostEvent(self.parent, event) 
    447          
     455 
    448456    def onRedo(self, event): 
    449457        """ 
     
    452460        event = NextStateEvent(page=self) 
    453461        wx.PostEvent(self.parent, event) 
    454      
     462 
    455463    def define_page_structure(self): 
    456464        """ 
     
    465473        self.sizer5 = wx.BoxSizer(wx.VERTICAL) 
    466474        self.sizer6 = wx.BoxSizer(wx.VERTICAL) 
    467          
     475 
    468476        self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 
    469477        self.sizer1.SetMinSize((PANEL_WIDTH, -1)) 
     
    473481        self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 
    474482        self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 
    475          
     483 
    476484        self.vbox.Add(self.sizer0) 
    477485        self.vbox.Add(self.sizer1) 
     
    481489        self.vbox.Add(self.sizer5) 
    482490        self.vbox.Add(self.sizer6) 
    483          
     491 
    484492    def set_layout(self): 
    485493        """ 
     
    490498        self.SetSizer(self.vbox) 
    491499        self.Centre() 
    492   
     500 
    493501    def set_owner(self, owner): 
    494502        """ 
    495503        set owner of fitpage 
    496          
     504 
    497505        :param owner: the class responsible of plotting 
    498          
     506 
    499507        """ 
    500508        self.event_owner = owner 
    501509        self.state.event_owner = owner 
    502          
     510 
    503511    def get_state(self): 
    504512        """ 
     
    506514        """ 
    507515        return self.state 
    508      
     516 
    509517    def get_data(self): 
    510518        """ 
     
    512520        """ 
    513521        return self.data 
    514      
     522 
    515523    def get_data_list(self): 
    516524        """ 
     
    518526        """ 
    519527        return self.data_list 
    520      
     528 
    521529    def set_manager(self, manager): 
    522530        """ 
    523531        set panel manager 
    524          
     532 
    525533        :param manager: instance of plugin fitting 
    526          
     534 
    527535        """ 
    528536        self._manager = manager 
    529537        self.state.manager = manager 
    530          
     538 
    531539    def populate_box(self, model_dict): 
    532540        """ 
    533541        Store list of model 
    534          
     542 
    535543        :param model_dict: dictionary containing list of models 
    536          
     544 
    537545        """ 
    538546        self.model_list_box = model_dict 
    539547        self.state.model_list_box = self.model_list_box 
    540548        self.initialize_combox() 
    541          
     549 
    542550    def set_model_dictionary(self, model_dict): 
    543551        """ 
     
    551559        """ 
    552560        put default value in the combobox 
    553         """   
     561        """ 
    554562        ## fill combox box 
    555563        if self.model_list_box is None: 
     
    560568        ## These are called for first time by formfactor_combo_init 
    561569        ## itself called from fitpanel only.  If we find that I'm wrong and 
    562         ## we DO need to initialize somehow here - do it by a call to  
    563         ## formfactor_combo_init  
     570        ## we DO need to initialize somehow here - do it by a call to 
     571        ## formfactor_combo_init 
    564572        ## self.formfator_combo_init() 
    565         ## BUT NOT HERE -- make it last line of this  
     573        ## BUT NOT HERE -- make it last line of this 
    566574        ## method so that structure box is populated before _show_comboox_helper 
    567575        ## is called.  Otherwise wx will complain mightily:-) 
     
    575583#                               self.model_list_box["Shapes"]) 
    576584            self._populate_box(self.structurebox, 
    577                                 self.model_list_box["Structure Factors"]) 
     585                               self.model_list_box["Structure Factors"]) 
    578586            self.structurebox.Insert("None", 0, None) 
    579587            self.structurebox.SetSelection(0) 
     
    582590            self.structurebox.Disable() 
    583591            self.text2.Disable() 
    584               
     592 
    585593            if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 
    586594                self.structurebox.Show() 
     
    589597                self.text2.Enable() 
    590598 
    591                  
     599 
    592600    def set_dispers_sizer(self): 
    593601        """ 
    594602        fill sizer containing dispersity info 
    595603        """ 
     604        #print "==== entering set_dispers_sizer ===" 
    596605        self.sizer4.Clear(True) 
    597606        name = "Polydispersity and Orientational Distribution" 
    598         box_description = wx.StaticBox(self, -1, name) 
     607        box_description = wx.StaticBox(self, wx.ID_ANY, name) 
    599608        box_description.SetForegroundColour(wx.BLUE) 
    600609        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    601610        #---------------------------------------------------- 
    602         self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 
    603                                             style=wx.RB_GROUP) 
    604         self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 
     611        self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 
     612                                           style=wx.RB_GROUP) 
     613        self.enable_disp = wx.RadioButton(self, wx.ID_ANY, 'On', (10, 30)) 
    605614        # best size for MAC and PC 
    606615        if ON_MAC: 
     
    608617        else: 
    609618            size_q = (20, 15) 
    610         self.disp_help_bt = wx.Button(self, wx.NewId(), '?', 
     619        self.disp_help_bt = wx.Button(self, self.ID_DISPERSER_HELP, '?', 
    611620                                      style=wx.BU_EXACTFIT, 
    612621                                      size=size_q) 
     
    614623                               id=self.disp_help_bt.GetId()) 
    615624        self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 
    616          
     625 
    617626        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    618                      id=self.disable_disp.GetId()) 
     627                  id=self.disable_disp.GetId()) 
    619628        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    620                    id=self.enable_disp.GetId()) 
     629                  id=self.enable_disp.GetId()) 
    621630        #MAC needs SetValue 
    622631        self.disable_disp.SetValue(True) 
     
    624633        sizer_dispersion.Add((20, 20)) 
    625634        name = ""  # Polydispersity and \nOrientational Distribution " 
    626         sizer_dispersion.Add(wx.StaticText(self, -1, name)) 
     635        sizer_dispersion.Add(wx.StaticText(self, wx.ID_ANY, name)) 
    627636        sizer_dispersion.Add(self.enable_disp) 
    628637        sizer_dispersion.Add((20, 20)) 
     
    630639        sizer_dispersion.Add((25, 20)) 
    631640        sizer_dispersion.Add(self.disp_help_bt) 
    632          
     641 
    633642        ## fill a sizer for dispersion 
    634643        boxsizer1.Add(sizer_dispersion, 0, 
    635                 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 
    636                 border=5) 
     644                      wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 
     645                      border=5) 
    637646        self.sizer4_4 = wx.GridBagSizer(6, 5) 
    638647 
     
    643652        self.sizer4.Layout() 
    644653        self.Layout() 
    645       
     654 
    646655        self.Refresh() 
    647656        ## saving the state of enable dispersity button 
     
    649658        self.state.disable_disp = self.disable_disp.GetValue() 
    650659        self.SetupScrolling() 
    651      
     660 
    652661    def onResetModel(self, event): 
    653662        """ 
     
    667676            previous_state = self.saved_states[name] 
    668677            ## reset state of checkbox,textcrtl  and  regular parameters value 
    669              
     678 
    670679            self.reset_page(previous_state) 
    671680        self.state.m_name = self.m_name 
    672681        self.Show(True) 
    673                 
     682 
    674683    def on_preview(self, event): 
    675684        """ 
     
    680689        # get the report dialog 
    681690        self.state.report(images, canvases) 
    682          
     691 
    683692    def on_save(self, event): 
    684693        """ 
     
    693702                        self._manager.parent._default_save_location 
    694703        dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, 
    695                                         self.window_caption, "*.fitv", wx.SAVE) 
     704                            self.window_caption, "*.fitv", wx.SAVE) 
    696705 
    697706        if dlg.ShowModal() == wx.ID_OK: 
    698707            path = dlg.GetPath() 
    699708            self._default_save_location = os.path.dirname(path) 
    700             self._manager.parent._default_save_location =\ 
    701                                  self._default_save_location 
     709            self._manager.parent._default_save_location = \ 
     710                                self._default_save_location 
    702711        else: 
    703712            return None 
     
    709718        self._manager.save_fit_state(filepath=fName, fitstate=new_state) 
    710719        return new_state 
    711      
     720 
    712721    def on_copy(self, event): 
    713722        """ 
     
    726735            wx.CallAfter(self.get_copy) 
    727736 
    728          
     737 
    729738    def on_paste(self, event): 
    730739        """ 
     
    738747        # messages depending on the flag 
    739748        #self._copy_info(True) 
    740          
     749 
    741750    def _copy_info(self, flag): 
    742751        """ 
    743752        Send event dpemding on flag 
    744          
     753 
    745754        : Param flag: flag that distinguish event 
    746755        """ 
     
    758767        # inform msg to wx 
    759768        wx.PostEvent(self._manager.parent, 
    760                     StatusEvent(status=msg, info=infor)) 
    761          
     769                     StatusEvent(status=msg, info=infor)) 
     770 
    762771    def _get_time_stamp(self): 
    763772        """ 
     
    769778        current_date = str(month) + "/" + str(day) + "/" + str(year) 
    770779        return current_time, current_date 
    771        
     780 
    772781    def on_bookmark(self, event): 
    773782        """ 
     
    788797        name += "bookmarked at %s on %s" % (current_time, current_date) 
    789798        self.saved_states[name] = new_state 
    790          
     799 
    791800        ## Add item in the context menu 
    792801        msg = "Model saved at %s on %s" % (current_time, current_date) 
     
    794803        msg += " Saved! right click on this page to retrieve this model" 
    795804        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    796          
    797         id = wx.NewId() 
    798         self.popUpMenu.Append(id, name, str(msg)) 
    799         wx.EVT_MENU(self, id, self.onResetModel) 
     805 
     806        self.popUpMenu.Append(self.ID_BOOKMARK, name, str(msg)) 
     807        wx.EVT_MENU(self, self.ID_BOOKMARK, self.onResetModel) 
    800808        wx.PostEvent(self._manager.parent, 
    801809                     AppendBookmarkEvent(title=name, 
    802810                                         hint=str(msg), 
    803811                                         handler=self._back_to_bookmark)) 
    804      
     812 
    805813    def _back_to_bookmark(self, event): 
    806814        """ 
     
    810818        self.onResetModel(event) 
    811819        self._draw_model() 
    812                  
     820 
    813821    def onSetFocus(self, evt): 
    814822        """ 
     
    817825        """ 
    818826        return 
    819      
     827 
    820828    def read_file(self, path): 
    821829        """ 
    822830        Read two columns file 
    823          
     831 
    824832        :param path: the path to the file to read 
    825          
     833 
    826834        """ 
    827835        try: 
     
    856864        """ 
    857865        return self.state.clone() 
    858      
     866 
    859867    def save_current_state(self): 
    860868        """ 
     
    866874            self.state.disp_list = copy.deepcopy(self.disp_list) 
    867875            self.state.model = self.model.clone() 
    868              
     876 
    869877            #model combobox: complex code because of mac's silent error 
    870878            if self.structurebox != None: 
     
    885893                self.state.categorycombobox = self.categorybox.\ 
    886894                GetString(cb_select) 
    887          
     895 
    888896        self.state.enable2D = copy.deepcopy(self.enable2D) 
    889897        self.state.values = copy.deepcopy(self.values) 
     
    902910            self.state.enable_disp = self.enable_disp.GetValue() 
    903911            self.state.disable_disp = self.disable_disp.GetValue() 
    904              
     912 
    905913        self.state.smearer = copy.deepcopy(self.current_smearer) 
    906914        if hasattr(self, "enable_smearer"): 
     
    917925        self.state.dxw = copy.deepcopy(self.dxw) 
    918926        self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 
    919                    
     927 
    920928        if len(self._disp_obj_dict) > 0: 
    921929            for k, v in self._disp_obj_dict.iteritems(): 
     
    926934        ## save plotting range 
    927935        self._save_plotting_range() 
    928          
     936 
    929937        self.state.orientation_params = [] 
    930938        self.state.orientation_params_disp = [] 
     
    941949        self._copy_parameters_state(self.orientation_params_disp, 
    942950                                     self.state.orientation_params_disp) 
    943          
     951 
    944952        self._copy_parameters_state(self.parameters, self.state.parameters) 
    945953        self._copy_parameters_state(self.fittable_param, 
     
    948956        #save chisqr 
    949957        self.state.tcChi = self.tcChi.GetValue() 
    950          
     958 
    951959    def save_current_state_fit(self): 
    952960        """ 
     
    958966            self.state.disp_list = copy.deepcopy(self.disp_list) 
    959967            self.state.model = self.model.clone() 
    960              
     968 
    961969        self.state.enable2D = copy.deepcopy(self.enable2D) 
    962970        self.state.values = copy.deepcopy(self.values) 
     
    964972        ## save data 
    965973        self.state.data = copy.deepcopy(self.data) 
    966          
     974 
    967975        if hasattr(self, "enable_disp"): 
    968976            self.state.enable_disp = self.enable_disp.GetValue() 
    969977            self.state.disable_disp = self.disable_disp.GetValue() 
    970              
     978 
    971979        self.state.smearer = copy.deepcopy(self.current_smearer) 
    972980        if hasattr(self, "enable_smearer"): 
     
    975983            self.state.disable_smearer = \ 
    976984                                copy.deepcopy(self.disable_smearer.GetValue()) 
    977              
     985 
    978986        self.state.pinhole_smearer = \ 
    979987                                copy.deepcopy(self.pinhole_smearer.GetValue()) 
     
    9981006                for k, v in self._disp_obj_dict.iteritems(): 
    9991007                    self.state._disp_obj_dict[k] = v 
    1000                          
     1008 
    10011009            self.state.values = copy.deepcopy(self.values) 
    10021010            self.state.weights = copy.deepcopy(self.weights) 
    1003             
     1011 
    10041012        ## save plotting range 
    10051013        self._save_plotting_range() 
    1006          
     1014 
    10071015        ## save checkbutton state and txtcrtl values 
    10081016        self._copy_parameters_state(self.orientation_params, 
    1009                                      self.state.orientation_params) 
     1017                                    self.state.orientation_params) 
    10101018        self._copy_parameters_state(self.orientation_params_disp, 
    1011                                      self.state.orientation_params_disp) 
     1019                                    self.state.orientation_params_disp) 
    10121020        self._copy_parameters_state(self.parameters, self.state.parameters) 
    10131021        self._copy_parameters_state(self.fittable_param, 
    1014                                              self.state.fittable_param) 
     1022                                    self.state.fittable_param) 
    10151023        self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
    1016      
     1024 
    10171025    def check_invalid_panel(self): 
    10181026        """ 
     
    10251033            wx.MessageBox(msg, 'Info') 
    10261034            return  True 
    1027          
     1035 
    10281036    def set_model_state(self, state): 
    10291037        """ 
     
    10321040        self.disp_cb_dict = state.disp_cb_dict 
    10331041        self.disp_list = state.disp_list 
    1034        
     1042 
    10351043        ## set the state of the radio box 
    10361044        #self.shape_rbutton.SetValue(state.shape_rbutton) 
     
    10381046        #self.struct_rbutton.SetValue(state.struct_rbutton) 
    10391047        #self.plugin_rbutton.SetValue(state.plugin_rbutton) 
    1040          
     1048 
    10411049        ## fill model combobox 
    10421050        self._show_combox_helper() 
     
    10521060                    category_pos = int(ind_cat) 
    10531061                    break 
    1054              
     1062 
    10551063        self.categorybox.Select(category_pos) 
    10561064        try: 
     
    10641072                    formfactor_pos = int(ind_form) 
    10651073                    break 
    1066              
     1074 
    10671075        self.formfactorbox.Select(formfactor_pos) 
    1068          
     1076 
    10691077        try: 
    10701078            # to support older version 
     
    10771085                    structfactor_pos = int(ind_struct) 
    10781086                    break 
    1079                  
     1087 
    10801088        self.structurebox.SetSelection(structfactor_pos) 
    1081          
     1089 
    10821090        if state.multi_factor != None: 
    10831091            self.multifactorbox.SetSelection(state.multi_factor) 
    1084              
     1092 
    10851093        ## reset state of checkbox,textcrtl  and  regular parameters value 
    10861094        self._reset_parameters_state(self.orientation_params_disp, 
     
    10941102        self.enable_disp.SetValue(state.enable_disp) 
    10951103        self.disable_disp.SetValue(state.disable_disp) 
    1096          
     1104 
    10971105        if hasattr(self, "disp_box") and self.disp_box != None: 
    10981106            self.disp_box.SetSelection(state.disp_box) 
     
    11021110 
    11031111            self._set_dipers_Param(event=None) 
    1104         
     1112 
    11051113            if name == "ArrayDispersion": 
    1106                  
     1114 
    11071115                for item in self.disp_cb_dict.keys(): 
    1108                      
     1116 
    11091117                    if hasattr(self.disp_cb_dict[item], "SetValue"): 
    11101118                        self.disp_cb_dict[item].SetValue(\ 
    11111119                                                    state.disp_cb_dict[item]) 
    11121120                        # Create the dispersion objects 
    1113                         #from sas.models.dispersion_models import ArrayDispersion 
    1114                         from sasmodels.weights import ArrayDispersion 
     1121                        from sas.models.dispersion_models import ArrayDispersion 
    11151122                        disp_model = ArrayDispersion() 
    11161123                        if hasattr(state, "values") and \ 
     
    11231130                            else: 
    11241131                                self._reset_dispersity() 
    1125                          
     1132 
    11261133                        self._disp_obj_dict[item] = disp_model 
    11271134                        # Set the new model as the dispersion object 
    11281135                        #for the selected parameter 
    11291136                        self.model.set_dispersion(item, disp_model) 
    1130                      
     1137 
    11311138                        self.model._persistency_dict[item] = \ 
    11321139                                                [state.values, state.weights] 
    1133                      
     1140 
    11341141            else: 
    11351142                keys = self.model.getParamList() 
     
    11491156        self.pinhole_smearer.SetValue(state.pinhole_smearer) 
    11501157        self.slit_smearer.SetValue(state.slit_smearer) 
    1151          
     1158 
    11521159        self.dI_noweight.SetValue(state.dI_noweight) 
    11531160        self.dI_didata.SetValue(state.dI_didata) 
    11541161        self.dI_sqrdata.SetValue(state.dI_sqrdata) 
    11551162        self.dI_idata.SetValue(state.dI_idata) 
    1156          
     1163 
    11571164        ## we have two more options for smearing 
    11581165        if self.pinhole_smearer.GetValue(): 
     
    11601167        elif self.slit_smearer.GetValue(): 
    11611168            self.onSlitSmear(event=None) 
    1162         
     1169 
    11631170        ## reset state of checkbox,textcrtl  and dispersity parameters value 
    11641171        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    11651172        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    1166          
     1173 
    11671174        ## draw the model with previous parameters value 
    11681175        self._onparamEnter_helper() 
     
    11721179        self._lay_out() 
    11731180        self.Refresh() 
    1174          
     1181 
    11751182    def reset_page_helper(self, state): 
    11761183        """ 
    11771184        Use page_state and change the state of existing page 
    1178          
     1185 
    11791186        :precondition: the page is already drawn or created 
    1180          
     1187 
    11811188        :postcondition: the state of the underlying data change as well as the 
    11821189            state of the graphic interface 
     
    12041211        else: 
    12051212            self.set_data(data) 
    1206              
     1213 
    12071214        self.enable2D = state.enable2D 
    12081215        try: 
     
    12141221        self.disp_cb_dict = state.disp_cb_dict 
    12151222        self.disp_list = state.disp_list 
    1216        
     1223 
    12171224        ## set the state of the radio box 
    12181225        #self.shape_rbutton.SetValue(state.shape_rbutton) 
     
    12201227        #self.struct_rbutton.SetValue(state.struct_rbutton) 
    12211228        #self.plugin_rbutton.SetValue(state.plugin_rbutton) 
    1222          
     1229 
    12231230        ## fill model combobox 
    12241231        self._show_combox_helper() 
     
    12341241                    category_pos = int(ind_cat) 
    12351242                    break 
    1236              
     1243 
    12371244        self.categorybox.Select(category_pos) 
    12381245        self._show_combox(None) 
     
    12471254                    formfactor_pos = int(ind_form) 
    12481255                    break 
    1249              
     1256 
    12501257        self.formfactorbox.Select(formfactor_pos) 
    1251          
     1258 
    12521259        try: 
    12531260            # to support older version 
     
    12601267                    structfactor_pos = int(ind_struct) 
    12611268                    break 
    1262              
     1269 
    12631270        self.structurebox.SetSelection(structfactor_pos) 
    12641271 
     
    12681275        #draw the panel according to the new model parameter 
    12691276        self._on_select_model(event=None) 
    1270              
     1277 
    12711278        # take care of 2D button 
    12721279        if data == None and self.model_view.IsEnabled(): 
     
    12751282            else: 
    12761283                self.model_view.SetLabel("1D Mode") 
    1277                  
     1284         
    12781285        ## set the select all check box to the a given state 
    12791286        self.cb1.SetValue(state.cb1) 
    1280       
     1287 
    12811288        ## reset state of checkbox,textcrtl  and  regular parameters value 
    12821289        self._reset_parameters_state(self.orientation_params_disp, 
     
    13171324            self.dI_sqrdata.SetValue(False) 
    13181325            self.dI_idata.SetValue(False) 
    1319   
     1326 
    13201327        ## we have two more options for smearing 
    13211328        if self.pinhole_smearer.GetValue(): 
     
    13331340                self.smear_slit_height.SetValue(str(self.dxl)) 
    13341341            if self.dxw != None: 
    1335                 self.smear_slit_width.SetValue(str(self.dxw))   
     1342                self.smear_slit_width.SetValue(str(self.dxw)) 
    13361343            else: 
    1337                 self.smear_slit_width.SetValue('')   
     1344                self.smear_slit_width.SetValue('') 
    13381345            self.onSlitSmear(event=None) 
    1339          
     1346 
    13401347        ## reset state of checkbox,textcrtl  and dispersity parameters value 
    13411348        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    13421349        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    1343          
     1350 
    13441351        ## draw the model with previous parameters value 
    13451352        self._onparamEnter_helper() 
     
    13481355        ## reset context menu items 
    13491356        self._reset_context_menu() 
    1350          
     1357 
    13511358        ## set the value of the current state to the state given as parameter 
    13521359        self.state = state.clone() 
    13531360        self.state.m_name = self.m_name 
    1354      
     1361 
    13551362    def _reset_page_disp_helper(self, state): 
    13561363        """ 
     
    13671374        self.values = copy.deepcopy(state.values) 
    13681375        self.weights = copy.deepcopy(state.weights) 
    1369          
     1376 
    13701377        for key, disp in state._disp_obj_dict.iteritems(): 
    13711378            # From saved file, disp_model can not be sent in model obj. 
     
    13731380            if disp.__class__.__name__ == 'str': 
    13741381                disp_model = None 
    1375                 #com_str = "from sas.models.dispersion_models " 
    13761382                com_str = "from sasmodels.weights " 
    13771383                com_str += "import %s as disp_func \ndisp_model = disp_func()" 
     
    14151421                        except: 
    14161422                            logging.error(sys.exc_info()[1]) 
    1417      
     1423 
    14181424        # Make sure the check box updated when all checked 
    14191425        if self.cb1.GetValue(): 
    14201426            self.select_all_param(None) 
    1421        
     1427 
    14221428    def _selectDlg(self): 
    14231429        """ 
    1424         open a dialog file to selected the customized dispersity  
     1430        open a dialog file to selected the customized dispersity 
    14251431        """ 
    14261432        if self.parent != None: 
     
    14281434                        self._manager.parent.get_save_location() 
    14291435        dlg = wx.FileDialog(self, "Choose a weight file", 
    1430                                 self._default_save_location, "", 
    1431                                 "*.*", wx.OPEN) 
     1436                            self._default_save_location, "", 
     1437                            "*.*", wx.OPEN) 
    14321438        path = None 
    14331439        if dlg.ShowModal() == wx.ID_OK: 
     
    14401446        reset the context menu 
    14411447        """ 
     1448        ids = iter(self._id_pool)  # Reusing ids for context menu 
    14421449        for name, _ in self.state.saved_states.iteritems(): 
    14431450            self.number_saved_state += 1 
    14441451            ## Add item in the context menu 
    1445             id = wx.NewId() 
     1452            wx_id = ids.next() 
    14461453            msg = 'Save model and state %g' % self.number_saved_state 
    1447             self.popUpMenu.Append(id, name, msg) 
    1448             wx.EVT_MENU(self, id, self.onResetModel) 
    1449      
     1454            self.popUpMenu.Append(wx_id, name, msg) 
     1455            wx.EVT_MENU(self, wx_id, self.onResetModel) 
     1456 
    14501457    def _reset_plotting_range(self, state): 
    14511458        """ 
     
    14661473        self.state.formfactorcombobox = self.formfactorbox.GetLabel() 
    14671474        self.state.categorycombobox = self.categorybox.GetLabel() 
    1468         
     1475 
    14691476        ## post state to fit panel 
    14701477        event = PageInfoEvent(page=self) 
    14711478        wx.PostEvent(self.parent, event) 
    1472          
     1479 
    14731480    def _save_plotting_range(self): 
    14741481        """ 
     
    14781485        self.state.qmax = self.qmax_x 
    14791486        self.state.npts = self.npts_x 
    1480              
     1487 
    14811488    def _onparamEnter_helper(self): 
    14821489        """ 
     
    14951502            try: 
    14961503                is_modified = self._check_value_enter(self.fittable_param, 
    1497                                                      is_modified) 
     1504                                                      is_modified) 
    14981505                is_modified = self._check_value_enter(self.fixed_param, 
    14991506                                                      is_modified) 
     
    15151522                    self.qmax_x = tempmax 
    15161523                    is_modified = True 
    1517              
     1524 
    15181525                if is_2Ddata: 
    15191526                    # set mask 
    15201527                    is_modified = self._validate_Npts() 
    1521                      
     1528 
    15221529            else: 
    15231530                self.fitrange = False 
    1524                  
     1531 
    15251532            if not self.data.is_data: 
    15261533                is_modified = True 
     
    15421549                self.Refresh() 
    15431550        return is_modified 
    1544      
     1551 
    15451552    def _update_paramv_on_fit(self): 
    15461553        """ 
     
    15671574            self._check_value_enter(self.parameters, is_modified) 
    15681575 
    1569             # If qmin and qmax have been modified, update qmin and qmax and  
     1576            # If qmin and qmax have been modified, update qmin and qmax and 
    15701577            # Here we should check whether the boundaries have been modified. 
    1571             # If qmin and qmax have been modified, update qmin and qmax and  
     1578            # If qmin and qmax have been modified, update qmin and qmax and 
    15721579            # set the is_modified flag to True 
    15731580            self.fitrange = self._validate_qrange(self.qmin, self.qmax) 
     
    15961603                                                  qmax=float(self.qmax_x), 
    15971604                                                  enable_smearer=enable_smearer, 
    1598                                                       draw=False) 
     1605                                                  draw=False) 
    15991606                elif not self._is_2D(): 
    16001607                    enable_smearer = not self.disable_smearer.GetValue() 
     
    16051612                                              qmax=float(self.qmax_x), 
    16061613                                              enable_smearer=enable_smearer, 
    1607                                                  draw=False) 
     1614                                              draw=False) 
    16081615                    if self.data != None: 
    16091616                        index_data = ((self.qmin_x <= self.data.x) & \ 
     
    16411648            msg += " model or Fitting range is not valid!!!  " 
    16421649            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1643          
     1650 
    16441651        try: 
    16451652            self.save_current_state() 
    16461653        except: 
    16471654            logging.error(sys.exc_info()[1]) 
    1648     
     1655 
    16491656        return flag 
    1650                 
     1657 
    16511658    def _is_modified(self, is_modified): 
    16521659        """ 
     
    16541661        """ 
    16551662        return is_modified 
    1656                         
     1663 
    16571664    def _reset_parameters_state(self, listtorestore, statelist): 
    16581665        """ 
     
    16931700                item_page[5].Show(item_page_info[5][0]) 
    16941701                item_page[5].SetValue(item_page_info[5][1]) 
    1695                  
     1702 
    16961703            if item_page[6] != None: 
    16971704                ## show of hide the text crtl for fitting error 
    16981705                item_page[6].Show(item_page_info[6][0]) 
    16991706                item_page[6].SetValue(item_page_info[6][1]) 
    1700                      
     1707 
    17011708    def _reset_strparam_state(self, listtorestore, statelist): 
    17021709        """ 
     
    17071714 
    17081715        listtorestore = copy.deepcopy(statelist) 
    1709          
     1716 
    17101717        for j in range(len(listtorestore)): 
    17111718            item_page = listtorestore[j] 
    17121719            item_page_info = statelist[j] 
    17131720            ##change the state of the check box for simple parameters 
    1714              
     1721 
    17151722            if item_page[0] != None: 
    17161723                item_page[0].SetValue(format_number(item_page_info[0], True)) 
     
    17241731                item_page[2].SetValue(selection) 
    17251732                self.model.setParam(param_name, selection) 
    1726                                        
     1733 
    17271734    def _copy_parameters_state(self, listtocopy, statelist): 
    17281735        """ 
    17291736        copy the state of button 
    1730          
     1737 
    17311738        :param listtocopy: the list of check button to copy 
    17321739        :param statelist: list of state object to store the current state 
    1733          
     1740 
    17341741        """ 
    17351742        if len(listtocopy) == 0: 
    17361743            return 
    1737         
     1744 
    17381745        for item in listtocopy: 
    1739    
     1746 
    17401747            checkbox_state = None 
    17411748            if item[0] != None: 
     
    17531760                error_value = item[4].GetValue() 
    17541761                error_state = item[4].IsShown() 
    1755                  
     1762 
    17561763            min_value = None 
    17571764            min_state = None 
     
    17591766                min_value = item[5].GetValue() 
    17601767                min_state = item[5].IsShown() 
    1761                  
     1768 
    17621769            max_value = None 
    17631770            max_state = None 
     
    17681775            if item[7] != None: 
    17691776                unit = item[7].GetLabel() 
    1770                 
     1777 
    17711778            statelist.append([checkbox_state, parameter_name, parameter_value, 
    17721779                              static_text, [error_state, error_value], 
    17731780                              [min_state, min_value], 
    17741781                              [max_state, max_value], unit]) 
    1775             
    1776                  
     1782 
     1783 
    17771784    def _draw_model(self, update_chisqr=True, source='model'): 
    17781785        """ 
     
    17801787        The method will use the data member from the model page 
    17811788        to build a call to the fitting perspective manager. 
    1782          
     1789 
    17831790        :param chisqr: update chisqr value [bool] 
    17841791        """ 
    17851792        wx.CallAfter(self._draw_model_after, update_chisqr, source) 
    1786          
     1793 
    17871794    def _draw_model_after(self, update_chisqr=True, source='model'): 
    17881795        """ 
     
    17901797        The method will use the data member from the model page 
    17911798        to build a call to the fitting perspective manager. 
    1792          
     1799 
    17931800        :param chisqr: update chisqr value [bool] 
    17941801        """ 
     
    18181825                                    source='model', 
    18191826                                    weight=weight) 
    1820         
     1827 
    18211828    def _on_show_sld(self, event=None): 
    18221829        """ 
     
    18331840        sld_data.name = 'SLD' 
    18341841        sld_data.axes = self.sld_axes 
    1835         self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 
     1842        self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, 
     1843                              id=wx.ID_ANY) 
    18361844        self.panel.ShowModal() 
    1837          
     1845 
    18381846    def _set_multfactor_combobox(self, multiplicity=10): 
    18391847        """ 
     
    18451853            self.multifactorbox.Append(str(idx), int(idx)) 
    18461854        self._hide_multfactor_combobox() 
    1847          
     1855 
    18481856    def _show_multfactor_combobox(self): 
    18491857        """ 
     
    18551863        if not self.multifactorbox.IsShown(): 
    18561864            self.multifactorbox.Show(True) 
    1857               
     1865 
    18581866    def _hide_multfactor_combobox(self): 
    18591867        """ 
     
    18651873        if self.multifactorbox.IsShown(): 
    18661874            self.multifactorbox.Hide() 
    1867      
     1875 
    18681876    def formfactor_combo_init(self): 
    18691877        """ 
     
    18711879        """ 
    18721880        self._show_combox(None) 
    1873                  
     1881 
    18741882    def _show_combox_helper(self): 
    18751883        """ 
     
    19041912                         StatusEvent(status=msg, info="error")) 
    19051913        self._populate_box(self.formfactorbox, m_list) 
    1906      
    1907     def _on_modify_cat(self, event=None):   
     1914 
     1915    def _on_modify_cat(self, event=None): 
    19081916        """ 
    19091917        Called when category manager is opened 
    19101918        """ 
    1911         self._manager.parent.on_category_panel(event)   
    1912          
     1919        self._manager.parent.on_category_panel(event) 
     1920 
    19131921    def _show_combox(self, event=None): 
    19141922        """ 
     
    19241932        self.Layout() 
    19251933        self.Refresh() 
    1926    
     1934 
    19271935    def _populate_box(self, combobox, list): 
    19281936        """ 
    19291937        fill combox box with dict item 
    1930          
     1938 
    19311939        :param list: contains item to fill the combox 
    19321940            item must model class 
     
    19421950                    name = model.name 
    19431951                mlist.append((name, models)) 
    1944                  
     1952 
    19451953        # Sort the models 
    19461954        mlist_sorted = sorted(mlist) 
     
    19481956            combobox.Append(item[0], item[1]) 
    19491957        return 0 
    1950      
     1958 
    19511959    def _onQrangeEnter(self, event): 
    19521960        """ 
    19531961        Check validity of value enter in the Q range field 
    1954          
     1962 
    19551963        """ 
    19561964        tcrtl = event.GetEventObject() 
     
    20052013            self.create_default_data() 
    20062014        self._draw_model() 
    2007                     
     2015 
    20082016    def _theory_qrange_enter(self, event): 
    20092017        """ 
    20102018        Check validity of value enter in the Q range field 
    20112019        """ 
    2012          
     2020 
    20132021        tcrtl = event.GetEventObject() 
    20142022        #Clear msg if previously shown. 
     
    20622070        self.create_default_data() 
    20632071        self._draw_model() 
    2064                     
     2072 
    20652073    def _on_select_model_helper(self): 
    20662074        """ 
     
    20882096            self.structurebox.Enable() 
    20892097            self.text2.Enable() 
    2090              
     2098 
    20912099        if form_factor != None: 
    20922100            # set multifactor for Mutifunctional models 
     
    21052113                    # default value 
    21062114                    m_id = 1 
    2107                      
     2115 
    21082116                self.multi_factor = self.multifactorbox.GetClientData(m_id) 
    21092117                if self.multi_factor == None: 
     
    21332141            self.show_sld_button.Hide() 
    21342142            self.multi_factor = None 
    2135                
     2143 
    21362144        s_id = self.structurebox.GetCurrentSelection() 
    21372145        struct_factor = self.structurebox.GetClientData(s_id) 
    2138          
     2146 
    21392147        if  struct_factor != None: 
    21402148            from sas.models.MultiplicationModel import MultiplicationModel 
     
    21512159        # check if model has magnetic parameters 
    21522160        if len(self.model.magnetic_params) > 0: 
    2153             self._has_magnetic = True  
     2161            self._has_magnetic = True 
    21542162        else: 
    2155             self._has_magnetic = False   
     2163            self._has_magnetic = False 
    21562164        ## post state to fit panel 
    21572165        self.state.parameters = [] 
     
    21632171        self.on_set_focus(None) 
    21642172        self.Layout() 
    2165          
     2173 
    21662174    def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 
    21672175        """ 
    21682176        Verify that the Q range controls have valid values 
    21692177        and that Qmin < Qmax. 
    2170          
     2178 
    21712179        :param qmin_ctrl: text control for Qmin 
    21722180        :param qmax_ctrl: text control for Qmax 
    2173          
     2181 
    21742182        :return: True is the Q range is value, False otherwise 
    2175          
     2183 
    21762184        """ 
    21772185        qmin_validity = check_float(qmin_ctrl) 
     
    21972205                return False 
    21982206        return True 
    2199      
     2207 
    22002208    def _validate_Npts(self): 
    22012209        """ 
     
    22322240                self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 
    22332241                self.fitrange = True 
    2234              
     2242 
    22352243        return flag 
    22362244 
     
    22672275                self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 
    22682276                self.fitrange = True 
    2269              
     2277 
    22702278        return flag 
    2271      
     2279 
    22722280    def _check_value_enter(self, list, modified): 
    22732281        """ 
     
    22912299            #try: 
    22922300            name = str(item[1]) 
    2293              
     2301 
    22942302            if string.find(name, ".npts") == -1 and \ 
    22952303                                        string.find(name, ".nsigmas") == -1: 
     
    22972305                param_min = None 
    22982306                param_max = None 
    2299                 
     2307 
    23002308                ## check minimun value 
    23012309                if item[5] != None and item[5] != "": 
     
    23062314                                if numpy.isfinite(param_min): 
    23072315                                    item[2].SetValue(format_number(param_min)) 
    2308                              
     2316 
    23092317                            item[5].SetBackgroundColour(wx.WHITE) 
    23102318                            item[2].SetBackgroundColour(wx.WHITE) 
    2311                                             
     2319 
    23122320                        except: 
    23132321                            msg = "Wrong fit parameter range entered" 
     
    23242332                                if numpy.isfinite(param_max): 
    23252333                                    item[2].SetValue(format_number(param_max)) 
    2326                              
     2334 
    23272335                            item[6].SetBackgroundColour(wx.WHITE) 
    23282336                            item[2].SetBackgroundColour(wx.WHITE) 
     
    23332341                            raise ValueError, msg 
    23342342                        is_modified = True 
    2335                  
     2343 
    23362344                if param_min != None and param_max != None: 
    23372345                    if not self._validate_qrange(item[5], item[6]): 
     
    23402348                        wx.PostEvent(self._manager.parent, 
    23412349                                     StatusEvent(status=msg)) 
    2342                  
     2350 
    23432351                if name in self.model.details.keys(): 
    23442352                    self.model.details[name][1:3] = param_min, param_max 
     
    23612369                msg = "Wrong Fit parameter value entered " 
    23622370                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    2363                  
     2371 
    23642372        return is_modified 
    2365          
     2373 
    23662374    def _set_dipers_Param(self, event): 
    23672375        """ 
     
    23822390 
    23832391        self._reset_dispersity() 
    2384      
     2392 
    23852393        if self.model == None: 
    23862394            self.model_disp.Hide() 
     
    23902398        if self.enable_disp.GetValue(): 
    23912399            ## layout for model containing no dispersity parameters 
    2392              
     2400 
    23932401            self.disp_list = self.model.getDispParamList() 
    2394               
     2402 
    23952403            if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 
    23962404                self._layout_sizer_noDipers() 
     
    24002408        else: 
    24012409            self.sizer4_4.Clear(True) 
    2402              
     2410 
    24032411        ## post state to fit panel 
    24042412        self.save_current_state() 
     
    24082416        #draw the model with the current dispersity 
    24092417        self._draw_model() 
    2410         self.sizer4_4.Layout() 
    2411         self.sizer5.Layout() 
    2412         self.Layout() 
    2413         self.Refresh() 
    2414            
     2418        ## Need to use FitInside again here to replace the next four lines. 
     2419        ## Otherwised polydispersity off does not resize the scrollwindow.  
     2420        ## PDB Nov 28, 2015 
     2421        self.FitInside() 
     2422#        self.sizer4_4.Layout() 
     2423#        self.sizer5.Layout() 
     2424#        self.Layout() 
     2425#        self.Refresh() 
     2426 
    24152427    def _layout_sizer_noDipers(self): 
    24162428        """ 
     
    24222434        self.fixed_param = [] 
    24232435        self.orientation_params_disp = [] 
    2424          
     2436 
    24252437        self.sizer4_4.Clear(True) 
    24262438        text = "No polydispersity available for this model" 
    2427         model_disp = wx.StaticText(self, -1, text) 
     2439        model_disp = wx.StaticText(self, wx.ID_ANY, text) 
    24282440        self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 
    24292441                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    24302442        self.sizer4_4.Layout() 
    24312443        self.sizer4.Layout() 
    2432      
     2444 
    24332445    def _reset_dispersity(self): 
    24342446        """ 
     
    24432455                if item in self.param_toFit: 
    24442456                    self.param_toFit.remove(item) 
    2445           
     2457 
    24462458        self.fittable_param = [] 
    24472459        self.fixed_param = [] 
     
    24622474                # Go back to Gaussian model (with 0 pts) 
    24632475                disp_model = GaussianDispersion() 
    2464                 
     2476 
    24652477                self._disp_obj_dict[p] = disp_model 
    24662478                # Set the new model as the dispersion object 
     
    24752487        self.Layout() 
    24762488        self.Refresh() 
    2477                    
     2489 
    24782490    def _on_select_Disp(self, event): 
    24792491        """ 
     
    24882500        event = PageInfoEvent(page=self) 
    24892501        wx.PostEvent(self.parent, event) 
    2490          
     2502 
    24912503        self.sizer4_4.Layout() 
    24922504        self.sizer4.Layout() 
    24932505        self.SetupScrolling() 
    2494      
     2506 
    24952507    def _on_disp_func(self, event=None): 
    24962508        """ 
    24972509        Select a distribution function for the polydispersion 
    2498          
     2510 
    24992511        :Param event: ComboBox event 
    25002512        """ 
     
    25122524            disp_name = disp_box.GetValue() 
    25132525            dispersity = disp_box.GetClientData(selection) 
    2514      
     2526 
    25152527            #disp_model =  GaussianDispersion() 
    25162528            disp_model = dispersity() 
     
    25302542                self.model.set_dispersion(param_name, disp_model) 
    25312543                self.state._disp_obj_dict[name1] = disp_model 
    2532   
     2544 
    25332545                value1 = str(format_number(self.model.getParam(name1), True)) 
    25342546                value2 = str(format_number(self.model.getParam(name2))) 
     
    25582570            for item in self.fixed_param: 
    25592571                if item[1] == name2: 
    2560                     item[2].SetValue(value2)  
     2572                    item[2].SetValue(value2) 
    25612573                    # Disable Npts for array 
    25622574                    if disp_name.lower() == "array": 
     
    25712583                    else: 
    25722584                        item[2].Enable() 
    2573                  
     2585 
    25742586            # Make sure the check box updated when all checked 
    25752587            if self.cb1.GetValue(): 
     
    25922604            wx.PostEvent(self._manager.parent, 
    25932605                         StatusEvent(status=msg, info="error")) 
    2594          
     2606 
    25952607    def _set_array_disp(self, name=None, disp=None): 
    25962608        """ 
    25972609        Set array dispersion 
    2598          
     2610 
    25992611        :param name: name of the parameter for the dispersion to be set 
    26002612        :param disp: the polydisperion object 
     
    26132625        self._default_save_location = os.path.dirname(path) 
    26142626        if self._manager != None: 
    2615             self._manager.parent._default_save_location =\ 
     2627            self._manager.parent._default_save_location = \ 
    26162628                             self._default_save_location 
    26172629 
    26182630        basename = os.path.basename(path) 
    26192631        values, weights = self.read_file(path) 
    2620          
     2632 
    26212633        # If any of the two arrays is empty, notify the user that we won't 
    26222634        # proceed 
     
    26312643                                    values=values, weights=weights) 
    26322644        return basename 
    2633      
     2645 
    26342646    def _set_array_disp_model(self, name=None, disp=None, 
    26352647                              values=[], weights=[]): 
    26362648        """ 
    26372649        Set array dispersion model 
    2638          
     2650 
    26392651        :param name: name of the parameter for the dispersion to be set 
    26402652        :param disp: the polydisperion object 
     
    26652677        self.state.model._persistency_dict[name.split('.')[0]] = \ 
    26662678                                        [values, weights] 
    2667                                          
     2679 
    26682680    def _del_array_values(self, name=None): 
    26692681        """ 
    26702682        Reset array dispersion 
    2671          
     2683 
    26722684        :param name: name of the parameter for the dispersion to be set 
    26732685        """ 
     
    26832695        except: 
    26842696            logging.error(sys.exc_info()[1]) 
    2685                                              
     2697 
    26862698    def _lay_out(self): 
    26872699        """ 
    26882700        returns self.Layout 
    2689          
     2701 
    26902702        :Note: Mac seems to like this better when self. 
    26912703            Layout is called after fitting. 
     
    26942706        self.Layout() 
    26952707        return 
    2696      
     2708 
    26972709    def _sleep4sec(self): 
    26982710        """ 
     
    27032715        if ON_MAC == True: 
    27042716            time.sleep(1) 
    2705              
     2717 
    27062718    def _find_polyfunc_selection(self, disp_func=None): 
    27072719        """ 
    27082720        FInd Comboox selection from disp_func 
    2709          
     2721 
    27102722        :param disp_function: dispersion distr. function 
    27112723        """ 
     
    27212733        except: 
    27222734            return 3 
    2723                              
     2735 
    27242736    def on_reset_clicked(self, event): 
    27252737        """ 
     
    27332745            flag = False 
    27342746            return 
    2735              
     2747 
    27362748        elif self.data.__class__.__name__ == "Data2D": 
    27372749            data_min = 0 
     
    27392751            y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 
    27402752            self.qmin_x = data_min 
    2741             self.qmax_x = math.sqrt(x*x + y*y) 
     2753            self.qmax_x = math.sqrt(x * x + y * y) 
    27422754            #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 
    27432755            # check smearing 
     
    27492761                else: 
    27502762                    flag = True 
    2751                      
     2763 
    27522764        elif self.data == None: 
    27532765            self.qmin_x = _QMIN_DEFAULT 
     
    27552767            self.num_points = _NPTS_DEFAULT 
    27562768            self.state.npts = self.num_points 
    2757              
     2769 
    27582770        elif self.data.__class__.__name__ != "Data2D": 
    27592771            self.qmin_x = min(self.data.x) 
     
    27712783        else: 
    27722784            flag = False 
    2773              
     2785 
    27742786        if flag == False: 
    27752787            msg = "Cannot Plot :Must enter a number!!!  " 
     
    27882800        self.state.qmin = self.qmin_x 
    27892801        self.state.qmax = self.qmax_x 
    2790          
     2802 
    27912803        #reset the q range values 
    27922804        self._reset_plotting_range(self.state) 
    27932805        self._draw_model() 
    2794          
     2806 
    27952807    def select_log(self, event): 
    27962808        """ 
     
    28012813        """ 
    28022814        Get the images of the plots corresponding this panel for report 
    2803          
     2815 
    28042816        : return graphs: list of figures 
    28052817        : Need Move to guiframe 
     
    28252837                        # append to the list 
    28262838                        graphs.append(item2.figure) 
    2827                         canvases.append(item2.canvas)   
     2839                        canvases.append(item2.canvas) 
    28282840            except: 
    28292841                # Not for control panels 
     
    28562868            name = self.formfactorbox.GetValue() 
    28572869            _PageAnchor = '#' + name.lower() 
    2858             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2870            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    28592871                                              _PageAnchor, name + " Help") 
    28602872        else: 
    2861             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
    2862                                                 "General Model Help") 
     2873            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
     2874                                              "", "General Model Help") 
    28632875 
    28642876 
     
    28752887        :param evt: on Description Button pressed event 
    28762888        """ 
    2877          
     2889 
    28782890        if self.model == None: 
    28792891            name = 'index.html' 
     
    28812893            name = self.formfactorbox.GetValue() 
    28822894 
    2883                 msg = 'Model description:\n' 
     2895        msg = 'Model description:\n' 
    28842896        info = "Info" 
    28852897        if self.model != None: 
    28862898#                frame.Destroy() 
    2887                 if str(self.model.description).rstrip().lstrip() == '': 
    2888                     msg += "Sorry, no information is available for this model." 
    2889                 else: 
    2890                     msg += self.model.description + '\n' 
    2891                 wx.MessageBox(msg, info) 
     2899            if str(self.model.description).rstrip().lstrip() == '': 
     2900                msg += "Sorry, no information is available for this model." 
    28922901            else: 
     2902                msg += self.model.description + '\n' 
     2903            wx.MessageBox(msg, info) 
     2904        else: 
    28932905            msg += "You must select a model to get information on this" 
    28942906            wx.MessageBox(msg, info) 
     
    29112923 
    29122924        _TreeLocation = "_images/M_angles_pic.bmp" 
    2913         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2925        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29142926                                          "Magnetic Angle Defintions") 
    29152927 
    2916     def _on_mag_help(self, event):     
     2928    def _on_mag_help(self, event): 
    29172929        """ 
    29182930        Bring up Magnetic Angle definition bmp image whenever the ? button 
     
    29312943 
    29322944        _TreeLocation = "user/perspectives/fitting/mag_help.html" 
    2933         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2945        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29342946                                          "Polarized Beam/Magnetc Help") 
    29352947 
    2936     def _on_mag_on(self, event):     
     2948    def _on_mag_on(self, event): 
    29372949        """ 
    29382950        Magnetic Parameters ON/OFF 
     
    29552967                    #reset mag value to zero fo safety 
    29562968                    self.model.setParam(key, 0.0) 
    2957                      
    2958         self.Show(False)     
     2969 
     2970        self.Show(False) 
    29592971        self.set_model_param_sizer(self.model) 
    29602972        #self._set_sizer_dispersion()  
     
    29622974        self.SetupScrolling() 
    29632975        self.Show(True) 
    2964              
     2976 
    29652977    def on_pd_help_clicked(self, event): 
    29662978        """ 
     
    29722984        webbrowser does not pass anything past the # to the browser when it is 
    29732985        running "file:///...." 
    2974          
     2986 
    29752987        :param evt: Triggers on clicking ? in polydispersity box 
    29762988        """ 
     
    29782990        _TreeLocation = "user/perspectives/fitting/pd_help.html" 
    29792991        _PageAnchor = "" 
    2980         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2992        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    29812993                                          _PageAnchor, "Polydispersity Help") 
    2982          
     2994 
    29832995    def on_left_down(self, event): 
    29842996        """ 
     
    29953007        # make event free 
    29963008        event.Skip() 
    2997          
     3009 
    29983010    def get_copy(self): 
    29993011        """ 
     
    30043016        self._copy_info(flag) 
    30053017        return flag 
    3006              
     3018 
    30073019    def get_copy_params(self): 
    30083020        """ 
     
    30123024        # Do it if params exist 
    30133025        if  self.parameters != []: 
    3014              
     3026 
    30153027            # go through the parameters 
    30163028            strings = self._get_copy_helper(self.parameters, 
    30173029                                           self.orientation_params) 
    30183030            content += strings 
    3019              
     3031 
    30203032            # go through the fittables 
    30213033            strings = self._get_copy_helper(self.fittable_param, 
     
    30273039                                           self.orientation_params_disp) 
    30283040            content += strings 
    3029                  
     3041 
    30303042            # go through the str params 
    30313043            strings = self._get_copy_helper(self.str_parameters, 
     
    30603072                content += param[1] #parameter name 
    30613073                content += tab 
    3062                 content += param[1]+"_err" 
     3074                content += param[1] + "_err" 
    30633075                content += tab 
    30643076 
     
    30683080            for param in self.parameters: 
    30693081                content += param[2].GetValue() #value 
    3070                 content +=tab 
     3082                content += tab 
    30713083                content += param[4].GetValue() #error 
    3072                 content +=tab 
     3084                content += tab 
    30733085 
    30743086            return content 
     
    31063118 
    31073119            for index, param in enumerate(self.parameters): 
    3108                 content += param[1].replace('_','\_') #parameter name 
     3120                content += param[1].replace('_', '\_') #parameter name 
    31093121                content += ' & ' 
    3110                 content += param[1].replace('_','\_')+"\_err" 
    3111                 if index < len(self.parameters)-1: 
     3122                content += param[1].replace('_', '\_') + "\_err" 
     3123                if index < len(self.parameters) - 1: 
    31123124                    content += ' & ' 
    31133125            content += '\\\\ \\hline' 
     
    31193131                content += ' & ' 
    31203132                content += param[4].GetValue() #parameter error 
    3121                 if index < len(self.parameters)-1: 
     3133                if index < len(self.parameters) - 1: 
    31223134                    content += ' & ' 
    31233135            content += '\\\\ \\hline' 
     
    31423154            return True 
    31433155        return None 
    3144      
     3156 
    31453157    def _get_copy_helper(self, param, orient_param): 
    31463158        """ 
    31473159        Helping get value and name of the params 
    3148          
     3160 
    31493161        : param param:  parameters 
    31503162        : param orient_param = oritational params 
     
    31633175            except: 
    31643176                logging.error(sys.exc_info()[1]) 
    3165              
     3177 
    31663178            # 2D 
    31673179            if self.data.__class__.__name__ == "Data2D": 
     
    31853197            # add to the content 
    31863198            if disfunc != '': 
    3187                  
     3199 
    31883200                disfunc = ',' + disfunc 
    31893201            # Need to support array func for copy/paste 
     
    32013213 
    32023214        return content 
    3203     
     3215 
    32043216    def get_clipboard(self): 
    32053217        """ 
     
    32213233            wx.TheClipboard.Close() 
    32223234        return text 
    3223      
     3235 
    32243236    def get_paste(self): 
    32253237        """ 
     
    32303242        self._copy_info(flag) 
    32313243        return flag 
    3232          
     3244 
    32333245    def get_paste_params(self, text=''): 
    32343246        """ 
     
    32593271                    val = [float(a_val) for a_val in array_values[1:]] 
    32603272                    weit = [float(a_weit) for a_weit in array_weights[1:]] 
    3261                      
     3273 
    32623274                    context[name].append(val) 
    32633275                    context[name].append(weit) 
     
    32823294            self._get_paste_helper(self.fixed_param, 
    32833295                                   self.orientation_params_disp, context) 
    3284              
     3296 
    32853297            # go through the str params 
    32863298            self._get_paste_helper(self.str_parameters, 
    32873299                                   self.orientation_params, context) 
    3288                  
     3300 
    32893301            return True 
    32903302        return None 
    3291      
     3303 
    32923304    def _get_paste_helper(self, param, orient_param, content): 
    32933305        """ 
    32943306        Helping set values of the params 
    3295          
     3307 
    32963308        : param param:  parameters 
    32973309        : param orient_param: oritational params 
     
    33213333                            fun_val = self.model.fun_list[content[name][1]] 
    33223334                            self.model.setParam(name, fun_val) 
    3323                      
     3335 
    33243336                    value = content[name][1:] 
    33253337                    self._paste_poly_help(item, value) 
     
    33673379                        if is_true != None: 
    33683380                            item[0].SetValue(is_true) 
    3369                          
     3381 
    33703382    def _paste_poly_help(self, item, value): 
    33713383        """ 
    33723384        Helps get paste for poly function 
    3373          
     3385 
    33743386        :param item: Gui param items 
    33753387        :param value: the values for parameter ctrols 
     
    34113423                                            [self.state.values, 
    34123424                                             self.state.weights] 
    3413                           
     3425 
    34143426            except: 
    34153427                logging.error(sys.exc_info()[1]) 
    34163428                print "Error in BasePage._paste_poly_help: %s" % \ 
    34173429                                        sys.exc_info()[1] 
    3418      
     3430 
    34193431    def _set_disp_array_cb(self, item): 
    34203432        """ 
     
    34303442        item[6].SetValue('') 
    34313443        item[6].Enable(False) 
    3432          
     3444 
    34333445    def update_pinhole_smear(self): 
    34343446        """ 
     
    34523464            if not os.path.isfile(categorization_file): 
    34533465                categorization_file = CategoryInstaller.get_default_file() 
    3454             cat_file = open(categorization_file, 'rb')                            
     3466            cat_file = open(categorization_file, 'rb') 
    34553467            self.master_category_dict = json.load(cat_file) 
    34563468            self._regenerate_model_dict() 
     
    34643476    def _regenerate_model_dict(self): 
    34653477        """ 
    3466         regenerates self.by_model_dict which has each model name as the  
     3478        regenerates self.by_model_dict which has each model name as the 
    34673479        key and the list of categories belonging to that model 
    34683480        along with the enabled mapping 
     
    34733485                self.by_model_dict[model].append(category) 
    34743486                self.model_enabled_dict[model] = enabled 
    3475      
     3487 
    34763488    def _populate_listbox(self): 
    34773489        """ 
     
    34853497        if not uncat_str in cat_list: 
    34863498            cat_list.append(uncat_str) 
    3487          
     3499 
    34883500        for category in cat_list: 
    34893501            if category != '': 
     
    34933505            self.categorybox.SetSelection(0) 
    34943506        else: 
    3495             self.categorybox.SetSelection( \ 
     3507            self.categorybox.SetSelection(\ 
    34963508                self.categorybox.GetSelection()) 
    34973509        #self._on_change_cat(None) 
     
    35133525 
    35143526        else: 
    3515             for (model,enabled) in sorted(self.master_category_dict[category], 
    3516                                       key = lambda name: name[0]): 
     3527            for (model, enabled) in sorted(self.master_category_dict[category], 
     3528                                      key=lambda name: name[0]): 
    35173529                if(enabled): 
    35183530                    self.model_box.Append(model) 
     
    35223534        fill sizer containing model info 
    35233535        """ 
     3536        # This should only be called once per fit tab 
     3537        #print "==== Entering _fill_model_sizer" 
    35243538        ##Add model function Details button in fitpanel. 
    35253539        ##The following 3 lines are for Mac. Let JHC know before modifying... 
     
    35273541        self.formfactorbox = None 
    35283542        self.multifactorbox = None 
    3529         self.mbox_description = wx.StaticBox(self, -1, str(title)) 
     3543        self.mbox_description = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    35303544        boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) 
    35313545        sizer_cat = wx.BoxSizer(wx.HORIZONTAL) 
    35323546        self.mbox_description.SetForegroundColour(wx.RED) 
    3533         id = wx.NewId() 
    3534         self.model_func = wx.Button(self, id, 'Help', size=(80, 23)) 
    3535         self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, id=id) 
     3547        wx_id = self._ids.next() 
     3548        self.model_func = wx.Button(self, wx_id, 'Help', size=(80, 23)) 
     3549        self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, 
     3550                             id=wx_id) 
    35363551        self.model_func.SetToolTipString("Full Model Function Help") 
    3537         id = wx.NewId() 
    3538         self.model_help = wx.Button(self, id, 'Description', size=(80, 23)) 
    3539         self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, id=id) 
     3552        wx_id = self._ids.next() 
     3553        self.model_help = wx.Button(self, wx_id, 'Description', size=(80, 23)) 
     3554        self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, 
     3555                             id=wx_id) 
    35403556        self.model_help.SetToolTipString("Short Model Function Description") 
    3541         id = wx.NewId() 
    3542         self.model_view = wx.Button(self, id, "Show 2D", size=(80, 23)) 
    3543         self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) 
     3557        wx_id = self._ids.next() 
     3558        self.model_view = wx.Button(self, wx_id, "Show 2D", size=(80, 23)) 
     3559        self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=wx_id) 
    35443560        hint = "toggle view of model from 1D to 2D  or 2D to 1D" 
    35453561        self.model_view.SetToolTipString(hint) 
    3546          
    3547         cat_set_box = wx.StaticBox(self, -1, 'Category') 
     3562 
     3563        cat_set_box = wx.StaticBox(self, wx.ID_ANY, 'Category') 
    35483564        sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 
    35493565        sizer_cat_box.SetMinSize((200, 50)) 
    3550         self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3551         self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type") ) 
     3566        self.categorybox = wx.ComboBox(self, wx.ID_ANY, 
     3567                                       style=wx.CB_READONLY) 
     3568        self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 
    35523569        self._populate_listbox() 
    3553         wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) 
    3554         #self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', 
     3570        wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 
     3571        #self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 
    35553572        #                                     style=wx.RB_GROUP) 
    3556         #self.shape_indep_rbutton = wx.RadioButton(self, -1, 
     3573        #self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 
    35573574        #                                          "Shape-Independent") 
    3558         #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 
    3559         #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 
    3560                  
     3575        #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3576        #                                     "Structure Factor ") 
     3577        #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3578        #                                     "Uncategorized") 
     3579 
    35613580        #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35623581        #                   id=self.shape_rbutton.GetId()) 
     
    35683587        #                    id=self.plugin_rbutton.GetId()) 
    35693588        #MAC needs SetValue 
    3570          
    3571         show_cat_button = wx.Button(self, -1, "Modify") 
     3589 
     3590        show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 
    35723591        cat_tip = "Modify model categories \n" 
    35733592        cat_tip += "(also accessible from the menu bar)." 
     
    35943613        sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 
    35953614        mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 
    3596          
    3597         self.text1 = wx.StaticText(self, -1, "") 
    3598         self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 
    3599         self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") 
    3600         self.mutifactor_text1 = wx.StaticText(self, -1, "") 
    3601         self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") 
     3615 
     3616        self.text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3617        self.text2 = wx.StaticText(self, wx.ID_ANY, "P(Q)*S(Q)") 
     3618        self.mutifactor_text = wx.StaticText(self, wx.ID_ANY, "No. of Shells: ") 
     3619        self.mutifactor_text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3620        self.show_sld_button = wx.Button(self, wx.ID_ANY, "Show SLD Profile") 
    36023621        self.show_sld_button.Bind(wx.EVT_BUTTON, self._on_show_sld) 
    36033622 
    3604         self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3605         self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model") ) 
     3623        self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     3624        self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 
    36063625        if self.model != None: 
    36073626            self.formfactorbox.SetValue(self.model.name) 
    3608         self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3609         self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3627        self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     3628        self.multifactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    36103629        self.initialize_combox() 
    3611         wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) 
    3612  
    3613         wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) 
    3614         wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) 
     3630        wx.EVT_COMBOBOX(self.formfactorbox, wx.ID_ANY, self._on_select_model) 
     3631 
     3632        wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 
     3633        wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 
    36153634        ## check model type to show sizer 
    36163635        if self.model != None: 
    36173636            print "_set_model_sizer_selection: disabled." 
    36183637            #self._set_model_sizer_selection(self.model) 
    3619          
     3638 
    36203639        sizer_selection.Add(self.text1) 
    36213640        sizer_selection.Add((10, 5)) 
     
    36253644        sizer_selection.Add((5, 5)) 
    36263645        sizer_selection.Add(self.structurebox) 
    3627         
     3646 
    36283647        mutifactor_selection.Add((13, 5)) 
    36293648        mutifactor_selection.Add(self.mutifactor_text) 
     
    36393658        boxsizer1.Add((10, 10)) 
    36403659        boxsizer1.Add(mutifactor_selection) 
    3641          
     3660 
    36423661        self._set_multfactor_combobox() 
    36433662        self.multifactorbox.SetSelection(1) 
     
    36453664        sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    36463665        sizer.Layout() 
    3647          
     3666 
    36483667    def on_smear_helper(self, update=False): 
    36493668        """ 
    36503669        Help for onSmear if implemented 
    3651          
     3670 
    36523671        :param update: force or not to update 
    36533672        """ 
     
    36583677    def onSmear(self, event): 
    36593678        """ 
    3660         Create a smear object if implemented  
     3679        Create a smear object if implemented 
    36613680        """ 
    36623681    def onPinholeSmear(self, event): 
  • src/sas/perspectives/fitting/batchfitpage.py

    r373d4ee r6f16e25  
    3838        fill sizer 0 with data info 
    3939        """ 
    40         self.data_box_description = wx.StaticBox(self, -1, 'I(q) Data Source') 
     40        self.data_box_description = wx.StaticBox(self, wx.ID_ANY, 'I(q) Data Source') 
    4141        if check_data_validity(self.data): 
    4242            dname_color = wx.BLUE 
     
    4747        #---------------------------------------------------------- 
    4848        sizer_data = wx.BoxSizer(wx.VERTICAL) 
    49         text1 = wx.StaticText(self, -1, ' - Choose a file to set initial fit parameters -') 
     49        text1 = wx.StaticText(self, wx.ID_ANY, ' - Choose a file to set initial fit parameters -') 
    5050        text1.SetForegroundColour(wx.RED) 
    5151        sizer_data.Add(text1) 
    52         text2 = wx.StaticText(self, -1, ' - This panel is not designed to view individual fits. - ') 
     52        text2 = wx.StaticText(self, wx.ID_ANY, ' - This panel is not designed to view individual fits. - ') 
    5353        text2.SetForegroundColour(wx.RED) 
    5454        sizer_data.Add(text2) 
    5555 
    5656        combo = wx.BoxSizer(wx.HORIZONTAL) 
    57         self.dataSource = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    58         wx.EVT_COMBOBOX(self.dataSource, -1, self.on_select_data) 
     57        self.dataSource = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     58        wx.EVT_COMBOBOX(self.dataSource, wx.ID_ANY, self.on_select_data) 
    5959        self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) 
    6060 
    61         combo.Add(wx.StaticText(self, -1, 'Name : ')) 
     61        combo.Add(wx.StaticText(self, wx.ID_ANY, 'Name : ')) 
    6262        combo.Add((0, 5)) 
    6363        combo.Add(self.dataSource) 
     
    8686#          
    8787#         #Sizers 
    88 #         box_description_range = wx.StaticBox(self, -1, str(title)) 
     88#         box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    8989#         boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL)       
    9090#         self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) 
     
    9696#         sizer_fit = wx.GridSizer(2, 4, 2, 6) 
    9797#         #Fit button 
    98 #         self.btFit = wx.Button(self, wx.NewId(), 'Fit', size=(88, 25)) 
     98#         self.btFit = wx.Button(self, self._ids.next(), 'Fit', size=(88, 25)) 
    9999#         self.default_bt_colour =  self.btFit.GetDefaultAttributes() 
    100100#         self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id= self.btFit.GetId()) 
     
    102102#  
    103103#         # Update and Draw button 
    104 #         self.draw_button = wx.Button(self, wx.NewId(), 'Compute', size=(88, 24)) 
     104#         self.draw_button = wx.Button(self, self._ids.next(), 'Compute', size=(88, 24)) 
    105105#         self.draw_button.Bind(wx.EVT_BUTTON, \ 
    106106#                               self._onDraw,id=self.draw_button.GetId()) 
     
    122122#         self.sizer5.Clear(True) 
    123123#       
    124 #         self.qmin  = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     124#         self.qmin  = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    125125#                                           style=wx.TE_PROCESS_ENTER,  
    126126#                                     text_enter_callback = self._onQrangeEnter) 
     
    128128#         self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 
    129129#       
    130 #         self.qmax  = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     130#         self.qmax  = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    131131#                                           style=wx.TE_PROCESS_ENTER,  
    132132#                                         text_enter_callback=self._onQrangeEnter) 
     
    134134#         self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 
    135135#          
    136 #         id = wx.NewId() 
     136#         id = self._ids.next() 
    137137#         self.reset_qrange =wx.Button(self, id, 'Reset', size=(77, 20)) 
    138138#        
     
    144144#         sizer = wx.GridSizer(2, 4, 2, 6) 
    145145#  
    146 #         self.btEditMask = wx.Button(self, wx.NewId(),'Editor', size=(88, 23)) 
     146#         self.btEditMask = wx.Button(self, self._ids.next(),'Editor', size=(88, 23)) 
    147147#         self.btEditMask.Bind(wx.EVT_BUTTON,  
    148148#                              self._onMask,id=self.btEditMask.GetId()) 
    149149#         self.btEditMask.SetToolTipString("Edit Mask.") 
    150 #         self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') 
    151 #  
    152 #         sizer.Add(wx.StaticText(self, -1, 'Q range'))      
    153 #         sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) 
    154 #         sizer.Add(wx.StaticText(self, -1, ' Max[1/A]')) 
     150#         self.EditMask_title = wx.StaticText(self, wx.ID_ANY, ' Masking(2D)') 
     151#  
     152#         sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Q range')) 
     153#         sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Min[1/A]')) 
     154#         sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 
    155155#         sizer.Add(self.EditMask_title) 
    156156 
  • src/sas/perspectives/fitting/fitpage.py

    rcd5e29b r1c2bf90  
    3434    FitPanel class contains fields allowing to display results when 
    3535    fitting  a model and one data 
    36      
     36 
    3737    :note: For Fit to be performed the user should check at least one parameter 
    3838        on fit Panel window. 
     
    4444        """ 
    4545        BasicPage.__init__(self, parent, color=color) 
    46          
     46 
    4747        ## draw sizer 
    4848        self._fill_data_sizer() 
     
    7171        self.create_default_data() 
    7272        self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 
    73      
     73 
    7474    def enable_fit_button(self): 
    7575        """ 
     
    9393        fill sizer 0 with data info 
    9494        """ 
    95         self.data_box_description = wx.StaticBox(self, -1, 'I(q) Data Source') 
     95        self.data_box_description = wx.StaticBox(self, wx.ID_ANY, 
     96                                                 'I(q) Data Source') 
    9697        if check_data_validity(self.data): 
    9798            dname_color = wx.BLUE 
     
    102103        #---------------------------------------------------------- 
    103104        sizer_data = wx.BoxSizer(wx.HORIZONTAL) 
    104         self.dataSource = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    105         wx.EVT_COMBOBOX(self.dataSource, -1, self.on_select_data) 
     105        self.dataSource = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     106        wx.EVT_COMBOBOX(self.dataSource, wx.ID_ANY, self.on_select_data) 
    106107        self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) 
    107         sizer_data.Add(wx.StaticText(self, -1, 'Name : ')) 
     108        sizer_data.Add(wx.StaticText(self, wx.ID_ANY, 'Name : ')) 
    108109        sizer_data.Add(self.dataSource) 
    109110        sizer_data.Add((0, 5)) 
     
    111112        self.sizer0.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    112113        self.sizer0.Layout() 
    113          
     114 
    114115    def enable_datasource(self): 
    115116        """ 
     
    120121        else: 
    121122            self.dataSource.Enable() 
    122              
     123 
    123124    def fill_data_combobox(self, data_list): 
    124125        """ 
     
    155156        if len(data_list) == 1: 
    156157            self.dataSource.Disable() 
    157                  
     158 
    158159    def on_select_data(self, event=None): 
    159160        """ 
     
    167168            data = self.dataSource.GetClientData(pos) 
    168169            self.set_data(data) 
    169      
     170 
    170171    def _on_fit_complete(self): 
    171172        """ 
     
    174175        self.fit_started = False 
    175176        self.set_fitbutton() 
    176          
     177 
    177178    def _is_2D(self): 
    178179        """ 
    179180        Check if data_name is Data2D 
    180          
     181 
    181182        :return: True or False 
    182          
     183 
    183184        """ 
    184185        if self.data.__class__.__name__ == "Data2D" or \ 
     
    186187            return True 
    187188        return False 
    188              
     189 
    189190    def _fill_range_sizer(self): 
    190191        """ 
     
    195196        """ 
    196197        is_2Ddata = False 
    197          
     198 
    198199        # Check if data is 2D 
    199200        if self.data.__class__.__name__ == "Data2D" or \ 
    200201                        self.enable2D: 
    201202            is_2Ddata = True 
    202              
     203 
    203204        title = "Fitting" 
    204205        #smear messages & titles 
     
    217218        smear_message_slit_height_title = "Slit height[1/A]:" 
    218219        smear_message_slit_width_title = "Slit width[1/A]:" 
    219          
     220 
    220221        self._get_smear_info() 
    221          
     222 
    222223        #Sizers 
    223         box_description_range = wx.StaticBox(self, -1, str(title)) 
     224        box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    224225        box_description_range.SetForegroundColour(wx.BLUE) 
    225226        boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) 
     
    229230        self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) 
    230231        sizer_chi2 = wx.BoxSizer(wx.VERTICAL) 
    231         smear_set_box = wx.StaticBox(self, -1, 'Set Instrumental Smearing') 
     232        smear_set_box = wx.StaticBox(self, wx.ID_ANY, 
     233                                     'Set Instrumental Smearing') 
    232234        sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) 
    233235        sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH, 60)) 
    234          
    235         weighting_set_box = wx.StaticBox(self, -1, \ 
     236 
     237        weighting_set_box = wx.StaticBox(self, wx.ID_ANY, 
    236238                                'Set Weighting by Selecting dI Source') 
    237239        weighting_box = wx.StaticBoxSizer(weighting_set_box, wx.HORIZONTAL) 
     
    239241        weighting_box.SetMinSize((_DATA_BOX_WIDTH, 40)) 
    240242        #Filling the sizer containing weighting info. 
    241         self.dI_noweight = wx.RadioButton(self, -1, 'No Weighting', 
    242                                           style=wx.RB_GROUP) 
    243         self.dI_didata = wx.RadioButton(self, -1, 'Use dI Data') 
    244         self.dI_sqrdata = wx.RadioButton(self, -1, 'Use |sqrt(I Data)|') 
    245         self.dI_idata = wx.RadioButton(self, -1, 'Use |I Data|') 
     243        self.dI_noweight = wx.RadioButton(self, wx.ID_ANY, 
     244                                          'No Weighting', style=wx.RB_GROUP) 
     245        self.dI_didata = wx.RadioButton(self, wx.ID_ANY, 'Use dI Data') 
     246        self.dI_sqrdata = wx.RadioButton(self, wx.ID_ANY, 'Use |sqrt(I Data)|') 
     247        self.dI_idata = wx.RadioButton(self, wx.ID_ANY, 'Use |I Data|') 
    246248        self.Bind(wx.EVT_RADIOBUTTON, self.onWeighting, 
    247249                  id=self.dI_noweight.GetId()) 
     
    267269        self.dI_idata.Enable(False) 
    268270        weighting_box.Add(sizer_weighting) 
    269          
     271 
    270272        # combobox for smear2d accuracy selection 
    271         self.smear_accuracy = wx.ComboBox(self, -1, size=(50, -1), 
    272                                           style=wx.CB_READONLY) 
     273        self.smear_accuracy = wx.ComboBox(self, wx.ID_ANY, 
     274                                          size=(50, -1), style=wx.CB_READONLY) 
    273275        self._set_accuracy_list() 
    274276        self.smear_accuracy.SetValue(self.smear2d_accuracy) 
    275277        self.smear_accuracy.SetSelection(0) 
    276         self.smear_accuracy.SetToolTipString(\ 
     278        self.smear_accuracy.SetToolTipString( 
    277279            "'Higher' uses more Gaussian points for smearing computation.") 
    278                     
    279         wx.EVT_COMBOBOX(self.smear_accuracy, -1, self._on_select_accuracy) 
     280 
     281        wx.EVT_COMBOBOX(self.smear_accuracy, wx.ID_ANY, 
     282                        self._on_select_accuracy) 
    280283 
    281284        #Fit button 
    282         self.btFit = wx.Button(self, wx.NewId(), 'Fit') 
     285        self.btFit = wx.Button(self, self._ids.next(), 'Fit') 
    283286        self.default_bt_colour = self.btFit.GetDefaultAttributes() 
    284287        self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id=self.btFit.GetId()) 
    285288        self.btFit.SetToolTipString("Start fitting.") 
    286          
     289 
    287290        #General Help button 
    288         self.btFitHelp = wx.Button(self, -1, 'Help') 
     291        self.btFitHelp = wx.Button(self, wx.ID_ANY, 'Help') 
    289292        self.btFitHelp.SetToolTipString("General fitting help.") 
    290293        self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 
     
    299302        else: 
    300303            size_q = (30, 20)  #on MAC 
    301         self.btSmearHelp = wx.Button(self, -1, '?', style=wx.BU_EXACTFIT,\ 
    302                                      size=size_q) 
     304        self.btSmearHelp = wx.Button(self, wx.ID_ANY, '?', 
     305                                     style=wx.BU_EXACTFIT, size=size_q) 
    303306        self.btSmearHelp.SetToolTipString("Resolution smearing help.") 
    304307        self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 
    305308         
    306309        #textcntrl for custom resolution 
    307         self.smear_pinhole_max = ModelTextCtrl(self, -1, 
     310        self.smear_pinhole_max = ModelTextCtrl(self, wx.ID_ANY, 
    308311                            size=(_BOX_WIDTH - 25, 20), 
    309312                            style=wx.TE_PROCESS_ENTER, 
    310313                            text_enter_callback=self.onPinholeSmear) 
    311         self.smear_pinhole_min = ModelTextCtrl(self, -1, 
     314        self.smear_pinhole_min = ModelTextCtrl(self, wx.ID_ANY, 
    312315                            size=(_BOX_WIDTH - 25, 20), 
    313316                            style=wx.TE_PROCESS_ENTER, 
    314317                            text_enter_callback=self.onPinholeSmear) 
    315         self.smear_slit_height = ModelTextCtrl(self, -1, 
     318        self.smear_slit_height = ModelTextCtrl(self, wx.ID_ANY, 
    316319                            size=(_BOX_WIDTH - 25, 20), 
    317320                            style=wx.TE_PROCESS_ENTER, 
    318321                            text_enter_callback=self.onSlitSmear) 
    319         self.smear_slit_width = ModelTextCtrl(self, -1, 
     322        self.smear_slit_width = ModelTextCtrl(self, wx.ID_ANY, 
    320323                            size=(_BOX_WIDTH - 25, 20), 
    321324                            style=wx.TE_PROCESS_ENTER, 
     
    323326 
    324327        ## smear 
    325         self.smear_data_left = BGTextCtrl(self, -1, 
    326                                          size=(_BOX_WIDTH - 25, 20), style=0) 
     328        self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 
     329                                          size=(_BOX_WIDTH - 25, 20), style=0) 
    327330        self.smear_data_left.SetValue(str(self.dq_l)) 
    328         self.smear_data_right = BGTextCtrl(self, -1, 
    329                                         size=(_BOX_WIDTH - 25, 20), style=0) 
     331        self.smear_data_right = BGTextCtrl(self, wx.ID_ANY, 
     332                                           size=(_BOX_WIDTH - 25, 20), style=0) 
    330333        self.smear_data_right.SetValue(str(self.dq_r)) 
    331334 
     
    337340 
    338341        #Filling the sizer containing instruments smearing info. 
    339         self.disable_smearer = wx.RadioButton(self, -1, 
     342        self.disable_smearer = wx.RadioButton(self, wx.ID_ANY, 
    340343                                              'None', style=wx.RB_GROUP) 
    341         self.enable_smearer = wx.RadioButton(self, -1, 
    342                                              'Use dQ Data') 
     344        self.enable_smearer = wx.RadioButton(self, wx.ID_ANY, 'Use dQ Data') 
    343345        #self.enable_smearer.SetToolTipString( 
    344346        #"Click to use the loaded dQ data for smearing.") 
    345         self.pinhole_smearer = wx.RadioButton(self, -1, 
     347        self.pinhole_smearer = wx.RadioButton(self, wx.ID_ANY, 
    346348                                              'Custom Pinhole Smear') 
    347349        #self.pinhole_smearer.SetToolTipString 
    348350        #("Click to input custom resolution for pinhole smearing.") 
    349         self.slit_smearer = wx.RadioButton(self, -1, 'Custom Slit Smear') 
     351        self.slit_smearer = wx.RadioButton(self, wx.ID_ANY, 'Custom Slit Smear') 
    350352        #self.slit_smearer.SetToolTipString 
    351353        #("Click to input custom resolution for slit smearing.") 
     
    359361                  id=self.slit_smearer.GetId()) 
    360362        self.disable_smearer.SetValue(True) 
    361          
     363 
    362364        sizer_smearer.Add(self.disable_smearer, 0, wx.LEFT, 10) 
    363365        sizer_smearer.Add(self.enable_smearer) 
     
    366368        sizer_smearer.Add(self.btSmearHelp) 
    367369        sizer_smearer.Add((10, 10)) 
    368          
     370 
    369371        # StaticText for chi2, N(for fitting), Npts + Log/linear spacing 
    370         self.tcChi = BGTextCtrl(self, -1, "-", size=(75, 20), style=0) 
     372        self.tcChi = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 
    371373        self.tcChi.SetToolTipString("Chi2/Npts(Fit)") 
    372         self.Npts_fit = BGTextCtrl(self, -1, "-", size=(75, 20), style=0) 
    373         self.Npts_fit.SetToolTipString(\ 
     374        self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 
     375        self.Npts_fit.SetToolTipString( 
    374376                            " Npts : number of points selected for fitting") 
    375         self.Npts_total = ModelTextCtrl(self, -1, 
    376                         size=(_BOX_WIDTH, 20), 
    377                         style=wx.TE_PROCESS_ENTER, 
    378                         text_enter_callback=self._onQrangeEnter) 
     377        self.Npts_total = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
     378                            style=wx.TE_PROCESS_ENTER, 
     379                            text_enter_callback=self._onQrangeEnter) 
    379380        self.Npts_total.SetValue(format_number(self.npts_x)) 
    380381        self.Npts_total.SetToolTipString(\ 
    381382                                " Total Npts : total number of data points") 
    382                  
     383 
    383384        # Update and Draw button 
    384         self.draw_button = wx.Button(self, wx.NewId(), 'Compute') 
    385         self.draw_button.Bind(wx.EVT_BUTTON, \ 
     385        self.draw_button = wx.Button(self, self._ids.next(), 'Compute') 
     386        self.draw_button.Bind(wx.EVT_BUTTON, 
    386387                              self._onDraw, id=self.draw_button.GetId()) 
    387388        self.draw_button.SetToolTipString("Compute and Draw.") 
    388          
    389         self.points_sizer = wx.BoxSizer(wx.HORIZONTAL)  
    390         self.pointsbox = wx.CheckBox(self, -1, 'Log?', (10, 10)) 
     389 
     390        self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     391        self.pointsbox = wx.CheckBox(self, wx.ID_ANY, 'Log?', (10, 10)) 
    391392        self.pointsbox.SetValue(False) 
    392393        self.pointsbox.SetToolTipString("Check mark to use log spaced points") 
    393394        wx.EVT_CHECKBOX(self, self.pointsbox.GetId(), self.select_log) 
    394          
    395         self.points_sizer.Add(wx.StaticText(self, -1, 'Npts    ')) 
     395 
     396        self.points_sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Npts    ')) 
    396397        self.points_sizer.Add(self.pointsbox) 
    397398 
    398         box_description_1 = wx.StaticText(self, -1, '   Chi2/Npts') 
    399         box_description_2 = wx.StaticText(self, -1, 'Npts(Fit)') 
     399        box_description_1 = wx.StaticText(self, wx.ID_ANY, '   Chi2/Npts') 
     400        box_description_2 = wx.StaticText(self, wx.ID_ANY, 'Npts(Fit)') 
    400401 
    401402        # StaticText for smear 
    402         self.smear_description_none = wx.StaticText(self, -1, 
     403        self.smear_description_none = wx.StaticText(self, wx.ID_ANY, 
    403404                                    smear_message_none, style=wx.ALIGN_LEFT) 
    404         self.smear_description_dqdata = wx.StaticText(self, 
    405                                 -1, smear_message_dqdata, style=wx.ALIGN_LEFT) 
    406         self.smear_description_type = wx.StaticText(self, 
    407                                      -1, "Type:", style=wx.ALIGN_LEFT) 
    408         self.smear_description_accuracy_type = wx.StaticText(self, -1, 
    409                                         "Accuracy:", style=wx.ALIGN_LEFT) 
    410         self.smear_description_smear_type = BGTextCtrl(self, -1, 
     405        self.smear_description_dqdata = wx.StaticText(self, wx.ID_ANY, 
     406                                smear_message_dqdata, style=wx.ALIGN_LEFT) 
     407        self.smear_description_type = wx.StaticText(self, wx.ID_ANY, 
     408                                    "Type:", style=wx.ALIGN_LEFT) 
     409        self.smear_description_accuracy_type = wx.StaticText(self, wx.ID_ANY, 
     410                                    "Accuracy:", style=wx.ALIGN_LEFT) 
     411        self.smear_description_smear_type = BGTextCtrl(self, wx.ID_ANY, 
    411412                                                       size=(57, 20), style=0) 
    412413        self.smear_description_smear_type.SetValue(str(self.dq_l)) 
    413414        self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) 
    414         self.smear_description_2d = wx.StaticText(self, -1, 
     415        self.smear_description_2d = wx.StaticText(self, wx.ID_ANY, 
    415416                                    smear_message_2d, style=wx.ALIGN_LEFT) 
    416         self.smear_message_new_s = wx.StaticText(self, -1, 
     417        self.smear_message_new_s = wx.StaticText(self, wx.ID_ANY, 
    417418                         smear_message_new_ssmear, style=wx.ALIGN_LEFT) 
    418         self.smear_message_new_p = wx.StaticText(self, -1, 
     419        self.smear_message_new_p = wx.StaticText(self, wx.ID_ANY, 
    419420                            smear_message_new_psmear, style=wx.ALIGN_LEFT) 
    420         self.smear_description_2d_x = wx.StaticText(self, -1, 
     421        self.smear_description_2d_x = wx.StaticText(self, wx.ID_ANY, 
    421422                            smear_message_2d_x_title, style=wx.ALIGN_LEFT) 
    422         self.smear_description_2d_x.SetToolTipString(\ 
     423        self.smear_description_2d_x.SetToolTipString( 
    423424                                        "  dQp(parallel) in q_r direction.") 
    424         self.smear_description_2d_y = wx.StaticText(self, -1, 
     425        self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 
    425426                            smear_message_2d_y_title, style=wx.ALIGN_LEFT) 
    426427        self.smear_description_2d_y.SetToolTipString(\ 
    427428                                    " dQs(perpendicular) in q_phi direction.") 
    428         self.smear_description_pin_min = wx.StaticText(self, -1, 
     429        self.smear_description_pin_min = wx.StaticText(self, wx.ID_ANY, 
    429430                        smear_message_pinhole_min_title, style=wx.ALIGN_LEFT) 
    430         self.smear_description_pin_max = wx.StaticText(self, -1, 
     431        self.smear_description_pin_max = wx.StaticText(self, wx.ID_ANY, 
    431432                        smear_message_pinhole_max_title, style=wx.ALIGN_LEFT) 
    432         self.smear_description_slit_height = wx.StaticText(self, -1, 
     433        self.smear_description_slit_height = wx.StaticText(self, wx.ID_ANY, 
    433434                        smear_message_slit_height_title, style=wx.ALIGN_LEFT) 
    434         self.smear_description_slit_width = wx.StaticText(self, -1, 
     435        self.smear_description_slit_width = wx.StaticText(self, wx.ID_ANY, 
    435436                        smear_message_slit_width_title, style=wx.ALIGN_LEFT) 
    436          
     437 
    437438        #arrange sizers 
    438439        self.sizer_set_smearer.Add(sizer_smearer) 
     
    467468        self.sizer_new_smear.Add((20, -1)) 
    468469        self.sizer_new_smear.Add(self.smear_description_2d_y, 
    469                                   0, wx.CENTER, 10 ) 
     470                                  0, wx.CENTER, 10) 
    470471        self.sizer_new_smear.Add(self.smear_description_pin_max, 
    471                                   0, wx.CENTER, 10 ) 
     472                                  0, wx.CENTER, 10) 
    472473        self.sizer_new_smear.Add(self.smear_description_slit_width, 
    473                                   0, wx.CENTER, 10 ) 
     474                                  0, wx.CENTER, 10) 
    474475 
    475476        self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) 
    476477        self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 
    477478        self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) 
    478             
     479 
    479480        self.sizer_set_smearer.Add(self.smear_message_new_s, 0, wx.CENTER, 10) 
    480481        self.sizer_set_smearer.Add(self.smear_message_new_p, 0, wx.CENTER, 10) 
    481482        self.sizer_set_smearer.Add((5, 2)) 
    482483        self.sizer_set_smearer.Add(self.sizer_new_smear, 0, wx.CENTER, 10) 
    483          
     484 
    484485        # add all to chi2 sizer 
    485486        sizer_smearer_box.Add(self.sizer_set_smearer) 
     
    488489        sizer_chi2.Add(weighting_box) 
    489490        sizer_chi2.Add((-1, 5)) 
    490          
     491 
    491492        # hide all smear messages and textctrl 
    492493        self._hide_all_smear_info() 
    493          
     494 
    494495        # get smear_selection 
    495496        self.current_smearer = smear_selection(self.data, self.model) 
     
    512513        #2D data? default 
    513514        is_2Ddata = False 
    514          
     515 
    515516        #check if it is 2D data 
    516517        if self.data.__class__.__name__ == "Data2D" or self.enable2D: 
    517518            is_2Ddata = True 
    518              
     519 
    519520        self.sizer5.Clear(True) 
    520       
    521         self.qmin = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    522                                     style=wx.TE_PROCESS_ENTER, 
    523                                     set_focus_callback=self.qrang_set_focus, 
    524                                     text_enter_callback=self._onQrangeEnter, 
    525                                     name='qmin') 
     521 
     522        self.qmin = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
     523                                  style=wx.TE_PROCESS_ENTER, 
     524                                  set_focus_callback=self.qrang_set_focus, 
     525                                  text_enter_callback=self._onQrangeEnter, 
     526                                  name='qmin') 
    526527        self.qmin.SetValue(str(self.qmin_x)) 
    527528        q_tip = "Click outside of the axes\n to remove the lines." 
     
    529530        qmin_tip += q_tip 
    530531        self.qmin.SetToolTipString(qmin_tip) 
    531       
    532         self.qmax = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    533                                        style=wx.TE_PROCESS_ENTER, 
    534                                        set_focus_callback=self.qrang_set_focus, 
    535                                        text_enter_callback=self._onQrangeEnter, 
    536                                        name='qmax') 
     532 
     533        self.qmax = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
     534                                  style=wx.TE_PROCESS_ENTER, 
     535                                  set_focus_callback=self.qrang_set_focus, 
     536                                  text_enter_callback=self._onQrangeEnter, 
     537                                  name='qmax') 
    537538        self.qmax.SetValue(str(self.qmax_x)) 
    538539        qmax_tip = "Maximum value of Q.\n" 
     
    545546        self.qmin.Bind(wx.EVT_TEXT, self.on_qrange_text) 
    546547        self.qmax.Bind(wx.EVT_TEXT, self.on_qrange_text) 
    547         wx_id = wx.NewId() 
     548        wx_id = self._ids.next() 
    548549        self.reset_qrange = wx.Button(self, wx_id, 'Reset') 
    549        
     550 
    550551        self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=wx_id) 
    551552        self.reset_qrange.SetToolTipString("Reset Q range to the default") 
    552       
     553 
    553554        sizer = wx.GridSizer(5, 5, 2, 6) 
    554555 
    555         self.btEditMask = wx.Button(self, wx.NewId(), 'Editor') 
     556        self.btEditMask = wx.Button(self, self._ids.next(), 'Editor') 
    556557        self.btEditMask.Bind(wx.EVT_BUTTON, self._onMask, 
    557558                             id=self.btEditMask.GetId()) 
    558559        self.btEditMask.SetToolTipString("Edit Mask.") 
    559         self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') 
    560          
    561         sizer.Add(wx.StaticText(self, -1, '   Q range')) 
    562         sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) 
    563         sizer.Add(wx.StaticText(self, -1, ' Max[1/A]')) 
     560        self.EditMask_title = wx.StaticText(self, wx.ID_ANY, ' Masking(2D)') 
     561 
     562        sizer.Add(wx.StaticText(self, wx.ID_ANY, '   Q range')) 
     563        sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Min[1/A]')) 
     564        sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 
    564565        sizer.Add(self.EditMask_title) 
    565566        sizer.Add((-1,5)) 
     
    598599        self.sizer5.Layout() 
    599600 
    600          
     601 
    601602    def _set_sizer_dispersion(self): 
    602603        """ 
     
    614615            ## the user didn't select dispersity display 
    615616            return 
    616              
     617 
    617618        self._reset_dispersity() 
    618          
     619 
    619620        ## fill a sizer with the combobox to select dispersion type 
    620         model_disp = wx.StaticText(self, -1, 'Function') 
     621        model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 
    621622        CHECK_STATE = self.cb1.GetValue() 
    622         #import sas.models.dispersion_models 
    623         #self.polydisp = sas.models.dispersion_models.models 
    624         import sasmodels.weights 
    625         self.polydisp = sasmodels.weights.models 
     623        import sas.models.dispersion_models 
     624        self.polydisp = sas.models.dispersion_models.models 
    626625 
    627626        ix = 0 
    628627        iy = 0 
    629         disp = wx.StaticText(self, -1, ' ') 
     628        disp = wx.StaticText(self, wx.ID_ANY, ' ') 
    630629        self.sizer4_4.Add(disp, (iy, ix), (1, 1), 
    631630                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    632631        ix += 1 
    633         values = wx.StaticText(self, -1, 'PD[ratio]') 
     632        values = wx.StaticText(self, wx.ID_ANY, 'PD[ratio]') 
    634633        polytext = "Polydispersity (= STD/mean); " 
    635634        polytext += "the standard deviation over the mean value." 
     
    643642        else: 
    644643            err_text = '' 
    645         self.text_disp_1 = wx.StaticText(self, -1, err_text) 
     644        self.text_disp_1 = wx.StaticText(self, wx.ID_ANY, err_text) 
    646645        self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \ 
    647646                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    648          
     647 
    649648        ix += 1 
    650         self.text_disp_min = wx.StaticText(self, -1, 'Min') 
     649        self.text_disp_min = wx.StaticText(self, wx.ID_ANY, 'Min') 
    651650        self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), \ 
    652651                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    653652 
    654653        ix += 1 
    655         self.text_disp_max = wx.StaticText(self, -1, 'Max') 
     654        self.text_disp_max = wx.StaticText(self, wx.ID_ANY, 'Max') 
    656655        self.sizer4_4.Add(self.text_disp_max, (iy, ix), (1, 1), 
    657656                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    658         
     657 
    659658        ix += 1 
    660         npts = wx.StaticText(self, -1, 'Npts') 
     659        npts = wx.StaticText(self, wx.ID_ANY, 'Npts') 
    661660        npts.SetToolTipString("Number of sampling points for the numerical\n\ 
    662661        integration over the distribution function.") 
     
    664663                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    665664        ix += 1 
    666         nsigmas = wx.StaticText(self, -1, 'Nsigs') 
     665        nsigmas = wx.StaticText(self, wx.ID_ANY, 'Nsigs') 
    667666        nsigmas.SetToolTipString("Number of sigmas between which the range\n\ 
    668667         of the distribution function will be used for weighting. \n\ 
     
    674673        self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 
    675674                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    676          
     675 
    677676        self.text_disp_max.Show(True) 
    678677        self.text_disp_min.Show(True) 
     
    694693                iy += 1 
    695694                for p in self.model.dispersion[item].keys(): 
    696          
     695 
    697696                    if p == "width": 
    698697                        ix = 0 
    699                         cb = wx.CheckBox(self, -1, name0, (10, 10)) 
     698                        cb = wx.CheckBox(self, wx.ID_ANY, name0, (10, 10)) 
    700699                        cb.SetValue(CHECK_STATE) 
    701700                        cb.SetToolTipString("Check mark to fit") 
     
    705704                        ix = 1 
    706705                        value = self.model.getParam(name1) 
    707                         ctl1 = ModelTextCtrl(self, -1, 
    708                                                   size=(_BOX_WIDTH / 1.3, 20), 
    709                                                   style=wx.TE_PROCESS_ENTER) 
     706                        ctl1 = ModelTextCtrl(self, wx.ID_ANY, 
     707                                             size=(_BOX_WIDTH / 1.3, 20), 
     708                                             style=wx.TE_PROCESS_ENTER) 
    710709                        ctl1.SetLabel('PD[ratio]') 
    711710                        poly_text = "Polydispersity (STD/mean) of %s\n" % item 
     
    717716                        ## text to show error sign 
    718717                        ix = 2 
    719                         text2 = wx.StaticText(self, -1, '+/-') 
     718                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    720719                        self.sizer4_4.Add(text2, (iy, ix), (1, 1), 
    721720                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    724723 
    725724                        ix = 3 
    726                         ctl2 = wx.TextCtrl(self, -1, 
     725                        ctl2 = wx.TextCtrl(self, wx.ID_ANY, 
    727726                                           size=(_BOX_WIDTH / 1.3, 20), 
    728727                                           style=0) 
    729                    
     728 
    730729                        self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 
    731730                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    734733 
    735734                        ix = 4 
    736                         ctl3 = ModelTextCtrl(self, -1, 
    737                                                   size=(_BOX_WIDTH / 2, 20), 
    738                                                   style=wx.TE_PROCESS_ENTER, 
    739                                 text_enter_callback=self._onparamRangeEnter) 
    740                          
     735                        ctl3 = ModelTextCtrl(self, wx.ID_ANY, 
     736                                             size=(_BOX_WIDTH / 2, 20), 
     737                                             style=wx.TE_PROCESS_ENTER, 
     738                            text_enter_callback=self._onparamRangeEnter) 
     739 
    741740                        self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), 
    742741                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    743                         
     742 
    744743                        ix = 5 
    745                         ctl4 = ModelTextCtrl(self, -1, 
    746                                                   size=(_BOX_WIDTH / 2, 20), 
    747                                                   style=wx.TE_PROCESS_ENTER, 
     744                        ctl4 = ModelTextCtrl(self, wx.ID_ANY, 
     745                                             size=(_BOX_WIDTH / 2, 20), 
     746                                             style=wx.TE_PROCESS_ENTER, 
    748747                            text_enter_callback=self._onparamRangeEnter) 
    749                          
     748 
    750749                        self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 
    751750                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    753752                        ctl3.Show(True) 
    754753                        ctl4.Show(True) 
    755                                                                
     754 
    756755                    elif p == "npts": 
    757756                        ix = 6 
    758757                        value = self.model.getParam(name2) 
    759                         Tctl = ModelTextCtrl(self, -1, 
    760                                                   size=(_BOX_WIDTH / 2.2, 20), 
    761                                                   style=wx.TE_PROCESS_ENTER) 
    762                          
     758                        Tctl = ModelTextCtrl(self, wx.ID_ANY, 
     759                                             size=(_BOX_WIDTH / 2.2, 20), 
     760                                             style=wx.TE_PROCESS_ENTER) 
     761 
    763762                        Tctl.SetValue(str(format_number(value))) 
    764763                        self.sizer4_4.Add(Tctl, (iy, ix), (1, 1), 
     
    769768                        ix = 7 
    770769                        value = self.model.getParam(name3) 
    771                         Tct2 = ModelTextCtrl(self, -1, 
    772                                                   size=(_BOX_WIDTH / 2.2, 20), 
    773                                                   style=wx.TE_PROCESS_ENTER) 
    774                          
     770                        Tct2 = ModelTextCtrl(self, wx.ID_ANY, 
     771                                             size=(_BOX_WIDTH / 2.2, 20), 
     772                                             style=wx.TE_PROCESS_ENTER) 
     773 
    775774                        Tct2.SetValue(str(format_number(value))) 
    776775                        self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 
     
    781780 
    782781                ix = 8 
    783                 disp_box = wx.ComboBox(self, -1, size=(65, -1), 
     782                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    784783                                       style=wx.CB_READONLY, name='%s' % name1) 
    785784                for key, value in self.polydisp.iteritems(): 
     
    787786                    disp_box.Append(name_disp, value) 
    788787                    disp_box.SetStringSelection("gaussian") 
    789                 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func) 
     788                wx.EVT_COMBOBOX(disp_box, wx.ID_ANY, self._on_disp_func) 
    790789                self.sizer4_4.Add(disp_box, (iy, ix), (1, 1), wx.EXPAND) 
    791790                self.fittable_param.append([cb, name1, ctl1, text2, 
    792791                                            ctl2, ctl3, ctl4, disp_box]) 
    793                             
     792 
    794793        ix = 0 
    795794        iy += 1 
     
    808807                name2 = item + ".npts" 
    809808                name3 = item + ".nsigmas" 
    810                  
     809 
    811810                if not name1 in self.model.details: 
    812811                    self.model.details[name1] = ["", None, None] 
    813   
     812 
    814813                iy += 1 
    815814                for p in self.model.dispersion[item].keys(): 
    816          
     815 
    817816                    if p == "width": 
    818817                        ix = 0 
    819                         cb = wx.CheckBox(self, -1, name0, (10, 10)) 
     818                        cb = wx.CheckBox(self, wx.ID_ANY, name0, (10, 10)) 
    820819                        cb.SetValue(CHECK_STATE) 
    821820                        cb.SetToolTipString("Check mark to fit") 
     
    830829                        ix = 1 
    831830                        value = self.model.getParam(name1) 
    832                         ctl1 = ModelTextCtrl(self, -1, 
    833                                                   size=(_BOX_WIDTH / 1.3, 20), 
    834                                                   style=wx.TE_PROCESS_ENTER) 
     831                        ctl1 = ModelTextCtrl(self, wx.ID_ANY, 
     832                                             size=(_BOX_WIDTH / 1.3, 20), 
     833                                             style=wx.TE_PROCESS_ENTER) 
    835834                        poly_tip = "Absolute Sigma for %s." % item 
    836835                        ctl1.SetToolTipString(poly_tip) 
     
    846845                                poly_text += "It is the STD (ratio*mean)" 
    847846                                poly_text += " of the distribution.\n " 
    848                              
     847 
    849848                                values.SetToolTipString(poly_text) 
    850849                                first_orient = False 
     
    852851                        elif ctl1.IsShown(): 
    853852                            ctl1.Hide() 
    854                          
     853 
    855854                        self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    856855                        ## text to show error sign 
    857856                        ix = 2 
    858                         text2 = wx.StaticText(self, -1, '+/-') 
     857                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    859858                        self.sizer4_4.Add(text2, (iy, ix), (1, 1), 
    860859                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    863862 
    864863                        ix = 3 
    865                         ctl2 = wx.TextCtrl(self, -1, 
     864                        ctl2 = wx.TextCtrl(self, wx.ID_ANY, 
    866865                                           size=(_BOX_WIDTH / 1.3, 20), 
    867866                                           style=0) 
    868                      
     867 
    869868                        self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 
    870869                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    876875                                text2.Show(True) 
    877876                                ctl2.Show(True) 
    878                              
     877 
    879878                        ix = 4 
    880                         ctl3 = ModelTextCtrl(self, -1, 
    881                                                   size=(_BOX_WIDTH / 2, 20), 
    882                                                   style=wx.TE_PROCESS_ENTER, 
     879                        ctl3 = ModelTextCtrl(self, wx.ID_ANY, 
     880                                             size=(_BOX_WIDTH / 2, 20), 
     881                                             style=wx.TE_PROCESS_ENTER, 
    883882                                text_enter_callback=self._onparamRangeEnter) 
    884883 
     
    887886 
    888887                        ctl3.Hide() 
    889                  
     888 
    890889                        ix = 5 
    891                         ctl4 = ModelTextCtrl(self, -1, 
    892                             size=(_BOX_WIDTH / 2, 20), 
    893                             style=wx.TE_PROCESS_ENTER, 
     890                        ctl4 = ModelTextCtrl(self, wx.ID_ANY, 
     891                                             size=(_BOX_WIDTH / 2, 20), 
     892                                             style=wx.TE_PROCESS_ENTER, 
    894893                            text_enter_callback=self._onparamRangeEnter) 
    895894                        self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 
    896895                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    897896                        ctl4.Hide() 
    898                          
     897 
    899898                        if self.data.__class__.__name__ == "Data2D" or \ 
    900899                                self.enable2D: 
    901900                            ctl3.Show(True) 
    902901                            ctl4.Show(True) 
    903                               
     902 
    904903                    elif p == "npts": 
    905904                        ix = 6 
    906905                        value = self.model.getParam(name2) 
    907                         Tctl = ModelTextCtrl(self, -1, 
    908                                                  size=(_BOX_WIDTH / 2.2, 20), 
    909                                                  style=wx.TE_PROCESS_ENTER) 
    910                          
     906                        Tctl = ModelTextCtrl(self, wx.ID_ANY, 
     907                                             size=(_BOX_WIDTH / 2.2, 20), 
     908                                             style=wx.TE_PROCESS_ENTER) 
     909 
    911910                        Tctl.SetValue(str(format_number(value))) 
    912911                        if self.data.__class__.__name__ == "Data2D" or \ 
     
    925924                        ix = 7 
    926925                        value = self.model.getParam(name3) 
    927                         Tct2 = ModelTextCtrl(self, -1, 
    928                                                   size=(_BOX_WIDTH / 2.2, 20), 
    929                                                   style=wx.TE_PROCESS_ENTER) 
    930                          
     926                        Tct2 = ModelTextCtrl(self, wx.ID_ANY, 
     927                                             size=(_BOX_WIDTH / 2.2, 20), 
     928                                             style=wx.TE_PROCESS_ENTER) 
     929 
    931930                        Tct2.SetValue(str(format_number(value))) 
    932931                        if self.data.__class__.__name__ == "Data2D" or \ 
     
    940939                        self.fixed_param.append([None, name3, Tct2, 
    941940                                                 None, None, None, None, None]) 
    942                                                     
     941 
    943942                        self.orientation_params_disp.append([None, name3, 
    944943                                        Tct2, None, None, None, None, None]) 
    945944 
    946945                ix = 8 
    947                 disp_box = wx.ComboBox(self, -1, size=(65, -1), 
     946                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    948947                                style=wx.CB_READONLY, name='%s' % name1) 
    949948                for key, value in self.polydisp.iteritems(): 
     
    951950                    disp_box.Append(name_disp, value) 
    952951                    disp_box.SetStringSelection("gaussian") 
    953                 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func) 
     952                wx.EVT_COMBOBOX(disp_box, wx.ID_ANY, self._on_disp_func) 
    954953                self.sizer4_4.Add(disp_box, (iy, ix), (1, 1), wx.EXPAND) 
    955954                self.fittable_param.append([cb, name1, ctl1, text2, 
     
    957956                self.orientation_params_disp.append([cb, name1, ctl1, 
    958957                                            text2, ctl2, ctl3, ctl4, disp_box]) 
    959                         
     958 
    960959                if self.data.__class__.__name__ == "Data2D" or \ 
    961960                                self.enable2D: 
     
    963962                else: 
    964963                    disp_box.Hide() 
    965          
     964 
    966965        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 
    967            
     966 
    968967        self.state.model = self.model.clone() 
    969968        ## save state into 
     
    998997        """ 
    999998        flag = self._update_paramv_on_fit() 
    1000      
     999 
    10011000        wx.CallAfter(self._onparamEnter_helper) 
    10021001        if not flag: 
     
    10041003            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    10051004            return 
    1006          
     1005 
    10071006    def _onFit(self, event): 
    10081007        """ 
     
    10291028                         StatusEvent(status="Fit: %s" % msg, type="stop")) 
    10301029            return 
    1031          
     1030 
    10321031        if len(self.param_toFit) <= 0: 
    10331032            msg = "Select at least one parameter to fit" 
     
    10361035                         StatusEvent(status=msg, type="stop")) 
    10371036            return 
    1038          
     1037 
    10391038        flag = self._update_paramv_on_fit() 
    1040          
     1039 
    10411040        if self.batch_on and not self._is_2D(): 
    10421041            if not self._validate_Npts_1D(): 
    10431042                return 
    1044                  
     1043 
    10451044        if not flag: 
    10461045            msg = "Fitting range or parameters are invalid" 
     
    10481047                         StatusEvent(status=msg, type="stop")) 
    10491048            return 
    1050                
     1049 
    10511050        self.select_param(event=None) 
    10521051 
     
    10641063        self.fit_started = self._manager.onFit(uid=self.uid) 
    10651064        wx.CallAfter(self.set_fitbutton) 
    1066      
     1065 
    10671066    def _onFitHelp(self, event): 
    10681067        """ 
     
    10811080 
    10821081        _TreeLocation = "user/perspectives/fitting/fitting_help.html" 
    1083         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     1082        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    10841083                                          "General Fitting Help") 
    10851084 
     
    11001099 
    11011100        _TreeLocation = "user/perspectives/fitting/sm_help.html" 
    1102         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     1101        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    11031102                                          "Instrumental Resolution Smearing \ 
    11041103                                          Help") 
     
    11121111        if self.is_mac: 
    11131112            return 
    1114          
     1113 
    11151114        if self.fit_started: 
    11161115            label = "Stop" 
     
    11231122        self.btFit.SetForegroundColour(color) 
    11241123        self.btFit.Enable(True) 
    1125                       
     1124 
    11261125    def get_weight_flag(self): 
    11271126        """ 
     
    11451144                break 
    11461145        return flag 
    1147                  
     1146 
    11481147    def _StopFit(self, event=None): 
    11491148        """ 
     
    11551154        self._manager._reset_schedule_problem(value=0) 
    11561155        self._on_fit_complete() 
    1157           
     1156 
    11581157    def rename_model(self): 
    11591158        """ 
     
    11621161        if self.model is not None: 
    11631162            self.model.name = "M" + str(self.index_model) 
    1164      
     1163 
    11651164    def _on_select_model(self, event=None): 
    11661165        """ 
     
    11841183            self._keep.Enable(False) 
    11851184            self._set_save_flag(False) 
     1185        # TODO: why do we have to variables for one flag?? 
    11861186        self.enable_disp.SetValue(False) 
    11871187        self.disable_disp.SetValue(True) 
     1188        # TODO: should not have an untrapped exception when displaying disperser 
     1189        # TODO: do we need to create the disperser panel on every model change? 
     1190        # Note: if we fix this, then remove ID_DISPERSER_HELP from basepage 
    11881191        try: 
    11891192            self.set_dispers_sizer() 
     
    11941197        self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 
    11951198        self.state.slit_smearer = self.slit_smearer.GetValue() 
    1196      
     1199 
    11971200        self.state.structurecombobox = self.structurebox.GetLabel() 
    11981201        self.state.formfactorcombobox = self.formfactorbox.GetLabel() 
     
    12101213                    self._keep.Enable(not self.batch_on) 
    12111214                    self._set_save_flag(True) 
    1212      
     1215 
    12131216            # more disables for 2D 
    12141217            self._set_smear_buttons() 
    1215              
     1218 
    12161219            try: 
    12171220                # update smearer sizer 
     
    12271230            ## event to post model to fit to fitting plugins 
    12281231            (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 
    1229           
     1232 
    12301233            ## set smearing value whether or not 
    12311234            #    the data contain the smearing info 
     
    12371240                            caption=self.window_caption, 
    12381241                            qmax=float(self.qmax_x)) 
    1239     
     1242 
    12401243            self._manager._on_model_panel(evt=evt) 
    1241             self.mbox_description.SetLabel("Model [ %s ]"% str(self.model.name)) 
     1244            self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) 
    12421245            self.mbox_description.SetForegroundColour(wx.BLUE) 
    12431246            self.state.model = self.model.clone() 
     
    12721275                self.get_paste_params(copy_flag) 
    12731276                wx.CallAfter(self._onDraw, None) 
    1274                  
     1277 
    12751278        else: 
    12761279            self._draw_model() 
    1277              
     1280 
    12781281        if self.batch_on: 
    12791282            self.slit_smearer.Enable(False) 
     
    12811284            self.btEditMask.Disable() 
    12821285            self.EditMask_title.Disable() 
    1283              
     1286 
    12841287        self.Show(True) 
    12851288        self.SetupScrolling() 
    1286           
     1289 
    12871290    def _onparamEnter(self, event): 
    12881291        """ 
     
    13271330                                              qmax=float(self.qmax_x), 
    13281331                                              enable_smearer=enable_smearer, 
    1329                                             draw=True) 
     1332                                              draw=True) 
    13301333                if flag: 
    13311334                    #self.compute_chisqr(smearer= temp_smearer) 
    1332          
     1335 
    13331336                    ## new state posted 
    13341337                    if self.state_change: 
     
    13451348            msg = "Cannot Plot :Must enter a number!!!  " 
    13461349            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1347               
     1350 
    13481351        self.save_current_state() 
    13491352        return 
    1350     
     1353 
    13511354    def _onparamRangeEnter(self, event): 
    13521355        """ 
     
    13711374        else: 
    13721375            tcrtl.SetBackgroundColour(wx.WHITE) 
    1373             
     1376 
    13741377        #self._undo.Enable(True) 
    13751378        self.save_current_state() 
     
    13771380        wx.PostEvent(self.parent, event) 
    13781381        self.state_change = False 
    1379          
    1380     def qrang_set_focus(self, event=None):   
     1382 
     1383    def qrang_set_focus(self, event=None): 
    13811384        """ 
    13821385        ON Qrange focus 
     
    13861389        #tcrtl = event.GetEventObject() 
    13871390        self._validate_qrange(self.qmin, self.qmax) 
    1388          
     1391 
    13891392    def qrange_click(self, event): 
    13901393        """ 
     
    14001403            d_group_id = self.data.group_id 
    14011404            act_ctrl = event.GetEventObject() 
    1402             wx.PostEvent(self._manager.parent,  
    1403                          PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
     1405            wx.PostEvent(self._manager.parent, 
     1406                         PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 
    14041407                                     group_id=d_group_id, leftdown=is_click, 
    14051408                                     active=act_ctrl)) 
    1406              
     1409 
    14071410    def on_qrange_text(self, event): 
    14081411        """ 
     
    14161419        d_id = self.data.id 
    14171420        d_group_id = self.data.group_id 
    1418         wx.PostEvent(self._manager.parent,  
    1419                      PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
    1420                                      group_id=d_group_id, leftdown=False,  
     1421        wx.PostEvent(self._manager.parent, 
     1422                     PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 
     1423                                     group_id=d_group_id, leftdown=False, 
    14211424                                     active=act_ctrl)) 
    14221425        self._validate_qrange(self.qmin, self.qmax) 
    1423      
    1424     def on_key(self, event):    
     1426 
     1427    def on_key(self, event): 
    14251428        """ 
    14261429        On Key down 
     
    14331436            x_data = float(ctrl.GetValue()) 
    14341437        except: 
    1435             return  
     1438            return 
    14361439        key = event.GetKeyCode() 
    14371440        length = len(self.data.x) 
     
    14501453        ctrl.SetValue(str(self.data.x[indx])) 
    14511454        self._validate_qrange(self.qmin, self.qmax) 
    1452                 
     1455 
    14531456    def _onQrangeEnter(self, event): 
    14541457        """ 
     
    15111514                              (self.data.x <= self.qmax_x)) 
    15121515                self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) 
    1513              
     1516 
    15141517            self.npts_x = self.Npts_total.GetValue() 
    15151518            self.create_default_data() 
     
    15191522            msg = "Model Error:wrong value entered!!!" 
    15201523            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1521          
     1524 
    15221525        self._draw_model() 
    15231526        self.save_current_state() 
     
    15261529        self.state_change = False 
    15271530        return 
    1528      
     1531 
    15291532    def _clear_Err_on_Fit(self): 
    15301533        """ 
     
    15561559                    if item[4] != None and item[4].IsShown(): 
    15571560                        item[4].Hide() 
    1558    
     1561 
    15591562        if len(self.fittable_param) > 0: 
    15601563            for item in self.fittable_param: 
     
    15761579                        item[4].Hide() 
    15771580        return 
    1578                  
     1581 
    15791582    def _get_defult_custom_smear(self): 
    15801583        """ 
     
    15901593        if self.dx_max == None: 
    15911594            self.dx_max = SMEAR_SIZE_H 
    1592          
     1595 
    15931596    def _get_smear_info(self): 
    15941597        """ 
    15951598        Get the smear info from data. 
    1596         
     1599 
    15971600        :return: self.smear_type, self.dq_l and self.dq_r, 
    15981601            respectively the type of the smear, dq_min and 
     
    16251628            self.dq_l = data.dx[0] 
    16261629            self.dq_r = data.dx[-1] 
    1627              
     1630 
    16281631        # check if it is slit smear and get min max if it is. 
    16291632        elif data.dxl != None or data.dxw != None: 
     
    16341637                self.dq_r = data.dxw[0] 
    16351638        #return self.smear_type,self.dq_l,self.dq_r 
    1636      
     1639 
    16371640    def _show_smear_sizer(self): 
    16381641        """ 
     
    16981701        self.smear_description_2d_y.Hide() 
    16991702        self.smear_description_2d.Hide() 
    1700          
     1703 
    17011704        self.smear_accuracy.Hide() 
    17021705        self.smear_data_left.Hide() 
     
    17121715        self.smear_message_new_p.Hide() 
    17131716        self.smear_message_new_s.Hide() 
    1714      
     1717 
    17151718    def _set_accuracy_list(self): 
    17161719        """ 
     
    17221725        for idx in range(len(list)): 
    17231726            self.smear_accuracy.Append(list[idx], idx) 
    1724              
     1727 
    17251728    def _set_fun_box_list(self, fun_box): 
    17261729        """