improve boost::python docstrings for map, color, and stroke, adding currently unused patch against enumeration from podolsir

This commit is contained in:
Dane Springmeyer 2009-09-25 17:50:37 +00:00
parent 23ab337f5c
commit ef1e210269
4 changed files with 71 additions and 19 deletions

View File

@ -46,7 +46,7 @@ void export_color ()
using namespace boost::python;
class_<color>("Color", init<int,int,int,int>(
#if BOOST_VERSION >= 103500
args("self", "r", "g", "b", "a"),
( arg("self"), arg("r"), arg("g"), arg("b"), arg("a") ),
#endif
"Creates a new color from its RGB components\n"
"and an alpha value.\n"
@ -54,14 +54,14 @@ void export_color ()
)
.def(init<int,int,int>(
#if BOOST_VERSION >= 103500
args("self", "r", "g", "b"),
( arg("self"), arg("r"), arg("g"), arg("b") ),
#endif
"Creates a new color from its RGB components.\n"
"All values between 0 and 255.\n")
)
.def(init<std::string>(
#if BOOST_VERSION >= 103500
args("self", "color_string"),
( arg("self"), arg("color_string") ),
#endif
"Creates a new color from its CSS string representation.\n"
"The string may be a CSS color name (e.g. 'blue')\n"
@ -92,7 +92,7 @@ void export_color ()
.def("__str__",&color::to_string)
.def("to_hex_string",&color::to_hex_string,
#if BOOST_VERSION >= 103500
args("self"),
( arg("self") ),
#endif
"Returns the hexadecimal representation of this color.\n"
"\n"

View File

@ -42,6 +42,11 @@ class enumeration_ :
{
init();
}
enumeration_(const char * python_alias, const char * doc) :
base_type( python_alias, doc )
{
init();
}
private:
struct converter

View File

@ -148,7 +148,7 @@ void export_map()
class_<Map>("Map","The map object.",init<int,int,optional<std::string const&> >(
#if BOOST_VERSION >= 103500
( args("self"),arg("width"),arg("height"),arg("srs") ),
( arg("self"),arg("width"),arg("height"),arg("srs") ),
#endif
"Create a Map with a width and height as integers and, optionally,\n"
"an srs string either with a Proj.4 epsg code ('+init=epsg:<code>')\n"

View File

@ -21,8 +21,11 @@
*****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp>
#include <boost/version.hpp>
// mapnik
#include <mapnik/stroke.hpp>
#include "mapnik_enumeration.hpp"
@ -40,7 +43,7 @@ namespace {
mapnik::dash_array::const_iterator iter = dash.begin();
mapnik::dash_array::const_iterator end = dash.end();
for (; iter != end; ++iter) {
l.append(make_tuple(iter->first, iter->second));
l.append(make_tuple(iter->first, iter->second));
}
}
@ -77,9 +80,9 @@ struct stroke_pickle_suite : boost::python::pickle_suite
);
throw_error_already_set();
}
s.set_opacity(extract<float>(state[0]));
if (state[1])
{
list dashes = extract<list>(state[1]);
@ -104,29 +107,73 @@ void export_stroke ()
using namespace boost::python;
enumeration_<line_cap_e>("line_cap")
/*
enumeration_<line_cap_e>("line_cap",
"The possible values for a line cap used when drawing\n"
"with a stroke.\n")
*/
.value("BUTT_CAP",BUTT_CAP)
.value("SQUARE_CAP",SQUARE_CAP)
.value("ROUND_CAP",ROUND_CAP)
;
enumeration_<line_join_e>("line_join")
/*
enumeration_<line_join_e>("line_join",
"The possible values for the line joining mode\n"
"when drawing with a stroke.\n")
*/
.value("MITER_JOIN",MITER_JOIN)
.value("MITER_REVERT_JOIN",MITER_REVERT_JOIN)
.value("ROUND_JOIN",ROUND_JOIN)
.value("BEVEL_JOIN",BEVEL_JOIN)
;
class_<stroke>("Stroke",init<>())
.def(init<color,float>())
class_<stroke>("Stroke",init<>(
#if BOOST_VERSION >= 103400
( arg("self") ),
#endif
"Creates a new default black stroke with the width of 1.\n"))
.def(init<color,float>(
#if BOOST_VERSION >= 103400
( arg("self"), arg("color"), arg("width") ),
#endif
"Creates a new stroke object with a specified color and width.\n")
)
.def_pickle(stroke_pickle_suite())
.add_property("color",make_function
(&stroke::get_color,return_value_policy<copy_const_reference>()),
&stroke::set_color)
.add_property("width",&stroke::get_width,&stroke::set_width)
.add_property("opacity",&stroke::get_opacity,&stroke::set_opacity)
.add_property("line_cap",&stroke::get_line_cap,&stroke::set_line_cap)
.add_property("line_join",&stroke::get_line_join,&stroke::set_line_join)
// todo combine into single get/set property
.def("add_dash",&stroke::add_dash)
.def("get_dashes", get_dashes_list)
(&stroke::get_color,return_value_policy<copy_const_reference>()),
&stroke::set_color,
"Gets or sets the stroke color.\n"
"Returns a new Color object on retrieval.\n")
.add_property("width",
&stroke::get_width,
&stroke::set_width,
"Gets or sets the stroke width in pixels.\n")
.add_property("opacity",
&stroke::get_opacity,
&stroke::set_opacity,
"Gets or sets the opacity of this stroke.\n"
"The value is a float between 0 and 1.\n")
.add_property("line_cap",
&stroke::get_line_cap,
&stroke::set_line_cap,
"Gets or sets the line cap of this stroke.\n")
.add_property("line_join",
&stroke::get_line_join,
&stroke::set_line_join,
"Returns the line join mode of this stroke.\n")
// todo consider providing a single get/set property
.def("add_dash",&stroke::add_dash,
#if BOOST_VERSION >= 103400
( arg("self"), arg("length"), arg("gap") ),
#endif
"Adds a dash segment to the dash patterns of this stroke.\n")
.def("get_dashes", get_dashes_list,
#if BOOST_VERSION >= 103400
( arg("self") ),
#endif
"Returns the list of dash segments for this stroke.\n")
;
}