Changeset cc03f59 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Aug 5, 2016 4:00:40 AM (8 years ago)
Author:
lewis
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
28e2b3a
Parents:
2760662
Message:

Implement getters in python class

Location:
src/sas/sascalc/file_converter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/BSLLoader.py

    r2760662 rcc03f59  
    1111    # See invertor.py for implementation of pickling and setters/getters 
    1212 
    13     # def __setattr__(self, name, value): 
    14     #     # if name == 'param': 
    15     #     #     return self.set_param(value) 
    16     #     return CBSLLoader.__set_attr__(self, name, value) 
     13    def __setattr__(self, name, value): 
     14        if name == 'filename': 
     15            return self.set_filename(value) 
     16        elif name == 'frame': 
     17            return self.set_frame(value) 
     18        elif name == 'n_pixels': 
     19            return self.set_n_pixels(value) 
     20        elif name == 'n_rasters': 
     21            return self.set_n_rasters(value) 
     22        return CBSLLoader.__set_attr__(self, name, value) 
    1723 
    1824    def __getattr__(self, name): 
  • src/sas/sascalc/file_converter/c_ext/bsl_loader.c

    r2760662 rcc03f59  
    5757} 
    5858 
     59static PyObject *set_filename(CLoader *self, PyObject *args) { 
     60    const char *new_filename; 
     61    if (!PyArg_ParseTuple(args, "s", &new_filename)) 
     62        return NULL; 
     63    strcpy(self->params.filename, new_filename); 
     64 
     65    return Py_BuildValue("s", self->params.filename); 
     66} 
     67 
    5968static PyObject *get_frame(CLoader *self, PyObject *args) { 
    6069    return Py_BuildValue("i", self->params.frame); 
    6170} 
    6271 
     72static PyObject *set_frame(CLoader *self, PyObject *args) { 
     73    int new_frame; 
     74    if (!PyArg_ParseTuple(args, "i", &new_frame)) 
     75        return NULL; 
     76    self->params.frame = new_frame; 
     77 
     78    return Py_BuildValue("i", self->params.frame); 
     79} 
     80 
    6381static PyObject *get_n_pixels(CLoader *self, PyObject *args) { 
    6482    return Py_BuildValue("i", self->params.n_pixels); 
    6583} 
    6684 
     85static PyObject *set_n_pixels(CLoader *self, PyObject *args) { 
     86    int new_pixels; 
     87    if (!PyArg_ParseTuple(args, "i", &new_pixels)) 
     88        return NULL; 
     89    self->params.n_pixels = new_pixels; 
     90 
     91    return Py_BuildValue("i", self->params.n_pixels); 
     92} 
     93 
    6794static PyObject *get_n_rasters(CLoader *self, PyObject *args) { 
     95    return Py_BuildValue("i", self->params.n_rasters); 
     96} 
     97 
     98static PyObject *set_n_rasters(CLoader *self, PyObject *args) { 
     99    int new_rasters; 
     100    if (!PyArg_ParseTuple(args, "i", &new_rasters)) 
     101        return NULL; 
     102    self->params.n_rasters = new_rasters; 
     103 
    68104    return Py_BuildValue("i", self->params.n_rasters); 
    69105} 
     
    117153    { "to_string", (PyCFunction)to_string, METH_VARARGS, "Print the objects params" }, 
    118154    { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 
     155    { "set_filename", (PyCFunction)set_filename, METH_VARARGS, "Set the filename" }, 
    119156    { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 
     157    { "set_frame", (PyCFunction)set_frame, METH_VARARGS, "Set the frame that will be loaded" }, 
    120158    { "get_n_pixels", (PyCFunction)get_n_pixels, METH_VARARGS, "Get n_pixels" }, 
     159    { "set_n_pixels", (PyCFunction)set_n_pixels, METH_VARARGS, "Set n_pixels" }, 
    121160    { "get_n_rasters", (PyCFunction)get_n_rasters, METH_VARARGS, "Get n_rasters" }, 
     161    { "set_n_rasters", (PyCFunction)set_n_rasters, METH_VARARGS, "Set n_rasters" }, 
    122162    { "load_data", (PyCFunction)load_data, METH_VARARGS, "Load the data into a numpy array" }, 
    123163    {NULL} 
Note: See TracChangeset for help on using the changeset viewer.