From 678ecf64dbd863eca2d65877bb9c4de21ebb26a8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 23 Feb 2023 10:40:22 +0100 Subject: [PATCH] Gui: handle language change events in task dialogs --- src/Gui/TaskView/TaskDialogPython.cpp | 24 ++++++++++++++++++++++++ src/Gui/TaskView/TaskDialogPython.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/Gui/TaskView/TaskDialogPython.cpp b/src/Gui/TaskView/TaskDialogPython.cpp index e79240f008..d0f15658f3 100644 --- a/src/Gui/TaskView/TaskDialogPython.cpp +++ b/src/Gui/TaskView/TaskDialogPython.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ # include +# include # include # include #endif @@ -534,6 +535,7 @@ TaskDialogPython::TaskDialogPython(const Py::Object& o) : dlg(o) form = loader.load(&file, nullptr); file.close(); if (form) { + form->installEventFilter(this); auto taskbox = new Gui::TaskView::TaskBox( QPixmap(icon), form->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(form); @@ -561,6 +563,7 @@ TaskDialogPython::TaskDialogPython(const Py::Object& o) : dlg(o) if (object) { QWidget* form = qobject_cast(object); if (form) { + form->installEventFilter(this); auto taskbox = new Gui::TaskView::TaskBox( form->windowIcon().pixmap(32), form->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(form); @@ -690,6 +693,27 @@ void TaskDialogPython::helpRequested() } } +bool TaskDialogPython::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) { + Base::PyGILStateLocker lock; + try { + if (dlg.hasAttr(std::string("changeEvent"))) { + Py::Callable method(dlg.getAttr(std::string("changeEvent"))); + Py::Tuple args{1}; + args.setItem(0, Py::Long(static_cast(event->type()))); + method.apply(args); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + } + + return TaskDialog::eventFilter(watched, event); +} + QDialogButtonBox::StandardButtons TaskDialogPython::getStandardButtons() const { Base::PyGILStateLocker lock; diff --git a/src/Gui/TaskView/TaskDialogPython.h b/src/Gui/TaskView/TaskDialogPython.h index 838a2d1e36..4d19284ac3 100644 --- a/src/Gui/TaskView/TaskDialogPython.h +++ b/src/Gui/TaskView/TaskDialogPython.h @@ -172,6 +172,9 @@ public: /// is called by the framework if the user press the help button void helpRequested() override; + /// event handling + bool eventFilter(QObject *watched, QEvent *event) override; + private: void clearForm();