From 70aebe98f178f2679cc29704f1bbc5ee807735c2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 23 Jan 2016 18:07:00 +0100 Subject: [PATCH] py3: ported Sandbox to python3 --- src/Mod/Sandbox/App/AppSandbox.cpp | 12 +++++++++--- src/Mod/Sandbox/Gui/AppSandboxGui.cpp | 16 +++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sandbox/App/AppSandbox.cpp b/src/Mod/Sandbox/App/AppSandbox.cpp index 9cf93f0e04..37b569ce65 100644 --- a/src/Mod/Sandbox/App/AppSandbox.cpp +++ b/src/Mod/Sandbox/App/AppSandbox.cpp @@ -236,17 +236,23 @@ private: } }; +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + } // namespace Sandbox /* Python entry */ -PyMODINIT_FUNC initSandbox() { - +PyMOD_INIT_FUNC(Sandbox) +{ Sandbox::DocumentProtector ::init(); Sandbox::SandboxObject ::init(); // the following constructor call registers our extension module // with the Python runtime system - (void)new Sandbox::Module; + PyObject* mod = Sandbox::initModule(); Base::Console().Log("Loading Sandbox module... done\n"); + PyMOD_Return(mod); } diff --git a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp index 456ab48bd0..f7d47abad4 100644 --- a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp +++ b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp @@ -153,7 +153,7 @@ private: args.setItem(3,Py::Vector(Base::Vector3d(0,0,1))); args.setItem(4,Py::Float(radius)); //args.setItem(5,Py::Int((int)0)); - args.setItem(5,Py::Int((int)1)); + args.setItem(5,Py::Long((long)1)); Py::Tuple ret(method.apply(args)); Py::Vector S1(ret.getItem(0)); Py::Vector S2(ret.getItem(1)); @@ -239,14 +239,19 @@ private: } }; +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + } // namespace SandboxGui /* Python entry */ -PyMODINIT_FUNC initSandboxGui() +PyMOD_INIT_FUNC(SandboxGui) { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); - return; + PyMOD_Return(0); } // Load Python modules this module depends on @@ -255,7 +260,7 @@ PyMODINIT_FUNC initSandboxGui() } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); - return; + PyMOD_Return(0); } // instanciating the commands @@ -265,6 +270,7 @@ PyMODINIT_FUNC initSandboxGui() // the following constructor call registers our extension module // with the Python runtime system - (void)new SandboxGui::Module; + PyObject* mod = SandboxGui::initModule(); Base::Console().Log("Loading GUI of Sandbox module... done\n"); + PyMOD_Return(mod); }