annotate libgui/src/interpreter-qobject.cc @ 27197:b8c0d5ad024f

refactor and rename some qt application objects * octave-qobject.h, octave-qobject.cc: New files. Move octave_qapplication, octave_qt_app, octave_qt_cli_app, and octave_qt_gui_app classes here from main-window.h and main-window.cc. Rename octave_qt_app to base_qobject. Rename octave_qt_cli_app to cli_qobject. Rename octave_qt_gui_app to gui_qobject. * qt-application.h, qt-application.cc: Rename from octave-gui.h and octave-gui.cc. Rename gui_application class to qt_application. Change all uses. * libgui/src/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Sat, 22 Jun 2019 17:30:16 -0500
parents d993642352d0
children a044202208af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 Copyright (C) 2013-2019 John W. Eaton
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 Copyright (C) 2011-2019 Jacob Dawid
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 (at your option) any later version.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 GNU General Public License for more details.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 <https://www.gnu.org/licenses/>.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #if defined (HAVE_CONFIG_H)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 # include "config.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #endif
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include "interpreter-qobject.h"
27197
b8c0d5ad024f refactor and rename some qt application objects
John W. Eaton <jwe@octave.org>
parents: 27196
diff changeset
29 #include "qt-application.h"
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "input.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "interpreter.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 namespace octave
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 {
27197
b8c0d5ad024f refactor and rename some qt application objects
John W. Eaton <jwe@octave.org>
parents: 27196
diff changeset
36 interpreter_qobject::interpreter_qobject (qt_application& app_context)
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 : QObject (), m_app_context (app_context)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 { }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 void interpreter_qobject::execute (void)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 // The application context owns the interpreter.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 interpreter& interp = m_app_context.create_interpreter ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 int exit_status = 0;
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 try
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 // Final initialization.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 interp.initialize ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 if (m_app_context.start_gui_p ())
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 input_system& input_sys = interp.get_input_system ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 input_sys.PS1 (">> ");
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 input_sys.PS2 ("");
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 if (interp.initialized ())
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 // The interpreter should be completely ready at this point so let
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 // the GUI know.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 emit octave_ready_signal ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 // Start executing commands in the command window.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 exit_status = interp.execute ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 catch (const exit_exception& ex)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 exit_status = ex.exit_status ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 // Whether or not initialization succeeds we need to clean up the
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 // interpreter once we are done with it.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 m_app_context.delete_interpreter ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 emit octave_finished_signal (exit_status);
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 }