From 5ef5a8ec3c5fe9bbe7fa9fd021e0d67369b6a221 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 2 Feb 2016 15:01:42 -0200 Subject: [PATCH] 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. --- src/Gui/Application.h | 1 + src/Gui/ApplicationPy.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 50520bfb9..96baeb1dc 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -239,6 +239,7 @@ public: PYFUNCDEF_S(sAddModule); PYFUNCDEF_S(sShowDownloads); + PYFUNCDEF_S(sShowPreferences); static PyMethodDef Methods[]; diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index a723dc77a..7a6992d2e 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -54,6 +54,7 @@ #include "WorkbenchManager.h" #include "Language/Translator.h" #include "DownloadManager.h" +#include "DlgPreferencesImp.h" #include #include #include @@ -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; +}