GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave-gui.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2015 Jacob Dawid
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <QApplication>
28 #include <QTextCodec>
29 #include <QThread>
30 #include <QTranslator>
31 
32 #include <iostream>
33 
34 #include <unistd.h>
35 #include <fcntl.h>
36 
37 #if defined (HAVE_SYS_IOCTL_H)
38 #include <sys/ioctl.h>
39 #endif
40 
41 #include "lo-utils.h"
42 #include "oct-env.h"
43 #include "oct-syscalls.h"
44 #include "syswait.h"
45 
46 #include "octave.h"
47 #include "sighandlers.h"
48 
49 #include "welcome-wizard.h"
50 #include "resource-manager.h"
51 #include "shortcut-manager.h"
52 #include "main-window.h"
53 #include "octave-gui.h"
54 #include "thread-manager.h"
55 
56 #include "builtin-defun-decls.h"
57 #include "__init_qt__.h"
58 
59 // Allow the Octave interpreter to start as in CLI mode with a
60 // QApplication context so that it can use Qt for things like plotting
61 // and UI widgets.
62 
63 class octave_cli_thread : public QThread
64 {
65 public:
66 
67  octave_cli_thread (int argc, char **argv)
68  : m_argc (argc), m_argv (argv), m_result (0) { }
69 
70  int result (void) const { return m_result; }
71 
72 protected:
73 
74  void run (void)
75  {
77 
79 
81 
82  QApplication::exit (m_result);
83  }
84 
85 private:
86 
87  int m_argc;
88  char** m_argv;
89  int m_result;
90 };
91 
92 // Disable all Qt messages by default.
93 
94 static void
95 message_handler (QtMsgType, const char *)
96 {
97 }
98 
99 // If START_GUI is false, we still set up the QApplication so that we
100 // can use Qt widgets for plot windows.
101 
102 int
103 octave_start_gui (int argc, char *argv[], bool start_gui)
104 {
106 
107  std::string show_gui_msgs = octave_env::getenv ("OCTAVE_SHOW_GUI_MESSAGES");
108 
109  // Installing our handler suppresses the messages.
110  if (show_gui_msgs.empty ())
111  qInstallMsgHandler (message_handler);
112 
114 
116 
117  QApplication application (argc, argv);
118  QTranslator gui_tr, qt_tr, qsci_tr;
119 
120  // Set the codec for all strings (before wizard)
121 #if ! defined (Q_OS_WIN32)
122  QTextCodec::setCodecForCStrings (QTextCodec::codecForName ("UTF-8"));
123 #endif
124 
125  if (start_gui)
126  {
127  // show wizard if this is the first run
129  {
130  // before wizard
131  resource_manager::config_translators (&qt_tr, &qsci_tr, &gui_tr);
132  application.installTranslator (&qt_tr);
133  application.installTranslator (&qsci_tr);
134  application.installTranslator (&gui_tr);
135 
136  welcome_wizard welcomeWizard;
137 
138  if (welcomeWizard.exec () == QDialog::Rejected)
139  exit (1);
140 
141  resource_manager::reload_settings (); // install settings file
142  }
143  else
144  {
145  resource_manager::reload_settings (); // get settings file
146 
147  // after settings
148  resource_manager::config_translators (&qt_tr, &qsci_tr, &gui_tr);
149  application.installTranslator (&qt_tr);
150  application.installTranslator (&qsci_tr);
151  application.installTranslator (&gui_tr);
152  }
153 
154  // update network-settings
156 
157 #if ! defined (__WIN32__) || defined (__CYGWIN__)
158  // If we were started from a launcher, TERM might not be
159  // defined, but we provide a terminal with xterm
160  // capabilities.
161 
162  std::string term = octave_env::getenv ("TERM");
163 
164  if (term.empty ())
165  octave_env::putenv ("TERM", "xterm");
166 #else
167  std::string term = octave_env::getenv ("TERM");
168 
169  if (term.empty ())
170  octave_env::putenv ("TERM", "cygwin");
171 #endif
172 
173  // shortcut manager
175  }
176 
177  // Create and show main window.
178 
179  main_window w (0, start_gui);
180 
181  w.read_settings ();
182 
183  if (start_gui)
184  {
185  w.init_terminal_size ();
186 
187  // Connect signals for changes in visibility not before w
188  // is shown.
189 
191 
193  }
194  else
195  application.setQuitOnLastWindowClosed (false);
196 
197  return application.exec ();
198 }
int octave_execute_interpreter(void)
Definition: octave.cc:844
void run(void)
Definition: octave-gui.cc:74
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:245
void read_settings(void)
static void config_translators(QTranslator *, QTranslator *, QTranslator *)
static void unblock_interrupt_signal(void)
void octave_initialize_interpreter(int argc, char **argv, int embedded)
Definition: octave.cc:725
void install___init_qt___functions(void)
Definition: __init_qt__.cc:136
std::complex< double > w(std::complex< double > z, double relerr=0)
void connect_visibility_changed(void)
static std::string getenv(const std::string &name)
Definition: oct-env.cc:238
static void message_handler(QtMsgType, const char *)
Definition: octave-gui.cc:95
int octave_start_gui(int argc, char *argv[], bool start_gui)
Definition: octave-gui.cc:103
int result(void) const
Definition: octave-gui.cc:70
octave_value_list ovl(const octave_value &a0)
Definition: oct-obj.h:178
void focus_command_window(void)
Definition: main-window.cc:227
OCTINTERP_API octave_value_list Fregister_graphics_toolkit(const octave_value_list &=octave_value_list(), int=0)
Definition: graphics.cc:11132
octave_cli_thread(int argc, char **argv)
Definition: octave-gui.cc:67
static void update_network_settings(void)
void init_terminal_size(void)
static bool start_gui
Definition: octave.cc:169
static bool is_first_run(void)
static void block_interrupt_signal(void)
static void reload_settings(void)
static void init_data()