SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PythonInterpreter.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef CORE_PYTHON_PYTHONINTERPRETER_H
30 #define CORE_PYTHON_PYTHONINTERPRETER_H
31 
32 //#include <boost/python.hpp>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/signals2/signal.hpp>
35 
36 #include <Core/Utils/Singleton.h>
37 #include <Core/Python/share.h>
38 //#include <Core/EventHandler/EventHandler.h>
39 //#include <Core/Python/PythonActionContext.h>
40 
41 class PythonStdIO;
42 
43 namespace SCIRun
44 {
45 namespace Core
46 {
47 
48 ///@class PythonInterpreter
49 ///@brief A wrapper class of the python interpreter.
50 ///@details It calls the python interpreter on a separate thread.
51 
53 typedef boost::shared_ptr< PythonInterpreterPrivate > PythonInterpreterPrivateHandle;
54 
55 class SCISHARE PythonInterpreter /*: private Core::EventHandler*/
56 {
58 
59 public:
60 
61 
62 private:
64  virtual ~PythonInterpreter();
65 
66  // -- overloaded event handler --
67 private:
68  // INITIALIZE_EVENTHANDLER:
69  /// This function initializes the event handler associated with the singleton
70  /// class. It initializes the python interpreter.
71  void initialize_eventhandler();
72 
73 public:
74  // PRINT_BANNER:
75  /// Print the basic information about the python interpreter to output_signal_.
76  void print_banner();
77 
78  // RUN_STRING:
79  /// Execute a single python command.
80  /// NOTE: The command is run in the main namespace.
81  void run_string( const std::string& command );
82 
83  // RUN_SCRIPT:
84  /// Execute a python script.
85  /// NOTE: The script is run in its own local namespace.
86  void run_script( const std::string& script );
87 
88  // RUN_FILE:
89  /// Execute a python script from file.
90  /// NOTE: The script is run in its own local namespace.
91  void run_file( const std::string& file_name );
92 
93  // INTERRUPT:
94  /// Interrupt the current execution.
95  void interrupt();
96 
97  // START_TERMINAL:
98  /// To be implemented.
99  void start_terminal();
100 
101  // -- signals --
102 public:
103  typedef boost::signals2::signal< void ( const std::string& ) > console_output_signal_type;
107 
108 private:
109  friend class ::PythonStdIO;
111 
112 public:
113  // ESCAPEQUOTES:
114  /// Escape the quotes(') and backslashes(\) in a string so it can be used as a python string enclosed
115  /// by a pair of single quotes.
116  static std::string EscapeSingleQuotedString( const std::string& input_str );
117 };
118 
119 }}
120 
121 #endif
console_output_signal_type prompt_signal_
Definition: PythonInterpreter.h:104
#define SCISHARE
Definition: share.h:39
console_output_signal_type error_signal_
Definition: PythonInterpreter.h:105
boost::shared_ptr< PythonInterpreterPrivate > PythonInterpreterPrivateHandle
Definition: PythonInterpreter.h:52
#define CORE_SINGLETON(name)
Definition: Singleton.h:59
console_output_signal_type output_signal_
Definition: PythonInterpreter.h:106
boost::signals2::signal< void(const std::string &) > console_output_signal_type
Definition: PythonInterpreter.h:103
A wrapper class of the python interpreter.
Definition: PythonInterpreter.h:55
Definition: PythonInterpreter.cc:60
Definition: PythonInterpreter.cc:162