MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / setEditorMode

Method setEditorMode

src/App/PropertyContainerPyImp.cpp:163–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163PyObject* PropertyContainerPy::setEditorMode(PyObject* args)
164{
165 char* name {};
166 short type {};
167 if (PyArg_ParseTuple(args, "sh", &name, &type)) {
168 App::Property* prop = getPropertyContainerPtr()->getPropertyByName(name);
169 if (!prop) {
170 PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", name);
171 return nullptr;
172 }
173
174 std::bitset<32> status(prop->getStatus());
175 status.set(Property::ReadOnly, (type & 1) > 0);
176 status.set(Property::Hidden, (type & 2) > 0);
177 prop->setStatusValue(status.to_ulong());
178
179 Py_Return;
180 }
181
182 PyErr_Clear();
183 PyObject* iter {};
184 if (PyArg_ParseTuple(args, "sO", &name, &iter)) {
185 if (PyTuple_Check(iter) || PyList_Check(iter)) {
186 Py::Sequence seq(iter);
187 App::Property* prop = getPropertyContainerPtr()->getPropertyByName(name);
188 if (!prop) {
189 PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", name);
190 return nullptr;
191 }
192
193 // reset all bits first
194 std::bitset<32> status(prop->getStatus());
195 status.reset(Property::ReadOnly);
196 status.reset(Property::Hidden);
197 for (Py::Sequence::iterator it = seq.begin(); it != seq.end(); ++it) {
198 std::string str = static_cast<std::string>(Py::String(*it));
199 if (str == "ReadOnly") {
200 status.set(Property::ReadOnly);
201 }
202 else if (str == "Hidden") {
203 status.set(Property::Hidden);
204 }
205 }
206 prop->setStatusValue(status.to_ulong());
207
208 Py_Return;
209 }
210 }
211
212 PyErr_SetString(PyExc_TypeError,
213 "First argument must be str, second can be int, list or tuple");
214 return nullptr;
215}
216
217static const std::map<std::string, int>& getStatusMap()
218{

Callers

nothing calls this directly

Calls 9

statusClass · 0.85
setStatusValueMethod · 0.80
StringClass · 0.70
getPropertyByNameMethod · 0.45
getStatusMethod · 0.45
setMethod · 0.45
resetMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected