Properly load new PythonQtViewModule.

Only initialize Python if it's not initialized yet.
Inject @calamares_module decorator to fetch the entry class.
main
Teo Mrnjavac 9 years ago
parent 2736ad6e09
commit c618999418

@ -20,8 +20,9 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
#include "viewpages/PythonQtViewStep.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "PythonQtConsoleViewStep.h" #include "CalamaresConfig.h"
#include <PythonQt.h> #include <PythonQt.h>
#include <extensions/PythonQt_QtAll/PythonQt_QtAll.h> #include <extensions/PythonQt_QtAll/PythonQt_QtAll.h>
@ -52,39 +53,85 @@ PythonQtViewModule::loadSelf()
{ {
if ( PythonQt::self() == nullptr ) if ( PythonQt::self() == nullptr )
{ {
PythonQt::init(); if ( Py_IsInitialized() )
PythonQt::init( PythonQt::IgnoreSiteModule |
PythonQt::RedirectStdOut |
PythonQt::PythonAlreadyInitialized );
else
PythonQt::init();
PythonQt_QtAll::init(); PythonQt_QtAll::init();
cDebug() << "Initializing PythonQt bindings."
<< "This should only happen once.";
PythonQt::self()->registerClass( &PythonQtViewStep::staticMetaObject,
"calamares" );
QObject::connect( PythonQt::self(), &PythonQt::pythonStdOut,
[]( const QString& message )
{
cDebug() << "PythonQt OUT>" << message;
} );
QObject::connect( PythonQt::self(), &PythonQt::pythonStdErr,
[]( const QString& message )
{
cDebug() << "PythonQt ERR>" << message;
} );
}
QDir workingDir( m_workingPath );
if ( !workingDir.exists() )
{
cDebug() << "Invalid working directory"
<< m_workingPath
<< "for module"
<< name();
return;
}
QString fullPath = workingDir.absoluteFilePath( m_scriptFileName );
QFileInfo scriptFileInfo( fullPath );
if ( !scriptFileInfo.isReadable() )
{
cDebug() << "Invalid main script file path"
<< fullPath
<< "for module"
<< name();
return;
} }
// Construct empty Python module with the given name
PythonQtObjectPtr cxt = PythonQtObjectPtr cxt =
PythonQt::self()-> PythonQt::self()->
createModuleFromFile( name(), createModuleFromScript( name() );
m_workingPath + if ( cxt.isNull() )
QDir::separator() + {
m_scriptFileName ); cDebug() << "Cannot load PythonQt context from file"
cDebug() << "Creating viewstep for script at" << fullPath
<< m_workingPath + << "for module"
QDir::separator() + << name();
m_scriptFileName; return;
}
m_viewStep = new PythonQtConsoleViewStep( cxt );
QString calamares_module_annotation =
// m_viewStep = reinterpret_cast< ViewStep* >( "_calamares_module_typename = 'foo'\n"
// PythonQt::self()-> "def calamares_module(viewmodule_type):\n"
// lookupObject( cxt, " global _calamares_module_typename\n"
// "_calamares_module" ).object() ); " _calamares_module_typename = viewmodule_type.__name__\n"
" return viewmodule_type\n";
// if ( !m_viewStep )
// { // Load in the decorator
// cDebug() << Q_FUNC_INFO << m_loader->errorString(); PythonQt::self()->evalScript( cxt, calamares_module_annotation );
// return;
// } // Load the module
PythonQt::self()->evalFile( cxt, fullPath );
// cDebug() << "PythonQtViewModule loading self for instance" << instanceKey() m_viewStep = new PythonQtViewStep( cxt );
// << "\nPythonQtViewModule at address" << this
// << "\nCalamares::PluginFactory at address" << pf cDebug() << "PythonQtViewModule loading self for instance" << instanceKey()
// << "\nViewStep at address" << m_viewStep; << "\nPythonQtViewModule at address" << this
<< "\nViewStep at address" << m_viewStep;
m_viewStep->setModuleInstanceKey( instanceKey() ); m_viewStep->setModuleInstanceKey( instanceKey() );
m_viewStep->setConfigurationMap( m_configurationMap ); m_viewStep->setConfigurationMap( m_configurationMap );

Loading…
Cancel
Save