Skip to content

Commit

Permalink
py3: ported Robot to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 28, 2017
1 parent 8b5fb47 commit 21ffbea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/Mod/Robot/App/AppRobot.cpp
Expand Up @@ -85,19 +85,25 @@ class Module : public Py::ExtensionModule<Module>
return Py::Float(0.0);
}
};

PyObject* initModule()
{
return (new Module)->module().ptr();
}

} // namespace Robot


/* Python entry */
PyMODINIT_FUNC initRobot()
PyMOD_INIT_FUNC(Robot)
{
// load dependent module
try {
Base::Interpreter().runString("import Part");
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(0);
}

PyObject* robotModule = (new Robot::Module())->module().ptr();
Expand All @@ -122,4 +128,6 @@ PyMODINIT_FUNC initRobot()
Robot::PropertyTrajectory ::init();
Robot::TrajectoryCompound ::init();
Robot::TrajectoryDressUpObject ::init();

PyMOD_Return(robotModule);
}
4 changes: 2 additions & 2 deletions src/Mod/Robot/App/WaypointPy.xml
Expand Up @@ -53,13 +53,13 @@ In Case of WAIT s wait time
<Documentation>
<UserDocu>descripe which tool frame to use for that point</UserDocu>
</Documentation>
<Parameter Name="Tool" Type="Int"/>
<Parameter Name="Tool" Type="Long"/>
</Attribute>
<Attribute Name="Base" ReadOnly="false">
<Documentation>
<UserDocu>descripe which Base frame to use for that point</UserDocu>
</Documentation>
<Parameter Name="Base" Type="Int"/>
<Parameter Name="Base" Type="Long"/>
</Attribute>
</PythonExport>
</GenerateModel>
12 changes: 6 additions & 6 deletions src/Mod/Robot/App/WaypointPyImp.cpp
Expand Up @@ -218,12 +218,12 @@ void WaypointPy::setCont(Py::Boolean arg)
getWaypointPtr()->Cont = (bool)arg;
}

Py::Int WaypointPy::getTool(void) const
Py::Long WaypointPy::getTool(void) const
{
return Py::Int((int)getWaypointPtr()->Tool);
return Py::Long((long)getWaypointPtr()->Tool);
}

void WaypointPy::setTool(Py::Int arg)
void WaypointPy::setTool(Py::Long arg)
{
long value = static_cast<long>(arg);
if (value >= 0)
Expand All @@ -232,12 +232,12 @@ void WaypointPy::setTool(Py::Int arg)
throw Py::ValueError("negative tool not allowed!");
}

Py::Int WaypointPy::getBase(void) const
Py::Long WaypointPy::getBase(void) const
{
return Py::Int((int)getWaypointPtr()->Base);
return Py::Long((long)getWaypointPtr()->Base);
}

void WaypointPy::setBase(Py::Int arg)
void WaypointPy::setBase(Py::Long arg)
{
long value = static_cast<long>(arg);
if (value >= 0)
Expand Down
16 changes: 12 additions & 4 deletions src/Mod/Robot/Gui/AppRobotGui.cpp
Expand Up @@ -66,15 +66,21 @@ class Module : public Py::ExtensionModule<Module>

private:
};

PyObject* initModule()
{
return (new Module)->module().ptr();
}

} // namespace RobotGui


/* Python entry */
PyMODINIT_FUNC initRobotGui()
PyMOD_INIT_FUNC(RobotGui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
try {
Base::Interpreter().runString("import PartGui");
Expand All @@ -94,9 +100,9 @@ PyMODINIT_FUNC initRobotGui()
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(0);
}
(void)new RobotGui::Module();
PyObject* mod = RobotGui::initModule();
Base::Console().Log("Loading GUI of Robot module... done\n");

// instantiating the commands
Expand All @@ -115,4 +121,6 @@ PyMODINIT_FUNC initRobotGui()

// add resources and reloads the translators
loadRobotResource();

PyMOD_Return(mod);
}

0 comments on commit 21ffbea

Please sign in to comment.