GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
interpreter-qobject.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "interpreter-qobject.h"
31 #include "octave-qobject.h"
32 #include "qt-application.h"
33 #include "qt-interpreter-events.h"
34 
35 #include "graphics-init.h"
36 #include "input.h"
37 #include "interpreter.h"
38 
39 namespace octave
40 {
42  : QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr)
43  { }
44 
46  {
47  // The Octave application context owns the interpreter.
48 
49  qt_application& app_context = m_octave_qobj.app_context ();
50 
51  interpreter& interp = app_context.create_interpreter ();
52 
53  event_manager& evmgr = interp.get_event_manager ();
54 
56  evmgr.enable ();
57 
58  int exit_status = 0;
59 
60  try
61  {
62  // Final initialization.
63 
64  interp.initialize ();
65 
66  if (app_context.start_gui_p ())
67  {
68  input_system& input_sys = interp.get_input_system ();
69 
70  input_sys.PS1 (">> ");
71  input_sys.PS2 ("");
72  }
73 
74  if (interp.initialized ())
75  {
76  // The interpreter should be completely ready at this point so let
77  // the GUI know.
78 
79  m_interpreter = &interp;
80 
81  emit ready ();
82 
83  graphics_init (interp, m_octave_qobj);
84 
85  // Start executing commands in the command window.
86 
87  exit_status = interp.execute ();
88  }
89  }
90  catch (const exit_exception& ex)
91  {
92  exit_status = ex.exit_status ();
93  }
94 
95  // Signal that the interpreter is done executing code in the main
96  // REPL, from script files, or command line eval arguments. By
97  // using a signal here, we give the GUI a chance to process any
98  // pending events, then signal that it is safe to shutdown the
99  // interpreter. Our notification here allows the GUI to insert the
100  // request to shutdown the interpreter in the event queue after any
101  // other pending signals. The application context owns the
102  // interpreter and will be responsible for deleting it later, when
103  // the application object destructor is executed.
104 
105  emit execution_finished (exit_status);
106  }
107 
108  // This function is expected to be executed when the GUI signals that
109  // it is finished processing events and ready for the interpreter to
110  // perform shutdown actions.
111 
112  void interpreter_qobject::shutdown (int exit_status)
113  {
114  if (m_interpreter)
116 
117  // Signal that the interpreter has executed shutdown actions.
118 
119  emit shutdown_finished (exit_status);
120  }
121 
123  {
124  if (! m_interpreter)
125  return;
126 
128 
129  evmgr.post_event (fcn);
130  }
131 
133  {
134  if (! m_interpreter)
135  return;
136 
138 
139  evmgr.post_event (meth);
140  }
141 
143  {
144  return m_octave_qobj.qt_link ();
145  }
146 }
virtual interpreter & create_interpreter(void)
Definition: octave.cc:299
Base class for Octave interfaces that use Qt.
qt_application & app_context(void)
std::shared_ptr< qt_interpreter_events > get_qt_interpreter_events(void)
qt_interpreter_events * qt_link(void)
Provides threadsafe access to octave.
void post_event(const fcn_callback &fcn)
void connect_link(const std::shared_ptr< interpreter_events > &obj)
octave_value PS1(const octave_value_list &args, int nargout)
octave_value PS2(const octave_value_list &args, int nargout)
interpreter_qobject(base_qobject &oct_qobj)
void interpreter_event(const fcn_callback &fcn)
qt_interpreter_events * qt_link(void)
void execute(void)
Initialize and execute the octave interpreter.
input_system & get_input_system(void)
Definition: interpreter.h:223
bool initialized(void) const
Definition: interpreter.h:193
event_manager & get_event_manager(void)
Definition: interpreter.h:290
void initialize(void)
Definition: interpreter.cc:714
This class inherits from the pure-virtual base class octave::application and provides an implementati...
bool start_gui_p(void) const
std::function< void(octave::interpreter &)> meth_callback
Definition: event-manager.h:47
std::function< void(void)> fcn_callback
Definition: event-manager.h:46
void graphics_init(interpreter &interp, base_qobject &oct_qobj)