Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Python class registered for C++ class mapnik::enumeration<mapnik::text_transform, 4> #1420

Closed
springmeyer opened this issue Aug 21, 2012 · 5 comments
Milestone

Comments

@springmeyer
Copy link
Member

Not sure why this is happening or if this ever worked post text_placement refactoring by @herm.

>>> sym = mapnik.TextSymbolizer()
>>> sym.text_transform
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/mapnik/__init__.py", line 815, in text_transform
    return self.format.text_transform
TypeError: No Python class registered for C++ class mapnik::enumeration<mapnik::text_transform, 4>
@springmeyer
Copy link
Member Author

looks like it works if set, just not when unset, so this is likely also the boost::optional bug we hit in #1367 and it will impact all text format options as they are optional. ugh....

@lightmare
Copy link
Contributor

I don't see any optionals here, it's more like this issue.

This fixes the above for me:

diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp
index d149406..0c1c95e 100644
--- a/bindings/python/mapnik_text_placement.cpp
+++ b/bindings/python/mapnik_text_placement.cpp
@@ -390,8 +390,9 @@ void export_text_placement()
        set_old_style expression is just a compatibility wrapper and doesn't need to be exposed in python. */
     ;

-    class_<char_properties>
+    class_with_converter<char_properties>
         ("CharProperties")
+        .def_readwrite_convert("text_transform", &char_properties::text_transform)
         .def(init<char_properties const&>()) //Copy constructor
         .def_readwrite("face_name", &char_properties::face_name)
         .def_readwrite("fontset", &char_properties::fontset)
@@ -401,7 +402,6 @@ void export_text_placement()
         .def_readwrite("text_opacity", &char_properties::text_opacity)
         .def_readwrite("wrap_char", &char_properties::wrap_char)
         .def_readwrite("wrap_before", &char_properties::wrap_before)
-        .def_readwrite("text_transform", &char_properties::text_transform)
         .def_readwrite("fill", &char_properties::fill)
         .def_readwrite("halo_fill", &char_properties::halo_fill)
         .def_readwrite("halo_radius", &char_properties::halo_radius)

@springmeyer
Copy link
Member Author

ah, interesting. I saw optionals here, which is why I assumed #1367.

regarding your patch - I'll try it now...

@springmeyer
Copy link
Member Author

great, patch works, but I have to comment out the .def(init<char_properties const&>()) //Copy constructor otherwise I get this compile error:

bindings/python/mapnik_text_placement.cpp:397:10: error: no member named 'def_readwrite_convert' in
      'boost::python::class_<mapnik::char_properties, boost::python::detail::not_specified,
      boost::python::detail::not_specified, boost::python::detail::not_specified>'; did you mean 'def_readwrite_impl'?
        .def_readwrite_convert("text_transform", &char_properties::text_transform)
         ^~~~~~~~~~~~~~~~~~~~~
         def_readwrite_impl
/opt/boost-50/include/boost/python/class.hpp:474:11: note: 'def_readwrite_impl' declared here
    self& def_readwrite_impl(
          ^
bindings/python/mapnik_text_placement.cpp:397:10: error: cannot refer to member 'def_readwrite_impl' in 'self' (aka
      'class_<mapnik::char_properties, boost::python::detail::not_specified, boost::python::detail::not_specified,
      boost::python::detail::not_specified>') with '.'
        .def_readwrite_convert("text_transform", &char_properties::text_transform)
         ^
/opt/boost-50/include/boost/python/class.hpp:474:11: note: member 'def_readwrite_impl' declared here
    self& def_readwrite_impl(
          ^
2 errors generated.

@herm
Copy link
Member

herm commented Aug 21, 2012

You have to use exactly the same order as in the patch provided by @lightmare.
def_readwrite_convert() returns an object of type class_with_converter again, but
def() returns an object of type class_.

class_ doesn't have the def_readwrite_convert() function. It's not the nicest solution, but at least it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants