py3: Gui: files A-P ported to python3

This commit is contained in:
Yorik van Havre
2017-05-05 19:33:03 +02:00
committed by wmayer
parent 226dd17e5f
commit aa3f9288d6
10 changed files with 274 additions and 25 deletions

View File

@@ -212,7 +212,11 @@ FreeCADGui_getSoDBVersion(PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(SoDB::getVersion());
#else
return PyString_FromString(SoDB::getVersion());
#endif
}
struct PyMethodDef FreeCADGui_methods[] = {
@@ -281,7 +285,8 @@ Application::Application(bool GUIenabled)
// setting up Python binding
Base::PyGILStateLocker lock;
PyObject* module = Py_InitModule3("FreeCADGui", Application::Methods,
PyDoc_STRVAR(FreeCADGui_doc,
"The functions in the FreeCADGui module allow working with GUI documents,\n"
"view providers, views, workbenches and much more.\n\n"
"The FreeCADGui instance provides a list of references of GUI documents which\n"
@@ -289,7 +294,25 @@ Application::Application(bool GUIenabled)
"objects in the associated App document. An App and GUI document can be\n"
"accessed with the same name.\n\n"
"The FreeCADGui module also provides a set of functions to work with so called\n"
"workbenches.");
"workbenches."
);
#if PY_MAJOR_VERSION >= 3
// if this returns a valid pointer then the 'FreeCADGui' Python module was loaded,
// otherwise the executable was launched
PyObject *module = PyImport_AddModule("FreeCADGui");
if (!module) {
static struct PyModuleDef FreeCADGuiModuleDef = {PyModuleDef_HEAD_INIT,"FreeCADGui", FreeCADGui_doc, -1, Application::Methods};
module = PyModule_Create(&FreeCADGuiModuleDef);
_PyImport_FixupBuiltin(module, "FreeCADGui");
}
else {
// extend the method list
PyModule_AddFunctions(module, Application::Methods);
}
#else
PyObject* module = Py_InitModule3("FreeCADGui", Application::Methods, FreeCADGui_doc);
#endif
Py::Module(module).setAttr(std::string("ActiveDocument"),Py::None());
UiLoaderPy::init_type();
@@ -303,8 +326,12 @@ Application::Application(bool GUIenabled)
PyModule_AddObject(module, "PySideUic", pySide->module().ptr());
//insert Selection module
PyObject* pSelectionModule = Py_InitModule3("Selection", SelectionSingleton::Methods,
"Selection module");
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef SelectionModuleDef = {PyModuleDef_HEAD_INIT,"Selection", "Selection module", -1, SelectionSingleton::Methods};
PyObject* pSelectionModule = PyModule_Create(&SelectionModuleDef);
#else
PyObject* pSelectionModule = Py_InitModule3("Selection", SelectionSingleton::Methods,"Selection module");
#endif
Py_INCREF(pSelectionModule);
PyModule_AddObject(module, "Selection", pSelectionModule);
@@ -1204,7 +1231,11 @@ QStringList Application::workbenches(void) const
// insert all items
while (PyDict_Next(_pcWorkbenchDictionary, &pos, &key, &value)) {
/* do something interesting with the values... */
#if PY_MAJOR_VERSION >= 3
const char* wbName = PyUnicode_AsUTF8(key);
#else
const char* wbName = PyString_AsString(key);
#endif
// add only allowed workbenches
bool ok = true;
if (!extra.isEmpty()&&ok) {