diff --git a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/IMDDimension.cpp b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/IMDDimension.cpp index 344412f4b38f..53d53027bb19 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/IMDDimension.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/IMDDimension.cpp @@ -8,6 +8,18 @@ using Mantid::Geometry::IMDDimension; using Mantid::Geometry::IMDDimension_sptr; using namespace boost::python; +namespace +{ + /** + * @param self A reference to the calling object + * @return A plain-text string giving the units + */ + std::string getUnitsAsStr(IMDDimension & self) + { + return self.getUnits().ascii(); + } +} + void export_IMDDimension() { register_ptr_to_python>(); @@ -21,7 +33,7 @@ void export_IMDDimension() .def("getX", &IMDDimension::getX, "Return coordinate of the axis at the given index") .def("getDimensionId", &IMDDimension::getDimensionId, "Return a short name which identify the dimension among other dimension." "A dimension can be usually find by its ID and various ") - .def("getUnits", &IMDDimension::getUnits, "Return the units associated with this dimension.") + .def("getUnits", &getUnitsAsStr, "Return the units associated with this dimension.") ; } diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/Unit.cpp b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/Unit.cpp index e11a33d62ef0..479d4a2b295e 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/Unit.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/Unit.cpp @@ -19,6 +19,16 @@ namespace return self.caption(); } + /** + * Returns the label of the unit as a std::string & raises a deprecation warning + * @param self A reference to calling object + */ + const std::string deprecatedLabel(Unit & self) + { + PyErr_Warn(PyExc_DeprecationWarning, "'unit.label()' is deprecated, use 'str(unit.symbol())' instead."); + return self.label().ascii(); + } + } void export_Unit() @@ -28,7 +38,8 @@ void export_Unit() class_("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("label", &deprecatedLabel, "Returns a plain-text label to be used as the symbol for the unit (deprecated, use symbol())") + .def("symbol", &Unit::label, "Returns a UnitLabel object that holds information on the symbol to use for unit") .def("unitID", &Unit::unitID, "Returns the string ID of the unit. This may/may not match its name") ; diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py index d9c0bd26b86d..6f889ed09fcc 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py @@ -58,9 +58,9 @@ def test_axes(self): self.assertEquals(xunit.unitID(), "TOF") yunit = yaxis.getUnit() - self.assertEquals(yunit.caption(), "") + self.assertEquals(yunit.caption(), "Spectrum") self.assertEquals(yunit.label(), "") - self.assertEquals(yunit.unitID(), "Empty") + self.assertEquals(yunit.unitID(), "Label") def test_detector_retrieval(self): diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitLabelTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitLabelTest.py index 7087ad223128..11e4b806ed80 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitLabelTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitLabelTest.py @@ -15,7 +15,7 @@ def test_UnitLabel_can_be_built_simple_string_and_unicode_object(self): def test_utf8_is_converted_to_unicode_object(self): tof = UnitFactory.Instance().create("TOF") - unit_lbl = tof.label() + unit_lbl = tof.symbol() self.assertTrue(isinstance(unit_lbl.utf8(), types.UnicodeType)) self.assertEquals(u"\u03bcs", unit_lbl.utf8()) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitsTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitsTest.py index 906bb190f05c..3f18b9eb6bbf 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitsTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/UnitsTest.py @@ -1,5 +1,5 @@ import unittest -from mantid.kernel import UnitFactory, Unit, Label +from mantid.kernel import UnitFactory, Unit, Label, UnitLabel import types class UnitsTest(unittest.TestCase): @@ -11,6 +11,7 @@ def test_Label_is_returned_from_Factory(self): label_unit.setLabel("Temperature", "K") self.assertEquals("Temperature", label_unit.caption()) self.assertEquals("K", label_unit.label()) + self.assertTrue(isinstance(label_unit.symbol(), UnitLabel)) if __name__ == '__main__': unittest.main()