Gui: added Gui.showPreferences() python function

This function accepts 2 optional arguments: a string (ex. "Draft")
and an integer (ex. 2). If given, the preferences dialog will open at
the third tab of the Draft group, if existing.
This commit is contained in:
Yorik van Havre 2016-02-02 15:01:42 -02:00
parent 388ea0629c
commit 5ef5a8ec3c
2 changed files with 20 additions and 0 deletions

View File

@ -239,6 +239,7 @@ public:
PYFUNCDEF_S(sAddModule);
PYFUNCDEF_S(sShowDownloads);
PYFUNCDEF_S(sShowPreferences);
static PyMethodDef Methods[];

View File

@ -54,6 +54,7 @@
#include "WorkbenchManager.h"
#include "Language/Translator.h"
#include "DownloadManager.h"
#include "DlgPreferencesImp.h"
#include <App/DocumentObjectPy.h>
#include <App/DocumentPy.h>
#include <App/PropertyFile.h>
@ -159,6 +160,9 @@ PyMethodDef Application::Methods[] = {
{"showDownloads", (PyCFunction) Application::sShowDownloads,1,
"showDownloads() -> None\n\n"
"Shows the downloads manager window"},
{"showPreferences", (PyCFunction) Application::sShowPreferences,1,
"showPreferences([string,int]) -> None\n\n"
"Shows the preferences window. If string and int are provided, the given page index in the given group is shown."},
{NULL, NULL} /* Sentinel */
};
@ -1052,3 +1056,18 @@ PyObject* Application::sShowDownloads(PyObject * /*self*/, PyObject *args,PyObje
Py_INCREF(Py_None);
return Py_None;
}
PyObject* Application::sShowPreferences(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char *pstr=0;
int idx=0;
if (!PyArg_ParseTuple(args, "|si", &pstr, &idx)) // convert args: Python->C
return NULL; // NULL triggers exception
Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
if (pstr)
cDlg.activateGroupPage(QString::fromUtf8(pstr),idx);
cDlg.exec();
Py_INCREF(Py_None);
return Py_None;
}