Changeset ed5beb3 in sasview


Ignore:
Timestamp:
Nov 25, 2015 6:47:02 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:
abcbe09
Parents:
e8e3e38 (diff), 3596467 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

Files:
1 added
6 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    ra93d6b1 rbc873053  
    1515.mplconfig 
    1616 
     17/setup.cfg 
     18 
    1719/dist 
    1820/build 
     
    2123**/test/logs 
    2224*.pyc 
     25*.so 
    2326default_categories.json 
    2427 
     
    3437/docs/sphinx-docs/source/user/perspectives 
    3538 
     39# test outputs 
     40/test/pr_inversion/test/test_output.txt 
     41/test/sasdataloader/test/plugins.zip 
     42/test/sasdataloader/test/test_log.txt 
  • 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 
  • 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

    r2c8dc19 r6f16e25  
    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    # These two buttons have specific IDs since they seem to be created more 
     60    # frequently than they need to.  In particular, set_dispers_sizer() is 
     61    # called by _on_select_model 
     62    ID_BOOKMARK = wx.NewId() 
     63    ID_DISPERSER_HELP = wx.NewId() 
     64    _id_pool = IdList() 
    5965 
    6066    def __init__(self, parent, color='blue', **kwargs): 
     
    6672        #Set window's font size 
    6773        self.SetWindowVariant(variant=FONT_VARIANT) 
    68  
    6974        self.SetBackgroundColour(color) 
     75 
     76        self._ids = iter(self._id_pool) 
    7077        ## parent of the page 
    7178        self.parent = parent 
     
    199206        self.popUpMenu = wx.Menu() 
    200207 
    201         id = wx.NewId() 
    202         self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 
     208        wx_id = self._ids.next() 
     209        self._keep = wx.MenuItem(self.popUpMenu, wx_id, "Add bookmark", 
    203210                                 " Keep the panel status to recall it later") 
    204211        self.popUpMenu.AppendItem(self._keep) 
     
    206213        self._set_bookmark_flag(False) 
    207214        self._set_save_flag(False) 
    208         wx.EVT_MENU(self, id, self.on_bookmark) 
     215        wx.EVT_MENU(self, wx_id, self.on_bookmark) 
    209216        self.popUpMenu.AppendSeparator() 
    210217 
     
    594601        fill sizer containing dispersity info 
    595602        """ 
     603        #print "==== entering set_dispers_sizer ===" 
    596604        self.sizer4.Clear(True) 
    597605        name = "Polydispersity and Orientational Distribution" 
    598         box_description = wx.StaticBox(self, -1, name) 
     606        box_description = wx.StaticBox(self, wx.ID_ANY, name) 
    599607        box_description.SetForegroundColour(wx.BLUE) 
    600608        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    601609        #---------------------------------------------------- 
    602         self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 
     610        self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 
    603611                                           style=wx.RB_GROUP) 
    604         self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 
     612        self.enable_disp = wx.RadioButton(self, wx.ID_ANY, 'On', (10, 30)) 
    605613        # best size for MAC and PC 
    606614        if ON_MAC: 
     
    608616        else: 
    609617            size_q = (20, 15) 
    610         self.disp_help_bt = wx.Button(self, wx.NewId(), '?', 
     618        self.disp_help_bt = wx.Button(self, self.ID_DISPERSER_HELP, '?', 
    611619                                      style=wx.BU_EXACTFIT, 
    612620                                      size=size_q) 
     
    624632        sizer_dispersion.Add((20, 20)) 
    625633        name = ""  # Polydispersity and \nOrientational Distribution " 
    626         sizer_dispersion.Add(wx.StaticText(self, -1, name)) 
     634        sizer_dispersion.Add(wx.StaticText(self, wx.ID_ANY, name)) 
    627635        sizer_dispersion.Add(self.enable_disp) 
    628636        sizer_dispersion.Add((20, 20)) 
     
    795803        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    796804 
    797         id = wx.NewId() 
    798         self.popUpMenu.Append(id, name, str(msg)) 
    799         wx.EVT_MENU(self, id, self.onResetModel) 
     805        self.popUpMenu.Append(self.ID_BOOKMARK, name, str(msg)) 
     806        wx.EVT_MENU(self, self.ID_BOOKMARK, self.onResetModel) 
    800807        wx.PostEvent(self._manager.parent, 
    801808                     AppendBookmarkEvent(title=name, 
     
    14381445        reset the context menu 
    14391446        """ 
     1447        ids = iter(self._id_pool)  # Reusing ids for context menu 
    14401448        for name, _ in self.state.saved_states.iteritems(): 
    14411449            self.number_saved_state += 1 
    14421450            ## Add item in the context menu 
    1443             id = wx.NewId() 
     1451            wx_id = ids.next() 
    14441452            msg = 'Save model and state %g' % self.number_saved_state 
    1445             self.popUpMenu.Append(id, name, msg) 
    1446             wx.EVT_MENU(self, id, self.onResetModel) 
     1453            self.popUpMenu.Append(wx_id, name, msg) 
     1454            wx.EVT_MENU(self, wx_id, self.onResetModel) 
    14471455 
    14481456    def _reset_plotting_range(self, state): 
     
    18311839        sld_data.name = 'SLD' 
    18321840        sld_data.axes = self.sld_axes 
    1833         self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= -1) 
     1841        self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, 
     1842                              id=wx.ID_ANY) 
    18341843        self.panel.ShowModal() 
    18351844 
     
    24212430        self.sizer4_4.Clear(True) 
    24222431        text = "No polydispersity available for this model" 
    2423         model_disp = wx.StaticText(self, -1, text) 
     2432        model_disp = wx.StaticText(self, wx.ID_ANY, text) 
    24242433        self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 
    24252434                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     
    28512860            name = self.formfactorbox.GetValue() 
    28522861            _PageAnchor = '#' + name.lower() 
    2853             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2862            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    28542863                                              _PageAnchor, name + " Help") 
    28552864        else: 
    2856             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
    2857                                                 "General Model Help") 
     2865            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
     2866                                              "", "General Model Help") 
    28582867 
    28592868 
     
    29062915 
    29072916        _TreeLocation = "_images/M_angles_pic.bmp" 
    2908         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2917        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29092918                                          "Magnetic Angle Defintions") 
    29102919 
     
    29262935 
    29272936        _TreeLocation = "user/perspectives/fitting/mag_help.html" 
    2928         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2937        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29292938                                          "Polarized Beam/Magnetc Help") 
    29302939 
     
    29732982        _TreeLocation = "user/perspectives/fitting/pd_help.html" 
    29742983        _PageAnchor = "" 
    2975         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2984        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    29762985                                          _PageAnchor, "Polydispersity Help") 
    29772986 
     
    35173526        fill sizer containing model info 
    35183527        """ 
     3528        # This should only be called once per fit tab 
     3529        #print "==== Entering _fill_model_sizer" 
    35193530        ##Add model function Details button in fitpanel. 
    35203531        ##The following 3 lines are for Mac. Let JHC know before modifying... 
     
    35223533        self.formfactorbox = None 
    35233534        self.multifactorbox = None 
    3524         self.mbox_description = wx.StaticBox(self, -1, str(title)) 
     3535        self.mbox_description = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    35253536        boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) 
    35263537        sizer_cat = wx.BoxSizer(wx.HORIZONTAL) 
    35273538        self.mbox_description.SetForegroundColour(wx.RED) 
    3528         id = wx.NewId() 
    3529         self.model_func = wx.Button(self, id, 'Help', size=(80, 23)) 
    3530         self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, id=id) 
     3539        wx_id = self._ids.next() 
     3540        self.model_func = wx.Button(self, wx_id, 'Help', size=(80, 23)) 
     3541        self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, 
     3542                             id=wx_id) 
    35313543        self.model_func.SetToolTipString("Full Model Function Help") 
    3532         id = wx.NewId() 
    3533         self.model_help = wx.Button(self, id, 'Description', size=(80, 23)) 
    3534         self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, id=id) 
     3544        wx_id = self._ids.next() 
     3545        self.model_help = wx.Button(self, wx_id, 'Description', size=(80, 23)) 
     3546        self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, 
     3547                             id=wx_id) 
    35353548        self.model_help.SetToolTipString("Short Model Function Description") 
    3536         id = wx.NewId() 
    3537         self.model_view = wx.Button(self, id, "Show 2D", size=(80, 23)) 
    3538         self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) 
     3549        wx_id = self._ids.next() 
     3550        self.model_view = wx.Button(self, wx_id, "Show 2D", size=(80, 23)) 
     3551        self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=wx_id) 
    35393552        hint = "toggle view of model from 1D to 2D  or 2D to 1D" 
    35403553        self.model_view.SetToolTipString(hint) 
    35413554 
    3542         cat_set_box = wx.StaticBox(self, -1, 'Category') 
     3555        cat_set_box = wx.StaticBox(self, wx.ID_ANY, 'Category') 
    35433556        sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 
    35443557        sizer_cat_box.SetMinSize((200, 50)) 
    3545         self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3558        self.categorybox = wx.ComboBox(self, wx.ID_ANY, 
     3559                                       style=wx.CB_READONLY) 
    35463560        self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 
    35473561        self._populate_listbox() 
    3548         wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) 
    3549         #self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', 
     3562        wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 
     3563        #self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 
    35503564        #                                     style=wx.RB_GROUP) 
    3551         #self.shape_indep_rbutton = wx.RadioButton(self, -1, 
     3565        #self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 
    35523566        #                                          "Shape-Independent") 
    3553         #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 
    3554         #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 
     3567        #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3568        #                                     "Structure Factor ") 
     3569        #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3570        #                                     "Uncategorized") 
    35553571 
    35563572        #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     
    35643580        #MAC needs SetValue 
    35653581 
    3566         show_cat_button = wx.Button(self, -1, "Modify") 
     3582        show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 
    35673583        cat_tip = "Modify model categories \n" 
    35683584        cat_tip += "(also accessible from the menu bar)." 
     
    35903606        mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 
    35913607 
    3592         self.text1 = wx.StaticText(self, -1, "") 
    3593         self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 
    3594         self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") 
    3595         self.mutifactor_text1 = wx.StaticText(self, -1, "") 
    3596         self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") 
     3608        self.text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3609        self.text2 = wx.StaticText(self, wx.ID_ANY, "P(Q)*S(Q)") 
     3610        self.mutifactor_text = wx.StaticText(self, wx.ID_ANY, "No. of Shells: ") 
     3611        self.mutifactor_text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3612        self.show_sld_button = wx.Button(self, wx.ID_ANY, "Show SLD Profile") 
    35973613        self.show_sld_button.Bind(wx.EVT_BUTTON, self._on_show_sld) 
    35983614 
    3599         self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3615        self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    36003616        self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 
    36013617        if self.model != None: 
    36023618            self.formfactorbox.SetValue(self.model.name) 
    3603         self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3604         self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3619        self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     3620        self.multifactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    36053621        self.initialize_combox() 
    3606         wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) 
    3607  
    3608         wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) 
    3609         wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) 
     3622        wx.EVT_COMBOBOX(self.formfactorbox, wx.ID_ANY, self._on_select_model) 
     3623 
     3624        wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 
     3625        wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 
    36103626        ## check model type to show sizer 
    36113627        if self.model != None: 
  • 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

    r225aca8 r6f16e25  
    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)) 
     
    221222 
    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)) 
    234236 
    235         weighting_set_box = wx.StaticBox(self, -1, \ 
     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()) 
     
    269271 
    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.") 
    278280 
    279         wx.EVT_COMBOBOX(self.smear_accuracy, -1, self._on_select_accuracy) 
     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()) 
     
    286289 
    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, 
     328        self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 
    326329                                          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, 
     331        self.smear_data_right = BGTextCtrl(self, wx.ID_ANY, 
    329332                                           size=(_BOX_WIDTH - 25, 20), style=0) 
    330333        self.smear_data_right.SetValue(str(self.dq_r)) 
     
    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.") 
     
    368370 
    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        self.Npts_total = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    377378                            style=wx.TE_PROCESS_ENTER, 
    378379                            text_enter_callback=self._onQrangeEnter) 
     
    382383 
    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.") 
    388389 
    389390        self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    390         self.pointsbox = wx.CheckBox(self, -1, 'Log?', (10, 10)) 
     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) 
    394395 
    395         self.points_sizer.Add(wx.StaticText(self, -1, 'Npts    ')) 
     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) 
    436437 
     
    519520        self.sizer5.Clear(True) 
    520521 
    521         self.qmin = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     522        self.qmin = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    522523                                  style=wx.TE_PROCESS_ENTER, 
    523524                                  set_focus_callback=self.qrang_set_focus, 
     
    530531        self.qmin.SetToolTipString(qmin_tip) 
    531532 
    532         self.qmax = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     533        self.qmax = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    533534                                  style=wx.TE_PROCESS_ENTER, 
    534535                                  set_focus_callback=self.qrang_set_focus, 
     
    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') 
    549550 
     
    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)) 
     
    618619 
    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() 
    622623        import sas.models.dispersion_models 
     
    625626        ix = 0 
    626627        iy = 0 
    627         disp = wx.StaticText(self, -1, ' ') 
     628        disp = wx.StaticText(self, wx.ID_ANY, ' ') 
    628629        self.sizer4_4.Add(disp, (iy, ix), (1, 1), 
    629630                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    630631        ix += 1 
    631         values = wx.StaticText(self, -1, 'PD[ratio]') 
     632        values = wx.StaticText(self, wx.ID_ANY, 'PD[ratio]') 
    632633        polytext = "Polydispersity (= STD/mean); " 
    633634        polytext += "the standard deviation over the mean value." 
     
    641642        else: 
    642643            err_text = '' 
    643         self.text_disp_1 = wx.StaticText(self, -1, err_text) 
     644        self.text_disp_1 = wx.StaticText(self, wx.ID_ANY, err_text) 
    644645        self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \ 
    645646                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    646647 
    647648        ix += 1 
    648         self.text_disp_min = wx.StaticText(self, -1, 'Min') 
     649        self.text_disp_min = wx.StaticText(self, wx.ID_ANY, 'Min') 
    649650        self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), \ 
    650651                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    651652 
    652653        ix += 1 
    653         self.text_disp_max = wx.StaticText(self, -1, 'Max') 
     654        self.text_disp_max = wx.StaticText(self, wx.ID_ANY, 'Max') 
    654655        self.sizer4_4.Add(self.text_disp_max, (iy, ix), (1, 1), 
    655656                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    656657 
    657658        ix += 1 
    658         npts = wx.StaticText(self, -1, 'Npts') 
     659        npts = wx.StaticText(self, wx.ID_ANY, 'Npts') 
    659660        npts.SetToolTipString("Number of sampling points for the numerical\n\ 
    660661        integration over the distribution function.") 
     
    662663                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    663664        ix += 1 
    664         nsigmas = wx.StaticText(self, -1, 'Nsigs') 
     665        nsigmas = wx.StaticText(self, wx.ID_ANY, 'Nsigs') 
    665666        nsigmas.SetToolTipString("Number of sigmas between which the range\n\ 
    666667         of the distribution function will be used for weighting. \n\ 
     
    695696                    if p == "width": 
    696697                        ix = 0 
    697                         cb = wx.CheckBox(self, -1, name0, (10, 10)) 
     698                        cb = wx.CheckBox(self, wx.ID_ANY, name0, (10, 10)) 
    698699                        cb.SetValue(CHECK_STATE) 
    699700                        cb.SetToolTipString("Check mark to fit") 
     
    703704                        ix = 1 
    704705                        value = self.model.getParam(name1) 
    705                         ctl1 = ModelTextCtrl(self, -1, 
     706                        ctl1 = ModelTextCtrl(self, wx.ID_ANY, 
    706707                                             size=(_BOX_WIDTH / 1.3, 20), 
    707708                                             style=wx.TE_PROCESS_ENTER) 
     
    715716                        ## text to show error sign 
    716717                        ix = 2 
    717                         text2 = wx.StaticText(self, -1, '+/-') 
     718                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    718719                        self.sizer4_4.Add(text2, (iy, ix), (1, 1), 
    719720                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    722723 
    723724                        ix = 3 
    724                         ctl2 = wx.TextCtrl(self, -1, 
     725                        ctl2 = wx.TextCtrl(self, wx.ID_ANY, 
    725726                                           size=(_BOX_WIDTH / 1.3, 20), 
    726727                                           style=0) 
     
    732733 
    733734                        ix = 4 
    734                         ctl3 = ModelTextCtrl(self, -1, 
     735                        ctl3 = ModelTextCtrl(self, wx.ID_ANY, 
    735736                                             size=(_BOX_WIDTH / 2, 20), 
    736737                                             style=wx.TE_PROCESS_ENTER, 
     
    741742 
    742743                        ix = 5 
    743                         ctl4 = ModelTextCtrl(self, -1, 
     744                        ctl4 = ModelTextCtrl(self, wx.ID_ANY, 
    744745                                             size=(_BOX_WIDTH / 2, 20), 
    745746                                             style=wx.TE_PROCESS_ENTER, 
     
    755756                        ix = 6 
    756757                        value = self.model.getParam(name2) 
    757                         Tctl = ModelTextCtrl(self, -1, 
     758                        Tctl = ModelTextCtrl(self, wx.ID_ANY, 
    758759                                             size=(_BOX_WIDTH / 2.2, 20), 
    759760                                             style=wx.TE_PROCESS_ENTER) 
     
    767768                        ix = 7 
    768769                        value = self.model.getParam(name3) 
    769                         Tct2 = ModelTextCtrl(self, -1, 
     770                        Tct2 = ModelTextCtrl(self, wx.ID_ANY, 
    770771                                             size=(_BOX_WIDTH / 2.2, 20), 
    771772                                             style=wx.TE_PROCESS_ENTER) 
     
    779780 
    780781                ix = 8 
    781                 disp_box = wx.ComboBox(self, -1, size=(65, -1), 
     782                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    782783                                       style=wx.CB_READONLY, name='%s' % name1) 
    783784                for key, value in self.polydisp.iteritems(): 
     
    785786                    disp_box.Append(name_disp, value) 
    786787                    disp_box.SetStringSelection("gaussian") 
    787                 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func) 
     788                wx.EVT_COMBOBOX(disp_box, wx.ID_ANY, self._on_disp_func) 
    788789                self.sizer4_4.Add(disp_box, (iy, ix), (1, 1), wx.EXPAND) 
    789790                self.fittable_param.append([cb, name1, ctl1, text2, 
     
    815816                    if p == "width": 
    816817                        ix = 0 
    817                         cb = wx.CheckBox(self, -1, name0, (10, 10)) 
     818                        cb = wx.CheckBox(self, wx.ID_ANY, name0, (10, 10)) 
    818819                        cb.SetValue(CHECK_STATE) 
    819820                        cb.SetToolTipString("Check mark to fit") 
     
    828829                        ix = 1 
    829830                        value = self.model.getParam(name1) 
    830                         ctl1 = ModelTextCtrl(self, -1, 
     831                        ctl1 = ModelTextCtrl(self, wx.ID_ANY, 
    831832                                             size=(_BOX_WIDTH / 1.3, 20), 
    832833                                             style=wx.TE_PROCESS_ENTER) 
     
    854855                        ## text to show error sign 
    855856                        ix = 2 
    856                         text2 = wx.StaticText(self, -1, '+/-') 
     857                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    857858                        self.sizer4_4.Add(text2, (iy, ix), (1, 1), 
    858859                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    861862 
    862863                        ix = 3 
    863                         ctl2 = wx.TextCtrl(self, -1, 
     864                        ctl2 = wx.TextCtrl(self, wx.ID_ANY, 
    864865                                           size=(_BOX_WIDTH / 1.3, 20), 
    865866                                           style=0) 
     
    876877 
    877878                        ix = 4 
    878                         ctl3 = ModelTextCtrl(self, -1, 
     879                        ctl3 = ModelTextCtrl(self, wx.ID_ANY, 
    879880                                             size=(_BOX_WIDTH / 2, 20), 
    880881                                             style=wx.TE_PROCESS_ENTER, 
     
    887888 
    888889                        ix = 5 
    889                         ctl4 = ModelTextCtrl(self, -1, 
     890                        ctl4 = ModelTextCtrl(self, wx.ID_ANY, 
    890891                                             size=(_BOX_WIDTH / 2, 20), 
    891892                                             style=wx.TE_PROCESS_ENTER, 
     
    903904                        ix = 6 
    904905                        value = self.model.getParam(name2) 
    905                         Tctl = ModelTextCtrl(self, -1, 
     906                        Tctl = ModelTextCtrl(self, wx.ID_ANY, 
    906907                                             size=(_BOX_WIDTH / 2.2, 20), 
    907908                                             style=wx.TE_PROCESS_ENTER) 
     
    923924                        ix = 7 
    924925                        value = self.model.getParam(name3) 
    925                         Tct2 = ModelTextCtrl(self, -1, 
     926                        Tct2 = ModelTextCtrl(self, wx.ID_ANY, 
    926927                                             size=(_BOX_WIDTH / 2.2, 20), 
    927928                                             style=wx.TE_PROCESS_ENTER) 
     
    943944 
    944945                ix = 8 
    945                 disp_box = wx.ComboBox(self, -1, size=(65, -1), 
     946                disp_box = wx.ComboBox(self, wx.ID_ANY, size=(65, -1), 
    946947                                style=wx.CB_READONLY, name='%s' % name1) 
    947948                for key, value in self.polydisp.iteritems(): 
     
    949950                    disp_box.Append(name_disp, value) 
    950951                    disp_box.SetStringSelection("gaussian") 
    951                 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func) 
     952                wx.EVT_COMBOBOX(disp_box, wx.ID_ANY, self._on_disp_func) 
    952953                self.sizer4_4.Add(disp_box, (iy, ix), (1, 1), wx.EXPAND) 
    953954                self.fittable_param.append([cb, name1, ctl1, text2, 
     
    10791080 
    10801081        _TreeLocation = "user/perspectives/fitting/fitting_help.html" 
    1081         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     1082        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    10821083                                          "General Fitting Help") 
    10831084 
     
    10981099 
    10991100        _TreeLocation = "user/perspectives/fitting/sm_help.html" 
    1100         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     1101        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    11011102                                          "Instrumental Resolution Smearing \ 
    11021103                                          Help") 
     
    11821183            self._keep.Enable(False) 
    11831184            self._set_save_flag(False) 
     1185        # TODO: why do we have to variables for one flag?? 
    11841186        self.enable_disp.SetValue(False) 
    11851187        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 
    11861191        try: 
    11871192            self.set_dispers_sizer() 
     
    28312836            return 
    28322837 
    2833         box_description = wx.StaticBox(self, -1, str("Model Parameters")) 
     2838        box_description = wx.StaticBox(self, wx.ID_ANY, str("Model Parameters")) 
    28342839        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    28352840        sizer = wx.GridBagSizer(5, 5) 
     
    28982903        ix = 0 
    28992904        select_text = "Select All" 
    2900         self.cb1 = wx.CheckBox(self, -1, str(select_text), (10, 10)) 
     2905        self.cb1 = wx.CheckBox(self, wx.ID_ANY, str(select_text), (10, 10)) 
    29012906        wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 
    29022907        self.cb1.SetToolTipString("To check/uncheck all the boxes below.") 
     
    29062911                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    29072912        ix += 1 
    2908         self.text2_2 = wx.StaticText(self, -1, 'Value') 
     2913        self.text2_2 = wx.StaticText(self, wx.ID_ANY, 'Value') 
    29092914        sizer.Add(self.text2_2, (iy, ix), (1, 1), \ 
    29102915                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    29112916        ix += 2 
    2912         self.text2_3 = wx.StaticText(self, -1, 'Error') 
     2917        self.text2_3 = wx.StaticText(self, wx.ID_ANY, 'Error') 
    29132918        sizer.Add(self.text2_3, (iy, ix), (1, 1), \ 
    29142919                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    29162921            self.text2_3.Hide() 
    29172922        ix += 1 
    2918         self.text2_min = wx.StaticText(self, -1, 'Min') 
     2923        self.text2_min = wx.StaticText(self, wx.ID_ANY, 'Min') 
    29192924        sizer.Add(self.text2_min, (iy, ix), (1, 1), \ 
    29202925                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    29212926        #self.text2_min.Hide() 
    29222927        ix += 1 
    2923         self.text2_max = wx.StaticText(self, -1, 'Max') 
     2928        self.text2_max = wx.StaticText(self, wx.ID_ANY, 'Max') 
    29242929        sizer.Add(self.text2_max, (iy, ix), (1, 1), \ 
    29252930                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    29262931        #self.text2_max.Hide() 
    29272932        ix += 1 
    2928         self.text2_4 = wx.StaticText(self, -1, '[Units]') 
     2933        self.text2_4 = wx.StaticText(self, wx.ID_ANY, '[Units]') 
    29292934        sizer.Add(self.text2_4, (iy, ix), (1, 1), \ 
    29302935                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    29472952                    self.temp_multi_functional)\ 
    29482953                    and (item in self.model.non_fittable): 
    2949                     non_fittable_name = wx.StaticText(self, -1, item) 
     2954                    non_fittable_name = wx.StaticText(self, wx.ID_ANY, item) 
    29502955                    sizer.Add(non_fittable_name, (iy, ix), (1, 1), \ 
    29512956                            wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) 
     
    29552960                    if len(self.model.fun_list) > 0: 
    29562961                        #num = item.split('_')[1][5:7] 
    2957                         fun_box = wx.ComboBox(self, -1, size=(100, -1), 
     2962                        fun_box = wx.ComboBox(self, wx.ID_ANY, size=(100, -1), 
    29582963                                    style=wx.CB_READONLY, name='%s' % item) 
    29592964                        self._set_fun_box_list(fun_box) 
     
    29612966                        #self.fun_box.SetToolTipString("A function 
    29622967                        #    describing the interface") 
    2963                         wx.EVT_COMBOBOX(fun_box, -1, self._on_fun_box) 
     2968                        wx.EVT_COMBOBOX(fun_box, wx.ID_ANY, self._on_fun_box) 
    29642969                    else: 
    2965                         fun_box = ModelTextCtrl(self, -1, 
     2970                        fun_box = ModelTextCtrl(self, wx.ID_ANY, 
    29662971                                                size=(_BOX_WIDTH, 20), 
    29672972                                style=wx.TE_PROCESS_ENTER, name='%s' % item) 
     
    29752980                else: 
    29762981                    ## add parameters name with checkbox for selecting to fit 
    2977                     cb = wx.CheckBox(self, -1, item) 
     2982                    cb = wx.CheckBox(self, wx.ID_ANY, item) 
    29782983                    cb.SetValue(CHECK_STATE) 
    29792984                    cb.SetToolTipString(" Check mark to fit.") 
     
    29872992                    ix += 1 
    29882993                    value = self.model.getParam(item) 
    2989                     ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
     2994                    ctl1 = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    29902995                                         style=wx.TE_PROCESS_ENTER) 
    29912996                    ctl1.SetToolTipString(\ 
     
    29953000                    ## text to show error sign 
    29963001                    ix += 1 
    2997                     text2 = wx.StaticText(self, -1, '+/-') 
     3002                    text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    29983003                    sizer.Add(text2, (iy, ix), (1, 1), \ 
    29993004                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    30013006                        text2.Hide() 
    30023007                    ix += 1 
    3003                     ctl2 = wx.TextCtrl(self, -1, 
     3008                    ctl2 = wx.TextCtrl(self, wx.ID_ANY, 
    30043009                                       size=(_BOX_WIDTH / 1.2, 20), style=0) 
    30053010                    sizer.Add(ctl2, (iy, ix), (1, 1), 
     
    30093014 
    30103015                    ix += 1 
    3011                     ctl3 = ModelTextCtrl(self, -1, 
     3016                    ctl3 = ModelTextCtrl(self, wx.ID_ANY, 
    30123017                                         size=(_BOX_WIDTH / 1.9, 20), 
    30133018                                         style=wx.TE_PROCESS_ENTER, 
     
    30213026 
    30223027                    ix += 1 
    3023                     ctl4 = ModelTextCtrl(self, -1, 
     3028                    ctl4 = ModelTextCtrl(self, wx.ID_ANY, 
    30243029                                         size=(_BOX_WIDTH / 1.9, 20), 
    30253030                                         style=wx.TE_PROCESS_ENTER, 
     
    30343039                    # Units 
    30353040                    if item in self.model.details: 
    3036                         units = wx.StaticText(self, -1, 
     3041                        units = wx.StaticText(self, wx.ID_ANY, 
    30373042                            self.model.details[item][0], style=wx.ALIGN_LEFT) 
    30383043                    else: 
    3039                         units = wx.StaticText(self, -1, "", 
     3044                        units = wx.StaticText(self, wx.ID_ANY, "", 
    30403045                                              style=wx.ALIGN_LEFT) 
    30413046                    sizer.Add(units, (iy, ix), (1, 1), 
     
    30603065        for item in keys: 
    30613066            if item in self.model.orientation_params: 
    3062                 orient_angle = wx.StaticText(self, -1, '[For 2D only]:') 
    3063                 mag_on_button = wx.Button(self, -1, "Magnetic ON") 
     3067                orient_angle = wx.StaticText(self, wx.ID_ANY, '[For 2D only]:') 
     3068                mag_on_button = wx.Button(self, wx.ID_ANY, "Magnetic ON") 
    30643069                mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 
    30653070                mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) 
    3066                 mag_angle_help_button = wx.Button(self, -1, "Magnetic angles?") 
     3071                mag_angle_help_button = wx.Button(self, wx.ID_ANY, "Magnetic angles?") 
    30673072                mag_angle_help_button.SetToolTipString("see angle definitions") 
    3068                 mag_help_button = wx.Button(self, -1, "Mag HELP") 
     3073                mag_help_button = wx.Button(self, wx.ID_ANY, "Mag HELP") 
    30693074                mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 
    30703075                mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) 
     
    31243129                    ix = 0 
    31253130                    ## add parameters name with checkbox for selecting to fit 
    3126                     cb = wx.CheckBox(self, -1, item) 
     3131                    cb = wx.CheckBox(self, wx.ID_ANY, item) 
    31273132                    cb.SetValue(CHECK_STATE) 
    31283133                    cb.SetToolTipString("Check mark to fit") 
  • src/sas/perspectives/fitting/fitpanel.py

    rac7be54 r6f16e25  
    3636        """ 
    3737        """ 
    38         nb.__init__(self, parent, -1, 
     38        nb.__init__(self, parent, wx.ID_ANY, 
    3939                    style=wx.aui.AUI_NB_WINDOWLIST_BUTTON | 
    4040                    wx.aui.AUI_NB_DEFAULT_STYLE | 
     
    324324        if caption == "Const & Simul Fit": 
    325325            self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, 
    326                                                  id= -1, batch_on=False) 
     326                                                 id= wx.ID_ANY, batch_on=False) 
    327327            self.sim_page.window_caption = caption 
    328328            self.sim_page.window_name = caption 
  • src/sas/perspectives/fitting/fitting.py

    r7945367 r6f16e25  
    277277        model_list = model_manager.get_model_name_list() 
    278278        plug_dir = models.find_plugins_dir() 
    279         textdial = TextDialog(None, self, -1, 'Easy Sum/Multi(p1, p2) Editor', 
     279        textdial = TextDialog(None, self, wx.ID_ANY, 'Easy Sum/Multi(p1, p2) Editor', 
    280280                              model_list, plug_dir) 
    281281        self.put_icon(textdial) 
     
    760760        _TreeLocation = "user/perspectives/fitting/optimizer.html" 
    761761        _anchor = "#fit-"+algorithm_id 
    762         DocumentationWindow(self.parent, -1, _TreeLocation, _anchor, "Optimizer Help") 
     762        DocumentationWindow(self.parent, wx.ID_ANY, _TreeLocation, _anchor, "Optimizer Help") 
    763763 
    764764 
  • src/sas/perspectives/fitting/fitting_widgets.py

    r2f4b430 r6f16e25  
    4141        """ 
    4242        vbox = wx.BoxSizer(wx.VERTICAL) 
    43         box_description = wx.StaticBox(self, -1, str("Hint")) 
     43        box_description = wx.StaticBox(self, wx.ID_ANY, str("Hint")) 
    4444        hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    4545        selection_sizer = wx.GridBagSizer(5, 5) 
    4646        button_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    47         self.data_1d_selected = wx.RadioButton(self, -1, 'Data1D', 
     47        self.data_1d_selected = wx.RadioButton(self, wx.ID_ANY, 'Data1D', 
    4848                                                style=wx.RB_GROUP) 
    49         self.data_2d_selected = wx.RadioButton(self, -1, 'Data2D') 
     49        self.data_2d_selected = wx.RadioButton(self, wx.ID_ANY, 'Data2D') 
    5050        self.data_1d_selected.SetValue(True) 
    5151        self.data_2d_selected.SetValue(False) 
     
    5555        hint = "Selected Data set contains both 1D and 2D Data.\n" 
    5656        hint += "Please select on type of analysis before proceeding.\n" 
    57         hint_sizer.Add(wx.StaticText(self, -1, hint)) 
     57        hint_sizer.Add(wx.StaticText(self, wx.ID_ANY, hint)) 
    5858        #draw area containing radio buttons 
    5959        ix = 0 
     
    7272        vbox.Add(hint_sizer, 0, wx.EXPAND | wx.ALL, 10) 
    7373        vbox.Add(selection_sizer, 0, wx.TOP | wx.BOTTOM, 10) 
    74         vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 
     74        vbox.Add(wx.StaticLine(self, wx.ID_ANY), 0, wx.EXPAND, 0) 
    7575        vbox.Add(button_sizer, 0, wx.TOP | wx.BOTTOM, 10) 
    7676        self.SetSizer(vbox) 
     
    103103            return 
    104104        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data) 
    105         self._data_text_ctrl = wx.StaticText(self, -1, str(select_data_text)) 
     105        self._data_text_ctrl = wx.StaticText(self, wx.ID_ANY, str(select_data_text)) 
    106106 
    107107        self._data_text_ctrl.SetForegroundColour('blue') 
     
    126126            text += "for adequate plot display size. \n" 
    127127            text += "unchecked data won't be send to fitting . \n" 
    128         text_ctrl = wx.StaticText(self, -1, str(text)) 
     128        text_ctrl = wx.StaticText(self, wx.ID_ANY, str(text)) 
    129129        self._sizer_txt.Add(text_ctrl) 
    130130        iy = 0 
     
    133133        for i in range(len(data_list)): 
    134134            data_count += 1 
    135             cb = wx.CheckBox(self._panel, -1, str(data_list[i].name), (10, 10)) 
     135            cb = wx.CheckBox(self._panel, wx.ID_ANY, str(data_list[i].name), (10, 10)) 
    136136            wx.EVT_CHECKBOX(self, cb.GetId(), self._count_selected_data) 
    137137            if data_count <= MAX_NBR_DATA: 
     
    153153        self._sizer_button.Add(button_OK, 0, 
    154154                                wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
    155         static_line = wx.StaticLine(self, -1) 
     155        static_line = wx.StaticLine(self, wx.ID_ANY) 
    156156        self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 10) 
    157157        self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 10) 
  • src/sas/perspectives/fitting/hint_fitpage.py

    r2f4b430 r6f16e25  
    2727        """ 
    2828        name = "Hint" 
    29         box_description = wx.StaticBox(self, -1, name) 
     29        box_description = wx.StaticBox(self, wx.ID_ANY, name) 
    3030        boxsizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    3131        msg = "    How to link data to the control panel: \n \n" 
     
    3333        msg += "    Then Highlight and right click on the data plot. \n" 
    3434        msg += "    Finally, select 'Select data for fitting' in the pop-up menu. \n" 
    35         self.hint_txt = wx.StaticText(self, -1, msg, style=wx.ALIGN_LEFT) 
     35        self.hint_txt = wx.StaticText(self, wx.ID_ANY, msg, style=wx.ALIGN_LEFT) 
    3636        boxsizer.Add(self.hint_txt, wx.ALL | wx.EXPAND, 20) 
    3737        self.vbox = wx.BoxSizer(wx.VERTICAL) 
  • src/sas/perspectives/fitting/pagestate.py

    r0e33a8d r6f16e25  
    605605        images = self.set_plot_state(figs, canvases) 
    606606        report_list = [report_str, text_str, images] 
    607         dialog = ReportDialog(report_list, None, -1, "") 
     607        dialog = ReportDialog(report_list, None, wx.ID_ANY, "") 
    608608        dialog.Show() 
    609609 
  • src/sas/perspectives/fitting/resultpanel.py

    r9df6a03 r6f16e25  
    4141                 | wx.CLIP_CHILDREN) 
    4242                 & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 
    43         Notebook.__init__(self, parent, -1, style=style) 
     43        Notebook.__init__(self, parent, wx.ID_ANY, style=style) 
    4444        PanelBase.__init__(self, parent) 
    4545        self.frame = parent 
  • src/sas/perspectives/fitting/simfitpage.py

    racf8e4a5 r662d8d87  
    22    Simultaneous fit page 
    33""" 
    4 import sys, re, string, wx 
     4import sys 
     5from collections import namedtuple 
     6 
     7import wx 
    58import wx.lib.newevent 
     9from wx.lib.scrolledpanel import ScrolledPanel 
     10 
    611from sas.guiframe.events import StatusEvent 
    712from sas.guiframe.panel_base import PanelBase 
    8 from wx.lib.scrolledpanel import ScrolledPanel 
    913from sas.guiframe.events import PanelOnFocusEvent 
     14from sas.guiframe.utils import IdList 
     15from sas.guiframe.documentation_window import DocumentationWindow 
     16 
    1017#Control panel width  
    1118if sys.platform.count("darwin") == 0: 
     
    1724 
    1825 
     26# Each constraint requires five widgets and sizer.  Package them in 
     27# a named tuple for easy access. 
     28ConstraintLine = namedtuple('ConstraintLine', 
     29        'model_cbox param_cbox egal_txt constraint btRemove sizer') 
     30 
    1931def get_fittableParam(model): 
    2032    """ 
    21     return list of fittable parameters name of a model 
     33    return list of fittable parameters from a model 
    2234 
    2335    :param model: the model used 
     
    3446 
    3547    return fittable_param 
    36  
    3748 
    3849class SimultaneousFitPage(ScrolledPanel, PanelBase): 
     
    4657    ## Title to appear on top of the window 
    4758    window_caption = "Simultaneous Fit Page" 
    48  
    49     def __init__(self, parent, page_finder={}, id= -1, batch_on=False, 
    50                      *args, **kwargs): 
     59    ID_DOC = wx.NewId() 
     60    ID_SET_ALL = wx.NewId() 
     61    ID_FIT = wx.NewId() 
     62    ID_ADD = wx.NewId() 
     63    _id_pool = IdList() 
     64 
     65    def __init__(self, parent, page_finder={}, id=wx.ID_ANY, batch_on=False, 
     66                 *args, **kwargs): 
    5167        ScrolledPanel.__init__(self, parent, id=id, 
    5268                               style=wx.FULL_REPAINT_ON_RESIZE, 
     
    5672        Simultaneous page display 
    5773        """ 
     74        self._ids = iter(self._id_pool) 
    5875        self.SetupScrolling() 
    5976        ##Font size 
     
    6481        ## store page_finder 
    6582        self.page_finder = page_finder 
    66         ## list contaning info to set constraint 
     83        ## list containing info to set constraint 
    6784        ## look like self.constraint_dict[page_id]= page 
    6885        self.constraint_dict = {} 
    6986        ## item list 
    70         # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
     87        ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
    7188        self.constraints_list = [] 
    7289        ## list of current model 
     
    7895        self.model_cbox_left = None 
    7996        self.model_cbox_right = None 
    80         self.uid = wx.NewId() 
    8197        ## draw page 
    8298        self.define_page_structure() 
    8399        self.draw_page() 
    84         self.set_layout() 
    85100        self._set_save_flag(False) 
    86101 
    87102    def define_page_structure(self): 
    88103        """ 
    89         Create empty sizer for a panel 
     104        Create empty sizers, their hierarchy and set the sizer for the panel 
    90105        """ 
    91106        self.vbox = wx.BoxSizer(wx.VERTICAL) 
     
    100115        self.vbox.Add(self.sizer2) 
    101116        self.vbox.Add(self.sizer3) 
    102  
    103     def set_scroll(self): 
    104         """ 
    105         """ 
    106         self.Layout() 
    107  
    108     def set_layout(self): 
    109         """ 
    110         layout 
    111         """ 
    112         self.vbox.Layout() 
    113         self.vbox.Fit(self) 
    114117        self.SetSizer(self.vbox) 
    115         self.set_scroll() 
    116118        self.Centre() 
     119 
     120    def draw_page(self): 
     121        """ 
     122        Construct the Simultaneous/Constrained fit page. fills the first 
     123        region (sizer1) with the list of available fit page pairs of data  
     124        and models.  Then fills sizer2 with the checkbox for adding 
     125        constraints, and finally fills sizer3 with the fit button and 
     126        instructions. 
     127        """ 
     128 
     129        # create blank list of constraints 
     130        self.model_list = [] 
     131        self.model_toFit = [] 
     132        self.constraints_list = [] 
     133        self.constraint_dict = {} 
     134        self.nb_constraint = 0 
     135        self.model_cbox_left = None 
     136        self.model_cbox_right = None 
     137 
     138        if len(self.model_list) > 0: 
     139            for item in self.model_list: 
     140                item[0].SetValue(False) 
     141                self.manager.schedule_for_fit(value=0, uid=item[2]) 
     142 
     143        #------------------------------------------------------- 
     144        ## setup sizer1 (which fitpages to include) 
     145        self.sizer1.Clear(True) 
     146        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 
     147        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     148        sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
     149        sizer_couples = wx.GridBagSizer(5, 5) 
     150 
     151        #This if statement should be obsolete and can be removed in version 4 
     152        #Leave it here for now as no time to thoroughly test.  However if no 
     153        #fit page is found the menu item that calls this page is inactive  
     154        # Nov. 22 2015  --PDB 
     155        if len(self.page_finder) == 0: 
     156            msg = " No fit combinations are found! \n\n" 
     157            msg += " Please load data and set up " 
     158            msg += "at least one fit panels first..." 
     159            sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 
     160        else: 
     161            ## store model 
     162            self._store_model() 
     163 
     164            self.cb1 = wx.CheckBox(self, wx.ID_ANY, 'Select all') 
     165            self.cb1.SetValue(False) 
     166            wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) 
     167 
     168            sizer_title.Add((10, 10), 0, 
     169                wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
     170            sizer_title.Add(self.cb1, 0, 
     171                wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
     172 
     173            ## draw list of model and data names 
     174            self._fill_sizer_model_list(sizer_couples) 
     175 
     176        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 
     177        boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 
     178        self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
     179#        self.sizer1.Layout() 
     180 
     181        #-------------------------------------------------------- 
     182        ## set up the other 2 sizers: the constraints list and the 
     183        ## buttons (fit, help etc) sizer at the bottom of the page. 
     184        ## Note: the if statement should be removed along with the above 
     185        ## if statement as soon as it can be properly tested. 
     186        ## Nov. 22 2015  --PDB 
     187        if len(self.page_finder) > 0: 
     188            ## draw the sizer containing constraint info 
     189            if not self.batch_on: 
     190                self._fill_sizer_constraint() 
     191            ## draw fit button sizer 
     192            self._fill_sizer_fit() 
     193 
     194 
     195    def _fill_sizer_model_list(self, sizer): 
     196        """ 
     197        Receive a dictionary containing information to display model name 
     198        """ 
     199        ix = 0 
     200        iy = 0 
     201        list = [] 
     202        sizer.Clear(True) 
     203 
     204        new_name = wx.StaticText(self, wx.ID_ANY, '  Model Title ', 
     205                                 style=wx.ALIGN_CENTER) 
     206        new_name.SetBackgroundColour('orange') 
     207        new_name.SetForegroundColour(wx.WHITE) 
     208        sizer.Add(new_name, (iy, ix), (1, 1), 
     209                            wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     210        ix += 2 
     211        model_type = wx.StaticText(self, wx.ID_ANY, '  Model ') 
     212        model_type.SetBackgroundColour('grey') 
     213        model_type.SetForegroundColour(wx.WHITE) 
     214        sizer.Add(model_type, (iy, ix), (1, 1), 
     215                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     216        ix += 1 
     217        data_used = wx.StaticText(self, wx.ID_ANY, '  Data ') 
     218        data_used.SetBackgroundColour('grey') 
     219        data_used.SetForegroundColour(wx.WHITE) 
     220        sizer.Add(data_used, (iy, ix), (1, 1), 
     221                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     222        ix += 1 
     223        tab_used = wx.StaticText(self, wx.ID_ANY, '  FitPage ') 
     224        tab_used.SetBackgroundColour('grey') 
     225        tab_used.SetForegroundColour(wx.WHITE) 
     226        sizer.Add(tab_used, (iy, ix), (1, 1), 
     227                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     228        for id, value in self.page_finder.iteritems(): 
     229            if id not in self.parent.opened_pages: 
     230                continue 
     231 
     232            if self.batch_on != self.parent.get_page_by_id(id).batch_on: 
     233                continue 
     234 
     235            data_list = [] 
     236            model_list = [] 
     237            # get data name and model objetta 
     238            for fitproblem in value.get_fit_problem(): 
     239 
     240                data = fitproblem.get_fit_data() 
     241                if not data.is_data: 
     242                    continue 
     243                name = '-' 
     244                if data is not None and data.is_data: 
     245                    name = str(data.name) 
     246                data_list.append(name) 
     247 
     248                model = fitproblem.get_model() 
     249                if model is None: 
     250                    continue 
     251                model_list.append(model) 
     252 
     253            if len(model_list) == 0: 
     254                continue 
     255            # Draw sizer 
     256            ix = 0 
     257            iy += 1 
     258            model = model_list[0] 
     259            name = '_' 
     260            if model is not None: 
     261                name = str(model.name) 
     262            cb = wx.CheckBox(self, wx.ID_ANY, name) 
     263            cb.SetValue(False) 
     264            cb.Enable(model is not None and data.is_data) 
     265            sizer.Add(cb, (iy, ix), (1, 1), 
     266                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     267            wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 
     268            ix += 2 
     269            model_type = wx.StaticText(self, wx.ID_ANY, 
     270                                       model.__class__.__name__) 
     271            sizer.Add(model_type, (iy, ix), (1, 1), 
     272                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     273            if self.batch_on: 
     274                data_used = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     275                data_used.AppendItems(data_list) 
     276                data_used.SetSelection(0) 
     277            else: 
     278                data_used = wx.StaticText(self, wx.ID_ANY, data_list[0]) 
     279 
     280            ix += 1 
     281            sizer.Add(data_used, (iy, ix), (1, 1), 
     282                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     283            ix += 1 
     284            caption = value.get_fit_tab_caption() 
     285            tab_caption_used = wx.StaticText(self, wx.ID_ANY, str(caption)) 
     286            sizer.Add(tab_caption_used, (iy, ix), (1, 1), 
     287                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     288 
     289            self.model_list.append([cb, value, id, model]) 
     290 
     291        iy += 1 
     292        sizer.Add((20, 20), (iy, ix), (1, 1), 
     293                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     294 
     295    def _fill_sizer_constraint(self): 
     296        """ 
     297        Fill sizer containing constraint info 
     298        """ 
     299        msg = "Select at least 1 model to add constraint " 
     300        wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
     301 
     302        self.sizer2.Clear(True) 
     303        if self.batch_on: 
     304            if self.sizer2.IsShown(): 
     305                self.sizer2.Show(False) 
     306            return 
     307        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 
     308        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     309        sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
     310        self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 
     311        self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 
     312        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     313 
     314        self.hide_constraint = wx.RadioButton(self, wx.ID_ANY, 'No', (10, 10), 
     315                                              style=wx.RB_GROUP) 
     316        self.show_constraint = wx.RadioButton(self, wx.ID_ANY, 'Yes', (10, 30)) 
     317        self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
     318                  id=self.hide_constraint.GetId()) 
     319        self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
     320                  id=self.show_constraint.GetId()) 
     321        if self.batch_on: 
     322            self.hide_constraint.Enable(False) 
     323            self.show_constraint.Enable(False) 
     324        self.hide_constraint.SetValue(True) 
     325        self.show_constraint.SetValue(False) 
     326 
     327        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Model")) 
     328        sizer_title.Add((10, 10)) 
     329        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Parameter")) 
     330        sizer_title.Add((10, 10)) 
     331        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Add Constraint?")) 
     332        sizer_title.Add((10, 10)) 
     333        sizer_title.Add(self.show_constraint) 
     334        sizer_title.Add(self.hide_constraint) 
     335        sizer_title.Add((10, 10)) 
     336 
     337        self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 
     338        self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
     339                        id=self.btAdd.GetId()) 
     340        self.btAdd.SetToolTipString("Add another constraint?") 
     341        self.btAdd.Hide() 
     342 
     343        text_hint = wx.StaticText(self, wx.ID_ANY, 
     344                                  "Example: [M0][paramter] = M1.parameter") 
     345        sizer_button.Add(text_hint, 0, 
     346                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     347        sizer_button.Add(self.btAdd, 0, 
     348                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     349 
     350        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
     351        boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
     352                      border=10) 
     353        boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
     354                      border=10) 
     355        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
     356 
     357        self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
     358 
     359 
     360    def _fill_sizer_fit(self): 
     361        """ 
     362        Draw fit button 
     363        """ 
     364        self.sizer3.Clear(True) 
     365        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 
     366        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     367        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     368 
     369        #Fit button 
     370        self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 
     371        self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 
     372        self.btFit.SetToolTipString("Perform fit.") 
     373 
     374        #General Help button 
     375        self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 
     376        self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 
     377        self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 
     378 
     379        #hint text on button line 
     380        if self.batch_on: 
     381            text = " Fit in Parallel all Data sets\n" 
     382            text += "and model selected." 
     383        else: 
     384            text = " At least one set of model and data\n" 
     385            text += " must be selected for fitting." 
     386        text_hint = wx.StaticText(self, wx.ID_ANY, text) 
     387 
     388        sizer_button.Add(text_hint) 
     389        sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     390        sizer_button.Add(self.btHelp, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     391 
     392        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
     393        self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    117394 
    118395    def onRemove(self, event): 
     
    126403        if len(self.constraints_list) == 0: 
    127404            return 
     405        wx.CallAfter(self._remove_after, event.GetId()) 
     406        #self._onAdd_constraint(None) 
     407 
     408    def _remove_after(self, id): 
    128409        for item in self.constraints_list: 
    129             length = len(item) 
    130             if event.GetId() == item[length - 2].GetId(): 
    131                 sizer = item[length - 1] 
    132                 sizer.Clear(True) 
    133                 self.sizer_constraints.Remove(sizer) 
    134                 #self.SetScrollbars(20,20,25,65) 
     410            if id == item.btRemove.GetId(): 
     411                self.sizer_constraints.Hide(item.sizer) 
     412                item.sizer.Clear(True) 
     413                self.sizer_constraints.Remove(item.sizer) 
    135414                self.constraints_list.remove(item) 
    136415                self.nb_constraint -= 1 
    137416                self.sizer2.Layout() 
    138                 self.Layout() 
     417                self.FitInside() 
    139418                break 
    140  
    141         #self._onAdd_constraint(None) 
    142419 
    143420    def onFit(self, event): 
     
    171448            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    172449 
     450    def _onHelp(self, event): 
     451        """ 
     452        Bring up the simultaneous Fitting Documentation whenever the HELP 
     453        button is clicked. 
     454 
     455        Calls DocumentationWindow with the path of the location within the 
     456        documentation tree (after /doc/ ....".  Note that when using old 
     457        versions of Wx (before 2.9) and thus not the release version of 
     458        installers, the help comes up at the top level of the file as 
     459        webbrowser does not pass anything past the # to the browser when it is 
     460        running "file:///...." 
     461 
     462    :param evt: Triggers on clicking the help button 
     463    """ 
     464        _TreeLocation = "user/perspectives/fitting/fitting_help.html" 
     465        _PageAnchor = "#simultaneous-fit-mode" 
     466        _doc_viewer = DocumentationWindow(self, self.ID_DOC, _TreeLocation, 
     467                                          _PageAnchor, 
     468                                          "Simultaneous/Constrained Fitting Help") 
     469 
    173470    def set_manager(self, manager): 
    174471        """ 
     
    195492            if not self.batch_on: 
    196493                ## display constraint fields 
    197                 if self.show_constraint.GetValue() and\ 
    198                                  len(self.constraints_list) == 0: 
     494                if (self.show_constraint.GetValue() and 
     495                                 len(self.constraints_list) == 0): 
    199496                    self._show_all_constraint() 
    200497                    self._show_constraint() 
     
    203500                item[0].SetValue(False) 
    204501 
    205             self.model_toFit = [] 
    206502            if not self.batch_on: 
    207503                ##constraint info 
     
    209505 
    210506        self._update_easy_setup_cb() 
    211         self.Layout() 
    212         self.Refresh() 
     507        self.FitInside() 
     508 
    213509 
    214510    def check_model_name(self, event): 
     
    242538        if len(self.model_list) == len(self.model_toFit): 
    243539            self.cb1.SetValue(True) 
    244             self.Layout() 
     540            self.FitInside() 
    245541            return 
    246542        else: 
    247543            self.cb1.SetValue(False) 
    248             self.Layout() 
     544            self.FitInside() 
    249545 
    250546    def _update_easy_setup_cb(self): 
     
    252548        Update easy setup combobox on selecting a model 
    253549        """ 
    254         if self.model_cbox_left != None and self.model_cbox_right != None: 
    255             try: 
    256                 # when there is something 
    257                 self.model_cbox_left.Clear() 
    258                 self.model_cbox_right.Clear() 
    259                 self.model_cbox.Clear() 
    260             except: 
    261                 # when there is nothing 
    262                 pass 
    263             #for id, model in self.constraint_dict.iteritems(): 
    264             for item in self.model_toFit: 
    265                 model = item[3] 
    266                 ## check if all parameters have been selected for constraint 
    267                 ## then do not allow add constraint on parameters 
    268                 if str(model.name) not in self.model_cbox_left.GetItems(): 
    269                     self.model_cbox_left.Append(str(model.name), model) 
    270                 if str(model.name) not in self.model_cbox_right.GetItems(): 
    271                     self.model_cbox_right.Append(str(model.name), model) 
    272                 if str(model.name) not in self.model_cbox.GetItems(): 
    273                     self.model_cbox.Append(str(model.name), model) 
     550        if self.model_cbox_left == None or self.model_cbox_right == None: 
     551            return 
     552 
     553        models = [(item[3].name, item[3]) for item in self.model_toFit] 
     554        setComboBoxItems(self.model_cbox_left, models) 
     555        setComboBoxItems(self.model_cbox_right, models) 
     556        for item in self.constraints_list: 
     557            setComboBoxItems(item[0], models) 
     558        if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 
    274559            self.model_cbox_left.SetSelection(0) 
    275             self.sizer2.Layout() 
    276             self.sizer3.Layout() 
    277  
    278     def draw_page(self): 
    279         """ 
    280         Draw a sizer containing couples of data and model 
    281         """ 
    282         self.model_list = [] 
    283         self.model_toFit = [] 
    284         self.constraints_list = [] 
    285         self.constraint_dict = {} 
    286         self.nb_constraint = 0 
    287         self.model_cbox_left = None 
    288         self.model_cbox_right = None 
    289  
    290         if len(self.model_list) > 0: 
    291             for item in self.model_list: 
    292                 item[0].SetValue(False) 
    293                 self.manager.schedule_for_fit(value=0, uid=item[2]) 
    294  
    295         self.sizer1.Clear(True) 
    296         box_description = wx.StaticBox(self, -1, "Fit Combinations") 
    297         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    298         sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
    299         sizer_couples = wx.GridBagSizer(5, 5) 
    300         #------------------------------------------------------ 
    301         if len(self.page_finder) == 0: 
    302             msg = " No fit combinations are found! \n\n" 
    303             msg += " Please load data and set up " 
    304             msg += "at least two fit panels first..." 
    305             sizer_title.Add(wx.StaticText(self, -1, msg)) 
    306         else: 
    307             ## store model 
    308             self._store_model() 
    309  
    310             self.cb1 = wx.CheckBox(self, -1, 'Select all') 
    311             self.cb1.SetValue(False) 
    312  
    313             wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) 
    314  
    315             sizer_title.Add((10, 10), 0, 
    316                 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
    317             sizer_title.Add(self.cb1, 0, 
    318                 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
    319  
    320             ## draw list of model and data name 
    321             self._fill_sizer_model_list(sizer_couples) 
    322             ## draw the sizer containing constraint info 
    323             if not self.batch_on: 
    324                 self._fill_sizer_constraint() 
    325             ## draw fit button 
    326             self._fill_sizer_fit() 
    327         #-------------------------------------------------------- 
    328         boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 
    329         boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 
    330  
    331         self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
    332         self.sizer1.Layout() 
    333         #self.SetScrollbars(20,20,25,65) 
    334         self.AdjustScrollbars() 
    335         self.Layout() 
     560        self.sizer2.Layout() 
    336561 
    337562    def _store_model(self): 
     
    359584            self._show_all_constraint() 
    360585            self._show_constraint() 
    361             self.Layout() 
     586            self.FitInside() 
    362587            return 
    363588        else: 
    364589            self._hide_constraint() 
    365             self.Layout() 
    366590            return 
    367591 
     
    370594        Show constraint fields 
    371595        """ 
    372         box_description = wx.StaticBox(self, -1, "Easy Setup ") 
     596        box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 
    373597        boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 
    374598        sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 
    375         self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     599        self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    376600        self.model_cbox_left.Clear() 
    377         self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     601        self.model_cbox_right = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    378602        self.model_cbox_right.Clear() 
    379         wx.EVT_COMBOBOX(self.model_cbox_left, -1, self._on_select_modelcb) 
    380         wx.EVT_COMBOBOX(self.model_cbox_right, -1, self._on_select_modelcb) 
    381         egal_txt = wx.StaticText(self, -1, " = ") 
    382         self.set_button = wx.Button(self, wx.NewId(), 'Set All') 
     603        wx.EVT_COMBOBOX(self.model_cbox_left, wx.ID_ANY, self._on_select_modelcb) 
     604        wx.EVT_COMBOBOX(self.model_cbox_right, wx.ID_ANY, self._on_select_modelcb) 
     605        egal_txt = wx.StaticText(self, wx.ID_ANY, " = ") 
     606        self.set_button = wx.Button(self, self.ID_SET_ALL, 'Set All') 
    383607        self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal, 
    384608                             id=self.set_button.GetId()) 
     
    399623        boxsizer.Add(self.model_cbox_left, 
    400624                             flag=wx.RIGHT | wx.EXPAND, border=10) 
    401         boxsizer.Add(wx.StaticText(self, -1, ".parameters"), 
    402                              flag=wx.RIGHT | wx.EXPAND, border=5) 
     625        #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
     626        #                     flag=wx.RIGHT | wx.EXPAND, border=5) 
    403627        boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
    404628        boxsizer.Add(self.model_cbox_right, 
    405629                             flag=wx.RIGHT | wx.EXPAND, border=10) 
    406         boxsizer.Add(wx.StaticText(self, -1, ".parameters"), 
    407                              flag=wx.RIGHT | wx.EXPAND, border=5) 
     630        #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
     631        #                     flag=wx.RIGHT | wx.EXPAND, border=5) 
    408632        boxsizer.Add((20, -1)) 
    409633        boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 
     
    412636                             item=sizer_constraint, 
    413637                             flag=wx.TOP | wx.BOTTOM | wx.EXPAND, border=5) 
    414  
    415         self.sizer_all_constraints.Layout() 
    416         self.sizer2.Layout() 
    417         #self.SetScrollbars(20,20,25,65) 
     638        self.FitInside() 
    418639 
    419640    def _on_select_modelcb(self, event): 
     
    427648        if self.model_cbox_right.GetValue().strip() == '': 
    428649            flag = False 
    429         if self.model_cbox_left.GetValue() == \ 
    430                 self.model_cbox_right.GetValue(): 
     650        if (self.model_cbox_left.GetValue() == 
     651                self.model_cbox_right.GetValue()): 
    431652            flag = False 
    432653        self.set_button.Enable(flag) 
     
    460681            num_cbox += 1 
    461682            if param in param_listB: 
    462                 self.model_cbox.SetStringSelection(model_left) 
     683                item = self.constraints_list[-1] 
     684                item.model_cbox.SetStringSelection(model_left) 
    463685                self._on_select_model(None) 
    464                 self.param_cbox.Clear() 
    465                 self.param_cbox.Append(str(param), model) 
    466                 self.param_cbox.SetStringSelection(str(param)) 
    467                 self.ctl2.SetValue(str(model_right + "." + str(param))) 
     686                item.param_cbox.Clear() 
     687                item.param_cbox.Append(str(param), model) 
     688                item.param_cbox.SetStringSelection(str(param)) 
     689                item.constraint.SetValue(str(model_right + "." + str(param))) 
    468690                has_param = True 
    469691                if num_cbox == (len(param_list) + 1): 
     
    471693                self._show_constraint() 
    472694 
    473         self.sizer_constraints.Layout() 
    474         self.sizer2.Layout() 
    475         self.SetScrollbars(20, 20, 25, 65) 
    476         self.Layout() 
     695        self.FitInside() 
    477696        if not has_param: 
    478697            msg = " There is no adjustable parameter (checked to fit)" 
     
    496715            ##Don't add anymore 
    497716            if len(self.constraints_list) == nb_fit_param: 
    498                 msg = "Cannot add another constraint .Maximum of number " 
     717                msg = "Cannot add another constraint. Maximum of number " 
    499718                msg += "Parameters name reached %s" % str(nb_fit_param) 
    500719                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
     
    510729 
    511730        sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 
    512         model_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     731 
     732        # Model list 
     733        model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    513734        model_cbox.Clear() 
    514         param_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY, size=(100, -1),) 
    515         param_cbox.Hide() 
    516  
    517         #This is for GetCLientData() _on_select_param: Was None return on MAC. 
    518         self.param_cbox = param_cbox 
    519  
    520         wx.EVT_COMBOBOX(param_cbox, -1, self._on_select_param) 
    521         self.ctl2 = wx.TextCtrl(self, -1) 
    522         egal_txt = wx.StaticText(self, -1, " = ") 
    523         self.btRemove = wx.Button(self, wx.NewId(), 'Remove') 
    524         self.btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 
    525                            id=self.btRemove.GetId()) 
    526         self.btRemove.SetToolTipString("Remove constraint.") 
    527         self.btRemove.Hide() 
    528         if hasattr(self, "btAdd"): 
    529             self.btAdd.Hide() 
    530735        for id, model in self.constraint_dict.iteritems(): 
    531736            ## check if all parameters have been selected for constraint 
    532737            ## then do not allow add constraint on parameters 
    533738            model_cbox.Append(str(model.name), model) 
    534  
    535         #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. 
    536         self.model_cbox = model_cbox 
    537  
    538         wx.EVT_COMBOBOX(model_cbox, -1, self._on_select_model) 
     739        wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) 
     740 
     741        # Parameters in model 
     742        param_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY, 
     743                                 size=(100, -1)) 
     744        param_cbox.Hide() 
     745        wx.EVT_COMBOBOX(param_cbox, wx.ID_ANY, self._on_select_param) 
     746 
     747        egal_txt = wx.StaticText(self, wx.ID_ANY, " = ") 
     748 
     749        # Parameter constraint 
     750        constraint = wx.TextCtrl(self, wx.ID_ANY) 
     751 
     752        # Remove button 
     753        #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 
     754        btRemove = wx.Button(self, self._ids.next(), 'Remove') 
     755        btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 
     756                      id=btRemove.GetId()) 
     757        btRemove.SetToolTipString("Remove constraint.") 
     758        btRemove.Hide() 
     759 
     760        # Hid the add button, if it exists 
     761        if hasattr(self, "btAdd"): 
     762            self.btAdd.Hide() 
     763 
    539764        sizer_constraint.Add((5, -1)) 
    540765        sizer_constraint.Add(model_cbox, flag=wx.RIGHT | wx.EXPAND, border=10) 
    541766        sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, border=5) 
    542767        sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
    543         sizer_constraint.Add(self.ctl2, flag=wx.RIGHT | wx.EXPAND, border=10) 
    544         sizer_constraint.Add(self.btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 
     768        sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 
     769        sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 
    545770 
    546771        self.sizer_constraints.Insert(before=self.nb_constraint, 
    547                         item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 
    548                         border=5) 
    549         self.constraints_list.append([model_cbox, param_cbox, egal_txt, 
    550                                     self.ctl2, self.btRemove, sizer_constraint]) 
     772                item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 
     773                border=5) 
     774        c = ConstraintLine(model_cbox, param_cbox, egal_txt, 
     775                           constraint, btRemove, sizer_constraint) 
     776        self.constraints_list.append(c) 
    551777 
    552778        self.nb_constraint += 1 
    553779        self.sizer_constraints.Layout() 
    554780        self.sizer2.Layout() 
     781        self.Layout 
    555782 
    556783    def _hide_constraint(self): 
     
    558785        hide buttons related constraint 
    559786        """ 
    560         for id in  self.page_finder.iterkeys(): 
     787        for id in self.page_finder.iterkeys(): 
    561788            self.page_finder[id].clear_model_param() 
    562789 
     
    566793            self.btAdd.Hide() 
    567794        self._store_model() 
    568         if self.model_cbox_left != None: 
    569             try: 
    570                 self.model_cbox_left.Clear() 
    571             except: 
    572                 pass 
     795        if self.model_cbox_left is not None: 
     796            self.model_cbox_left.Clear() 
    573797            self.model_cbox_left = None 
    574         if self.model_cbox_right != None: 
    575             try: 
    576                 self.model_cbox_right.Clear() 
    577             except: 
    578                 pass 
     798        if self.model_cbox_right is not None: 
     799            self.model_cbox_right.Clear() 
    579800            self.model_cbox_right = None 
    580801        self.constraints_list = [] 
     
    584805        self.sizer_constraints.Layout() 
    585806        self.sizer2.Layout() 
     807        self.Layout 
     808        self.FitInside() 
    586809 
    587810    def _on_select_model(self, event): 
     
    589812        fill combox box with list of parameters 
    590813        """ 
     814        if not self.constraints_list: 
     815            return 
     816 
     817        ##This way PC/MAC both work, instead of using event.GetClientData(). 
     818        model_cbox = self.constraints_list[-1].model_cbox 
     819        n = model_cbox.GetCurrentSelection() 
     820        if n == wx.NOT_FOUND: 
     821            return 
     822 
     823        model = model_cbox.GetClientData(n) 
    591824        param_list = [] 
    592         ##This way PC/MAC both work, instead of using event.GetClientData(). 
    593         n = self.model_cbox.GetCurrentSelection() 
    594         model = self.model_cbox.GetClientData(n) 
    595825        for id, dic_model in self.constraint_dict.iteritems(): 
    596826            if model == dic_model: 
    597827                param_list = self.page_finder[id].get_param2fit() 
    598                 #break 
    599         length = len(self.constraints_list) 
    600         if length < 1: 
    601             return 
    602         param_cbox = self.constraints_list[length - 1][1] 
     828                break 
     829 
     830        param_cbox = self.constraints_list[-1].param_cbox 
    603831        param_cbox.Clear() 
    604832        ## insert only fittable paramaters 
    605833        for param in param_list: 
    606834            param_cbox.Append(str(param), model) 
    607  
    608835        param_cbox.Show(True) 
    609         self.btRemove.Show(True) 
     836 
     837        btRemove = self.constraints_list[-1].btRemove 
     838        btRemove.Show(True) 
    610839        self.btAdd.Show(True) 
    611         self.sizer2.Layout() 
     840#        self.Layout() 
     841        self.FitInside() 
    612842 
    613843    def _on_select_param(self, event): 
     
    620850        #param = event.GetString() 
    621851 
    622         length = len(self.constraints_list) 
    623         if length < 1: 
    624             return 
    625         egal_txt = self.constraints_list[length - 1][2] 
    626         egal_txt.Show(True) 
    627  
    628         ctl2 = self.constraints_list[length - 1][3] 
    629         ctl2.Show(True) 
     852        if self.constraints_list: 
     853            self.constraints_list[-1].egal_txt.Show(True) 
     854            self.constraints_list[-1].constraint.Show(True) 
    630855 
    631856    def _onAdd_constraint(self, event): 
     
    640865        # before allow to add another constraint 
    641866        for item in self.constraints_list: 
    642             model_cbox = item[0] 
    643             if model_cbox.GetString(0) == "": 
     867            if item.model_cbox.GetString(0) == "": 
    644868                msg = " Select a model Name! " 
    645869                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    646870                return 
    647             param_cbox = item[1] 
    648             if param_cbox.GetString(0) == "": 
     871            if item.param_cbox.GetString(0) == "": 
    649872                msg = " Select a parameter Name! " 
    650873                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    651874                return 
    652             ctl2 = item[3] 
    653             if ctl2.GetValue().lstrip().rstrip() == "": 
    654                 model = param_cbox.GetClientData(\ 
    655                                             param_cbox.GetCurrentSelection()) 
     875            if item.constraint.GetValue().lstrip().rstrip() == "": 
     876                model = item.param_cbox.GetClientData( 
     877                                        item.param_cbox.GetCurrentSelection()) 
    656878                if model != None: 
    657879                    msg = " Enter a constraint for %s.%s! " % (model.name, 
    658                                                         param_cbox.GetString(0)) 
     880                                        item.param_cbox.GetString(0)) 
    659881                else: 
    660                      msg = " Enter a constraint" 
     882                    msg = " Enter a constraint" 
    661883                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    662884                return 
    663885        ## some model or parameters can be constrained 
    664886        self._show_constraint() 
    665         self.sizer3.Layout() 
    666         self.Layout() 
    667         self.Refresh() 
    668  
    669     def _fill_sizer_fit(self): 
    670         """ 
    671         Draw fit button 
    672         """ 
    673         self.sizer3.Clear(True) 
    674         box_description = wx.StaticBox(self, -1, "Fit ") 
    675         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    676         sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    677  
    678         self.btFit = wx.Button(self, wx.NewId(), 'Fit', size=wx.DefaultSize) 
    679         self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 
    680         self.btFit.SetToolTipString("Perform fit.") 
    681         if self.batch_on: 
    682             text = " Fit in Parallel all Data set and model selected.\n" 
    683         else: 
    684             text = " This page requires at least one FitPage with a data\n" 
    685             text = " and a model for fitting." 
    686         text_hint = wx.StaticText(self, -1, text) 
    687  
    688         sizer_button.Add(text_hint, wx.RIGHT | wx.EXPAND, 10) 
    689         sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
    690  
    691         boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    692         self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    693         self.sizer3.Layout() 
    694  
    695     def _fill_sizer_constraint(self): 
    696         """ 
    697         Fill sizer containing constraint info 
    698         """ 
    699         msg = "Select at least 2 model to add constraint " 
    700         wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    701  
    702         self.sizer2.Clear(True) 
    703         if self.batch_on: 
    704             if self.sizer2.IsShown(): 
    705                 self.sizer2.Show(False) 
    706             return 
    707         box_description = wx.StaticBox(self, -1, "Fit Constraints") 
    708         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    709         sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
    710         self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 
    711         self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 
    712         sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    713  
    714         self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), 
    715                                               style=wx.RB_GROUP) 
    716         self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) 
    717         self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
    718                   id=self.hide_constraint.GetId()) 
    719         self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
    720                   id=self.show_constraint.GetId()) 
    721         if self.batch_on: 
    722             self.hide_constraint.Enable(False) 
    723             self.show_constraint.Enable(False) 
    724         self.hide_constraint.SetValue(True) 
    725         self.show_constraint.SetValue(False) 
    726  
    727         sizer_title.Add(wx.StaticText(self, -1, " Model")) 
    728         sizer_title.Add((10, 10)) 
    729         sizer_title.Add(wx.StaticText(self, -1, " Parameter")) 
    730         sizer_title.Add((10, 10)) 
    731         sizer_title.Add(wx.StaticText(self, -1, " Add Constraint?")) 
    732         sizer_title.Add((10, 10)) 
    733         sizer_title.Add(self.show_constraint) 
    734         sizer_title.Add(self.hide_constraint) 
    735         sizer_title.Add((10, 10)) 
    736  
    737         self.btAdd = wx.Button(self, wx.NewId(), 'Add') 
    738         self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
    739                         id=self.btAdd.GetId()) 
    740         self.btAdd.SetToolTipString("Add another constraint?") 
    741         self.btAdd.Hide() 
    742  
    743         text_hint = wx.StaticText(self, -1, 
    744                                   "Example: [M0][paramter] = M1.parameter") 
    745         sizer_button.Add(text_hint, 0 , wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    746         sizer_button.Add(self.btAdd, 0, wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    747  
    748         boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
    749         boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
    750                       border=10) 
    751         boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
    752                       border=10) 
    753         boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    754  
    755         self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    756         self.sizer2.Layout() 
    757  
    758         #self.SetScrollbars(20,20,25,65) 
     887        self.FitInside() 
    759888 
    760889    def _set_constraint(self): 
    761890        """ 
    762         get values from the constrainst textcrtl ,parses them into model name 
     891        get values from the constraint textcrtl ,parses them into model name 
    763892        parameter name and parameters values. 
    764893        store them in a list self.params .when when params is not empty 
     
    767896        """ 
    768897        for item in self.constraints_list: 
    769             select0 = item[0].GetSelection() 
     898            select0 = item.model_cbox.GetSelection() 
    770899            if select0 == wx.NOT_FOUND: 
    771900                continue 
    772             model = item[0].GetClientData(select0) 
    773             select1 = item[1].GetSelection() 
     901            model = item.model_cbox.GetClientData(select0) 
     902            select1 = item.param_cbox.GetSelection() 
    774903            if select1 == wx.NOT_FOUND: 
    775904                continue 
    776             param = item[1].GetString(select1) 
    777             constraint = item[3].GetValue().lstrip().rstrip() 
     905            param = item.param_cbox.GetString(select1) 
     906            constraint = item.constraint.GetValue().lstrip().rstrip() 
    778907            if param.lstrip().rstrip() == "": 
    779908                param = None 
     
    808937                        # wrap in param/constraint in str() to remove unicode 
    809938                        self.page_finder[id].set_model_param(str(param), 
    810                                                         str(constraint), fid=fid) 
     939                                str(constraint), fid=fid) 
    811940                    break 
    812941        return True 
    813  
    814     def _fill_sizer_model_list(self, sizer): 
    815         """ 
    816         Receive a dictionary containing information to display model name 
    817         """ 
    818         ix = 0 
    819         iy = 0 
    820         list = [] 
    821         sizer.Clear(True) 
    822  
    823         new_name = wx.StaticText(self, -1, '  Model Title ', 
    824                                  style=wx.ALIGN_CENTER) 
    825         new_name.SetBackgroundColour('orange') 
    826         new_name.SetForegroundColour(wx.WHITE) 
    827         sizer.Add(new_name, (iy, ix), (1, 1), 
    828                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    829         ix += 2 
    830         model_type = wx.StaticText(self, -1, '  Model ') 
    831         model_type.SetBackgroundColour('grey') 
    832         model_type.SetForegroundColour(wx.WHITE) 
    833         sizer.Add(model_type, (iy, ix), (1, 1), 
    834                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    835         ix += 1 
    836         data_used = wx.StaticText(self, -1, '  Data ') 
    837         data_used.SetBackgroundColour('grey') 
    838         data_used.SetForegroundColour(wx.WHITE) 
    839         sizer.Add(data_used, (iy, ix), (1, 1), 
    840                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    841         ix += 1 
    842         tab_used = wx.StaticText(self, -1, '  FitPage ') 
    843         tab_used.SetBackgroundColour('grey') 
    844         tab_used.SetForegroundColour(wx.WHITE) 
    845         sizer.Add(tab_used, (iy, ix), (1, 1), 
    846                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    847         for id, value in self.page_finder.iteritems(): 
    848             if id not in self.parent.opened_pages: 
    849                 continue 
    850  
    851             if self.batch_on != self.parent.get_page_by_id(id).batch_on: 
    852                 continue 
    853  
    854             data_list = [] 
    855             model_list = [] 
    856             # get data name and model objetta 
    857             for fitproblem in value.get_fit_problem(): 
    858  
    859                 data = fitproblem.get_fit_data() 
    860                 if not data.is_data: 
    861                     continue 
    862                 name = '-' 
    863                 if data is not None and data.is_data: 
    864                     name = str(data.name) 
    865                 data_list.append(name) 
    866  
    867                 model = fitproblem.get_model() 
    868                 if model is None: 
    869                     continue 
    870                 model_list.append(model) 
    871  
    872             if len(model_list) == 0: 
    873                 continue 
    874             # Draw sizer 
    875             ix = 0 
    876             iy += 1 
    877             model = model_list[0] 
    878             name = '_' 
    879             if model is not None: 
    880                 name = str(model.name) 
    881             cb = wx.CheckBox(self, -1, name) 
    882             cb.SetValue(False) 
    883             cb.Enable(model is not None and data.is_data) 
    884             sizer.Add(cb, (iy, ix), (1, 1), 
    885                        wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    886             wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 
    887             ix += 2 
    888             type = model.__class__.__name__ 
    889             model_type = wx.StaticText(self, -1, str(type)) 
    890             sizer.Add(model_type, (iy, ix), (1, 1), 
    891                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    892             if self.batch_on: 
    893                 data_used = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    894                 data_used.AppendItems(data_list) 
    895                 data_used.SetSelection(0) 
    896             else: 
    897                 data_used = wx.StaticText(self, -1, data_list[0]) 
    898  
    899             ix += 1 
    900             sizer.Add(data_used, (iy, ix), (1, 1), 
    901                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    902             ix += 1 
    903             caption = value.get_fit_tab_caption() 
    904             tab_caption_used = wx.StaticText(self, -1, str(caption)) 
    905             sizer.Add(tab_caption_used, (iy, ix), (1, 1), 
    906                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    907  
    908             self.model_list.append([cb, value, id, model]) 
    909  
    910         iy += 1 
    911         sizer.Add((20, 20), (iy, ix), (1, 1), 
    912                   wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    913         sizer.Layout() 
    914942 
    915943    def on_set_focus(self, event=None): 
     
    921949                wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self)) 
    922950            self.page_finder = self.parent._manager.get_page_finder() 
     951 
     952 
     953def setComboBoxItems(cbox, items): 
     954    assert isinstance(cbox, wx.ComboBox) 
     955    selected = cbox.GetStringSelection() 
     956    cbox.Clear() 
     957    for k, (name, value) in enumerate(items): 
     958        cbox.Append(name, value) 
     959    cbox.SetStringSelection(selected) 
  • src/sas/plottools/toolbar.py

    rd3d67f0 r2d88fc4  
    1919 
    2020class NavigationToolBar(NavigationToolbar2WxAgg): 
     21    _NTB2_HOME = wx.NewId() 
     22    _NTB2_BACK = wx.NewId() 
     23    _NTB2_FORWARD = wx.NewId() 
     24    _NTB2_PAN = wx.NewId() 
     25    _NTB2_ZOOM = wx.NewId() 
     26    _NTB2_SAVE = wx.NewId() 
     27    _NTB2_PRINT = wx.NewId() 
     28    _NTB2_RESET = wx.NewId() 
     29    _NTB2_COPY = wx.NewId() 
    2130    """ 
    2231    Overwrite matplotlib toolbar 
     
    3140    def _init_toolbar(self): 
    3241        self._parent = self.canvas.GetParent() 
    33         self._NTB2_HOME = wx.NewId() 
    34         self._NTB2_BACK = wx.NewId() 
    35         self._NTB2_FORWARD = wx.NewId() 
    36         self._NTB2_PAN = wx.NewId() 
    37         self._NTB2_ZOOM = wx.NewId() 
    38         self._NTB2_SAVE = wx.NewId() 
    39         self._NTB2_PRINT = wx.NewId() 
    40         self._NTB2_RESET = wx.NewId() 
    4142 
    4243        # for mpl 1.2+ compatibility 
     
    101102        """ 
    102103        # Slicer plot popup menu 
    103         wx_id = wx.NewId() 
    104104        popup = wx.Menu() 
    105         popup.Append(wx_id, '&Save image', 'Save image as PNG') 
    106         wx.EVT_MENU(self, wx_id, self.save_figure) 
     105        popup.Append(self._NTB2_SAVE, '&Save image', 'Save image as PNG') 
     106        wx.EVT_MENU(self, self._NTB2_SAVE, self.save_figure) 
    107107 
    108         wx_id = wx.NewId() 
    109         popup.Append(wx_id, '&Print image', 'Print image ') 
    110         wx.EVT_MENU(self, wx_id, self.print_figure) 
     108        popup.Append(self._NTB2_PRINT, '&Print image', 'Print image ') 
     109        wx.EVT_MENU(self, self._NTB2_PRINT, self.print_figure) 
    111110 
    112         wx_id = wx.NewId() 
    113         popup.Append(wx_id, '&Copy to Clipboard', 'Copy image to the clipboard') 
    114         wx.EVT_MENU(self, wx_id, self.copy_figure) 
     111        popup.Append(self._NTB2_COPY, '&Copy to Clipboard', 'Copy image to the clipboard') 
     112        wx.EVT_MENU(self, self._NTB2_COPY, self.copy_figure) 
    115113 
    116114        # Show the popup menu relative to the location of the toolbar 
  • test/sasfit/test/utest_fit_line.py

    racf8e4a5 rbc873053  
    1111from sas.models.LineModel import LineModel 
    1212from sas.models.Constant import Constant 
     13 
     14from bumps import fitters 
     15try: 
     16    from bumps.options import FIT_CONFIG 
     17    def set_fitter(alg, opts): 
     18        FIT_CONFIG.selected_id = alg 
     19        FIT_CONFIG.values[alg].update(opts, monitors=[]) 
     20except: 
     21    # CRUFT: Bumps changed its handling of fit options around 0.7.5.6 
     22    def set_fitter(alg, opts): 
     23        #print "fitting",alg,opts 
     24        #print "options",fitters.FIT_OPTIONS[alg].__dict__ 
     25        fitters.FIT_DEFAULT = alg 
     26        fitters.FIT_OPTIONS[alg].options.update(opts, monitors=[]) 
     27 
    1328 
    1429class testFitModule(unittest.TestCase): 
     
    6782 
    6883    def fit_bumps(self, alg, **opts): 
    69         #Importing the Fit module 
    70         from bumps import fitters 
    71         fitters.FIT_DEFAULT = alg 
    72         fitters.FIT_OPTIONS[alg].options.update(opts) 
    73         fitters.FIT_OPTIONS[alg].options.update(monitors=[]) 
    74         #print "fitting",alg,opts 
    75         #kprint "options",fitters.FIT_OPTIONS[alg].__dict__ 
     84        set_fitter(alg, opts) 
    7685        self.fit_single(isdream=(alg=='dream')) 
    7786 
  • test/sasfit/test/utest_fit_smeared.py

    racf8e4a5 rbc873053  
    1313from sas.models.CylinderModel import CylinderModel 
    1414from sas.models.SphereModel import SphereModel 
     15 
     16 
     17from bumps import fitters 
     18try: 
     19    from bumps.options import FIT_CONFIG 
     20    def set_fitter(alg, opts): 
     21        FIT_CONFIG.selected_id= alg 
     22        FIT_CONFIG.values[alg].update(opts, monitors=[]) 
     23except: 
     24    # CRUFT: Bumps changed its handling of fit options around 0.7.5.6 
     25    def set_fitter(alg, opts): 
     26        #print "fitting",alg,opts 
     27        #print "options",fitters.FIT_OPTIONS[alg].__dict__ 
     28        fitters.FIT_DEFAULT = alg 
     29        fitters.FIT_OPTIONS[alg].options.update(opts, monitors=[]) 
     30 
    1531 
    1632class testFitModule(unittest.TestCase): 
     
    5773            Cylinder fit with dispersion 
    5874        """ 
    59         alg = 'lm' 
    60         from bumps import fitters 
    61         fitters.FIT_DEFAULT = alg 
    62         #fitters.FIT_OPTIONS[alg].options.update(opts) 
    63         fitters.FIT_OPTIONS[alg].options.update(monitors=[]) 
     75        set_fitter('lm', {}) 
    6476        self._dispersion(fitter = Fit()) 
    6577 
  • sasview/setup_mac.py

    r49cd712 re8e3e38  
    121121VERSION = sasviewver.__version__ 
    122122APPNAME = "SasView "+VERSION 
    123 DMGNAME = "SasView-"+VERSION 
     123DMGNAME = "SasView-"+VERSION+"-MacOSX" 
    124124 
    125125APP = ['sasview.py'] 
Note: See TracChangeset for help on using the changeset viewer.