App: Use PyObject_IsTrue in combination with conditional ternary operator
This commit is contained in:
committed by
Chris Hennes
parent
69932742d2
commit
22763c9e4f
@@ -243,14 +243,14 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args, PyObje
|
||||
char* Name;
|
||||
PyObject *hidden = Py_False;
|
||||
static char *kwlist[] = {"name","hidden",nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "et|O", kwlist,
|
||||
"utf-8", &Name, &hidden))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "et|O!", kwlist,
|
||||
"utf-8", &Name, &PyBool_Type, &hidden))
|
||||
return nullptr;
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
try {
|
||||
// return new document
|
||||
return (GetApplication().openDocument(EncodedName.c_str(),!PyObject_IsTrue(hidden))->getPyObject());
|
||||
return (GetApplication().openDocument(EncodedName.c_str(),PyObject_IsTrue(hidden) ? false : true)->getPyObject());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_IOError, e.what());
|
||||
@@ -270,14 +270,14 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec
|
||||
PyObject *hidden = Py_False;
|
||||
PyObject *temp = Py_False;
|
||||
static char *kwlist[] = {"name","label","hidden","temp",nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|etetOO", kwlist,
|
||||
"utf-8", &docName, "utf-8", &usrName, &hidden, &temp))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|etetO!O!", kwlist,
|
||||
"utf-8", &docName, "utf-8", &usrName, &PyBool_Type, &hidden, &PyBool_Type, &temp))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
App::Document* doc = GetApplication().newDocument(docName, usrName,
|
||||
!PyObject_IsTrue(hidden),
|
||||
PyObject_IsTrue(temp));
|
||||
PyObject_IsTrue(hidden) ? false : true,
|
||||
PyObject_IsTrue(temp) ? true : false);
|
||||
PyMem_Free(docName);
|
||||
PyMem_Free(usrName);
|
||||
return doc->getPyObject();
|
||||
@@ -701,7 +701,7 @@ PyObject* Application::sGetUserMacroPath(PyObject * /*self*/, PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
std::string macroDir = Application::getUserMacroDir();
|
||||
if (PyObject_IsTrue(actual)) {
|
||||
if (PyObject_IsTrue(actual) ? true : false) {
|
||||
macroDir = App::GetApplication().
|
||||
GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath",macroDir.c_str());
|
||||
@@ -732,7 +732,7 @@ PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject *sort = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "|O",&sort))
|
||||
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &sort))
|
||||
return nullptr;
|
||||
PY_TRY {
|
||||
PyObject *pDict = PyDict_New();
|
||||
@@ -740,7 +740,7 @@ PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args)
|
||||
Base::PyObjectBase* pValue;
|
||||
|
||||
std::vector<Document*> docs = GetApplication().getDocuments();;
|
||||
if(PyObject_IsTrue(sort))
|
||||
if(PyObject_IsTrue(sort) ? true : false)
|
||||
docs = Document::getDependentDocuments(docs,true);
|
||||
|
||||
for (auto doc : docs) {
|
||||
@@ -942,11 +942,11 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args
|
||||
{
|
||||
char *name;
|
||||
PyObject *persist = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "s|O", &name,&persist))
|
||||
if (!PyArg_ParseTuple(args, "s|O!", &name, &PyBool_Type, &persist))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
Py::Int ret(GetApplication().setActiveTransaction(name,PyObject_IsTrue(persist)));
|
||||
Py::Int ret(GetApplication().setActiveTransaction(name,PyObject_IsTrue(persist) ? true : false));
|
||||
return Py::new_reference_to(ret);
|
||||
}PY_CATCH;
|
||||
}
|
||||
@@ -972,11 +972,11 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar
|
||||
{
|
||||
PyObject *abort = Py_False;
|
||||
int id = 0;
|
||||
if (!PyArg_ParseTuple(args, "|Oi", &abort,&id))
|
||||
if (!PyArg_ParseTuple(args, "|O!i", &PyBool_Type, &abort,&id))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
GetApplication().closeActiveTransaction(PyObject_IsTrue(abort),id);
|
||||
GetApplication().closeActiveTransaction(PyObject_IsTrue(abort) ? true : false, id);
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user