mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-25 03:15:44 -05:00
Use CalamaresUtils::lookupAndCall in PythonQtViewStep.
This is done to support both Pythonic and Qt style method names, i.e. both "isNextEnabled" and "is_next_enabled" is ok in a Python module. Also better documentation in PythonQtViewStep, and stub for setConfigurationMap. Finally, proper handling of PythonQtViewStep Python-facing basewidget: with this change, a call to PQVS::widget() only triggers a widget relayout if it's necessary, and leaves it alone otherwise.
This commit is contained in:
parent
fb9d1fa339
commit
a54f217173
2 changed files with 61 additions and 11 deletions
|
@ -19,12 +19,15 @@
|
||||||
#include "PythonQtViewStep.h"
|
#include "PythonQtViewStep.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
#include "utils/PythonQtUtils.h"
|
||||||
|
|
||||||
#include <gui/PythonQtScriptingConsole.h>
|
#include <gui/PythonQtScriptingConsole.h>
|
||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
|
PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
|
@ -32,13 +35,17 @@ PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
|
||||||
, m_widget( new QWidget() )
|
, m_widget( new QWidget() )
|
||||||
, m_cxt( cxt )
|
, m_cxt( cxt )
|
||||||
{
|
{
|
||||||
|
// The @calamares_module decorator should have filled _calamares_module_typename
|
||||||
|
// for us.
|
||||||
QString className = m_cxt.getVariable( "_calamares_module_typename" ).toString();
|
QString className = m_cxt.getVariable( "_calamares_module_typename" ).toString();
|
||||||
|
|
||||||
|
// Instantiate an object of the class marked with @calamares_module and
|
||||||
|
// store it as _calamares_module.
|
||||||
PythonQt::self()->evalScript( m_cxt, QString( "_calamares_module = %1()" )
|
PythonQt::self()->evalScript( m_cxt, QString( "_calamares_module = %1()" )
|
||||||
.arg( className ) );
|
.arg( className ) );
|
||||||
m_obj = PythonQt::self()->lookupObject( m_cxt, "_calamares_module" );
|
m_obj = PythonQt::self()->lookupObject( m_cxt, "_calamares_module" );
|
||||||
|
|
||||||
Q_ASSERT( !m_obj.isNull() );
|
Q_ASSERT( !m_obj.isNull() ); // no entry point, no party
|
||||||
|
|
||||||
m_widget->setLayout( new QVBoxLayout );
|
m_widget->setLayout( new QVBoxLayout );
|
||||||
CalamaresUtils::unmarginLayout( m_widget->layout() );
|
CalamaresUtils::unmarginLayout( m_widget->layout() );
|
||||||
|
@ -49,18 +56,37 @@ PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
|
||||||
QString
|
QString
|
||||||
PythonQtViewStep::prettyName() const
|
PythonQtViewStep::prettyName() const
|
||||||
{
|
{
|
||||||
return PythonQt::self()->call( m_obj, "prettyName" ).toString();
|
return CalamaresUtils::lookupAndCall( m_obj,
|
||||||
|
{ "prettyName",
|
||||||
|
"pretty_name" } ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QWidget*
|
QWidget*
|
||||||
PythonQtViewStep::widget()
|
PythonQtViewStep::widget()
|
||||||
{
|
{
|
||||||
m_widget->layout()->deleteLater();
|
if ( m_widget->layout()->count() > 1 )
|
||||||
m_widget->setLayout( new QVBoxLayout );
|
cDebug() << "WARNING: PythonQtViewStep wrapper widget has more than 1 child. "
|
||||||
CalamaresUtils::unmarginLayout( m_widget->layout() );
|
"This should never happen.";
|
||||||
|
|
||||||
|
bool nothingChanged = m_cxt.evalScript(
|
||||||
|
"_calamares_module_basewidget.contains(_calamares_module.widget())" ).toBool();
|
||||||
|
if ( nothingChanged )
|
||||||
|
return m_widget;
|
||||||
|
|
||||||
|
// Else, we either don't have a child widget, or we have a child widget that
|
||||||
|
// was previously set and doesn't apply any more since the Python module
|
||||||
|
// set a new one.
|
||||||
|
|
||||||
|
// First we clear the layout, which should only ever have 1 item.
|
||||||
|
// We only remove from the layout and not delete because Python is in charge
|
||||||
|
// of memory management for these widgets.
|
||||||
|
while ( m_widget->layout()->itemAt( 0 ) )
|
||||||
|
m_widget->layout()->takeAt( 0 );
|
||||||
|
|
||||||
m_cxt.evalScript(
|
m_cxt.evalScript(
|
||||||
"_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" );
|
"_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" );
|
||||||
|
|
||||||
return m_widget;
|
return m_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,42 +94,50 @@ PythonQtViewStep::widget()
|
||||||
void
|
void
|
||||||
PythonQtViewStep::next()
|
PythonQtViewStep::next()
|
||||||
{
|
{
|
||||||
|
CalamaresUtils::lookupAndCall( m_obj, { "next" } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PythonQtViewStep::back()
|
PythonQtViewStep::back()
|
||||||
{
|
{
|
||||||
|
CalamaresUtils::lookupAndCall( m_obj, { "back" } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PythonQtViewStep::isNextEnabled() const
|
PythonQtViewStep::isNextEnabled() const
|
||||||
{
|
{
|
||||||
return PythonQt::self()->call( m_obj, "isNextEnabled" ).toBool();
|
return CalamaresUtils::lookupAndCall( m_obj,
|
||||||
|
{ "isNextEnabled",
|
||||||
|
"is_next_enabled" } ).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PythonQtViewStep::isBackEnabled() const
|
PythonQtViewStep::isBackEnabled() const
|
||||||
{
|
{
|
||||||
return PythonQt::self()->call( m_obj, "isBackEnabled" ).toBool();
|
return CalamaresUtils::lookupAndCall( m_obj,
|
||||||
|
{ "isBackEnabled",
|
||||||
|
"is_back_enabled" } ).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PythonQtViewStep::isAtBeginning() const
|
PythonQtViewStep::isAtBeginning() const
|
||||||
{
|
{
|
||||||
return PythonQt::self()->call( m_obj, "isAtBeginning" ).toBool();
|
return CalamaresUtils::lookupAndCall( m_obj,
|
||||||
|
{ "isAtBeginning",
|
||||||
|
"is_at_beginning" } ).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PythonQtViewStep::isAtEnd() const
|
PythonQtViewStep::isAtEnd() const
|
||||||
{
|
{
|
||||||
return PythonQt::self()->call( m_obj, "isAtEnd" ).toBool();
|
return CalamaresUtils::lookupAndCall( m_obj,
|
||||||
|
{ "isAtEnd",
|
||||||
|
"is_at_end" } ).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +149,13 @@ PythonQtViewStep::jobs() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PythonQtViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
#warning "Not implemented yet."
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QWidget*
|
QWidget*
|
||||||
PythonQtViewStep::createScriptingConsole()
|
PythonQtViewStep::createScriptingConsole()
|
||||||
{
|
{
|
||||||
|
@ -123,3 +164,5 @@ PythonQtViewStep::createScriptingConsole()
|
||||||
m_cxt.getVariable( "_calamares_module_typename" ).toString() );
|
m_cxt.getVariable( "_calamares_module_typename" ).toString() );
|
||||||
return console;
|
return console;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
|
|
||||||
#include <PythonQt.h>
|
#include <PythonQt.h>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
class PythonQtViewStep : public Calamares::ViewStep
|
class PythonQtViewStep : public Calamares::ViewStep
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -45,6 +48,8 @@ public:
|
||||||
|
|
||||||
QList< Calamares::job_ptr > jobs() const override;
|
QList< Calamares::job_ptr > jobs() const override;
|
||||||
|
|
||||||
|
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||||
|
|
||||||
QWidget* createScriptingConsole();
|
QWidget* createScriptingConsole();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -56,4 +61,6 @@ private:
|
||||||
friend class PythonQtViewStepDecorator;
|
friend class PythonQtViewStepDecorator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PYTHONQTVIEWSTEP_H
|
#endif // PYTHONQTVIEWSTEP_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue