diff --git a/Examples/Plugins/PluginList.cmake b/Examples/Plugins/PluginList.cmake index b9d0c5d492..1f986c8b36 100644 --- a/Examples/Plugins/PluginList.cmake +++ b/Examples/Plugins/PluginList.cmake @@ -1,25 +1,26 @@ # Plug-ins must be ordered according to their dependencies set(MITK_EXAMPLE_PLUGINS org.mitk.example.gui.minimalapplication:ON org.mitk.example.gui.customviewer:ON org.mitk.example.gui.customviewer.views:ON org.mitk.example.gui.multipleperspectives:ON org.mitk.example.gui.selectionserviceqt:ON org.mitk.example.gui.selectionservicemitk:ON org.mitk.example.gui.selectionservicemitk.views:ON org.mitk.example.gui.extensionpointdefinition:ON org.mitk.example.gui.extensionpointcontribution:ON org.mitk.example.gui.regiongrowing:ON org.mitk.example.gui.pcaexample:ON org.mitk.example.gui.imaging:ON + org.mitk.example.gui.pythonexample:ON ) if(MITK_USE_OpenCV) list(APPEND MITK_EXAMPLE_PLUGINS org.mitk.example.gui.opencv:ON) else() list(APPEND MITK_EXAMPLE_PLUGINS org.mitk.example.gui.opencv:OFF) endif() diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/CMakeLists.txt b/Examples/Plugins/org.mitk.example.gui.pythonexample/CMakeLists.txt new file mode 100644 index 0000000000..8bb09bbf5d --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/CMakeLists.txt @@ -0,0 +1,7 @@ +project(org_mitk_example_gui_pythonexample) + +mitk_create_plugin( + EXPORT_DIRECTIVE PYTHONEXAMPLE_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDS MitkQtWidgetsExt MitkPython +) diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox new file mode 100644 index 0000000000..343ef00178 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/Manual.dox @@ -0,0 +1,17 @@ +/** +\page org_mitk_example_gui_pythonexample The Python Example + +\imageMacro{icon.png,"Icon of Python Example",2.00} + +\tableofcontents + +\section org_mitk_example_gui_pythonexampleOverview Overview +Describe the features of your awesome plugin here + + +*/ diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/icon.xpm b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/icon.xpm new file mode 100644 index 0000000000..9057c20bc6 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/UserManual/icon.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * icon_xpm[] = { +"16 16 2 1", +" c #FF0000", +". c #000000", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/doxygen/modules.dox b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/doxygen/modules.dox new file mode 100644 index 0000000000..d9018cfdd1 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/documentation/doxygen/modules.dox @@ -0,0 +1,16 @@ +/** + \defgroup org_mitk_example_gui_pythonexample org.mitk.example.gui.pythonexample + \ingroup MITKPlugins + + \brief Describe your plugin here. + +*/ + +/** + \defgroup org_mitk_example_gui_pythonexample_internal Internal + \ingroup org_mitk_example_gui_pythonexample + + \brief This subcategory includes the internal classes of the org.mitk.example.gui.pythonexample plugin. Other + plugins must not rely on these classes. They contain implementation details and their interface + may change at any time. We mean it. +*/ diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/files.cmake b/Examples/Plugins/org.mitk.example.gui.pythonexample/files.cmake new file mode 100644 index 0000000000..f6f9f8fdbd --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/files.cmake @@ -0,0 +1,44 @@ +set(SRC_CPP_FILES + +) + +set(INTERNAL_CPP_FILES + org_mitk_example_gui_pythonexample_Activator.cpp + PythonExample.cpp + PythonWorker.cpp +) + +set(UI_FILES + src/internal/PythonExampleControls.ui +) + +set(MOC_H_FILES + src/internal/org_mitk_example_gui_pythonexample_Activator.h + src/internal/PythonExample.h + src/internal/PythonWorker.h +) + +# list of resource files which can be used by the plug-in +# system without loading the plug-ins shared library, +# for example the icon used in the menu and tabs for the +# plug-in views in the workbench +set(CACHED_RESOURCE_FILES + resources/icon.xpm + plugin.xml +) + +# list of Qt .qrc files which contain additional resources +# specific to this plugin +set(QRC_FILES + +) + +set(CPP_FILES ) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach(file ${SRC_CPP_FILES}) + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/manifest_headers.cmake b/Examples/Plugins/org.mitk.example.gui.pythonexample/manifest_headers.cmake new file mode 100644 index 0000000000..1c8c1b2bfd --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/manifest_headers.cmake @@ -0,0 +1,5 @@ +set(Plugin-Name "Python Example") +set(Plugin-Version "0.1") +set(Plugin-Vendor "German Cancer Research Center (DKFZ)") +set(Plugin-ContactAddress "") +set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/plugin.xml b/Examples/Plugins/org.mitk.example.gui.pythonexample/plugin.xml new file mode 100644 index 0000000000..2669e08e5e --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/hello.py b/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/hello.py new file mode 100644 index 0000000000..d79cdc10c7 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/hello.py @@ -0,0 +1,8 @@ +import time + +inc = 1 +while inc<=3: + print(inc) + inc+=1 + time.sleep(5) +print("Done") \ No newline at end of file diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/icon.xpm b/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/icon.xpm new file mode 100644 index 0000000000..9057c20bc6 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/resources/icon.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * icon_xpm[] = { +"16 16 2 1", +" c #FF0000", +". c #000000", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.cpp b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.cpp new file mode 100644 index 0000000000..1f33f693fc --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.cpp @@ -0,0 +1,89 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include"org_mitk_example_gui_pythonexample_Activator.h" +// Blueberry +#include +#include + +// Qmitk +#include "PythonExample.h" + +// Qt +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + + +US_INITIALIZE_MODULE + + +const std::string PythonExample::VIEW_ID = "org.mitk.views.pythonexample"; + +PythonExample::~PythonExample() +{ + if (m_PythonThread->isRunning()) + { + m_PythonThread->quit(); + } +} + +void PythonExample::SetFocus() +{ + m_Controls.buttonRunPythonCode->setFocus(); +} + +void PythonExample::CreateQtPartControl(QWidget *parent) +{ + // create GUI widgets from the Qt Designer's .ui file + m_Controls.setupUi(parent); + connect(m_Controls.buttonRunPythonCode, &QPushButton::clicked, this, &PythonExample::OnRunPythonCode); + m_Controls.labelCodeRunning->setVisible(false); + m_PythonThread = new QThread; + m_Worker = new PythonWorker; + m_Worker->moveToThread(m_PythonThread); + connect(m_PythonThread, &QThread::finished, m_Worker, &QObject::deleteLater); + connect(this, &PythonExample::Operate, m_Worker, &PythonWorker::DoWork); + connect(m_Worker, &PythonWorker::Finished, this, &PythonExample::ExecutionFinished); + connect(m_Worker, &PythonWorker::Failed, this, &PythonExample::ExecutionFailed); +} + +void PythonExample::OnRunPythonCode() +{ + MITK_INFO << "[Start] Run Python Code"; + m_Controls.labelCodeRunning->setVisible(true); + m_Controls.buttonRunPythonCode->setEnabled(false); + m_PythonThread->start(); + emit Operate(); +} + +void PythonExample::ExecutionFinished() +{ + QMessageBox::information(nullptr, "Finished python execution", "Execution of python code finished successfully."); + m_Controls.labelCodeRunning->setVisible(false); + m_Controls.buttonRunPythonCode->setEnabled(true); +} + +void PythonExample::ExecutionFailed() +{ + QMessageBox::warning(nullptr, "Error in running python", "There was an error running the Python Code."); + m_Controls.labelCodeRunning->setVisible(false); + m_Controls.buttonRunPythonCode->setEnabled(true); +} diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.h b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.h new file mode 100644 index 0000000000..5437850da7 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExample.h @@ -0,0 +1,71 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + + +#ifndef PythonExample_h +#define PythonExample_h + +#include + +#include + +#include "PythonWorker.h" + +#include "ui_PythonExampleControls.h" +#include +#include +#include + +/** + \brief PythonExample + + \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. + + \sa QmitkAbstractView + \ingroup ${plugin_target}_internal +*/ +class PythonExample : public QmitkAbstractView +{ + // this is needed for all Qt objects that should have a Qt meta-object + // (everything that derives from QObject and wants to have signal/slots) + Q_OBJECT + +public: + static const std::string VIEW_ID; + ~PythonExample(); + +signals: + void Operate(); + +protected: + virtual void CreateQtPartControl(QWidget *parent) override; + + virtual void SetFocus() override; + + /// \brief called by QmitkFunctionality when DataManager's selection has changed + //virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, + // const QList &nodes) override; + + /// \brief Called when the user clicks the GUI button + void OnRunPythonCode(); + + void ExecutionFinished(); + + void ExecutionFailed(); + + QThread* m_PythonThread; + PythonWorker *m_Worker; + + Ui::PythonExampleControls m_Controls; +}; + +#endif // PythonExample_h diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExampleControls.ui b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExampleControls.ui new file mode 100644 index 0000000000..346c4ebb04 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonExampleControls.ui @@ -0,0 +1,61 @@ + + + PythonExampleControls + + + + 0 + 0 + 222 + 161 + + + + + 0 + 0 + + + + QmitkTemplate + + + + + + Do image processing + + + RunPythonCode + + + + + + + <html><head/><body><p><span style=" color:#ff0000;">Python Code running...</span></p></body></html> + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 220 + + + + + + + + + + diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.cpp b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.cpp new file mode 100644 index 0000000000..cd44ab873b --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.cpp @@ -0,0 +1,54 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ +#include"PythonWorker.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void PythonWorker::DoWork() +{ + MITK_INFO << "Here"; + auto *context = us::GetModuleContext(); + std::string filter = "(Name=PythonService)"; + mitk::IPythonService::ForceLoadModule(); + auto m_PythonServiceRefs = context->GetServiceReferences(filter); + + if (!m_PythonServiceRefs.empty()) + { + mitk::IPythonService *m_PythonService = + dynamic_cast(context->GetService(m_PythonServiceRefs.front())); + + try + { + std::string pythonFileName = "hello.py"; + std::string fileName = mitk::StandardFileLocations::GetInstance()->FindFile( + pythonFileName.c_str(), "Examples/Plugins/org.mitk.example.gui.pythonexample/resources"); + m_PythonService->ExecuteScript(fileName); + emit Finished(); + } + catch (const mitk::Exception &e) + { + MITK_ERROR << e.GetDescription(); + emit Failed(); + } + } + else + { + MITK_ERROR << "No Service reference found"; + } +} diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.h b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.h new file mode 100644 index 0000000000..e9d8dbfc07 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/PythonWorker.h @@ -0,0 +1,28 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ +#ifndef PythonWorker_h +#define PythonWorker_h + +#include + +class PythonWorker : public QObject +{ + Q_OBJECT +public slots: + void DoWork(); + +signals: + void Finished(); + void Failed(); +}; + +#endif \ No newline at end of file diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.cpp b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.cpp new file mode 100644 index 0000000000..482933622b --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.cpp @@ -0,0 +1,29 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + + +#include "org_mitk_example_gui_pythonexample_Activator.h" +#include "PythonExample.h" + +namespace mitk +{ + ctkPluginContext *org_mitk_example_gui_pythonexample_Activator::m_Context = nullptr; + void org_mitk_example_gui_pythonexample_Activator::start(ctkPluginContext *context) + { + m_Context = context; + BERRY_REGISTER_EXTENSION_CLASS(PythonExample, context) + } + + void org_mitk_example_gui_pythonexample_Activator::stop(ctkPluginContext *context) { Q_UNUSED(context) } + + ctkPluginContext *org_mitk_example_gui_pythonexample_Activator::GetContext() { return m_Context; } +} diff --git a/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.h b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.h new file mode 100644 index 0000000000..76f6717243 --- /dev/null +++ b/Examples/Plugins/org.mitk.example.gui.pythonexample/src/internal/org_mitk_example_gui_pythonexample_Activator.h @@ -0,0 +1,38 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + + +#ifndef org_mitk_example_gui_pythonexample_Activator_h +#define org_mitk_example_gui_pythonexample_Activator_h + +#include + +namespace mitk +{ + class org_mitk_example_gui_pythonexample_Activator : public QObject, public ctkPluginActivator + { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org_mitk_example_gui_pythonexample") + Q_INTERFACES(ctkPluginActivator) + + public: + void start(ctkPluginContext *context); + void stop(ctkPluginContext *context); + static ctkPluginContext *GetContext(); + + private: + static ctkPluginContext *m_Context; + + }; // org_mitk_example_gui_pythonexample_Activator +} + +#endif // org_mitk_example_gui_pythonexample_Activator_h