Parcourir la source

ENH: Added first draft of the application ctkSimplePythonShell

ctkSimplePythonShell is an attempt to demonstrate how easy it's possible
to script an application using PythonQt and CTK.
Jean-Christophe Fillion-Robin il y a 15 ans
Parent
commit
6f80162b32

+ 47 - 0
Applications/ctkSimplePythonShell/CMakeLists.txt

@@ -0,0 +1,47 @@
+PROJECT(ctkSimplePythonShell)
+
+#
+# See CTK/CMake/ctkMacroBuildApp.cmake for details
+#
+
+SET(KIT_SRCS
+  ctkSimplePythonManager.cpp
+  ctkSimplePythonManager.h
+  ctkSimplePythonShellMain.cpp
+)
+
+# Headers that should run through moc
+SET(KIT_MOC_SRCS
+  ctkSimplePythonManager.h
+  )
+
+# UI files
+SET(KIT_UI_FORMS
+)
+
+# Resources
+SET(KIT_resources
+)
+
+# Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
+# The following macro will read the target libraries from the file 'target_libraries.cmake'
+ctkMacroGetTargetLibraries(KIT_target_libraries)
+
+# Additional directories to include - Not that CTK_INCLUDE_LIBRARIES is already included
+SET(KIT_include_directories
+  )
+
+ctkMacroBuildApp(
+  NAME ${PROJECT_NAME}
+  INCLUDE_DIRECTORIES ${KIT_include_directories}
+  SRCS ${KIT_SRCS}
+  MOC_SRCS ${KIT_MOC_SRCS}
+  UI_FORMS ${KIT_UI_FORMS}
+  TARGET_LIBRARIES ${KIT_target_libraries}
+  RESOURCES ${KIT_resources}
+  )
+
+# Testing
+IF(BUILD_TESTING)
+#   ADD_SUBDIRECTORY(Testing)
+ENDIF(BUILD_TESTING)

+ 38 - 0
Applications/ctkSimplePythonShell/ctkSimplePythonManager.cpp

@@ -0,0 +1,38 @@
+
+// CTK includes
+#include "ctkSimplePythonManager.h"
+//#include "qSlicerBaseQTBasePythonQtDecorators.h"
+
+//-----------------------------------------------------------------------------
+ctkSimplePythonManager::ctkSimplePythonManager(QObject* _parent) : Superclass(_parent)
+{
+
+}
+
+//-----------------------------------------------------------------------------
+ctkSimplePythonManager::~ctkSimplePythonManager()
+{
+}
+
+//-----------------------------------------------------------------------------
+QStringList ctkSimplePythonManager::pythonPaths()
+{  
+  QStringList paths;  
+  
+  return paths; 
+}
+
+//-----------------------------------------------------------------------------
+void ctkSimplePythonManager::preInitialization()
+{
+  Superclass::preInitialization();
+
+  // Register decorators
+  //this->registerPythonQtDecorator(new qSlicerBaseQTBasePythonQtDecorators(this));
+
+  // Add object to python interpreter context
+  //this->addObjectToPythonMain("_qSlicerCoreApplicationInstance", app);
+
+  // Evaluate application script
+  //this->executeFile(app->slicerHome() + "/bin/Python/slicer/slicerqt.py");
+}

+ 27 - 0
Applications/ctkSimplePythonShell/ctkSimplePythonManager.h

@@ -0,0 +1,27 @@
+#ifndef __ctkSimplePythonManager_h
+#define __ctkSimplePythonManager_h
+
+// CTK includes
+# include <ctkAbstractPythonManager.h>
+
+class PythonQtObjectPtr;
+
+class ctkSimplePythonManager : public ctkAbstractPythonManager
+{
+  Q_OBJECT
+
+public:
+  typedef ctkAbstractPythonManager Superclass;
+  ctkSimplePythonManager(QObject* parent=0);
+  ~ctkSimplePythonManager();
+  
+protected:
+
+  virtual QStringList pythonPaths();
+  virtual void preInitialization();
+
+};
+
+
+#endif
+

+ 22 - 0
Applications/ctkSimplePythonShell/ctkSimplePythonShellMain.cpp

@@ -0,0 +1,22 @@
+
+// Qt includes
+#include <QApplication>
+
+// CTK includes
+#include <ctkPythonShell.h>
+
+#include "ctkSimplePythonManager.h"
+
+int main(int argc, char** argv)
+{
+  QApplication app(argc, argv);
+  
+  ctkSimplePythonManager pythonManager;
+  
+  ctkPythonShell shell(&pythonManager);
+  shell.setAttribute(Qt::WA_QuitOnClose, false);
+  shell.resize(600, 280);
+  shell.show();
+  
+  return app.exec();
+}

+ 9 - 0
Applications/ctkSimplePythonShell/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK application.
+# 
+
+SET(target_libraries
+  CTKScriptingPythonWidgets
+  )

+ 1 - 0
CMakeLists.txt

@@ -292,6 +292,7 @@ SET(CTK_APPLICATIONS
   ctkDICOMQuery:OFF
   ctkDICOMRetrieve:OFF
   ctkPluginBrowser:OFF
+  ctkSimplePythonShell:OFF
   )
   
 #-----------------------------------------------------------------------------