ctkAbstractPythonManager.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkAbstractPythonManager_h
  15. #define __ctkAbstractPythonManager_h
  16. // Qt includes
  17. #include <QObject>
  18. #include <QList>
  19. #include <QStringList>
  20. // CTK includes
  21. #include "CTKScriptingPythonCoreExport.h"
  22. class PythonQtObjectPtr;
  23. class CTK_SCRIPTING_PYTHON_CORE_EXPORT ctkAbstractPythonManager : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. typedef QObject Superclass;
  28. ctkAbstractPythonManager(QObject* _parent=NULL);
  29. ~ctkAbstractPythonManager();
  30. PythonQtObjectPtr mainContext();
  31. void addObjectToPythonMain(const QString& name, QObject* obj);
  32. void registerPythonQtDecorator(QObject* decorator);
  33. void registerClassForPythonQt(const QMetaObject* metaobject);
  34. void registerCPPClassForPythonQt(const char* name);
  35. ///
  36. /// Execute a python of python code (can be multiple lines separated with newline)
  37. /// and return the result as a QVariant.
  38. QVariant executeString(const QString& code);
  39. ///
  40. /// Gets the value of the variable looking in the __main__ module.
  41. /// If the variable is not found returns a default initialized QVariant.
  42. QVariant getVariable(const QString& varName);
  43. ///
  44. /// Execute a python script with the given filename.
  45. void executeFile(const QString& filename);
  46. signals:
  47. ///
  48. /// This signal is emitted after python is initialized. Observers can listen
  49. /// for this signal to handle additional initialization steps.
  50. void pythonInitialized();
  51. protected slots:
  52. void printStderr(const QString&);
  53. void printStdout(const QString&);
  54. protected:
  55. void initPythonQt();
  56. virtual QStringList pythonPaths();
  57. virtual void preInitialization();
  58. };
  59. #endif