Changeset 9c23f40 in sasview


Ignore:
Timestamp:
Apr 11, 2017 8:09:07 AM (7 years ago)
Author:
GitHub <noreply@…>
Parents:
6ca9d90 (diff), 083afa1 (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.
git-author:
Andrew Nelson <andyfaff@…> (04/11/17 08:09:07)
git-committer:
GitHub <noreply@…> (04/11/17 08:09:07)
Message:

Merge 083afa172eb22bb71ef1d12ab508761c46610fca into 6ca9d9028c2ab3eb66f62b1c8a17ba8c7fb852e1

Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/qsmearing.py

    r235f514 r083afa1  
    6565            raise ValueError('one or more of your dx values are negative, please check the data file!') 
    6666 
    67     if _found_sesans == True: 
     67    if _found_sesans: 
    6868        #Pre-compute the Hankel matrix (H) 
    6969        qmax, qunits = data.sample.zacceptance 
     
    8484            #print "data1D.dx[0]",data1D.dx[0],data1D.dxl[0] 
    8585    # If we found resolution smearing data, return a QSmearer 
    86     if _found_resolution == True: 
     86    if _found_resolution: 
    8787         return pinhole_smear(data, model) 
    8888 
     
    107107                break 
    108108    # If we found slit smearing data, return a slit smearer 
    109     if _found_slit == True: 
     109    if _found_slit: 
    110110        return slit_smear(data, model) 
    111111    return None 
  • src/sas/sascalc/dataloader/readers/abs_reader.py

    r959eb01 r083afa1  
    6969                data_conv_i = None 
    7070                 
    71                 if has_converter == True and output.x_unit != '1/A': 
     71                if has_converter and output.x_unit != '1/A': 
    7272                    data_conv_q = Converter('1/A') 
    7373                    # Test it 
    7474                    data_conv_q(1.0, output.x_unit) 
    7575                     
    76                 if has_converter == True and output.y_unit != '1/cm': 
     76                if has_converter and output.y_unit != '1/cm': 
    7777                    data_conv_i = Converter('1/cm') 
    7878                    # Test it 
     
    8282                     
    8383                    # Information line 1 
    84                     if is_info == True: 
     84                    if is_info: 
    8585                        is_info = False 
    8686                        line_toks = line.split() 
     
    8989                        try: 
    9090                            value = float(line_toks[1]) 
    91                             if has_converter == True and \ 
     91                            if has_converter and \ 
    9292                                output.source.wavelength_unit != 'A': 
    9393                                conv = Converter('A') 
     
    104104                        try: 
    105105                            value = float(line_toks[3]) 
    106                             if has_converter == True and \ 
     106                            if has_converter and \ 
    107107                                detector.distance_unit != 'm': 
    108108                                conv = Converter('m') 
     
    125125                        try: 
    126126                            value = float(line_toks[5]) 
    127                             if has_converter == True and \ 
     127                            if has_converter and \ 
    128128                                output.sample.thickness_unit != 'cm': 
    129129                                conv = Converter('cm') 
     
    142142                         
    143143                    # Find center info line 
    144                     if is_center == True: 
     144                    if is_center: 
    145145                        is_center = False 
    146146                        line_toks = line.split() 
     
    150150                         
    151151                        # Bin size 
    152                         if has_converter == True and \ 
     152                        if has_converter and \ 
    153153                            detector.pixel_size_unit != 'mm': 
    154154                            conv = Converter('mm') 
     
    163163                        # Store beam center in distance units 
    164164                        # Det 640 x 640 mm 
    165                         if has_converter == True and \ 
     165                        if has_converter and \ 
    166166                            detector.beam_center_unit != 'mm': 
    167167                            conv = Converter('mm') 
     
    187187                         
    188188                    # Parse the data 
    189                     if is_data_started == True: 
     189                    if is_data_started: 
    190190                        toks = line.split() 
    191191 
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    r235f514 r083afa1  
    147147                                pass 
    148148 
    149                         if has_error_dy == True: 
     149                        if has_error_dy: 
    150150                            tdy = np.append(tdy, _dy) 
    151                         if has_error_dx == True: 
     151                        if has_error_dx: 
    152152                            tdx = np.append(tdx, _dx) 
    153153                        tx = np.append(tx, _x) 
    154154                        ty = np.append(ty, _y) 
    155155 
    156                         #To remember the # of columns on the current line 
     156                        # To remember the # of columns on the current line 
    157157                        # for the next line of data 
    158158                        lentoks = new_lentoks 
     
    160160                    except ValueError: 
    161161                        # It is data and meet non - number, then stop reading 
    162                         if is_data == True: 
     162                        if is_data: 
    163163                            break 
    164164                        lentoks = 2 
     
    175175                    raise RuntimeError, msg 
    176176                # Sanity check 
    177                 if has_error_dy == True and not len(ty) == len(tdy): 
     177                if has_error_dy and not len(ty) == len(tdy): 
    178178                    msg = "ascii_reader: y and dy have different length" 
    179179                    raise RuntimeError, msg 
    180                 if has_error_dx == True and not len(tx) == len(tdx): 
     180                if has_error_dx and not len(tx) == len(tdx): 
    181181                    msg = "ascii_reader: y and dy have different length" 
    182182                    raise RuntimeError, msg 
     
    199199                    x[i] = tx[ind[i]] 
    200200                    y[i] = ty[ind[i]] 
    201                     if has_error_dy == True: 
     201                    if has_error_dy: 
    202202                        dy[i] = tdy[ind[i]] 
    203                     if has_error_dx == True: 
     203                    if has_error_dx: 
    204204                        dx[i] = tdx[ind[i]] 
    205205                # Zeros in dx, dy 
     
    211211                output.x = x[x != 0] 
    212212                output.y = y[x != 0] 
    213                 output.dy = dy[x != 0] if has_error_dy == True\ 
     213                output.dy = dy[x != 0] if has_error_dy\ 
    214214                    else np.zeros(len(output.y)) 
    215                 output.dx = dx[x != 0] if has_error_dx == True\ 
     215                output.dx = dx[x != 0] if has_error_dx\ 
    216216                    else np.zeros(len(output.x)) 
    217217 
     
    243243        if len(toks) < 2: 
    244244            toks = line.split() 
     245 
    245246        return toks 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r7432acb r083afa1  
    774774                if local_unit and default_unit and local_unit.lower() != default_unit.lower() \ 
    775775                        and local_unit.lower() != "none": 
    776                     if HAS_CONVERTER == True: 
     776                    if HAS_CONVERTER: 
    777777                        # Check local units - bad units raise KeyError 
    778778                        data_conv_q = Converter(local_unit) 
     
    11701170            pos, "z", datainfo.sample.position.z, 
    11711171            {"unit": datainfo.sample.position_unit}) 
    1172         if written == True: 
     1172        if written: 
    11731173            self.append(pos, sample) 
    11741174 
     
    11831183            ori, "yaw", datainfo.sample.orientation.z, 
    11841184            {"unit": datainfo.sample.orientation_unit}) 
    1185         if written == True: 
     1185        if written: 
    11861186            self.append(ori, sample) 
    11871187 
     
    12301230            size, "z", datainfo.source.beam_size.z, 
    12311231            {"unit": datainfo.source.beam_size_unit}) 
    1232         if written == True: 
     1232        if written: 
    12331233            self.append(size, source) 
    12341234 
     
    12861286                    size, "z", aperture.size.z, 
    12871287                    {"unit": aperture.size_unit}) 
    1288                 if written == True: 
     1288                if written: 
    12891289                    self.append(size, apert) 
    12901290 
     
    13091309            written = written | self.write_node(det, "SDD", item.distance, 
    13101310                                                {"unit": item.distance_unit}) 
    1311             if written == True: 
     1311            if written: 
    13121312                self.append(det, instr) 
    13131313 
     
    13191319            written = written | self.write_node(off, "z", item.offset.z, 
    13201320                                                {"unit": item.offset_unit}) 
    1321             if written == True: 
     1321            if written: 
    13221322                self.append(off, det) 
    13231323 
     
    13311331                                                item.orientation.z, 
    13321332                                                {"unit": item.orientation_unit}) 
    1333             if written == True: 
     1333            if written: 
    13341334                self.append(ori, det) 
    13351335 
     
    13431343                                                item.beam_center.z, 
    13441344                                                {"unit": item.beam_center_unit}) 
    1345             if written == True: 
     1345            if written: 
    13461346                self.append(center, det) 
    13471347 
     
    13531353            written = written | self.write_node(pix, "z", item.pixel_size.z, 
    13541354                                                {"unit": item.pixel_size_unit}) 
    1355             if written == True: 
     1355            if written: 
    13561356                self.append(pix, det) 
    13571357            self.write_node(det, "slit_length", item.slit_length, 
     
    14651465                exec "local_unit = storage.%s_unit" % toks[0] 
    14661466                if local_unit is not None and units.lower() != local_unit.lower(): 
    1467                     if HAS_CONVERTER == True: 
     1467                    if HAS_CONVERTER: 
    14681468                        try: 
    14691469                            conv = Converter(units) 
  • src/sas/sascalc/dataloader/readers/danse_reader.py

    r235f514 r083afa1  
    8787            data_conv_i = None 
    8888             
    89             if has_converter == True and output.Q_unit != '1/A': 
     89            if has_converter and output.Q_unit != '1/A': 
    9090                data_conv_q = Converter('1/A') 
    9191                # Test it 
    9292                data_conv_q(1.0, output.Q_unit) 
    9393                 
    94             if has_converter == True and output.I_unit != '1/cm': 
     94            if has_converter and output.I_unit != '1/cm': 
    9595                data_conv_i = Converter('1/cm') 
    9696                # Test it 
     
    162162                qx = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 
    163163                 
    164                 if has_converter == True and output.Q_unit != '1/A': 
     164                if has_converter and output.Q_unit != '1/A': 
    165165                    qx = data_conv_q(qx, units=output.Q_unit) 
    166166                 
     
    177177                qy = 4.0 * math.pi / wavelength * math.sin(theta/2.0) 
    178178                 
    179                 if has_converter == True and output.Q_unit != '1/A': 
     179                if has_converter and output.Q_unit != '1/A': 
    180180                    qy = data_conv_q(qy, units=output.Q_unit) 
    181181                 
     
    213213            # Store all data 
    214214            # Store wavelength 
    215             if has_converter == True and output.source.wavelength_unit != 'A': 
     215            if has_converter and output.source.wavelength_unit != 'A': 
    216216                conv = Converter('A') 
    217217                wavelength = conv(wavelength, 
     
    220220                 
    221221            # Store distance 
    222             if has_converter == True and detector.distance_unit != 'm': 
     222            if has_converter and detector.distance_unit != 'm': 
    223223                conv = Converter('m') 
    224224                distance = conv(distance, units=detector.distance_unit) 
     
    226226             
    227227            # Store pixel size 
    228             if has_converter == True and detector.pixel_size_unit != 'mm': 
     228            if has_converter and detector.pixel_size_unit != 'mm': 
    229229                conv = Converter('mm') 
    230230                pixel = conv(pixel, units=detector.pixel_size_unit) 
     
    242242            ymax = ymax + stepq / 2.0 
    243243             
    244             if has_converter == True and output.Q_unit != '1/A': 
     244            if has_converter and output.Q_unit != '1/A': 
    245245                xmin = data_conv_q(xmin, units=output.Q_unit) 
    246246                xmax = data_conv_q(xmax, units=output.Q_unit) 
     
    281281         
    282282        return None 
     283 
  • src/sas/sascalc/dataloader/readers/hfir1d_reader.py

    r959eb01 r083afa1  
    6262                data_conv_i = None 
    6363                 
    64                 if has_converter == True and output.x_unit != '1/A': 
     64                if has_converter and output.x_unit != '1/A': 
    6565                    data_conv_q = Converter('1/A') 
    6666                    # Test it 
    6767                    data_conv_q(1.0, output.x_unit) 
    6868                     
    69                 if has_converter == True and output.y_unit != '1/cm': 
     69                if has_converter and output.y_unit != '1/cm': 
    7070                    data_conv_i = Converter('1/cm') 
    7171                    # Test it 
  • src/sas/sascalc/dataloader/readers/red2d_reader.py

    r959eb01 r083afa1  
    107107         
    108108        # Set units: This is the unit assumed for Q and I in the data file. 
    109         if has_converter == True and output.Q_unit != '1/A': 
     109        if has_converter and output.Q_unit != '1/A': 
    110110            data_conv_q = Converter('1/A') 
    111111            # Test it 
    112112            data_conv_q(1.0, output.Q_unit) 
    113113             
    114         if has_converter == True and output.I_unit != '1/cm': 
     114        if has_converter and output.I_unit != '1/cm': 
    115115            data_conv_i = Converter('1/cm') 
    116116            # Test it 
     
    140140                    wavelength = float(line_toks[1]) 
    141141                    # Units 
    142                     if has_converter == True and \ 
     142                    if has_converter and \ 
    143143                    output.source.wavelength_unit != 'A': 
    144144                        conv = Converter('A') 
     
    152152                    distance = float(line_toks[3]) 
    153153                    # Units 
    154                     if has_converter == True and detector.distance_unit != 'm': 
     154                    if has_converter and detector.distance_unit != 'm': 
    155155                        conv = Converter('m') 
    156156                        distance = conv(distance, units=detector.distance_unit) 
     
    189189 
    190190            ## Read and get data. 
    191             if dataStarted == True: 
     191            if dataStarted: 
    192192                line_toks = line.split() 
    193193                if len(line_toks) == 0: 
     
    268268 
    269269        # units 
    270         if has_converter == True and output.Q_unit != '1/A': 
     270        if has_converter and output.Q_unit != '1/A': 
    271271            xmin = data_conv_q(xmin, units=output.Q_unit) 
    272272            xmax = data_conv_q(xmax, units=output.Q_unit) 
  • src/sas/sascalc/dataloader/readers/sesans_reader.py

    r9a5097c r083afa1  
    166166 
    167167    def _unit_conversion(self, value, value_unit, default_unit): 
    168         if has_converter == True and value_unit != default_unit: 
     168        if has_converter and value_unit != default_unit: 
    169169            data_conv_q = Converter(value_unit) 
    170170            value = data_conv_q(value, units=default_unit) 
  • docs/sphinx-docs/build_sphinx.py

    r751f4bd r01f1e17  
    66http://sphinx-doc.org/invocation.html 
    77""" 
     8from __future__ import print_function 
     9 
    810import subprocess 
    911import os 
     
    1214import shutil 
    1315import imp 
     16 
    1417from glob import glob 
    15  
    1618from distutils.dir_util import copy_tree 
    1719from distutils.util import get_platform 
     
    5557SASMODELS_DEST_BUILDIMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "models", "img") 
    5658 
    57 #if os.path.exists(SASMODELS_SOURCE_PROLOG): 
    58 #    print "Found models prolog folder at ", SASMODELS_SOURCE_PROLOG 
    59 #if os.path.exists(SASMODELS_SOURCE_REF_MODELS): 
    60 #    print "Found models ref folder at ", SASMODELS_SOURCE_REF_MODELS 
    61 #if os.path.exists(SASMODELS_SOURCE_MODELS): 
    62 #    print "Found models folder at ", SASMODELS_SOURCE_MODELS 
    63 #if os.path.exists(SASMODELS_SOURCE_IMG): 
    64 #    print "Found img folder at ", SASMODELS_SOURCE_IMG 
    65 #if os.path.exists(SASMODELS_DEST_REF_MODELS): 
    66 #    print "Found models ref folder at ", SASMODELS_DEST_REF_MODELS 
    67 #if os.path.exists(SASMODELS_DEST_MODELS): 
    68 #    print "Found models folder at ", SASMODELS_DEST_MODELS 
    69 #if os.path.exists(SASMODELS_DEST_IMG): 
    70 #    print "Found img folder at ", SASMODELS_DEST_IMG 
    71 #sys.exit() 
    7259 
    7360SPHINX_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build") 
     
    8875        s=open(filename).read() 
    8976        if old_string in s: 
    90                 print 'Changing "{old_string}" to "{new_string}"'.format(**locals()) 
     77                print('Changing "{old_string}" to "{new_string}"'.format(**locals())) 
    9178                s=s.replace(old_string, new_string) 
    9279                f=open(filename, 'w') 
     
    9582                f.close() 
    9683        else: 
    97                 print 'No occurences of "{old_string}" found.'.format(**locals()) 
     84                print('No occurences of "{old_string}" found.'.format(**locals())) 
    9885 
    9986def _remove_dir(dir_path): 
    10087    """Removes the given directory.""" 
    10188    if os.path.isdir(dir_path): 
    102         print "Removing \"%s\"... " % dir_path 
     89        print("Removing \"%s\"... " % dir_path) 
    10390        shutil.rmtree(dir_path) 
    10491 
     
    10794    Clean the sphinx build directory. 
    10895    """ 
    109     print "=== Cleaning Sphinx Build ===" 
     96    print("=== Cleaning Sphinx Build ===") 
    11097    _remove_dir(SASVIEW_DOCS) 
    11198    _remove_dir(SPHINX_BUILD) 
     
    120107    Copy the source toctrees to new folder for assembling the sphinx-docs 
    121108    """ 
    122     print "=== Copying Source toctrees ===" 
     109    print("=== Copying Source toctrees ===") 
    123110    if os.path.exists(SASVIEW_TOC_SOURCE): 
    124        print "Found docs folder at ", SASVIEW_TOC_SOURCE 
     111       print("Found docs folder at", SASVIEW_TOC_SOURCE) 
    125112       shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE) 
    126113 
     
    141128    so that Sphinx may pick it up when generating the documentation. 
    142129    """ 
    143     print "=== Retrieve User Docs ===" 
     130    print("=== Retrieve User Docs ===") 
    144131 
    145132    # Copy documentation files from their "source" to their "destination". 
     
    148135 
    149136            docs = os.path.abspath(os.path.join(root, dirname)) 
    150             print "Found docs folder at \"%s\"." % docs 
     137            print("Found docs folder at \"%s\"." % docs) 
    151138 
    152139            dest_dir_part = os.path.dirname(os.path.relpath(docs, SASVIEW_SRC)) 
     
    158145 
    159146    # Now pickup testdata_help.rst 
    160 #    print os.path.abspath(SASVIEW_TEST) 
    161 #    print os.path.abspath(SPHINX_SOURCE_TEST) 
    162     print "=== Including Test Data Docs ===" 
     147    print("=== Including Test Data Docs ===") 
    163148    if os.path.exists(SASVIEW_TEST): 
    164        print "Found docs folder at ", SASVIEW_TEST 
     149       print("Found docs folder at", SASVIEW_TEST) 
    165150       shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST) 
    166151 
    167     print "=== And the Sasmodels Docs ===" 
     152    print("=== And the Sasmodels Docs ===") 
    168153    # Make sure we have the relevant images for the new sasmodels documentation 
    169154    # First(!) we'll make a local reference copy for SasView (/new-models will be cleaned each build) 
    170155    if os.path.exists(SASMODELS_SOURCE_IMG): 
    171         print "Found img  folder SASMODELS_SOURCE_IMG    at ", SASMODELS_SOURCE_IMG 
     156        print("Found img folder SASMODELS_SOURCE_IMG at", SASMODELS_SOURCE_IMG) 
    172157        if not os.path.exists(SASMODELS_DEST_IMG): 
    173             print "Missing docs folder SASMODELS_DEST_IMG at ", SASMODELS_DEST_IMG 
     158            print("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG) 
    174159            os.makedirs(SASMODELS_DEST_IMG) 
    175             print "created SASMODELS_DEST_BUILDIMG at ", SASMODELS_DEST_BUILDIMG 
    176         else: print "Found img  folder SASMODELS_DEST_IMG      at ", SASMODELS_DEST_IMG 
    177         print "Copying sasmodels model image files..." 
     160            print("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG) 
     161        else: 
     162            print("Found img folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG) 
     163        print("Copying sasmodels model image files...") 
    178164        for files in os.listdir(SASMODELS_SOURCE_IMG): 
    179165            fromhere=os.path.join(SASMODELS_SOURCE_IMG,files) 
    180166            tohere=os.path.join(SASMODELS_DEST_IMG,files) 
    181167            shutil.copy(fromhere,tohere) 
    182     else: print "cannot find SASMODELS_SOURCE_IMG", SASMODELS_SOURCE_IMG 
     168    else: 
     169        print("no source directory",SASMODELS_SOURCE_IMG,"was found") 
    183170 
    184171    if os.path.exists(SASMODELS_SOURCE_AUTOIMG): 
    185         print "Found img  folder SASMODELS_SOURCE_AUTOIMG    at ", SASMODELS_SOURCE_AUTOIMG 
     172        print("Found img folder SASMODELS_SOURCE_AUTOIMG at", SASMODELS_SOURCE_AUTOIMG) 
    186173        if not os.path.exists(SASMODELS_DEST_IMG): 
    187             print "Missing docs folder SASMODELS_DEST_IMG at ", SASMODELS_DEST_IMG 
     174            print("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG) 
    188175            os.makedirs(SASMODELS_DEST_BUILDIMG) 
    189             print "created SASMODELS_DEST_BUILDIMG at ", SASMODELS_DEST_BUILDIMG 
    190         print "Copying sasmodels model auto-generated image files..." 
     176            print("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG) 
     177        print("Copying sasmodels model auto-generated image files...") 
    191178        for files in os.listdir(SASMODELS_SOURCE_AUTOIMG): 
    192179            fromhere=os.path.join(SASMODELS_SOURCE_AUTOIMG,files) 
    193180            tohere=os.path.join(SASMODELS_DEST_IMG,files) 
    194181            shutil.copy(fromhere,tohere) 
    195     else: print "no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found" 
     182    else: 
     183        print("no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found") 
    196184 
    197185    # And the rst prolog with the unit substitutions 
    198186    if os.path.exists(SASMODELS_SOURCE_PROLOG): 
    199         print "Found prolog folder SASMODELS_SOURCE_PROLOG at ", SASMODELS_SOURCE_PROLOG 
     187        print("Found prolog folder SASMODELS_SOURCE_PROLOG at", SASMODELS_SOURCE_PROLOG) 
    200188        if os.path.exists(SASMODELS_DEST_PROLOG): 
    201             print "Found docs folder SASMODELS_DEST_PROLOG   at ", SASMODELS_DEST_PROLOG 
    202             print "Copying sasmodels rst_prolog file..." 
     189            print("Found docs folder SASMODELS_DEST_PROLOG at", SASMODELS_DEST_PROLOG) 
     190            print("Copying sasmodels rst_prolog file...") 
    203191            for files in os.listdir(SASMODELS_SOURCE_PROLOG): 
    204192                if files.startswith("rst"): 
     
    206194                    tohere=os.path.join(SASMODELS_DEST_PROLOG,files) 
    207195                    shutil.copy(fromhere,tohere) 
     196    else: 
     197        print("no source directory",SASMODELS_SOURCE_PROLOG, "was found") 
    208198 
    209199    if os.path.exists(SASMODELS_SOURCE_GPU): 
    210         print "Found docs folder SASMODELS_SOURCE_GPU at ", SASMODELS_SOURCE_GPU 
     200        print("Found docs folder SASMODELS_SOURCE_GPU at", SASMODELS_SOURCE_GPU) 
    211201        if os.path.exists(SPHINX_SOURCE_USER): 
    212             print "Found docs folder SPHINX_SOURCE_USER      at ", SPHINX_SOURCE_USER 
    213             print "Copying sasmodels gpu files..." 
     202            print("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER) 
     203            print("Copying sasmodels gpu files...") 
    214204            for files in os.listdir(SASMODELS_SOURCE_GPU): 
    215205                if files.endswith(".rst"): 
     
    217207                    tohere=os.path.join(SPHINX_SOURCE_USER,files) 
    218208                    shutil.copy(fromhere,tohere) 
     209    else: 
     210        print("no source directory",SASMODELS_SOURCE_GPU,"was found") 
    219211 
    220212    if os.path.exists(SASMODELS_SOURCE_SESANS): 
    221         print "Found docs folder SASMODELS_SOURCE_SESANS at ", SASMODELS_SOURCE_SESANS 
     213        print("Found docs folder SASMODELS_SOURCE_SESANS at", SASMODELS_SOURCE_SESANS) 
    222214        if os.path.exists(SPHINX_SOURCE_USER): 
    223             print "Found docs folder SPHINX_SOURCE_USER      at ", SPHINX_SOURCE_USER 
    224             print "Copying sasmodels sesans files..." 
     215            print("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER) 
     216            print("Copying sasmodels sesans files...") 
    225217            for files in os.listdir(SASMODELS_SOURCE_SESANS): 
    226218                if files.endswith(".rst"): 
     
    228220                    tohere=os.path.join(SPHINX_SOURCE_USER,files) 
    229221                    shutil.copy(fromhere,tohere) 
     222    else: 
     223        print("no source directory",SASMODELS_SOURCE_SESANS,"was found") 
    230224 
    231225    if os.path.exists(SASMODELS_SOURCE_MAGNETISM): 
    232         print "Found docs folder SASMODELS_SOURCE_MAGNETISM at ", SASMODELS_SOURCE_MAGNETISM 
     226        print("Found docs folder SASMODELS_SOURCE_MAGNETISM at", SASMODELS_SOURCE_MAGNETISM) 
    233227        if os.path.exists(SASMODELS_DEST_REF_MODELS): 
    234             print "Found docs folder SASMODELS_DEST_REF_MODELS   at ", SASMODELS_DEST_REF_MODELS 
    235             print "Copying sasmodels model toctree files..." 
     228            print("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS) 
     229            print("Copying sasmodels model toctree files...") 
    236230            for files in os.listdir(SASMODELS_SOURCE_MAGNETISM): 
    237231                if files.endswith(".rst"): 
     
    239233                    tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 
    240234                    shutil.copy(fromhere,tohere) 
     235    else: 
     236        print("no source directory",SASMODELS_SOURCE_MAGNETISM,"was found") 
    241237 
    242238    if os.path.exists(SASMODELS_SOURCE_MAGIMG): 
    243         print "Found img folder SASMODELS_SOURCE_MAGIMG   at ", SASMODELS_SOURCE_MAGIMG 
     239        print("Found img folder SASMODELS_SOURCE_MAGIMG   at", SASMODELS_SOURCE_MAGIMG) 
    244240        if not os.path.exists(SASMODELS_DEST_MAGIMG): 
    245             print "Missing img folder SASMODELS_DEST_MAGIMG at ", SASMODELS_DEST_MAGIMG 
     241            print("Missing img folder SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG) 
    246242            os.makedirs(SASMODELS_DEST_MAGIMG) 
    247             print "created SASMODELS_DEST_MAGIMG at ", SASMODELS_DEST_MAGIMG 
    248         print "Copying sasmodels mag image files..." 
     243            print("created SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG) 
     244        print("Copying sasmodels mag image files...") 
    249245        for files in os.listdir(SASMODELS_SOURCE_MAGIMG): 
    250246            fromhere=os.path.join(SASMODELS_SOURCE_MAGIMG,files) 
    251247            tohere=os.path.join(SASMODELS_DEST_MAGIMG,files) 
    252248            shutil.copy(fromhere,tohere) 
    253     else: print "no source directory",SASMODELS_SOURCE_MAGIMG ,"was found" 
     249    else: 
     250        print("no source directory",SASMODELS_SOURCE_MAGIMG ,"was found") 
    254251 
    255252    if os.path.exists(SASMODELS_SOURCE_SESANSIMG): 
    256         print "Found img folder SASMODELS_SOURCE_SESANSIMG   at ", SASMODELS_SOURCE_SESANSIMG 
     253        print("Found img folder SASMODELS_SOURCE_SESANSIMG at", SASMODELS_SOURCE_SESANSIMG) 
    257254        if not os.path.exists(SASMODELS_DEST_SESANSIMG): 
    258             print "Missing img folder SASMODELS_DEST_SESANSIMG at ", SASMODELS_DEST_SESANSIMG 
     255            print("Missing img folder SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG) 
    259256            os.makedirs(SASMODELS_DEST_SESANSIMG) 
    260             print "created SASMODELS_DEST_SESANSIMG at ", SASMODELS_DEST_SESANSIMG 
    261         print "Copying sasmodels sesans image files..." 
     257            print("created SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG) 
     258        print("Copying sasmodels sesans image files...") 
    262259        for files in os.listdir(SASMODELS_SOURCE_SESANSIMG): 
    263260            fromhere=os.path.join(SASMODELS_SOURCE_SESANSIMG,files) 
    264261            tohere=os.path.join(SASMODELS_DEST_SESANSIMG,files) 
    265262            shutil.copy(fromhere,tohere) 
    266     else: print "no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found" 
     263    else: 
     264        print("no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found") 
    267265 
    268266    if os.path.exists(SASMODELS_SOURCE_REF_MODELS): 
    269         print "Found docs folder SASMODELS_SOURCE_REF_MODELS at ", SASMODELS_SOURCE_REF_MODELS 
     267        print("Found docs folder SASMODELS_SOURCE_REF_MODELS at", SASMODELS_SOURCE_REF_MODELS) 
    270268        if os.path.exists(SASMODELS_DEST_REF_MODELS): 
    271             print "Found docs folder SASMODELS_DEST_REF_MODELS   at ", SASMODELS_DEST_REF_MODELS 
    272             print "Copying sasmodels model toctree files..." 
     269            print("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS) 
     270            print("Copying sasmodels model toctree files...") 
    273271            for files in os.listdir(SASMODELS_SOURCE_REF_MODELS): 
    274272                if files.endswith(".rst"): 
     
    276274                    tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 
    277275                    shutil.copy(fromhere,tohere) 
    278     # But need to change the path to the model docs in the tocs 
    279     for files in os.listdir(SASMODELS_DEST_REF_MODELS): 
    280 #        print files 
    281         if files.startswith("shape"): 
    282             print "Changing toc paths in", files 
    283             inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
    284         if files.startswith("sphere"): 
    285             print "Changing toc paths in", files 
    286             inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
    287         if files.startswith("custom"): 
    288             print "Changing toc paths in", files 
    289             inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
    290         if files.startswith("structure"): 
    291             print "Changing toc paths in", files 
    292             inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
     276            # But need to change the path to the model docs in the tocs 
     277            for files in os.listdir(SASMODELS_DEST_REF_MODELS): 
     278        #        print files 
     279                if files.startswith("shape"): 
     280                    print("Changing toc paths in", files) 
     281                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
     282                if files.startswith("sphere"): 
     283                    print("Changing toc paths in", files) 
     284                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
     285                if files.startswith("custom"): 
     286                    print("Changing toc paths in", files) 
     287                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
     288                if files.startswith("structure"): 
     289                    print("Changing toc paths in", files) 
     290                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 
     291    else: 
     292        print("no source directory",SASMODELS_SOURCE_REF_MODELS," was found") 
    293293 
    294294    if os.path.exists(SASMODELS_SOURCE_MODELS): 
    295         print "Found docs folder SASMODELS_SOURCE_MODELS at ", SASMODELS_SOURCE_MODELS 
     295        print("Found docs folder SASMODELS_SOURCE_MODELS at", SASMODELS_SOURCE_MODELS) 
    296296        if os.path.exists(SASMODELS_DEST_MODELS): 
    297             print "Found docs folder SASMODELS_DEST_MODELS   at ", SASMODELS_DEST_MODELS 
    298             print "Copying sasmodels model files..." 
     297            print("Found docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS) 
     298            print("Copying sasmodels model files...") 
    299299            for files in os.listdir(SASMODELS_SOURCE_MODELS): 
    300300                if files.endswith(".rst"): 
     
    303303                    shutil.copy(fromhere,tohere) 
    304304        else: 
    305             print "Missing docs folder SASMODELS_DEST_MODELS at ", SASMODELS_DEST_MODELS 
     305            print("Missing docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS) 
    306306            os.makedirs(SASMODELS_DEST_MODELS) 
    307307            if not os.path.exists(SASMODELS_DEST_BUILDIMG): 
    308308                os.makedirs(SASMODELS_DEST_BUILDIMG) 
    309             print "Created docs folder SASMODELS_DEST_MODELS at ", SASMODELS_DEST_MODELS 
    310             print "Copying model files for build..." 
     309            print("Created docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS) 
     310            print("Copying model files for build...") 
    311311            for files in os.listdir(SASMODELS_SOURCE_MODELS): 
    312312                if files.endswith(".rst"): 
     
    315315                    shutil.copy(fromhere,tohere) 
    316316            # No choice but to do this because model files are all coded for images in /models/img 
    317             print "Copying image files for build..." 
     317            print("Copying image files for build...") 
    318318            for files in os.listdir(SASMODELS_DEST_IMG): 
    319319                fromhere=os.path.join(SASMODELS_DEST_IMG,files) 
    320320                tohere=os.path.join(SASMODELS_DEST_BUILDIMG,files) 
    321321                shutil.copy(fromhere,tohere) 
     322    else: 
     323        print("no source directory",SASMODELS_SOURCE_MODELS,"was found.") 
     324        print("!!!!NO MODEL DOCS WILL BE BUILT!!!!") 
    322325 
    323326 
     
    327330    """ 
    328331    if os.path.exists(BUMPS_DOCS): 
    329         print "=== Retrieve BUMPS Docs ===" 
     332        print("=== Retrieve BUMPS Docs ===") 
    330333        filenames = [os.path.join(BUMPS_DOCS, "optimizer.rst")] 
    331334        filenames += glob(os.path.join(BUMPS_DOCS, "dream-*.png")) 
    332335        filenames += glob(os.path.join(BUMPS_DOCS, "fit-*.png")) 
    333336        for f in filenames: 
    334             print "Copying file", f 
     337            print("Copying file", f) 
    335338            shutil.copy(f, BUMPS_TARGET) 
    336339    else: 
    337         print """ 
    338 *** Error *** missing directory %s 
     340        print(""" 
     341======= Error ======= 
     342missing directory %s 
    339343The documentation will not include the optimizer selection section. 
    340344Checkout the bumps source tree and rebuild the docs. 
    341  
    342  
    343 """ % BUMPS_DOCS 
     345""" % BUMPS_DOCS) 
    344346 
    345347def apidoc(): 
     
    348350    in the SasView build directory. 
    349351    """ 
    350     print "=== Generate API Rest Files ===" 
     352    print("=== Generate API Rest Files ===") 
    351353 
    352354    # Clean directory before generating a new version. 
     
    362364    Runs sphinx-build.  Reads in all .rst files and spits out the final html. 
    363365    """ 
    364     print "=== Build HTML Docs from Rest Files ===" 
     366    print("=== Build HTML Docs from Rest Files ===") 
    365367    subprocess.call(["sphinx-build", 
    366368                     "-b", "html", # Builder name. TODO: accept as arg to setup.py. 
     
    369371                     os.path.join(SPHINX_BUILD, "html")]) 
    370372 
    371     print "=== Copy HTML Docs to Build Directory ===" 
     373    print("=== Copy HTML Docs to Build Directory ===") 
    372374    html = os.path.join(SPHINX_BUILD, "html") 
    373375    copy_tree(html, SASVIEW_DOCS) 
     
    381383    build() 
    382384 
    383     print "=== Done ===" 
     385    print("=== Done ===") 
    384386 
    385387if __name__ == "__main__": 
  • run.py

    r64ca561 rf36e01f  
     1# -*- coding: utf-8 -*- 
    12#!/usr/bin/env python 
     3 
    24""" 
    35Run sasview in place.  This allows sasview to use the python 
     
    1416""" 
    1517 
     18import imp 
    1619import os 
    1720import sys 
    18 import imp 
    19 import logging 
    20 import logging.config 
    21  
    2221from contextlib import contextmanager 
    23 from os.path import abspath, dirname, join as joinpath 
     22from os.path import join as joinpath 
     23from os.path import abspath, dirname 
    2424 
    2525 
    26 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 
    27 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 
    28 logger = logging.getLogger(__name__) 
    29  
    30 def update_all_logs_to_debug(logger): 
    31     ''' 
    32     This updates all loggers and respective handlers to DEBUG 
    33     ''' 
    34     for handler in logger.handlers or logger.parent.handlers: 
    35         handler.setLevel(logging.DEBUG) 
    36     for name,_ in logging.Logger.manager.loggerDict.items(): 
    37         logging.getLogger(name).setLevel(logging.DEBUG) 
    38          
    3926def addpath(path): 
    4027    """ 
     
    5037    sys.path.insert(0, path) 
    5138 
     39 
    5240@contextmanager 
    5341def cd(path): 
     
    6048    os.chdir(old_dir) 
    6149 
     50 
    6251def import_package(modname, path): 
    6352    """Import a package into a particular point in the python namespace""" 
    64     mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
     53    mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py'))) 
    6554    sys.modules[modname] = mod 
    6655    mod.__path__ = [abspath(path)] 
    6756    return mod 
     57 
    6858 
    6959def import_dll(modname, build_path): 
     
    7262    ext = sysconfig.get_config_var('SO') 
    7363    # build_path comes from context 
    74     path = joinpath(build_path, *modname.split('.'))+ext 
    75     #print "importing", modname, "from", path 
     64    path = joinpath(build_path, *modname.split('.')) + ext 
     65    # print "importing", modname, "from", path 
    7666    return imp.load_dynamic(modname, path) 
     67 
    7768 
    7869def prepare(): 
     
    8677    from distutils.util import get_platform 
    8778    root = abspath(dirname(__file__)) 
    88     platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    89     build_path = joinpath(root, 'build','lib.'+platform) 
     79    platform = '%s-%s' % (get_platform(), sys.version[:3]) 
     80    build_path = joinpath(root, 'build', 'lib.' + platform) 
    9081 
    9182    # Notify the help menu that the Sphinx documentation is in a different 
     
    9889    #if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
    9990    #import matplotlib 
    100     #matplotlib.use('Agg') 
    101     #print matplotlib.__file__ 
     91    # matplotlib.use('Agg') 
     92    # print matplotlib.__file__ 
    10293    #import pylab; pylab.hold(False) 
    10394    # add periodictable to the path 
    104     try: import periodictable 
    105     except: addpath(joinpath(root, '..','periodictable')) 
     95    try: 
     96        import periodictable 
     97    except: 
     98        addpath(joinpath(root, '..', 'periodictable')) 
    10699 
    107     try: import bumps 
    108     except: addpath(joinpath(root, '..','bumps')) 
     100    try: 
     101        import bumps 
     102    except: 
     103        addpath(joinpath(root, '..', 'bumps')) 
    109104 
    110105    # select wx version 
     
    126121    # be better to just store the package in src/sas/sasview. 
    127122    import sas 
    128     sas.sasview = import_package('sas.sasview', joinpath(root,'sasview')) 
     123    sas.sasview = import_package('sas.sasview', joinpath(root, 'sasview')) 
    129124 
    130125    # The sas.models package Compiled Model files should be pulled in from the build directory even though 
     
    135130    import sas.sascalc.pr 
    136131    sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 
    137                                   joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
     132                                         joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
    138133 
    139134    # Compiled modules need to be pulled from the build directory. 
     
    141136    import sas.sascalc.file_converter 
    142137    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 
    143                                   joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                     
     138                                                     joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core')) 
    144139 
    145140    # Compiled modules need to be pulled from the build directory. 
     
    147142    import sas.sascalc.calculator 
    148143    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 
    149                                   joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
     144                                                 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
    150145 
    151146    sys.path.append(build_path) 
    152147 
    153     #print "\n".join(sys.path) 
     148    # print "\n".join(sys.path) 
     149 
    154150 
    155151if __name__ == "__main__": 
    156     update_all_logs_to_debug(logger) 
     152    # Need to add absolute path before actual prepare call, 
     153    # so logging can be done during initialization process too 
     154    root = abspath(dirname(__file__)) 
     155    addpath(joinpath(root, 'sasview')) 
     156    from logger_config import SetupLogger 
     157    logger = SetupLogger(__name__).config_development() 
     158 
     159    logger.debug("Starting SASVIEW in debug mode.") 
    157160    prepare() 
    158161    from sas.sasview.sasview import run 
    159162    run() 
    160      
     163    logger.debug("Ending SASVIEW in debug mode.") 
  • sasview/logging.ini

    r64ca561 rfc22533  
    1616 
    1717[formatter_detailed] 
    18 format=%(asctime)s:%(name)s:%(levelname)s: %(lineno)d: %(message)s 
     18#format=%(asctime)s : %(levelname)s : %(name)s: %(lineno)d: %(message)s 
     19format=%(asctime)s : %(levelname)s : %(name)s (%(filename)s:%(lineno)s) :: %(message)s 
    1920 
    2021############################################################################### 
     
    2728class=logging.StreamHandler 
    2829formatter=simple 
    29 level=INFO 
     30level=WARNING 
    3031args=tuple() 
    3132 
    3233[handler_log_file] 
    3334class=logging.FileHandler 
    34 level=INFO 
     35level=DEBUG 
    3536formatter=detailed 
    3637args=(os.path.join(os.path.expanduser("~"),'sasview.log'),"a") 
     
    4344 
    4445[logger_root] 
    45 level=INFO 
     46level=DEBUG 
    4647formatter=default 
    4748handlers=console,log_file 
     
    6061 
    6162[logger_sasgui] 
    62 level=INFO 
     63level=DEBUG 
    6364qualname=sas.sasgui 
    6465handlers=console,log_file 
  • sasview/sasview.py

    r3608cd1 rf36e01f  
     1# -*- coding: utf-8 -*- 
    12""" 
    23Base module for loading and running the main SasView application. 
    34""" 
    45################################################################################ 
    5 #This software was developed by the University of Tennessee as part of the 
    6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation. 
     6# This software was developed by the University of Tennessee as part of the 
     7# Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     8# project funded by the US National Science Foundation. 
    89# 
    9 #See the license text in license.txt 
     10# See the license text in license.txt 
    1011# 
    11 #copyright 2009, University of Tennessee 
     12# copyright 2009, University of Tennessee 
    1213################################################################################ 
    1314import os 
     15import os.path 
    1416import sys 
    15 import logging 
    16 import logging.config 
    1717import traceback 
    1818 
    19 logger = logging.getLogger(__name__) 
    20 if not logger.root.handlers: 
    21     LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini') 
    22     logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False) 
    23     logging.captureWarnings(True) 
     19from sas.sasview.logger_config import SetupLogger 
     20 
     21logger = SetupLogger(__name__).config_production() 
     22 
    2423 
    2524# Log the start of the session 
     
    5554import wxcruft 
    5655wxcruft.call_later_fix() 
    57 #wxcruft.trace_new_id() 
     56# wxcruft.trace_new_id() 
    5857 
    59 #Always use private .matplotlib setup to avoid conflicts with other 
    60 #uses of matplotlib 
    61 #Have to check if .sasview exists first 
     58# Always use private .matplotlib setup to avoid conflicts with other 
     59# uses of matplotlib 
     60# Have to check if .sasview exists first 
    6261sasdir = os.path.join(os.path.expanduser("~"),'.sasview') 
    6362if not os.path.exists(sasdir): 
     
    7271from sas.sasgui.guiframe.gui_style import GUIFRAME 
    7372from welcome_panel import WelcomePanel 
    74 # For py2exe, import config here 
    75 import local_config 
     73 
    7674PLUGIN_MODEL_DIR = 'plugin_models' 
    7775APP_NAME = 'SasView' 
     
    8785        """ 
    8886        """ 
    89         #from gui_manager import ViewApp 
     87        # from gui_manager import ViewApp 
    9088        self.gui = gui_manager.SasViewApp(0) 
    9189        # Set the application manager for the GUI 
     
    116114            logger.error(traceback.format_exc()) 
    117115 
    118         #Invariant perspective 
     116        # Invariant perspective 
    119117        try: 
    120118            import sas.sasgui.perspectives.invariant as module 
     
    134132            logger.error("Unable to load corfunc module") 
    135133 
    136         #Calculator perspective 
     134        # Calculator perspective 
    137135        try: 
    138136            import sas.sasgui.perspectives.calculator as module 
     
    153151                                                        APP_NAME) 
    154152            logger.error(traceback.format_exc()) 
    155  
    156153 
    157154        # Add welcome page 
     
    174171    if len(sys.argv) > 1: 
    175172        ## Run sasview as an interactive python interpreter 
    176         #if sys.argv[1] == "-i": 
     173        # if sys.argv[1] == "-i": 
    177174        #    sys.argv = ["ipython", "--pylab"] 
    178175        #    from IPython import start_ipython 
     
    188185        SasView() 
    189186 
     187 
    190188if __name__ == "__main__": 
    191189    run() 
  • sasview/setup_exe.py

    r8b645cc rf36e01f  
    6262        sys.argv.remove('--extrapath') 
    6363except: 
    64     print "Error processing extra python path needed to build SasView\n  %s" % \ 
    65                 sys.exc_value 
     64    print("Error processing extra python path needed to build SasView\n  %s" % \ 
     65                sys.exc_value) 
    6666 
    6767 
     
    8383        modulefinder.AddPackagePath(win32_folder, p) 
    8484    for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol", 
    85                     "win32com.axscript", "win32com.bits", "win32com.ifilter", 
    86                     "win32com.internet", "win32com.mapi", "win32com.propsys", 
    87                     "win32com.taskscheduler"]: 
    88          
    89             __import__(extra) 
    90             m = sys.modules[extra] 
    91             for p in m.__path__[1:]: 
    92                 modulefinder.AddPackagePath(extra, p) 
     85                  "win32com.axscript", "win32com.bits", "win32com.ifilter", 
     86                  "win32com.internet", "win32com.mapi", "win32com.propsys", 
     87                  "win32com.taskscheduler"]: 
     88        __import__(extra) 
     89        m = sys.modules[extra] 
     90        for p in m.__path__[1:]: 
     91            modulefinder.AddPackagePath(extra, p) 
    9392 
    9493except ImportError: 
     
    167166        self.copyright = "copyright 2009 - 2016" 
    168167        self.name = "SasView" 
    169          
     168 
    170169# 
    171170# Adapted from http://www.py2exe.org/index.cgi/MatPlotLib 
     
    236235    data_files.append(('config', [f])) 
    237236f = 'local_config.py' 
     237if os.path.isfile(f): 
     238    data_files.append(('.', [f])) 
     239 
     240f = 'logging.ini' 
    238241if os.path.isfile(f): 
    239242    data_files.append(('.', [f])) 
     
    337340    ]) 
    338341packages.append('periodictable.core') # not found automatically 
    339 #packages.append('IPython') 
     342# packages.append('IPython') 
    340343includes = ['site', 'lxml._elementpath', 'lxml.etree'] 
    341344 
     
    370373    other_resources = [(24, 1, manifest)], 
    371374    dest_base = "SasView" 
    372     ) 
     375) 
    373376 
    374377# bundle_option = 2 
  • sasview/setup_mac.py

    r235f514 rb854587  
    5050#CANSAxml reader data files 
    5151RESOURCES_FILES.append(os.path.join(sas.sascalc.dataloader.readers.get_data_path(),'defaults.json')) 
     52 
     53DATA_FILES.append('logging.ini') 
    5254 
    5355# Locate libxml2 library 
  • setup.py

    rf3bf622 rb854587  
     1# -*- coding: utf-8 -*- 
     2#!/usr/bin/env python 
     3 
    14""" 
    25    Setup for SasView 
    3     #TODO: Add checks to see that all the dependencies are on the system 
     6    TODO: Add checks to see that all the dependencies are on the system 
    47""" 
     8 
     9import os 
     10import subprocess 
     11import shutil 
    512import sys 
    6 import os 
    7 import shutil 
    8 from setuptools import setup, Extension 
    913from distutils.command.build_ext import build_ext 
    1014from distutils.core import Command 
     15 
    1116import numpy as np 
     17from setuptools import Extension, setup 
    1218 
    1319# Manage version number ###################################### 
    1420import sasview 
     21 
    1522VERSION = sasview.__version__ 
    1623############################################################## 
     
    2532# except when there is no such file 
    2633# Todo : make this list generic 
    27 #plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
     34# plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
    2835#                      'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', 
    2936#                      'testmodel_2.py', 'testmodel.py', 
     
    3542SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build") 
    3643 
    37 sas_dir = os.path.join(os.path.expanduser("~"),'.sasview') 
     44sas_dir = os.path.join(os.path.expanduser("~"), '.sasview') 
    3845if os.path.isdir(sas_dir): 
    3946    f_path = os.path.join(sas_dir, "sasview.log") 
     
    4754        os.remove(f_path) 
    4855    #f_path = os.path.join(sas_dir, 'plugin_models') 
    49     #if os.path.isdir(f_path): 
     56    # if os.path.isdir(f_path): 
    5057    #     for f in os.listdir(f_path): 
    5158    #         if f in plugin_model_list: 
     
    5360    #             os.remove(file_path) 
    5461    if os.path.exists(SASVIEW_BUILD): 
    55         print("Removing existing build directory", SASVIEW_BUILD, "for a clean build") 
     62        print("Removing existing build directory", 
     63              SASVIEW_BUILD, "for a clean build") 
    5664        shutil.rmtree(SASVIEW_BUILD) 
    5765 
     
    6371enable_openmp = False 
    6472 
    65 if sys.platform =='darwin': 
     73if sys.platform == 'darwin': 
    6674    if not is_64bits: 
    6775        # Disable OpenMP 
     
    7785 
    7886# Options to enable OpenMP 
    79 copt =  {'msvc': ['/openmp'], 
    80          'mingw32' : ['-fopenmp'], 
    81          'unix' : ['-fopenmp']} 
    82 lopt =  {'msvc': ['/MANIFEST'], 
    83          'mingw32' : ['-fopenmp'], 
    84          'unix' : ['-lgomp']} 
     87copt = {'msvc': ['/openmp'], 
     88        'mingw32': ['-fopenmp'], 
     89        'unix': ['-fopenmp']} 
     90lopt = {'msvc': ['/MANIFEST'], 
     91        'mingw32': ['-fopenmp'], 
     92        'unix': ['-lgomp']} 
    8593 
    8694# Platform-specific link options 
    87 platform_lopt = {'msvc' : ['/MANIFEST']} 
     95platform_lopt = {'msvc': ['/MANIFEST']} 
    8896platform_copt = {} 
    8997 
    9098# Set copts to get compile working on OS X >= 10.9 using clang 
    91 if sys.platform =='darwin': 
     99if sys.platform == 'darwin': 
    92100    try: 
    93101        darwin_ver = int(os.uname()[2].split('.')[0]) 
    94102        if darwin_ver >= 13 and darwin_ver < 14: 
    95             platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']} 
     103            platform_copt = { 
     104                'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']} 
    96105    except: 
    97106        print("PROBLEM determining Darwin version") 
     107 
    98108 
    99109class DisableOpenMPCommand(Command): 
     
    114124        pass 
    115125 
    116 class build_ext_subclass( build_ext ): 
     126 
     127class build_ext_subclass(build_ext): 
    117128    def build_extensions(self): 
    118129        # Get 64-bitness 
     
    124135            if c in copt: 
    125136                for e in self.extensions: 
    126                     e.extra_compile_args = copt[ c ] 
     137                    e.extra_compile_args = copt[c] 
    127138            if c in lopt: 
    128139                for e in self.extensions: 
    129                     e.extra_link_args = lopt[ c ] 
     140                    e.extra_link_args = lopt[c] 
    130141 
    131142        # Platform-specific build options 
    132143        if c in platform_lopt: 
    133144            for e in self.extensions: 
    134                 e.extra_link_args = platform_lopt[ c ] 
     145                e.extra_link_args = platform_lopt[c] 
    135146 
    136147        if c in platform_copt: 
    137148            for e in self.extensions: 
    138                 e.extra_compile_args = platform_copt[ c ] 
    139  
     149                e.extra_compile_args = platform_copt[c] 
    140150 
    141151        build_ext.build_extensions(self) 
     152 
    142153 
    143154class BuildSphinxCommand(Command): 
     
    152163 
    153164    def run(self): 
     165        ''' First builds the sasmodels documentation if the directory 
     166        is present. Then builds the sasview docs. 
     167        ''' 
     168        ### AJJ - Add code for building sasmodels docs here: 
     169        # check for doc path 
     170        SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc')) 
     171        print("========= check for sasmodels at", SASMODELS_DOCPATH, "============") 
     172        if os.path.exists(SASMODELS_DOCPATH): 
     173            if os.path.isdir(SASMODELS_DOCPATH): 
     174                # if available, build sasmodels docs 
     175                print("============= Building sasmodels model documentation ===============") 
     176                smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"]) 
     177        else: 
     178            # if not available warning message 
     179            print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==") 
     180 
     181        #Now build sasview (+sasmodels) docs 
    154182        sys.path.append("docs/sphinx-docs") 
    155183        import build_sphinx 
    156184        build_sphinx.rebuild() 
    157185 
     186 
    158187# sas module 
    159188package_dir["sas"] = os.path.join("src", "sas") 
     
    169198 
    170199# sas.sascalc.invariant 
    171 package_dir["sas.sascalc.invariant"] = os.path.join("src", "sas", "sascalc", "invariant") 
     200package_dir["sas.sascalc.invariant"] = os.path.join( 
     201    "src", "sas", "sascalc", "invariant") 
    172202packages.extend(["sas.sascalc.invariant"]) 
    173203 
     
    175205guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe") 
    176206package_dir["sas.sasgui.guiframe"] = guiframe_path 
    177 package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives")) 
     207package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join( 
     208    os.path.join(guiframe_path, "local_perspectives")) 
    178209package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*'] 
    179 packages.extend(["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"]) 
     210packages.extend( 
     211    ["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"]) 
    180212# build local plugin 
    181213for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")): 
    182     if d not in ['.svn','__init__.py', '__init__.pyc']: 
     214    if d not in ['.svn', '__init__.py', '__init__.pyc']: 
    183215        package_name = "sas.sasgui.guiframe.local_perspectives." + d 
    184216        packages.append(package_name) 
    185         package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d) 
     217        package_dir[package_name] = os.path.join( 
     218            guiframe_path, "local_perspectives", d) 
    186219 
    187220# sas.sascalc.dataloader 
    188 package_dir["sas.sascalc.dataloader"] = os.path.join("src", "sas", "sascalc", "dataloader") 
    189 package_data["sas.sascalc.dataloader.readers"] = ['defaults.json','schema/*.xsd'] 
    190 packages.extend(["sas.sascalc.dataloader","sas.sascalc.dataloader.readers","sas.sascalc.dataloader.readers.schema"]) 
     221package_dir["sas.sascalc.dataloader"] = os.path.join( 
     222    "src", "sas", "sascalc", "dataloader") 
     223package_data["sas.sascalc.dataloader.readers"] = [ 
     224    'defaults.json', 'schema/*.xsd'] 
     225packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers", 
     226                 "sas.sascalc.dataloader.readers.schema"]) 
     227 
    191228 
    192229# sas.sascalc.calculator 
    193230gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") 
    194231package_dir["sas.sascalc.calculator.core"] = gen_dir 
    195 package_dir["sas.sascalc.calculator"] = os.path.join("src", "sas", "sascalc", "calculator") 
    196 packages.extend(["sas.sascalc.calculator","sas.sascalc.calculator.core"]) 
    197 ext_modules.append( Extension("sas.sascalc.calculator.core.sld2i", 
    198         sources = [ 
    199             os.path.join(gen_dir, "sld2i_module.cpp"), 
    200             os.path.join(gen_dir, "sld2i.cpp"), 
    201             os.path.join(gen_dir, "libfunc.c"), 
    202             os.path.join(gen_dir, "librefl.c"), 
    203         ], 
    204         include_dirs=[gen_dir], 
    205     ) 
    206 ) 
     232package_dir["sas.sascalc.calculator"] = os.path.join( 
     233    "src", "sas", "sascalc", "calculator") 
     234packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"]) 
     235ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i", 
     236                             sources=[ 
     237                                 os.path.join(gen_dir, "sld2i_module.cpp"), 
     238                                 os.path.join(gen_dir, "sld2i.cpp"), 
     239                                 os.path.join(gen_dir, "libfunc.c"), 
     240                                 os.path.join(gen_dir, "librefl.c"), 
     241                             ], 
     242                             include_dirs=[gen_dir], 
     243                             ) 
     244                   ) 
    207245 
    208246# sas.sascalc.pr 
    209 srcdir  = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 
     247srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 
    210248package_dir["sas.sascalc.pr.core"] = srcdir 
    211 package_dir["sas.sascalc.pr"] = os.path.join("src","sas", "sascalc", "pr") 
    212 packages.extend(["sas.sascalc.pr","sas.sascalc.pr.core"]) 
    213 ext_modules.append( Extension("sas.sascalc.pr.core.pr_inversion", 
    214                               sources = [os.path.join(srcdir, "Cinvertor.c"), 
    215                                          os.path.join(srcdir, "invertor.c"), 
    216                                          ], 
    217                               include_dirs=[], 
    218                               ) ) 
     249package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr") 
     250packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"]) 
     251ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion", 
     252                             sources=[os.path.join(srcdir, "Cinvertor.c"), 
     253                                      os.path.join(srcdir, "invertor.c"), 
     254                                      ], 
     255                             include_dirs=[], 
     256                             )) 
     257 
    219258 
    220259# sas.sascalc.file_converter 
    221260mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") 
    222261package_dir["sas.sascalc.file_converter.core"] = mydir 
    223 package_dir["sas.sascalc.file_converter"] = os.path.join("src","sas", "sascalc", "file_converter") 
    224 packages.extend(["sas.sascalc.file_converter","sas.sascalc.file_converter.core"]) 
    225 ext_modules.append( Extension("sas.sascalc.file_converter.core.bsl_loader", 
    226                               sources = [os.path.join(mydir, "bsl_loader.c")], 
    227                               include_dirs=[np.get_include()], 
    228                               ) ) 
    229  
    230 #sas.sascalc.corfunc 
    231 package_dir["sas.sascalc.corfunc"] = os.path.join("src", "sas", "sascalc", "corfunc") 
     262package_dir["sas.sascalc.file_converter"] = os.path.join( 
     263    "src", "sas", "sascalc", "file_converter") 
     264packages.extend(["sas.sascalc.file_converter", 
     265                 "sas.sascalc.file_converter.core"]) 
     266ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader", 
     267                             sources=[os.path.join(mydir, "bsl_loader.c")], 
     268                             include_dirs=[np.get_include()], 
     269                             )) 
     270 
     271# sas.sascalc.corfunc 
     272package_dir["sas.sascalc.corfunc"] = os.path.join( 
     273    "src", "sas", "sascalc", "corfunc") 
     274 
    232275packages.extend(["sas.sascalc.corfunc"]) 
    233276 
     
    237280 
    238281# Perspectives 
    239 package_dir["sas.sasgui.perspectives"] = os.path.join("src", "sas", "sasgui", "perspectives") 
    240 package_dir["sas.sasgui.perspectives.pr"] = os.path.join("src", "sas", "sasgui", "perspectives", "pr") 
    241 packages.extend(["sas.sasgui.perspectives","sas.sasgui.perspectives.pr"]) 
     282package_dir["sas.sasgui.perspectives"] = os.path.join( 
     283    "src", "sas", "sasgui", "perspectives") 
     284package_dir["sas.sasgui.perspectives.pr"] = os.path.join( 
     285    "src", "sas", "sasgui", "perspectives", "pr") 
     286packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"]) 
    242287package_data["sas.sasgui.perspectives.pr"] = ['media/*'] 
    243288 
    244 package_dir["sas.sasgui.perspectives.invariant"] = os.path.join("src", "sas", "sasgui", "perspectives", "invariant") 
     289package_dir["sas.sasgui.perspectives.invariant"] = os.path.join( 
     290    "src", "sas", "sasgui", "perspectives", "invariant") 
    245291packages.extend(["sas.sasgui.perspectives.invariant"]) 
    246 package_data['sas.sasgui.perspectives.invariant'] = [os.path.join("media",'*')] 
    247  
    248 package_dir["sas.sasgui.perspectives.fitting"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting") 
    249 package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting", "plugin_models") 
    250 packages.extend(["sas.sasgui.perspectives.fitting", "sas.sasgui.perspectives.fitting.plugin_models"]) 
    251 package_data['sas.sasgui.perspectives.fitting'] = ['media/*', 'plugin_models/*'] 
    252  
    253 packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"]) 
     292package_data['sas.sasgui.perspectives.invariant'] = [ 
     293    os.path.join("media", '*')] 
     294 
     295package_dir["sas.sasgui.perspectives.fitting"] = os.path.join( 
     296    "src", "sas", "sasgui", "perspectives", "fitting") 
     297package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join( 
     298    "src", "sas", "sasgui", "perspectives", "fitting", "plugin_models") 
     299packages.extend(["sas.sasgui.perspectives.fitting", 
     300                 "sas.sasgui.perspectives.fitting.plugin_models"]) 
     301package_data['sas.sasgui.perspectives.fitting'] = [ 
     302    'media/*', 'plugin_models/*'] 
     303 
     304packages.extend(["sas.sasgui.perspectives", 
     305                 "sas.sasgui.perspectives.calculator"]) 
    254306package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*'] 
    255307 
    256 package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join("src", "sas", "sasgui", "perspectives", "corfunc") 
     308package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join( 
     309    "src", "sas", "sasgui", "perspectives", "corfunc") 
    257310packages.extend(["sas.sasgui.perspectives.corfunc"]) 
    258311package_data['sas.sasgui.perspectives.corfunc'] = ['media/*'] 
    259312 
    260 package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join("src", "sas", "sasgui", "perspectives", "file_converter") 
     313package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join( 
     314    "src", "sas", "sasgui", "perspectives", "file_converter") 
    261315packages.extend(["sas.sasgui.perspectives.file_converter"]) 
    262316package_data['sas.sasgui.perspectives.file_converter'] = ['media/*'] 
    263317 
    264318# Data util 
    265 package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util") 
     319package_dir["sas.sascalc.data_util"] = os.path.join( 
     320    "src", "sas", "sascalc", "data_util") 
    266321packages.append("sas.sascalc.data_util") 
    267322 
    268323# Plottools 
    269 package_dir["sas.sasgui.plottools"] = os.path.join("src", "sas", "sasgui", "plottools") 
     324package_dir["sas.sasgui.plottools"] = os.path.join( 
     325    "src", "sas", "sasgui", "plottools") 
    270326packages.append("sas.sasgui.plottools") 
    271327 
     
    275331 
    276332EXTENSIONS = [".c", ".cpp"] 
     333 
    277334 
    278335def append_file(file_list, dir_path): 
     
    294351                        file_list.append(os.path.join(sub_dir, new_f)) 
    295352 
     353 
    296354# Comment out the following to avoid rebuilding all the models 
    297355file_sources = [] 
    298356append_file(file_sources, gen_dir) 
    299357 
    300 #Wojtek's hacky way to add doc files while bundling egg 
    301 #def add_doc_files(directory): 
     358# Wojtek's hacky way to add doc files while bundling egg 
     359# def add_doc_files(directory): 
    302360#    paths = [] 
    303361#    for (path, directories, filenames) in os.walk(directory): 
     
    312370package_data['sas.sasview'] = ['images/*', 
    313371                               'media/*', 
     372                               'logging.ini', 
    314373                               'test/*.txt', 
    315374                               'test/1d_data/*', 
     
    331390    'lxml', 'h5py', 
    332391 
    333     ## The following dependecies won't install automatically, so assume them 
    334     ## The numbers should be bumped up for matplotlib and wxPython as well. 
     392    # The following dependecies won't install automatically, so assume them 
     393    # The numbers should be bumped up for matplotlib and wxPython as well. 
    335394    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1', 
    336395    # 'wxPython>=2.8.11', 'pil', 
    337     ] 
    338  
    339 if os.name=='nt': 
     396] 
     397 
     398if os.name == 'nt': 
    340399    required.extend(['html5lib', 'reportlab']) 
    341400else: 
     
    346405setup( 
    347406    name="sasview", 
    348     version = VERSION, 
    349     description = "SasView application", 
    350     author = "SasView Team", 
    351     author_email = "developers@sasview.org", 
    352     url = "http://sasview.org", 
    353     license = "PSF", 
    354     keywords = "small-angle x-ray and neutron scattering analysis", 
    355     download_url = "https://github.com/SasView/sasview.git", 
    356     package_dir = package_dir, 
    357     packages = packages, 
    358     package_data = package_data, 
    359     ext_modules = ext_modules, 
    360     install_requires = required, 
    361     zip_safe = False, 
    362     entry_points = { 
    363                     'console_scripts':[ 
    364                                        "sasview = sas.sasview.sasview:run", 
    365                                        ] 
    366                     }, 
    367     cmdclass = {'build_ext': build_ext_subclass, 
    368                 'docs': BuildSphinxCommand, 
    369                 'disable_openmp': DisableOpenMPCommand} 
    370     ) 
     407    version=VERSION, 
     408    description="SasView application", 
     409    author="SasView Team", 
     410    author_email="developers@sasview.org", 
     411    url="http://sasview.org", 
     412    license="PSF", 
     413    keywords="small-angle x-ray and neutron scattering analysis", 
     414    download_url="https://github.com/SasView/sasview.git", 
     415    package_dir=package_dir, 
     416    packages=packages, 
     417    package_data=package_data, 
     418    ext_modules=ext_modules, 
     419    install_requires=required, 
     420    zip_safe=False, 
     421    entry_points={ 
     422        'console_scripts': [ 
     423            "sasview = sas.sasview.sasview:run", 
     424        ] 
     425    }, 
     426    cmdclass={'build_ext': build_ext_subclass, 
     427              'docs': BuildSphinxCommand, 
     428              'disable_openmp': DisableOpenMPCommand} 
     429) 
  • src/sas/sasgui/guiframe/gui_manager.py

    r49165488 r38beeab  
    7777    # clean all these module variables and put them into a config class 
    7878    # that can be passed by sasview.py. 
    79     logger.info(sys.executable) 
    80     logger.info(str(sys.argv)) 
     79    logger.debug(sys.executable) 
     80    logger.debug(str(sys.argv)) 
    8181    from sas import sasview as sasview 
    8282    app_path = os.path.dirname(sasview.__file__) 
    83     logger.info("Using application path: %s", app_path) 
     83    logger.debug("Using application path: %s", app_path) 
    8484    return app_path 
    8585 
     
    109109        if fObj is not None: 
    110110            fObj.close() 
    111     logger.info("GuiManager loaded %s/%s" % (path, file)) 
     111    logger.debug("GuiManager loaded %s/%s" % (path, file)) 
    112112    return config_module 
    113113 
     
    126126        # Didn't find local config, load the default 
    127127        import sas.sasgui.guiframe.config as config 
    128         logger.info("using default local_config") 
     128        logger.debug("using default local_config") 
    129129    else: 
    130         logger.info("found local_config in %s" % os.getcwd()) 
     130        logger.debug("found local_config in %s" % os.getcwd()) 
    131131else: 
    132     logger.info("found local_config in %s" % PATH_APP) 
     132    logger.debug("found local_config in %s" % PATH_APP) 
    133133 
    134134from sas.sasgui.guiframe.customdir import SetupCustom 
     
    139139    if custom_config is None: 
    140140        msgConfig = "Custom_config file was not imported" 
    141         logger.info(msgConfig) 
     141        logger.debug(msgConfig) 
    142142    else: 
    143         logger.info("using custom_config in %s" % os.getcwd()) 
     143        logger.debug("using custom_config in %s" % os.getcwd()) 
    144144else: 
    145     logger.info("using custom_config from %s" % c_conf_dir) 
     145    logger.debug("using custom_config from %s" % c_conf_dir) 
    146146 
    147147# read some constants from config 
     
    21562156        if response is not None: 
    21572157            try: 
    2158                 #  
    21592158                content = response.read().strip() 
    2160                 logger.info("Connected to www.sasview.org. Latest version: %s" 
    2161                              % (content)) 
     2159                logger.info("Connected to www.sasview.org. Latest version: %s", content) 
    21622160                version_info = json.loads(content) 
    21632161            except: 
  • src/sas/sasgui/perspectives/calculator/sld_panel.py

    r7432acb r2d220dd  
    6060        # Object that receive status event 
    6161        self.base = base 
    62         self.wavelength = WAVELENGTH 
     62        self.neutron_wavelength = WAVELENGTH 
     63        self.xray_source_input = WAVELENGTH 
    6364        self.parent = parent 
    6465        #layout attribute 
     
    6768        self.compound = "" 
    6869        self.density = "" 
    69         self.wavelength_ctl = None 
     70        self.neutron_wavelength_ctl = None 
     71        self.xray_source_input_ctl = None 
     72        self.xray_cbox = None 
    7073        self.neutron_sld_real_ctl = None 
    7174        self.neutron_sld_im_ctl = None 
    72         self.mo_ka_sld_real_ctl = None 
    73         self.mo_ka_sld_im_ctl = None 
    74         self.cu_ka_sld_real_ctl = None 
    75         self.cu_ka_sld_im_ctl = None 
     75        self.xray_sld_real_ctl = None 
     76        self.xray_sld_im_ctl = None 
    7677        self.neutron_abs_ctl = None 
    7778        self.neutron_inc_ctl = None 
    7879        self.neutron_length_ctl = None 
    7980        self.button_calculate = None 
     81        self.xray_source = None 
    8082        #Draw the panel 
    8183        self._do_layout() 
    8284        self.SetAutoLayout(True) 
    8385        self.Layout() 
     86        self.fill_xray_cbox() 
    8487 
    8588    def _do_layout(self): 
     
    108111        self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    109112        unit_density_txt = wx.StaticText(self, -1, unit_density) 
    110         wavelength_txt = wx.StaticText(self, -1, 'Wavelength ') 
    111         self.wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    112         self.wavelength_ctl.SetValue(str(self.wavelength)) 
    113         unit_a_txt = wx.StaticText(self, -1, unit_a) 
     113        neutron_wavelength_txt = wx.StaticText(self, -1, 'Neutron wavelength') 
     114        self.neutron_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     115        self.neutron_wavelength_ctl.SetValue(str(self.neutron_wavelength)) 
     116        self.xray_source_input_txt = wx.StaticText(self, -1, 'X-ray wavelength') 
     117        self.xray_source_input_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     118        self.xray_source_input_ctl.SetValue(str(self.xray_source_input)) 
     119        neutron_unit_a_txt = wx.StaticText(self, -1, unit_a) 
     120 
     121        self.xray_cbox = wx.ComboBox(self, -1, size=(70, 20), style=wx.CB_READONLY) 
     122        xray_cbox_tip = "Select an element, wavelength or energy" 
     123        self.xray_cbox.SetToolTipString(xray_cbox_tip) 
     124        wx.EVT_COMBOBOX(self.xray_cbox, -1, self.on_select_xray) 
     125 
    114126        iy = 0 
    115127        ix = 0 
     
    131143        iy += 1 
    132144        ix = 0 
    133         sizer_input.Add(wavelength_txt, (iy, ix), (1, 1), 
    134                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    135         ix += 1 
    136         sizer_input.Add(self.wavelength_ctl, (iy, ix), (1, 1), 
    137                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    138         ix += 1 
    139         sizer_input.Add(unit_a_txt, (iy, ix), (1, 1), 
     145        sizer_input.Add(neutron_wavelength_txt, (iy, ix), (1, 1), 
     146                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     147        ix += 1 
     148        sizer_input.Add(self.neutron_wavelength_ctl, (iy, ix), (1, 1), 
     149                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     150        ix += 1 
     151        sizer_input.Add(neutron_unit_a_txt, (iy, ix), (1, 1), 
     152                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     153        iy += 1 
     154        ix = 0 
     155        sizer_input.Add(self.xray_source_input_txt, (iy, ix), (1, 1), 
     156                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     157        ix += 1 
     158        sizer_input.Add(self.xray_source_input_ctl, (iy, ix), (1, 1), 
     159                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     160        ix += 1 
     161        sizer_input.Add(self.xray_cbox, (iy, ix), (1, 1), 
    140162                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    141163        boxsizer1.Add(sizer_input) 
     
    151173                                                 size=(_BOX_WIDTH, -1)) 
    152174        self.neutron_sld_real_ctl.SetEditable(False) 
    153         self.neutron_sld_real_ctl.SetToolTipString("Neutron SLD real.") 
     175        self.neutron_sld_real_ctl.SetToolTipString("Neutron SLD real") 
    154176        self.neutron_sld_im_ctl = wx.TextCtrl(self, -1, 
    155177                                              size=(_BOX_WIDTH, -1)) 
    156178        self.neutron_sld_im_ctl.SetEditable(False) 
    157         self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary.") 
     179        self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary") 
    158180        neutron_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    159181 
    160         cu_ka_sld_txt = wx.StaticText(self, -1, 'Cu Ka SLD') 
    161         self.cu_ka_sld_real_ctl = wx.TextCtrl(self, -1, 
     182        xray_sld_txt = wx.StaticText(self, -1, 'X-ray SLD') 
     183        self.xray_sld_real_ctl = wx.TextCtrl(self, -1, 
    162184                                               size=(_BOX_WIDTH, -1)) 
    163         self.cu_ka_sld_real_ctl.SetEditable(False) 
    164         self.cu_ka_sld_real_ctl.SetToolTipString("Cu Ka SLD real.") 
    165         self.cu_ka_sld_im_ctl = wx.TextCtrl(self, -1, 
     185        self.xray_sld_real_ctl.SetEditable(False) 
     186        self.xray_sld_real_ctl.SetToolTipString("X-ray SLD real") 
     187        self.xray_sld_im_ctl = wx.TextCtrl(self, -1, 
    166188                                            size=(_BOX_WIDTH, -1)) 
    167         self.cu_ka_sld_im_ctl.SetEditable(False) 
    168         self.cu_ka_sld_im_ctl.SetToolTipString("Cu Ka SLD imaginary.") 
    169         cu_ka_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    170  
    171         mo_ka_sld_txt = wx.StaticText(self, -1, 'Mo Ka SLD') 
    172         self.mo_ka_sld_real_ctl = wx.TextCtrl(self, -1, 
    173                                                size=(_BOX_WIDTH, -1)) 
    174         self.mo_ka_sld_real_ctl.SetEditable(False) 
    175         self.mo_ka_sld_real_ctl.SetToolTipString("Mo Ka SLD real.") 
    176         self.mo_ka_sld_im_ctl = wx.TextCtrl(self, -1, 
    177                                              size=(_BOX_WIDTH, -1)) 
    178         self.mo_ka_sld_im_ctl.SetEditable(False) 
    179         self.mo_ka_sld_im_ctl.SetToolTipString("Mo Ka SLD imaginary.") 
    180         mo_ka_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
     189        self.xray_sld_im_ctl.SetEditable(False) 
     190        self.xray_sld_im_ctl.SetToolTipString("X-ray SLD imaginary") 
     191        xray_sld_units_txt = wx.StaticText(self, -1, unit_sld) 
    181192 
    182193        neutron_inc_txt = wx.StaticText(self, -1, 'Neutron Inc. Xs') 
     
    219230        iy += 1 
    220231        ix = 0 
    221         sizer_output.Add(cu_ka_sld_txt, (iy, ix), (1, 1), 
    222                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    223         ix += 1 
    224         sizer_output.Add(self.cu_ka_sld_real_ctl, (iy, ix), (1, 1), 
     232        sizer_output.Add(xray_sld_txt, (iy, ix), (1, 1), 
     233                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     234        ix += 1 
     235        sizer_output.Add(self.xray_sld_real_ctl, (iy, ix), (1, 1), 
    225236                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    226237        ix += 1 
     
    228239                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    229240        ix += 1 
    230         sizer_output.Add(self.cu_ka_sld_im_ctl, 
     241        sizer_output.Add(self.xray_sld_im_ctl, 
    231242                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    232243        ix += 1 
    233         sizer_output.Add(cu_ka_sld_units_txt, 
    234                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    235         iy += 1 
    236         ix = 0 
    237         sizer_output.Add(mo_ka_sld_txt, (iy, ix), (1, 1), 
    238                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    239         ix += 1 
    240         sizer_output.Add(self.mo_ka_sld_real_ctl, (iy, ix), (1, 1), 
    241                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    242         ix += 1 
    243         sizer_output.Add(wx.StaticText(self, -1, i_complex), 
    244                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    245         ix += 1 
    246         sizer_output.Add(self.mo_ka_sld_im_ctl, 
    247                          (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    248         ix += 1 
    249         sizer_output.Add(mo_ka_sld_units_txt, 
     244        sizer_output.Add(xray_sld_units_txt, 
    250245                         (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    251246        iy += 1 
     
    310305        self.SetSizer(vbox) 
    311306 
     307    def fill_xray_cbox(self): 
     308        """ 
     309        fill the x-ray combobox with the sources 
     310        """ 
     311        source_list = ['[A]', '[keV]', 'Element'] 
     312        for source in source_list: 
     313            pos = self.xray_cbox.Append(str(source)) 
     314            self.xray_cbox.SetClientData(pos, str(source.strip())) 
     315        self.xray_cbox.SetSelection(0) 
     316        self.xray_source = source_list[0] 
     317 
     318    def on_select_xray(self, event=None): 
     319        """ 
     320        On Selecting a source 
     321        """ 
     322        item = event.GetEventObject() 
     323        self.xray_source = item.GetValue().strip() 
     324 
     325        if self.xray_source == "[A]": 
     326            self.xray_source_input_txt.SetLabel("X-ray wavelength") 
     327        elif self.xray_source == "[keV]": 
     328            self.xray_source_input_txt.SetLabel("X-ray energy") 
     329        elif self.xray_source == "Element": 
     330            self.xray_source_input_txt.SetLabel("X-ray source") 
     331 
    312332    def on_help(self, event): 
    313333        """ 
     
    363383            msg += "Error for Density value :expect float" 
    364384 
    365         self.wavelength = self.wavelength_ctl.GetValue() 
    366         if str(self.wavelength).lstrip().rstrip() == "": 
    367             self.wavelength = WAVELENGTH 
    368             self.wavelength_ctl.SetValue(str(WAVELENGTH)) 
    369             self.wavelength_ctl.SetBackgroundColour(wx.WHITE) 
    370             self.wavelength_ctl.Refresh() 
     385        self.neutron_wavelength = self.neutron_wavelength_ctl.GetValue() 
     386        self.xray_source_input = self.xray_source_input_ctl.GetValue() 
     387 
     388        if str(self.neutron_wavelength).lstrip().rstrip() == "": 
     389            self.neutron_wavelength = WAVELENGTH 
     390            self.neutron_wavelength_ctl.SetValue(str(WAVELENGTH)) 
     391            self.neutron_wavelength_ctl.SetBackgroundColour(wx.WHITE) 
     392            self.neutron_wavelength_ctl.Refresh() 
    371393            msg += "Default value for wavelength is 6.0" 
    372394        else: 
    373             if check_float(self.wavelength_ctl): 
    374                 self.wavelength = float(self.wavelength) 
     395            if check_float(self.neutron_wavelength_ctl): 
     396                self.neutron_wavelength = float(self.neutron_wavelength) 
    375397            else: 
    376398                flag = False 
    377399                msg += "Error for wavelength value :expect float" 
     400 
     401        if str(self.xray_source_input).lstrip().rstrip() == "": 
     402            self.xray_source_input = WAVELENGTH 
     403            self.xray_source_input_ctl.SetValue(str(WAVELENGTH)) 
     404            self.xray_source_input_ctl.SetBackgroundColour(wx.WHITE) 
     405            self.xray_source_input_ctl.Refresh() 
     406            msg += "Default value for wavelength is 6.0" 
     407        else: 
     408            if (self.xray_source == '[A]') or (self.xray_source == '[keV]'): 
     409                if check_float(self.xray_source_input_ctl): 
     410                    self.xray_source_input = float(self.xray_source_input) 
     411                else: 
     412                    flag = False 
     413                    msg += "Error for wavelength value :expect float" 
     414            elif (self.xray_source == 'Element'): 
     415                try: 
     416                    import periodictable 
     417                    exec("periodictable." + self.xray_source_input) 
     418                except AttributeError: 
     419                    flag = False 
     420                    msg += "X-ray element supplied isn't in the database" 
     421 
     422 
    378423 
    379424        self.compound = self.compound_ctl.GetValue().lstrip().rstrip() 
     
    410455        return xray_sld_from_atoms(atom, density=density, energy=energy) 
    411456 
    412  
    413457    def calculateSld(self, event): 
    414458        """ 
     
    430474                        length = neutron_scattering(compound=self.compound, 
    431475                                   density=self.density, 
    432                                    wavelength=self.wavelength) 
    433             cu_real, cu_im = self.calculate_sld_helper(element="Cu", 
    434                                                  density=self.density, 
    435                                         molecule_formula=self.sld_formula) 
    436             mo_real, mo_im = self.calculate_sld_helper(element="Mo", 
    437                                                        density=self.density, 
    438                                      molecule_formula=self.sld_formula) 
     476                                   wavelength=self.neutron_wavelength) 
     477            if self.xray_source == "[A]": 
     478                energy = xray_energy(self.xray_source_input) 
     479                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms, 
     480                                                         density=self.density, 
     481                                                         energy=energy) 
     482            elif self.xray_source == "[keV]": 
     483                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms, 
     484                                                         density=self.density, 
     485                                                         energy=self.xray_source_input) 
     486            elif self.xray_source == "Element": 
     487                xray_real, xray_im = self.calculate_sld_helper(element=self.xray_source_input, 
     488                                                               density=self.density, 
     489                                                               molecule_formula=self.sld_formula) 
    439490            # set neutron sld values 
    440491            val = format_number(sld_real * _SCALE) 
     
    443494            self.neutron_sld_im_ctl.SetValue(val) 
    444495            # Compute the Cu SLD 
    445             self.cu_ka_sld_real_ctl.SetValue(format_number(cu_real * _SCALE)) 
    446             val = format_number(math.fabs(cu_im) * _SCALE) 
    447             self.cu_ka_sld_im_ctl.SetValue(val) 
    448             # Compute the Mo SLD 
    449             self.mo_ka_sld_real_ctl.SetValue(format_number(mo_real * _SCALE)) 
    450             val = format_number(math.fabs(mo_im) * _SCALE) 
    451             self.mo_ka_sld_im_ctl.SetValue(val) 
     496            self.xray_sld_real_ctl.SetValue(format_number(xray_real * _SCALE)) 
     497            val = format_number(math.fabs(xray_im) * _SCALE) 
     498            self.xray_sld_im_ctl.SetValue(val) 
    452499            # set incoherence and absorption 
    453500            self.neutron_inc_ctl.SetValue(format_number(incoh)) 
     
    456503            self.neutron_length_ctl.SetValue(format_number(length)) 
    457504            # display wavelength 
    458             self.wavelength_ctl.SetValue(str(self.wavelength)) 
     505            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
     506            #self.wavelength_ctl.SetValue(str(self.wavelength)) 
    459507        except: 
    460508            if self.base is not None: 
     
    470518        self.neutron_sld_real_ctl.SetValue("") 
    471519        self.neutron_sld_im_ctl.SetValue("") 
    472         self.mo_ka_sld_real_ctl.SetValue("") 
    473         self.mo_ka_sld_im_ctl.SetValue("") 
    474         self.cu_ka_sld_real_ctl.SetValue("") 
    475         self.cu_ka_sld_im_ctl.SetValue("") 
     520        self.xray_sld_real_ctl.SetValue("") 
     521        self.xray_sld_im_ctl.SetValue("") 
    476522        self.neutron_abs_ctl.SetValue("") 
    477523        self.neutron_inc_ctl.SetValue("") 
Note: See TracChangeset for help on using the changeset viewer.