ctkAbstractPythonManager.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkAbstractPythonManager_h
  11. #define __ctkAbstractPythonManager_h
  12. // Qt includes
  13. #include <QObject>
  14. #include <QList>
  15. #include <QStringList>
  16. // CTK includes
  17. #include "CTKScriptingPythonCoreExport.h"
  18. class PythonQtObjectPtr;
  19. class CTK_SCRIPTING_PYTHON_CORE_EXPORT ctkAbstractPythonManager : public QObject
  20. {
  21. Q_OBJECT
  22. public:
  23. typedef QObject Superclass;
  24. ctkAbstractPythonManager(QObject* _parent=NULL);
  25. ~ctkAbstractPythonManager();
  26. PythonQtObjectPtr mainContext();
  27. void addObjectToPythonMain(const QString& name, QObject* obj);
  28. void registerPythonQtDecorator(QObject* decorator);
  29. void registerClassForPythonQt(const QMetaObject* metaobject);
  30. void registerCPPClassForPythonQt(const char* name);
  31. ///
  32. /// Execute a python of python code (can be multiple lines separated with newline)
  33. /// and return the result as a QVariant.
  34. QVariant executeString(const QString& code);
  35. ///
  36. /// Gets the value of the variable looking in the __main__ module.
  37. /// If the variable is not found returns a default initialized QVariant.
  38. QVariant getVariable(const QString& varName);
  39. ///
  40. /// Execute a python script with the given filename.
  41. void executeFile(const QString& filename);
  42. signals:
  43. ///
  44. /// This signal is emitted after python is initialized. Observers can listen
  45. /// for this signal to handle additional initialization steps.
  46. void pythonInitialized();
  47. protected slots:
  48. void printStderr(const QString&);
  49. void printStdout(const QString&);
  50. protected:
  51. void initPythonQt();
  52. virtual QStringList pythonPaths();
  53. virtual void preInitialization();
  54. };
  55. #endif