+ Make Python API more pythonic
This commit is contained in:
parent
495cac2d25
commit
2a2acf4955
|
@ -349,8 +349,8 @@ PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*
|
|||
|
||||
PY_TRY {
|
||||
App::Document* doc = 0;
|
||||
Py::List list(object);
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Sequence list(object);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
|
|
|
@ -112,8 +112,8 @@ Py::Object ControlPy::closeDialog(const Py::Tuple&)
|
|||
Py::Object ControlPy::addTaskWatcher(const Py::Tuple& args)
|
||||
{
|
||||
std::vector<Gui::TaskView::TaskWatcher*> watcher;
|
||||
Py::List list(args[0]);
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Sequence list(args[0]);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
TaskWatcherPython* w = new TaskWatcherPython(*it);
|
||||
watcher.push_back(w);
|
||||
}
|
||||
|
@ -178,9 +178,9 @@ TaskWatcherPython::TaskWatcherPython(const Py::Object& o)
|
|||
Gui::TaskView::TaskBox *tb = 0;
|
||||
if (watcher.hasAttr(std::string("commands"))) {
|
||||
if (!tb) tb = new Gui::TaskView::TaskBox(icon, title, true, 0);
|
||||
Py::List cmds(watcher.getAttr(std::string("commands")));
|
||||
Py::Sequence cmds(watcher.getAttr(std::string("commands")));
|
||||
CommandManager &mgr = Gui::Application::Instance->commandManager();
|
||||
for (Py::List::iterator it = cmds.begin(); it != cmds.end(); ++it) {
|
||||
for (Py::Sequence::iterator it = cmds.begin(); it != cmds.end(); ++it) {
|
||||
Py::String name(*it);
|
||||
std::string s = (std::string)name;
|
||||
Command *c = mgr.getCommandByName(s.c_str());
|
||||
|
@ -192,11 +192,11 @@ TaskWatcherPython::TaskWatcherPython(const Py::Object& o)
|
|||
if (watcher.hasAttr(std::string("widgets"))) {
|
||||
if (!tb && !title.isEmpty())
|
||||
tb = new Gui::TaskView::TaskBox(icon, title, true, 0);
|
||||
Py::List list(watcher.getAttr(std::string("widgets")));
|
||||
Py::Sequence list(watcher.getAttr(std::string("widgets")));
|
||||
|
||||
Gui::PythonWrapper wrap;
|
||||
if (wrap.loadCoreModule()) {
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
QObject* object = wrap.toQObject(*it);
|
||||
if (object) {
|
||||
QWidget* w = qobject_cast<QWidget*>(object);
|
||||
|
|
|
@ -163,10 +163,10 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
|||
MeshObject global_mesh;
|
||||
|
||||
PY_TRY {
|
||||
Py::List list(object);
|
||||
Py::Sequence list(object);
|
||||
Base::Type meshId = Base::Type::fromName("Mesh::Feature");
|
||||
Base::Type partId = Base::Type::fromName("Part::Feature");
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
|
@ -382,25 +382,24 @@ createBox(PyObject *self, PyObject *args)
|
|||
|
||||
static PyObject *
|
||||
calculateEigenTransform(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *input;
|
||||
{
|
||||
PyObject *input;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O",&input))
|
||||
return NULL;
|
||||
if (!PyArg_ParseTuple(args, "O",&input))
|
||||
return NULL;
|
||||
|
||||
if(! PySequence_Check(input) ){
|
||||
PyErr_SetString(PyExc_Exception, "Input have to be a sequence of Base.Vector()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
|
||||
MeshCore::MeshKernel aMesh;
|
||||
MeshCore::MeshPointArray vertices;
|
||||
vertices.clear();
|
||||
MeshCore::MeshFacetArray faces;
|
||||
faces.clear();
|
||||
MeshCore::MeshPoint current_node;
|
||||
PY_TRY {
|
||||
MeshCore::MeshKernel aMesh;
|
||||
MeshCore::MeshPointArray vertices;
|
||||
vertices.clear();
|
||||
MeshCore::MeshFacetArray faces;
|
||||
faces.clear();
|
||||
MeshCore::MeshPoint current_node;
|
||||
|
||||
Py::Sequence list(input);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
|
|
|
@ -259,8 +259,8 @@ static PyObject * exporter(PyObject *self, PyObject *args)
|
|||
builder.MakeCompound(comp);
|
||||
|
||||
PY_TRY {
|
||||
Py::List list(object);
|
||||
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Sequence list(object);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
|
|
Loading…
Reference in New Issue
Block a user