MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / bindPyContext

Function bindPyContext

src/bindings/python/PyContext.cpp:48–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46} // namespace
47
48void bindPyContext(py::module & m)
49{
50 ContextRcPtr DEFAULT = Context::Create();
51
52 auto clsContext =
53 py::class_<Context, ContextRcPtr>(
54 m.attr("Context"));
55
56 auto clsStringVarNameIterator =
57 py::class_<StringVarNameIterator>(
58 clsContext, "StringVarNameIterator");
59
60 auto clsStringVarIterator =
61 py::class_<StringVarIterator>(
62 clsContext, "StringVarIterator");
63
64 auto clsSearchPathIterator =
65 py::class_<SearchPathIterator>(
66 clsContext, "SearchPathIterator");
67
68 clsContext
69 .def(py::init(&Context::Create),
70 DOC(Context, Create))
71 .def(py::init([](const std::string & workingDir,
72 const std::vector<std::string> & searchPaths,
73 const std::map<std::string, std::string> stringVars,
74 EnvironmentMode environmentMode)
75 {
76 ContextRcPtr p = Context::Create();
77 if (!workingDir.empty()) { p->setWorkingDir(workingDir.c_str()); }
78
79 if (!searchPaths.empty())
80 {
81 for (const auto & path : searchPaths)
82 {
83 p->addSearchPath(path.c_str());
84 }
85 }
86
87 if (!stringVars.empty())
88 {
89 for (const auto & var: stringVars)
90 {
91 p->setStringVar(var.first.c_str(), var.second.c_str());
92 }
93 }
94
95 p->setEnvironmentMode(environmentMode);
96 return p;
97 }),
98 "workingDir"_a = DEFAULT->getWorkingDir(),
99 "searchPaths"_a = getSearchPathsStdVec(DEFAULT),
100 "stringVars"_a = getStringVarsStdMap(DEFAULT),
101 "environmentMode"_a = DEFAULT->getEnvironmentMode(),
102 DOC(Context, Create))
103
104 .def("__deepcopy__", [](const ConstContextRcPtr & self, py::dict)
105 {

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 15

getSearchPathsStdVecFunction · 0.85
getStringVarsStdMapFunction · 0.85
CompareFunction · 0.85
defReprFunction · 0.85
checkIndexMethod · 0.80
nextIndexMethod · 0.80
emptyMethod · 0.45
setWorkingDirMethod · 0.45
addSearchPathMethod · 0.45
setStringVarMethod · 0.45
setEnvironmentModeMethod · 0.45
getWorkingDirMethod · 0.45

Tested by

no test coverage detected