| 42 | } |
| 43 | |
| 44 | void register_ui_operators(nb::module_& m) { |
| 45 | |
| 46 | nb::class_<PyOperatorProperties>(m, "OperatorProperties") |
| 47 | .def(nb::init<const std::string&>(), nb::arg("operator_id")) |
| 48 | .def("__setattr__", &PyOperatorProperties::set_property, "Set an operator property value") |
| 49 | .def("__getattr__", &PyOperatorProperties::get_property, "Get an operator property value") |
| 50 | .def_prop_ro("properties", &PyOperatorProperties::get_properties, "All properties as a dictionary") |
| 51 | .def_prop_ro("operator_id", &PyOperatorProperties::get_operator_id, "Operator identifier string"); |
| 52 | |
| 53 | m.def( |
| 54 | "unregister_operator", [](const std::string& id) { |
| 55 | vis::op::operators().unregisterOperator(id); |
| 56 | }, |
| 57 | nb::arg("id"), "Unregister an operator"); |
| 58 | |
| 59 | m.def( |
| 60 | "unregister_all_operators", []() { |
| 61 | vis::op::operators().unregisterAllPython(); |
| 62 | }, |
| 63 | "Unregister all Python operators"); |
| 64 | |
| 65 | m.def( |
| 66 | "execute_operator", [](const std::string& id) { |
| 67 | return vis::op::operators().invoke(id).status == vis::op::OperatorResult::FINISHED; |
| 68 | }, |
| 69 | nb::arg("id"), "Execute an operator by id"); |
| 70 | |
| 71 | m.def( |
| 72 | "poll_operator", [](const std::string& id) { |
| 73 | return vis::op::operators().poll(id); |
| 74 | }, |
| 75 | nb::arg("id"), "Check if an operator can run"); |
| 76 | |
| 77 | m.def( |
| 78 | "get_operator_ids", []() { |
| 79 | auto ops = vis::op::operators().getAllOperators(); |
| 80 | std::vector<std::string> ids; |
| 81 | ids.reserve(ops.size()); |
| 82 | for (const auto* desc : ops) { |
| 83 | ids.push_back(desc->id()); |
| 84 | } |
| 85 | return ids; |
| 86 | }, |
| 87 | "Get list of registered operator ids"); |
| 88 | |
| 89 | auto ops_module = m.def_submodule("ops", "Operator invocation"); |
| 90 | |
| 91 | ops_module.def( |
| 92 | "invoke", [](const std::string& id, nb::kwargs kwargs) -> PyOperatorReturnValue { |
| 93 | auto& registry = vis::op::operators(); |
| 94 | |
| 95 | nb::object instance = get_python_operator_instance(id); |
| 96 | std::vector<std::string> set_kwargs; |
| 97 | |
| 98 | if (kwargs && nb::len(kwargs) > 0) { |
| 99 | if (instance.is_valid() && !instance.is_none()) { |
| 100 | for (auto [key, value] : kwargs) { |
| 101 | std::string key_str = nb::cast<std::string>(key); |
no test coverage detected