[Gui] Show Preferences page by name rather than index
This commit is contained in:
@@ -354,6 +354,7 @@ public:
|
||||
|
||||
static PyObject* sShowDownloads (PyObject *self,PyObject *args);
|
||||
static PyObject* sShowPreferences (PyObject *self,PyObject *args);
|
||||
static PyObject* sShowPreferencesByName (PyObject *self,PyObject *args);
|
||||
|
||||
static PyObject* sCreateViewer (PyObject *self,PyObject *args);
|
||||
static PyObject* sGetMarkerIndex (PyObject *self,PyObject *args);
|
||||
|
||||
@@ -345,6 +345,13 @@ PyMethodDef Application::Methods[] = {
|
||||
"\n"
|
||||
"grp: str\n Group to show.\n"
|
||||
"index : int\n Page index."},
|
||||
{"showPreferencesByName", (PyCFunction) Application::sShowPreferencesByName, METH_VARARGS,
|
||||
"showPreferencesByName(grp, pagename) -> None\n"
|
||||
"\n"
|
||||
"Show the preferences window.\n"
|
||||
"\n"
|
||||
"grp: str\n Group to show.\n"
|
||||
"pagename : str\n Page to show."},
|
||||
{"createViewer", (PyCFunction) Application::sCreateViewer, METH_VARARGS,
|
||||
"createViewer(views=1, name) -> View3DInventorPy or AbstractSplitViewPy\n"
|
||||
"\n"
|
||||
@@ -1428,16 +1435,39 @@ PyObject* Application::sShowDownloads(PyObject * /*self*/, PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sShowPreferences(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sShowPreferences(PyObject* /*self*/, PyObject* args)
|
||||
{
|
||||
char *pstr = nullptr;
|
||||
int idx=0;
|
||||
if (!PyArg_ParseTuple(args, "|si", &pstr, &idx))
|
||||
char* pstr = nullptr;
|
||||
int idx = 0;
|
||||
if (!PyArg_ParseTuple(args, "|si", &pstr, &idx)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
|
||||
if (pstr)
|
||||
cDlg.activateGroupPage(QString::fromUtf8(pstr),idx);
|
||||
if (pstr) {
|
||||
cDlg.activateGroupPage(QString::fromUtf8(pstr), idx);
|
||||
}
|
||||
|
||||
WaitCursor wc;
|
||||
wc.restoreCursor();
|
||||
cDlg.exec();
|
||||
wc.setWaitCursor();
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sShowPreferencesByName(PyObject* /*self*/, PyObject* args)
|
||||
{
|
||||
char* pstr = nullptr;
|
||||
const char* prefType = "";
|
||||
if (!PyArg_ParseTuple(args, "s|s", &pstr, &prefType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
|
||||
if (pstr && prefType) {
|
||||
cDlg.activateGroupPageByPageName(QString::fromUtf8(pstr), QString::fromUtf8(prefType));
|
||||
}
|
||||
|
||||
WaitCursor wc;
|
||||
wc.restoreCursor();
|
||||
|
||||
@@ -503,6 +503,38 @@ void DlgPreferencesImp::activateGroupPage(const QString& group, int index)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the page with name \a pageName of the group with name \a group.
|
||||
*/
|
||||
void DlgPreferencesImp::activateGroupPageByPageName(const QString& group, const QString& pageName)
|
||||
{
|
||||
|
||||
for (int i = 0; i < ui->groupWidgetStack->count(); i++) {
|
||||
auto* pageStackWidget = qobject_cast<QStackedWidget*>(ui->groupWidgetStack->widget(i));
|
||||
|
||||
if (!pageStackWidget) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pageStackWidget->property(GroupNameProperty).toString() == group) {
|
||||
ui->groupWidgetStack->setCurrentWidget(pageStackWidget);
|
||||
for (int pageIdx = 0; pageIdx < pageStackWidget->count(); pageIdx++) {
|
||||
auto page = qobject_cast<PreferencePage*>(pageStackWidget->widget(pageIdx));
|
||||
if (page) {
|
||||
if (page->property(PageNameProperty).toString() == pageName) {
|
||||
pageStackWidget->setCurrentIndex(pageIdx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updatePageDependentWidgets();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group name \a group and position \a index of the active page.
|
||||
*/
|
||||
|
||||
@@ -149,6 +149,7 @@ public:
|
||||
void reject() override;
|
||||
void reload();
|
||||
void activateGroupPage(const QString& group, int index);
|
||||
void activateGroupPageByPageName(const QString& group, const QString& pageName);
|
||||
void activeGroupPage(QString& group, int& index) const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -111,7 +111,7 @@ def getPreferences():
|
||||
import ifcopenshell
|
||||
|
||||
if FreeCAD.GuiUp and params.get_param_arch("ifcShowDialog"):
|
||||
FreeCADGui.showPreferences("Import-Export", 1)
|
||||
FreeCADGui.showPreferencesByName("Import-Export", ":/ui/preferences-ifc-export.ui")
|
||||
ifcunit = params.get_param_arch("ifcUnit")
|
||||
|
||||
# Factor to multiply the dimension in millimeters
|
||||
|
||||
@@ -84,7 +84,7 @@ def getPreferences():
|
||||
3 = One compound per storey
|
||||
"""
|
||||
if FreeCAD.GuiUp and params.get_param_arch("ifcShowDialog"):
|
||||
Gui.showPreferences("Import-Export", 0)
|
||||
Gui.showPreferencesByName("Import-Export", ":/ui/preferences-ifc.ui")
|
||||
|
||||
preferences = {
|
||||
'DEBUG': params.get_param_arch("ifcDebug"),
|
||||
|
||||
@@ -4148,7 +4148,7 @@ def readPreferences():
|
||||
"""
|
||||
# reading parameters
|
||||
if gui and params.get_param("dxfShowDialog"):
|
||||
FreeCADGui.showPreferences("Import-Export", 3)
|
||||
FreeCADGui.showPreferencesByName("Import-Export", ":/ui/preferences-dxf.ui")
|
||||
global dxfCreatePart, dxfCreateDraft, dxfCreateSketch
|
||||
global dxfDiscretizeCurves, dxfStarBlocks
|
||||
global dxfMakeBlocks, dxfJoin, dxfRenderPolylineWidth
|
||||
|
||||
Reference in New Issue
Block a user