7 #ifndef PXR_BASE_TF_PY_UTILS_H
8 #define PXR_BASE_TF_PY_UTILS_H
29 #include "pxr/external/boost/python/dict.hpp"
30 #include "pxr/external/boost/python/extract.hpp"
31 #include "pxr/external/boost/python/handle.hpp"
32 #include "pxr/external/boost/python/object.hpp"
33 #include "pxr/external/boost/python/type_id.hpp"
42 #define TF_PY_REPR_PREFIX \
43 std::string(TF_PP_STRINGIZE(MFB_PACKAGE_MODULE) ".")
126 template <
typename T>
131 TF_CODING_ERROR(
"Called TfPyObject without python being initialized!");
141 }
catch (pxr_boost::python::error_already_set
const &) {
162 template <
typename T>
165 return "<python not initialized>";
171 template <
typename T>
174 typename std::vector<T>::const_iterator i = v.begin();
179 while (i != v.end()) {
193 std::string
const &expr,
194 pxr_boost::python::dict
const &extraGlobals = pxr_boost::python::dict());
213 template <
typename T>
222 std::function<
void()>
const&,
232 template <
typename T>
241 static bool isTypeWrapped =
false;
260 pxr_boost::python::dict d;
261 for (
typename Map::const_iterator i = map.begin(); i != map.end(); ++i)
262 d[i->first] = i->second;
269 pxr_boost::python::list l;
270 for (
typename Seq::const_iterator i = seq.begin();
283 pxr_boost::python::handle<>
set{pxr_boost::python::allow_null(PySet_New(
nullptr))};
285 pxr_boost::python::throw_error_already_set();
287 for (
auto const& item : seq) {
289 if (PySet_Add(
set.get(), obj.ptr()) == -1) {
290 pxr_boost::python::throw_error_already_set();
374 template <
typename T>
391 pxr_boost::python::extract<T> extractor(obj);
393 if (!extractor.check())
409 #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)
pxr_boost::python::object TfPyObject(T const &t, bool complainOnFailure=true)
TF_API std::string TfPyObjectRepr(pxr_boost::python::object const &t)
pxr_boost::python::list TfPyCopySequenceToList(Seq const &seq)
GLsizei const GLfloat * value
TF_API bool TfPyUnsetenv(const std::string &name)
TF_API void TfPyPrintError()
TF_API pxr_boost::python::object TfPyEvaluate(std::string const &expr, pxr_boost::python::dict const &extraGlobals=pxr_boost::python::dict())
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
std::string TfPyRepr(T const &t)
GLint GLint GLsizei GLint GLenum GLenum type
TF_API void Tf_PyWrapOnceImpl(pxr_boost::python::type_info const &, std::function< void()> const &, bool *)
TF_API bool TfPyIsNone(pxr_boost::python::object const &obj)
Return true iff obj is None.
TF_API std::string TfPyGetClassName(pxr_boost::python::object const &obj)
Return the name of the class of obj.
constexpr auto set(type rhs) -> int
TF_API void TfPyThrowTypeError(const char *msg)
void TfPyWrapOnce(std::function< void()> const &wrapFunc)
GLuint const GLchar * name
TF_API pxr_boost::python::object TfPyCopyBufferToByteArray(const char *buffer, size_t size)
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)
pxr_boost::python::tuple TfPyCopySequenceToTuple(Seq const &seq)
TF_API void TfPyThrowIndexError(const char *msg)
TF_API pxr_boost::python::object TfPyGetClassObject(std::type_info const &type)
pxr_boost::python::object TfPyCopySequenceToSet(Seq const &seq)
TF_API int64_t TfPyNormalizeIndex(int64_t index, uint64_t size, bool throwError=false)
TF_API bool Tf_PyEvaluateWithErrorCheck(const std::string &expr, pxr_boost::python::object *obj)
TF_API bool TfPySetenv(const std::string &name, const std::string &value)
TF_API void TfPyThrowRuntimeError(const char *msg)
TF_API std::vector< std::string > TfPyGetTraceback()
pxr_boost::python::dict TfPyCopyMapToDictionary(Map const &map)
Creates a python dictionary from a std::map.