Skip to content

Commit

Permalink
Material: Add mapping and sequence protocols to MaterialPy object
Browse files Browse the repository at this point in the history
  • Loading branch information
marioalexis84 committed Jan 5, 2025
1 parent d58f425 commit 0d4743d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Mod/Material/App/MaterialPy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,21 @@
<UserDocu>Set the value associated with the property</UserDocu>
</Documentation>
</Methode>
<Methode Name="keys" NoArgs="true">
<Documentation>
<UserDocu>Property keys</UserDocu>
</Documentation>
</Methode>
<Methode Name="values" NoArgs="true">
<Documentation>
<UserDocu>Property values</UserDocu>
</Documentation>
</Methode>
<Sequence
sq_length="true"
sq_item="true"
sq_contains="true"
mp_subscript="true">
</Sequence>
</PythonExport>
</GenerateModel>
32 changes: 32 additions & 0 deletions src/Mod/Material/App/MaterialPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,35 @@ PyObject* MaterialPy::setAppearanceValue(PyObject* args)
Py_INCREF(Py_None);
return Py_None;
}

PyObject* MaterialPy::keys()
{
return Py::new_reference_to(this->getProperties().keys());
}

PyObject* MaterialPy::values()
{
return Py::new_reference_to(this->getProperties().values());
}

Py_ssize_t MaterialPy::sequence_length(PyObject *self)
{
return static_cast<MaterialPy*>(self)->getProperties().size();
}

PyObject* MaterialPy::sequence_item(PyObject* self, Py_ssize_t item)
{
Py::List keys = static_cast<MaterialPy*>(self)->getProperties().keys();
return Py::new_reference_to(keys.getItem(item));
}

int MaterialPy::sequence_contains(PyObject* self, PyObject* key)
{
return PyDict_Contains(static_cast<MaterialPy*>(self)->getProperties().ptr(), key);
}

PyObject* MaterialPy::mapping_subscript(PyObject* self, PyObject* key)
{
Py::Dict dict = static_cast<MaterialPy*>(self)->getProperties();
return Py::new_reference_to(dict.getItem(Py::Object(key)));
}

0 comments on commit 0d4743d

Please sign in to comment.