+ Support preference pages for Python widget class

This commit is contained in:
wmayer
2015-07-16 00:10:23 +02:00
parent 62c6a61b8b
commit 3241b1ece1
3 changed files with 170 additions and 11 deletions

View File

@@ -729,6 +729,106 @@ void* PrefPageUiProducer::Produce () const
// ----------------------------------------------------
PrefPagePyProducer::PrefPagePyProducer (const Py::Object& p, const char* group)
: type(p)
{
std::string str;
Base::PyGILStateLocker lock;
if (type.hasAttr("__name__")) {
str = static_cast<std::string>(Py::String(type.getAttr("__name__")));
}
WidgetFactoryInst::instance().AddProducer(str.c_str(), this);
Gui::Dialog::DlgPreferencesImp::addPage(str, group);
}
PrefPagePyProducer::~PrefPagePyProducer ()
{
Base::PyGILStateLocker lock;
type = Py::None();
}
void* PrefPagePyProducer::Produce () const
{
Base::PyGILStateLocker lock;
Py::Callable method(type);
Py::Tuple args;
Py::Object page = method.apply(args);
return new Gui::Dialog::PreferencePagePython(page);
}
// ----------------------------------------------------
using namespace Gui::Dialog;
PreferencePagePython::PreferencePagePython(const Py::Object& p, QWidget* parent)
: PreferencePage(parent), page(p)
{
Base::PyGILStateLocker lock;
if (page.hasAttr(std::string("form"))) {
Py::Object widget(page.getAttr(std::string("form")));
Gui::PythonWrapper wrap;
if (wrap.loadCoreModule()) {
QObject* object = wrap.toQObject(widget);
if (object) {
QWidget* form = qobject_cast<QWidget*>(object);
if (form) {
this->setWindowTitle(form->windowTitle());
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(form);
setLayout(layout);
}
}
}
}
}
PreferencePagePython::~PreferencePagePython()
{
Base::PyGILStateLocker lock;
page = Py::None();
}
void PreferencePagePython::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
}
void PreferencePagePython::loadSettings()
{
Base::PyGILStateLocker lock;
try {
if (page.hasAttr(std::string("loadSettings"))) {
Py::Callable method(page.getAttr(std::string("loadSettings")));
Py::Tuple args;
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
void PreferencePagePython::saveSettings()
{
Base::PyGILStateLocker lock;
try {
if (page.hasAttr(std::string("saveSettings"))) {
Py::Callable method(page.getAttr(std::string("saveSettings")));
Py::Tuple args;
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
// ----------------------------------------------------
/* TRANSLATOR Gui::ContainerDialog */
/**