# HG changeset patch # User John W. Eaton # Date 1619020832 14400 # Node ID f6ad83cbe3c41ffcff8a6d069a24d6f1eb4beff3 # Parent 60af3f38f4b1d4501d5f0ac87d9cc1a7da44c77f simplify interpreter shutdown in the GUI * interpreter-qobject.h, interpreter-qobject.cc (interpreter_qobject::execution_finished): Delete signal. (interpreter_qobject::shutdown): Delete slot. (interpreter_qobject::execute): Perform the same actions for new and old terminal widgets. * octave-qobject.h, octave-qobject.cc (base_qobject::request_interpreter_shutdown): Delete signal. (base_qobject::base_qobject): Don't connect it to interpreter_qobject::shutdown. (base_qobject::handle_interpreter_execution_finished): Delete slot. (base_qobject::base_qobject): Don't connect it to interpreter_qobject::execution_finished. (base_qobject::handle_interpreter_shutdown_finished): Delete slot. (base_qobject::base_qobject): Don't connect it to interpreter_qobject::shutdown_finished. (base_qobject::base_qobject): For both new and old terminal widgets, connect interpreter_qobject::shutdown_finished to octave_qapplication::exit. (base_qobject::exec): Perform same actions for old and new terminal widgets. Wait for main thread and print newline for Mac systems here. diff -r 60af3f38f4b1 -r f6ad83cbe3c4 libgui/src/interpreter-qobject.cc --- a/libgui/src/interpreter-qobject.cc Wed Apr 21 11:43:23 2021 -0400 +++ b/libgui/src/interpreter-qobject.cc Wed Apr 21 12:00:32 2021 -0400 @@ -96,40 +96,20 @@ exit_status = xe.exit_status (); } - if (m_octave_qobj.experimental_terminal_widget ()) - { - interp.shutdown (); + interp.shutdown (); - emit shutdown_finished (exit_status); - } - else - { - // Signal that the interpreter is done executing code in the - // main REPL, from script files, or command line eval arguments. - // By using a signal here, we give the GUI a chance to process - // any pending events, then signal that it is safe to shutdown - // the interpreter. Our notification here allows the GUI to - // insert the request to shutdown the interpreter in the event - // queue after any other pending signals. The application - // context owns the interpreter and will be responsible for - // deleting it later, when the application object destructor is - // executed. + // Signal that the interpreter is done executing code in the + // main REPL, from script files, or command line eval arguments. + // By using a signal here, we give the GUI a chance to process + // any pending events, then signal that it is safe to shutdown + // the interpreter. Our notification here allows the GUI to + // insert the request to shutdown the interpreter in the event + // queue after any other pending signals. The application + // context owns the interpreter and will be responsible for + // deleting it later, when the application object destructor is + // executed. - emit execution_finished (exit_status); - } - } - - void interpreter_qobject::shutdown (int exit_status) - { - if (! m_octave_qobj.experimental_terminal_widget ()) - { - if (m_interpreter) - m_interpreter->shutdown (); - - // Signal that the interpreter has executed shutdown actions. - - emit shutdown_finished (exit_status); - } + emit shutdown_finished (exit_status); } void interpreter_qobject::interpreter_event (const fcn_callback& fcn) diff -r 60af3f38f4b1 -r f6ad83cbe3c4 libgui/src/interpreter-qobject.h --- a/libgui/src/interpreter-qobject.h Wed Apr 21 11:43:23 2021 -0400 +++ b/libgui/src/interpreter-qobject.h Wed Apr 21 12:00:32 2021 -0400 @@ -64,10 +64,6 @@ void ready (void); - void execution_finished (int); - - // Note: SHUTDOWN_FINISHED is currently only used by the new - // experimental terminal widget. void shutdown_finished (int); public slots: @@ -94,10 +90,6 @@ void execute (void); - // Note: SHUTDOWN is currently only used by the new experimental - // terminal widget. - void shutdown (int); - private: base_qobject& m_octave_qobj; diff -r 60af3f38f4b1 -r f6ad83cbe3c4 libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc Wed Apr 21 11:43:23 2021 -0400 +++ b/libgui/src/octave-qobject.cc Wed Apr 21 12:00:32 2021 -0400 @@ -204,17 +204,11 @@ // Force left-to-right alignment (see bug #46204) m_qapplication->setLayoutDirection (Qt::LeftToRight); - if (! m_app_context.experimental_terminal_widget ()) - { - connect (m_interpreter_qobj, SIGNAL (execution_finished (int)), - this, SLOT (handle_interpreter_execution_finished (int))); - - connect (this, SIGNAL (request_interpreter_shutdown (int)), - m_interpreter_qobj, SLOT (shutdown (int))); - } - - connect (m_interpreter_qobj, SIGNAL (shutdown_finished (int)), - this, SLOT (handle_interpreter_shutdown_finished (int))); + // Qt docs recommend using Qt::QueuedConnection when connecting to + // the QCoreApplication::exit slot. + connect (m_interpreter_qobj, &interpreter_qobject::shutdown_finished, + m_qapplication, &octave_qapplication::exit, + Qt::QueuedConnection); connect (m_main_thread, SIGNAL (finished (void)), m_main_thread, SLOT (deleteLater (void))); @@ -332,17 +326,15 @@ int base_qobject::exec (void) { - int status; - - if (m_app_context.experimental_terminal_widget ()) - { - status = m_qapplication->exec (); + int status = m_qapplication->exec (); - m_main_thread->quit (); - m_main_thread->wait (); - } - else - status = m_qapplication->exec (); +#if defined (Q_OS_MAC) + // fprintf to stderr is needed by macOS, for poorly-understood reasons. + fprintf (stderr, "\n"); +#endif + + m_main_thread->quit (); + m_main_thread->wait (); return status; } @@ -441,30 +433,11 @@ } } - void base_qobject::handle_interpreter_execution_finished (int exit_status) - { - if (! m_app_context.experimental_terminal_widget ()) - emit request_interpreter_shutdown (exit_status); - } - void base_qobject::interpreter_ready (void) { m_interpreter_ready = true; } - void base_qobject::handle_interpreter_shutdown_finished (int exit_status) - { -#if defined (Q_OS_MAC) - // fprintf to stderr is needed by macOS, for poorly-understood reasons. - fprintf (stderr, "\n"); -#endif - - m_main_thread->quit (); - m_main_thread->wait (); - - qApp->exit (exit_status); - } - void base_qobject::interpreter_event (const fcn_callback& fcn) { // The following is a direct function call across threads. It works diff -r 60af3f38f4b1 -r f6ad83cbe3c4 libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h Wed Apr 21 11:43:23 2021 -0400 +++ b/libgui/src/octave-qobject.h Wed Apr 21 12:00:32 2021 -0400 @@ -145,24 +145,15 @@ virtual bool confirm_shutdown (void); - signals: - - void request_interpreter_shutdown (int); - public slots: // Note: START_GUI and CLOSE_GUI don't currently perform any work - // with the old terminal widget and - // HANDLE_INTERPRETER_EXECUTION_FINISHED doesn't perform any action - // with the new experimental terminal widget. + // with the old terminal widget. void start_gui (bool gui_app); void close_gui (void); - void handle_interpreter_execution_finished (int); void interpreter_ready (void); - void handle_interpreter_shutdown_finished (int); - void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth);