ctkPythonShell.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /*=========================================================================
  11. Program: ParaView
  12. Module: $RCSfile$
  13. Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
  14. All rights reserved.
  15. ParaView is a free software; you can redistribute it and/or modify it
  16. under the terms of the ParaView license version 1.2.
  17. See License_v1.2.txt for the full ParaView license.
  18. A copy of this license can be obtained by contacting
  19. Kitware Inc.
  20. 28 Corporate Drive
  21. Clifton Park, NY 12065
  22. USA
  23. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  27. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. =========================================================================*/
  35. #ifndef __ctkPythonShell_h
  36. #define __ctkPythonShell_h
  37. // Qt includes
  38. #include <QWidget>
  39. // CTK includes
  40. #include "CTKScriptingPythonWidgetsExport.h"
  41. /**
  42. Qt widget that provides an interactive "shell" interface to an embedded Python interpreter.
  43. You can put an instance of ctkPythonShell in a dialog or a window, and the user will be able
  44. to enter Python commands and see their output, while the UI is still responsive.
  45. \sa pqConsoleWidget, pqPythonDialog
  46. */
  47. class ctkAbstractPythonManager;
  48. class CTK_SCRIPTING_PYTHON_WIDGETS_EXPORT ctkPythonShell :
  49. public QWidget
  50. {
  51. Q_OBJECT
  52. public:
  53. typedef QWidget Superclass;
  54. ctkPythonShell(ctkAbstractPythonManager* pythonManager, QWidget* _parent = 0);
  55. ~ctkPythonShell();
  56. /// Initializes the interpretor. If an interpretor is already setup (by an
  57. /// earlier call to this method), it will be destroyed.
  58. // void initializeInterpretor(int argc, char* argv[]);
  59. // void initializeInterpretor();
  60. /// Prints some text on the shell.
  61. void printMessage(const QString&);
  62. /// Calls MakeCurrent in the internal vtkPVPythonInteractiveInterpretor instance
  63. // void makeCurrent();
  64. /// Calls ReleaseControl in the internal vtkPVPythonInteractiveInterpretor instance
  65. // void releaseControl();
  66. /// Given a python variable name, lookup its attributes and return them in a
  67. /// string list.
  68. QStringList getPythonAttributes(const QString& pythonVariableName);
  69. signals:
  70. void executing(bool);
  71. public slots:
  72. void clear();
  73. void executeScript(const QString&);
  74. protected slots:
  75. void printStderr(const QString&);
  76. void printStdout(const QString&);
  77. void onExecuteCommand(const QString&);
  78. private:
  79. ctkPythonShell(const ctkPythonShell&);
  80. ctkPythonShell& operator=(const ctkPythonShell&);
  81. void promptForInput();
  82. void internalExecuteCommand(const QString&);
  83. struct pqImplementation;
  84. pqImplementation* const Implementation;
  85. };
  86. #endif // !__ctkPythonShell_h