Skip to content

Commit

Permalink
Merge branch 'feature/6639_deprecated_python_cmds' into develop.
Browse files Browse the repository at this point in the history
Refs #6639

Conflicts:
	Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/Axis.cpp
  • Loading branch information
martyngigg committed Mar 11, 2013
2 parents 96a47fd + cc4cbb5 commit c14acdb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/PythonInterface/mantid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def apiVersion():
except ImportError:
__gui__ = False

###############################################################################
# Set deprecation warnings back to default (they are ignored in 2.7)
###############################################################################
import warnings as _warnings
_warnings.filterwarnings("default",category=DeprecationWarning)

###############################################################################
# Try to be smarter when finding Mantid framework libraries
###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void export_Axis()

/**
* Creates a NumericAxis
* @param number :: of elements in the axis
* @param length The length of the new axis
* @return pointer to the axis object
*/
Axis* createNumericAxis(int length)
Expand All @@ -127,9 +127,29 @@ void export_NumericAxis()

}

/**
* Creates a SpectraAxis
* @param length The length of the new axis
* @return pointer to the axis object
*/
Axis* createSpectraAxis(int length)
{
return new Mantid::API::SpectraAxis(length);
}

void export_SpectraAxis()
{
class_< SpectraAxis, bases<Axis>, boost::noncopyable >("SpectraAxis", no_init)
.def("spectraNo", (const specid_t &(SpectraAxis::*)(const size_t &) const)&SpectraAxis::spectraNo,
return_value_policy<copy_const_reference>(), "Returns the spectrum no at the given index")
.def("create", &createSpectraAxis, return_internal_reference<>(), "Creates a new SpectraAxis of a specified length")
.staticmethod("create")
;
}

/**
* Creates a TextAxis
* @param number :: of elements in the axis
* @param length The length of the new axis
* @return pointer to the axis object
*/
Axis* createTextAxis(int length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ namespace
setSpectrumFromPyObject(self, &MatrixWorkspace::dataE, wsIndex, values);
}

/**
* Adds a deprecation warning to the getNumberBins call to warn about using blocksize instead
* @param self A reference to the calling object
* @returns The blocksize()
*/
size_t getNumberBinsDeprecated(MatrixWorkspace & self)
{
PyErr_Warn(PyExc_DeprecationWarning, "'getNumberBins' is deprecated, use 'blocksize' instead.");
return self.blocksize();
}

/**
* Adds a deprecation warning to the getSampleDetails call to warn about using getRun instead
* @param self A reference to the calling object
* @returns getRun()
*/
Mantid::API::Run & getSampleDetailsDeprecated(MatrixWorkspace & self)
{
PyErr_Warn(PyExc_DeprecationWarning, "'getSampleDetails' is deprecated, use 'getRun' instead.");
return self.mutableRun();
}

}

void export_MatrixWorkspace()
Expand Down Expand Up @@ -130,6 +152,10 @@ void export_MatrixWorkspace()
.def("YUnit", &MatrixWorkspace::YUnit, "Returns the current Y unit for the data (Y axis) in the workspace")
.def("YUnitLabel", &MatrixWorkspace::YUnitLabel, "Returns the caption for the Y axis")

// Deprecated
.def("getNumberBins", &getNumberBinsDeprecated, "Returns size of the Y data array (deprecated, use blocksize instead)")
.def("getSampleDetails", &getSampleDetailsDeprecated, return_internal_reference<>(), "Return the Run object for this workspace (deprecated, use getRun instead)")

//--------------------------------------- Setters -------------------------------------------------------------------------------
.def("setYUnitLabel", &MatrixWorkspace::setYUnitLabel, "Sets a new caption for the data (Y axis) in the workspace")
.def("setYUnit", &MatrixWorkspace::setYUnit, "Sets a new unit for the data (Y axis) in the workspace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ using Mantid::Kernel::Unit;
using Mantid::Kernel::Unit_sptr;
using namespace boost::python;

namespace
{
/**
* Returns the full name of the unit & raises a deprecation warning
* @param self A reference to calling object
*/
const std::string deprecatedName(Unit & self)
{
PyErr_Warn(PyExc_DeprecationWarning, "'name' is deprecated, use 'caption' instead.");
return self.caption();
}
}

void export_Unit()
{
REGISTER_SHARED_PTR_TO_PYTHON(Unit);

class_<Unit,boost::noncopyable>("Unit", no_init)
.def("name", &deprecatedName, "Return the full name of the unit (deprecated, use caption)")
.def("caption", &Unit::caption, "Return the full name of the unit")
.def("label", &Unit::label, "Returns a label to be printed on the axis")
.def("unitID", &Unit::unitID, "Returns the string ID of the unit. This may/may not match its name")
Expand Down

0 comments on commit c14acdb

Please sign in to comment.