24 #ifndef PXR_BASE_TF_PY_UTILS_H
25 #define PXR_BASE_TF_PY_UTILS_H
46 #include <hboost/python/dict.hpp>
47 #include <hboost/python/extract.hpp>
48 #include <hboost/python/handle.hpp>
49 #include <hboost/python/object.hpp>
50 #include <hboost/python/type_id.hpp>
59 #define TF_PY_REPR_PREFIX \
60 std::string(TF_PP_STRINGIZE(MFB_PACKAGE_MODULE) ".")
143 template <
typename T>
148 TF_CODING_ERROR(
"Called TfPyObject without python being initialized!");
158 }
catch (hboost::python::error_already_set
const &) {
179 template <
typename T>
182 return "<python not initialized>";
188 template <
typename T>
191 typename std::vector<T>::const_iterator i = v.begin();
196 while (i != v.end()) {
211 hboost::python::dict
const &extraGlobals = hboost::python::dict());
230 template <
typename T>
239 std::function<
void()>
const&,
249 template <
typename T>
258 static bool isTypeWrapped =
false;
277 hboost::python::dict d;
278 for (
typename Map::const_iterator i = map.begin(); i != map.end(); ++i)
279 d[i->first] = i->second;
286 hboost::python::list l;
287 for (
typename Seq::const_iterator i = seq.begin();
300 hboost::python::handle<> set{hboost::python::allow_null(PySet_New(
nullptr))};
302 hboost::python::throw_error_already_set();
304 for (
auto const& item : seq) {
306 if (PySet_Add(set.get(), obj.ptr()) == -1) {
307 hboost::python::throw_error_already_set();
402 template <
typename T>
419 hboost::python::extract<T> extractor(obj);
421 if (!extractor.check())
437 #endif // PXR_BASE_TF_PY_UTILS_H
TF_API bool TfPyIsInitialized()
Returns true if python is initialized.
TF_API void Tf_PyObjectError(bool printError)
TF_API void Tf_PyLoadScriptModule(std::string const &name)
TF_API std::string TfPyObjectRepr(hboost::python::object const &t)
GLsizei const GLchar *const * string
TF_API bool TfPyUnsetenv(const std::string &name)
TF_API void TfPyPrintError()
PXR_NAMESPACE_OPEN_SCOPE TF_API void TfPyInitialize()
TF_API void TfPyThrowStopIteration(const char *msg)
TF_API void TfPyThrowValueError(const char *msg)
**But if you need a result
hboost::python::tuple TfPyCopySequenceToTuple(Seq const &seq)
std::string TfPyRepr(T const &t)
TF_API hboost::python::object TfPyEvaluate(std::string const &expr, hboost::python::dict const &extraGlobals=hboost::python::dict())
TF_API hboost::python::object TfPyCopyBufferToByteArray(const char *buffer, size_t size)
hboost::python::object TfPyCopySequenceToSet(Seq const &seq)
TF_API void TfPyDumpTraceback()
Print the current python traceback to stdout.
hboost::python::dict TfPyCopyMapToDictionary(Map const &map)
Creates a python dictionary from a std::map.
TF_API void TfPyThrowTypeError(const char *msg)
TF_API void TfPyGetStackFrames(std::vector< uintptr_t > *frames)
TF_API bool Tf_PyEvaluateWithErrorCheck(const std::string &expr, hboost::python::object *obj)
hboost::python::object TfPyObject(T const &t, bool complainOnFailure=true)
TF_API hboost::python::object TfPyGetClassObject(std::type_info const &type)
void TfPyWrapOnce(std::function< void()> const &wrapFunc)
GLuint const GLchar * name
TF_API std::string TfPyGetClassName(hboost::python::object const &obj)
Return the name of the class of obj.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
bool TfPyEvaluateAndExtract(const std::string &expr, T *t)
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API void TfPyThrowKeyError(const char *msg)
TF_API void TfPyThrowIndexError(const char *msg)
TF_API void Tf_PyWrapOnceImpl(hboost::python::type_info const &, std::function< void()> const &, bool *)
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
TF_API bool TfPySetenv(const std::string &name, const std::string &value)
TF_API bool TfPyIsNone(hboost::python::object const &obj)
Return true iff obj is None.
hboost::python::list TfPyCopySequenceToList(Seq const &seq)
TF_API void TfPyThrowRuntimeError(const char *msg)
TF_API std::vector< std::string > TfPyGetTraceback()