diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index b1f6c48cf..fd94e3eab 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -58,6 +58,20 @@ if( WITH_PYTHON ) ) endif() +if( WITH_PYTHONQT ) + include_directories(${PYTHON_INCLUDE_DIRS}) + link_directories(${PYTHON_LIBRARIES}) + + include_directories(${PYTHONQT_INCLUDE_DIR}) + link_directories(${PYTHONQT_LIBRARY}) + + set( OPTIONAL_PRIVATE_LIBRARIES + ${OPTIONAL_PRIVATE_LIBRARIES} + ${PYTHON_LIBRARIES} + ${PYTHONQT_LIBRARY} + ) +endif() + add_library( calamares SHARED ${libSources} ) set_target_properties( calamares diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index e626969e3..8e712e47d 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -39,6 +39,21 @@ if( WITH_PYTHON ) ) endif() +if( WITH_PYTHONQT ) + include_directories(${PYTHON_INCLUDE_DIRS}) + include_directories(${PYTHONQT_INCLUDE_DIR}) + + list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES + PythonQtConsoleViewStep.cpp + modulesystem/PythonQtViewModule.cpp + ) + set( OPTIONAL_PRIVATE_LIBRARIES + ${OPTIONAL_PRIVATE_LIBRARIES} + ${PYTHON_LIBRARIES} + ${PYTHONQT_LIBRARIES} + ) +endif() + calamares_add_library( ${CALAMARESUI_LIBRARY_TARGET} SOURCES ${${CALAMARESUI_LIBRARY_TARGET}_SOURCES} UI ${${CALAMARESUI_LIBRARY_TARGET}_UI} diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 2a2fe779b..ff0d3ef8d 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -31,6 +31,10 @@ #include "PythonJobModule.h" #endif +#ifdef WITH_PYTHONQT +#include "PythonQtViewModule.h" +#endif + #include #include @@ -71,9 +75,18 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor, << instanceId; return nullptr; } - if ( typeString == "view" && intfString == "qtplugin" ) + if ( typeString == "view" ) { - m = new ViewModule(); + if ( intfString == "qtplugin" ) + { + m = new ViewModule(); + } +#ifdef WITH_PYTHONQT + else if ( intfString == "pythonqt" ) + { + m = new PythonQtViewModule(); + } +#endif } else if ( typeString == "job" ) { diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 336890ee9..171458f93 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -48,9 +48,10 @@ public: enum Interface { - QtPlugin, - Python, - Process + QtPluginInterface, + PythonInterface, + ProcessInterface, + PythonQtInterface }; virtual ~Module(); diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp index 5b6fa24f0..aefcbf6f0 100644 --- a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp @@ -35,7 +35,7 @@ ProcessJobModule::type() const Module::Interface ProcessJobModule::interface() const { - return Process; + return ProcessInterface; } diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.cpp b/src/libcalamaresui/modulesystem/PythonJobModule.cpp index e2982ef48..544f27e1f 100644 --- a/src/libcalamaresui/modulesystem/PythonJobModule.cpp +++ b/src/libcalamaresui/modulesystem/PythonJobModule.cpp @@ -36,7 +36,7 @@ PythonJobModule::type() const Module::Interface PythonJobModule::interface() const { - return Python; + return PythonInterface; } diff --git a/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp b/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp new file mode 100644 index 000000000..3a5f77a20 --- /dev/null +++ b/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp @@ -0,0 +1,127 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "PythonQtViewModule.h" + +#include "utils/Logger.h" +#include "viewpages/ViewStep.h" +#include "ViewManager.h" +#include "PythonQtConsoleViewStep.h" + +#include +#include + +#include + +namespace Calamares { + + +Module::Type +PythonQtViewModule::type() const +{ + return View; +} + + +Module::Interface +PythonQtViewModule::interface() const +{ + return PythonQtInterface; +} + + +void +PythonQtViewModule::loadSelf() +{ + if ( !m_scriptFileName.isEmpty() ) + { + if ( PythonQt::self() == nullptr ) + { + PythonQt::init(); + PythonQt_QtAll::init(); + } + + PythonQtObjectPtr cxt = + PythonQt::self()-> + createModuleFromFile( name(), + m_workingPath + + QDir::separator() + + m_scriptFileName ); + cDebug() << "Creating viewstep for script at" + << m_workingPath + + QDir::separator() + + m_scriptFileName; + + m_viewStep = new PythonQtConsoleViewStep( cxt ); + +// m_viewStep = reinterpret_cast< ViewStep* >( +// PythonQt::self()-> +// lookupObject( cxt, +// "_calamares_module" ).object() ); + +// if ( !m_viewStep ) +// { +// cDebug() << Q_FUNC_INFO << m_loader->errorString(); +// return; +// } + + +// cDebug() << "PythonQtViewModule loading self for instance" << instanceKey() +// << "\nPythonQtViewModule at address" << this +// << "\nCalamares::PluginFactory at address" << pf +// << "\nViewStep at address" << m_viewStep; + + m_viewStep->setModuleInstanceKey( instanceKey() ); + m_viewStep->setConfigurationMap( m_configurationMap ); + ViewManager::instance()->addViewStep( m_viewStep ); + m_loaded = true; + cDebug() << "PythonQtViewModule" << instanceKey() << "loading complete."; + } +} + + +QList< job_ptr > +PythonQtViewModule::jobs() const +{ + return m_viewStep->jobs(); +} + + +void +PythonQtViewModule::initFrom( const QVariantMap& moduleDescriptor ) +{ + Module::initFrom( moduleDescriptor ); + QDir directory( location() ); + m_workingPath = directory.absolutePath(); + + if ( !moduleDescriptor.value( "script" ).toString().isEmpty() ) + { + m_scriptFileName = moduleDescriptor.value( "script" ).toString(); + } +} + +PythonQtViewModule::PythonQtViewModule() + : Module() +{ +} + +PythonQtViewModule::~PythonQtViewModule() +{ +} + +} // namespace Calamares diff --git a/src/libcalamaresui/modulesystem/PythonQtViewModule.h b/src/libcalamaresui/modulesystem/PythonQtViewModule.h new file mode 100644 index 000000000..ba18cfac6 --- /dev/null +++ b/src/libcalamaresui/modulesystem/PythonQtViewModule.h @@ -0,0 +1,54 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_PYTHONQTVIEWMODULE_H +#define CALAMARES_PYTHONQTVIEWMODULE_H + +#include "UiDllMacro.h" +#include "Module.h" + +namespace Calamares { + +class ViewStep; + +class UIDLLEXPORT PythonQtViewModule : public Module +{ +public: + Type type() const override; + Interface interface() const override; + + void loadSelf() override; + QList< job_ptr > jobs() const override; + +protected: + void initFrom( const QVariantMap& moduleDescriptor ) override; + +private: + friend class Module; //so only the superclass can instantiate + explicit PythonQtViewModule(); + virtual ~PythonQtViewModule(); + + ViewStep* m_viewStep = nullptr; + + QString m_scriptFileName; + QString m_workingPath; +}; + +} // namespace Calamares + +#endif // CALAMARES_PYTHONQTVIEWMODULE_H diff --git a/src/libcalamaresui/modulesystem/ViewModule.cpp b/src/libcalamaresui/modulesystem/ViewModule.cpp index ddc70d869..a06ec3fba 100644 --- a/src/libcalamaresui/modulesystem/ViewModule.cpp +++ b/src/libcalamaresui/modulesystem/ViewModule.cpp @@ -39,7 +39,7 @@ ViewModule::type() const Module::Interface ViewModule::interface() const { - return QtPlugin; + return QtPluginInterface; }