Gui: Wrap PyArg_ParseTupleAndKeywords

This commit is contained in:
Chris Hennes
2023-08-25 13:16:29 -05:00
parent 393c1020f5
commit 3d7441c2a5
5 changed files with 30 additions and 19 deletions

View File

@@ -41,6 +41,7 @@
#include <App/PropertyFile.h>
#include <Base/Interpreter.h>
#include <Base/Console.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include <CXX/Objects.hxx>
#include "Application.h"
@@ -1475,7 +1476,7 @@ PyObject* Application::sReload(PyObject * /*self*/, PyObject *args)
PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args)
{
char *path, *mod = "";
const char *path, *mod = "";
if (!PyArg_ParseTuple(args, "s|s", &path, &mod))
return nullptr;

View File

@@ -34,6 +34,7 @@
#include "Selection.h"
#include "Window.h"
#include "PythonWrapper.h"
#include <Base/PyWrapParseTupleAndKeywords.h>
// inclusion of the generated files (generated out of CommandPy.xml)
#include "CommandPy.h"
@@ -296,10 +297,12 @@ PyObject* CommandPy::createCustomCommand(PyObject* args, PyObject* kw)
const char* statustipTxt = nullptr;
const char* pixmapTxt = nullptr;
const char* shortcutTxt = nullptr;
static char* kwlist[] = {"macroFile", "menuText", "toolTip", "whatsThis","statusTip", "pixmap", "shortcut", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|zzzzzz", kwlist, &macroFile, &menuTxt,
&tooltipTxt, &whatsthisTxt, &statustipTxt, &pixmapTxt, &shortcutTxt))
static const std::array<const char *, 8> kwlist{"macroFile", "menuText", "toolTip", "whatsThis", "statusTip",
"pixmap", "shortcut", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, kw, "s|zzzzzz", kwlist, &macroFile, &menuTxt,
&tooltipTxt, &whatsthisTxt, &statustipTxt, &pixmapTxt, &shortcutTxt)) {
return nullptr;
}
auto name = Application::Instance->commandManager().newMacroName();
CommandManager& commandManager = Application::Instance->commandManager();

View File

@@ -38,6 +38,7 @@
#include <Base/Interpreter.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include "Selection.h"
#include "SelectionObject.h"
@@ -2102,9 +2103,9 @@ PyObject *SelectionSingleton::sSetPreselection(PyObject * /*self*/, PyObject *ar
char* subname = nullptr;
float x = 0, y = 0, z = 0;
int type = 1;
static char *kwlist[] = {"obj","subname","x","y","z","tp",nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwd, "O!|sfffi", kwlist,
&(App::DocumentObjectPy::Type),&object,&subname,&x,&y,&z,&type)) {
static const std::array<const char *, 7> kwlist{"obj", "subname", "x", "y", "z", "tp", nullptr};
if (Base::Wrapped_ParseTupleAndKeywords(args, kwd, "O!|sfffi", kwlist, &(App::DocumentObjectPy::Type), &object,
&subname, &x, &y, &z, &type)) {
auto docObjPy = static_cast<App::DocumentObjectPy*>(object);
App::DocumentObject* docObj = docObjPy->getDocumentObjectPtr();
if (!docObj || !docObj->getNameInDocument()) {

View File

@@ -47,6 +47,7 @@
#include <Base/GeometryPyCXX.h>
#include <Base/Interpreter.h>
#include <Base/PlacementPy.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include <Base/RotationPy.h>
#include <Base/VectorPy.h>
@@ -368,11 +369,12 @@ Py::Object View3DInventorPy::fitAll(const Py::Tuple& args)
Py::Object View3DInventorPy::boxZoom(const Py::Tuple& args, const Py::Dict& kwds)
{
static char* kwds_box[] = {"XMin", "YMin", "XMax", "YMax", nullptr};
static const std::array<const char *, 5> kwds_box{"XMin", "YMin", "XMax", "YMax", nullptr};
short xmin, ymin, xmax, ymax;
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "hhhh", kwds_box,
&xmin, &ymin, &xmax, &ymax))
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "hhhh", kwds_box,
&xmin, &ymin, &xmax, &ymax)) {
throw Py::Exception();
}
SbBox2s box(xmin, ymin, xmax, ymax);
getView3DIventorPtr()->getViewer()->boxZoom(box);
@@ -2476,15 +2478,16 @@ Py::Object View3DInventorPy::setName(const Py::Tuple& args)
Py::Object View3DInventorPy::toggleClippingPlane(const Py::Tuple& args, const Py::Dict& kwds)
{
static char* keywords[] = {"toggle", "beforeEditing", "noManip", "pla", nullptr};
static const std::array<const char *, 5> keywords {"toggle", "beforeEditing", "noManip", "pla", nullptr};
int toggle = -1;
PyObject *beforeEditing = Py_False;
PyObject *noManip = Py_True;
PyObject *pyPla = Py_None;
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "|iO!O!O!", keywords,
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "|iO!O!O!", keywords,
&toggle, &PyBool_Type, &beforeEditing, &PyBool_Type, &noManip,
&Base::PlacementPy::Type, &pyPla))
&Base::PlacementPy::Type, &pyPla)) {
throw Py::Exception();
}
Base::Placement pla;
if(pyPla!=Py_None)

View File

@@ -32,6 +32,7 @@
#endif
#include <Base/BoundBoxPy.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include "PythonWrapper.h"
#include "SoFCDB.h"
@@ -185,10 +186,11 @@ PyObject* ViewProviderPy::canDropObject(PyObject *args, PyObject *kw)
PyObject *owner = Py_None;
PyObject *pyElements = Py_None;
const char *subname = nullptr;
static char* kwlist[] = {"obj","owner","subname","elem",nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kw, "|OOsO", kwlist,
&obj, &owner, &subname, &pyElements))
static const std::array<const char *, 5> kwlist{"obj", "owner", "subname", "elem", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, kw, "|OOsO", kwlist,
&obj, &owner, &subname, &pyElements)) {
return nullptr;
}
PY_TRY {
Base::PyTypeCheck(&obj, &App::DocumentObjectPy::Type, "expecting 'obj' to be of type App.DocumentObject or None");
@@ -245,10 +247,11 @@ PyObject* ViewProviderPy::dropObject(PyObject *args, PyObject *kw)
PyObject *owner = Py_None;
PyObject *pyElements = Py_None;
const char *subname = nullptr;
static char* kwlist[] = {"obj","owner","subname","elem",nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|OsO", kwlist,
&App::DocumentObjectPy::Type, &obj, &owner, &subname, &pyElements))
static const std::array<const char *, 5> kwlist{"obj", "owner", "subname", "elem", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, kw, "O!|OsO", kwlist,
&App::DocumentObjectPy::Type, &obj, &owner, &subname, &pyElements)) {
return nullptr;
}
PY_TRY {
Base::PyTypeCheck(&owner, &App::DocumentObjectPy::Type, "expecting 'owner' to be of type App.DocumentObject or None");