26 #if defined (HAVE_CONFIG_H)
32 #include "builtin-defun-decls.h"
64 ee.display (std::cerr);
68 : m_event_queue_mutex (new
mutex ()), m_gui_event_queue (),
69 m_debugging (false), m_link_enabled (true),
71 m_qt_event_handlers ()
104 warning (
"event_manager: must have connected link to enable");
138 std::shared_ptr<event_queue> evq (
new event_queue ());
202 if (interp.experimental_terminal_widget ())
218 warning (
"GUI desktop is already running");
221 error (
"desktop function requires new experimental terminal widget");
226 DEFMETHOD (__event_manager_enabled__, interp, , ,
237 DEFMETHOD (__event_manager_have_dialogs__, interp, , ,
248 DEFMETHOD (__event_manager_edit_file__, interp, args, ,
258 if (args.length () == 1)
261 = args(0).xstring_value (
"first argument must be filename");
267 else if (args.length () == 2)
270 = args(0).xstring_value (
"first argument must be filename");
280 DEFMETHOD (__event_manager_question_dialog__, interp, args, ,
288 if (args.length () == 6)
290 std::string msg = args(0).
xstring_value (
"invalid arguments");
291 std::string title = args(1).xstring_value (
"invalid arguments");
292 std::string btn1 = args(2).xstring_value (
"invalid arguments");
293 std::string btn2 = args(3).xstring_value (
"invalid arguments");
294 std::string btn3 = args(4).xstring_value (
"invalid arguments");
295 std::string btndef = args(5).xstring_value (
"invalid arguments");
307 DEFMETHOD (__event_manager_file_dialog__, interp, args, ,
313 if (args.length () != 5)
319 std::string title = args(1).string_value ();
320 std::string filename = args(2).string_value ();
321 std::string multi_on = args(3).string_value ();
322 std::string pathname = args(4).string_value ();
329 filter_lst.push_back (std::make_pair (flist(i, 0),
331 ? flist(i, 1) :
"")));
337 std::list<std::string> items_lst
338 = evmgr.
file_dialog (filter_lst, title, filename, pathname, multi_on);
340 nel = items_lst.size ();
345 if (items_lst.front ().empty ())
350 for (
auto& str : items_lst)
355 retval(idx++) = atoi (str.c_str ());
365 auto it = items_lst.begin ();
367 for (
int idx = 0; idx < nel; idx++, it++)
368 items.
xelem (idx) = *it;
370 retval =
ovl (items, *it++, atoi (it->c_str ()));
376 DEFMETHOD (__event_manager_list_dialog__, interp, args, ,
382 if (args.length () != 8)
385 Cell list = args(0).cell_value ();
388 std::list<std::string> list_lst;
390 list_lst.push_back (tlist(i));
392 std::string mode = args(1).string_value ();
394 Matrix size_matrix = args(2).matrix_value ();
395 int width = size_matrix(0);
396 int height = size_matrix(1);
398 Matrix initial_matrix = args(3).matrix_value ();
399 nel = initial_matrix.
numel ();
400 std::list<int> initial_lst;
402 initial_lst.push_back (initial_matrix(i));
404 std::string name = args(4).string_value ();
405 list = args(5).cell_value ();
407 nel = plist.
numel ();
408 std::list<std::string> prompt_lst;
410 prompt_lst.push_back (plist(i));
411 std::string ok_string = args(6).string_value ();
412 std::string cancel_string = args(7).string_value ();
418 std::pair<std::list<int>,
int> result
419 = evmgr.
list_dialog (list_lst, mode, width, height, initial_lst,
420 name, prompt_lst, ok_string, cancel_string);
422 std::list<int> items_lst = result.first;
423 nel = items_lst.size ();
426 for (
const auto& int_el : items_lst)
427 items.
xelem(i++) = int_el;
429 return ovl (items, result.second);
432 DEFMETHOD (__event_manager_input_dialog__, interp, args, ,
438 if (args.length () != 4)
441 Cell prompt = args(0).cell_value ();
444 std::list<std::string> prompt_lst;
446 prompt_lst.push_back (tmp(i));
448 std::string title = args(1).string_value ();
450 Matrix rc = args(2).matrix_value ();
456 nr.push_back (rc(i, 0));
457 nc.push_back (rc(i, 1));
460 Cell defaults = args(3).cell_value ();
463 std::list<std::string> defaults_lst;
465 defaults_lst.push_back (tmp(i));
471 std::list<std::string> items_lst
472 = evmgr.
input_dialog (prompt_lst, title, nr, nc, defaults_lst);
474 nel = items_lst.size ();
477 for (
const auto& str_el : items_lst)
478 items.
xelem(i++) = str_el;
484 DEFMETHOD (__event_manager_named_icon__, interp, args, ,
492 if (args.length () > 0)
494 std::string icon_name = args(0).xstring_value (
"invalid arguments");
505 DEFMETHOD (__event_manager_show_preferences__, interp, , ,
516 DEFMETHOD (__event_manager_apply_preferences__, interp, , ,
527 DEFMETHOD (__event_manager_gui_preference__, interp, args, ,
535 std::string value =
"";
537 if (args.length () >= 1)
538 key = args(0).string_value();
540 error (
"__event_manager_gui_preference__: "
541 "first argument must be the preference key");
543 if (args.length () >= 2)
544 value = args(1).string_value();
556 DEFMETHOD (__event_manager_file_remove__, interp, args, ,
562 std::string old_name, new_name;
564 if (args.length () == 2)
566 old_name = args(0).string_value();
567 new_name = args(1).string_value();
570 error (
"__event_manager_file_remove__: "
571 "old and new name expected as arguments");
580 DEFMETHOD (__event_manager_file_renamed__, interp, args, ,
588 if (args.length () == 1)
589 load_new = args(0).bool_value();
591 error (
"__event_manager_file_renamed__: "
592 "first argument must be boolean for reload new named file");
607 if (args.length () != 1)
610 if (! args(0).is_string ())
611 error (
"openvar: NAME must be a string");
613 std::string name = args(0).string_value ();
618 error (
"openvar: '%s' is not a variable", name.c_str ());
633 DEFMETHOD (__event_manager_show_terminal_window__, interp, , ,
648 DEFMETHOD (__event_manager_show_documentation__, interp, args, ,
656 if (args.length () >= 1)
657 file = args(0).string_value();
664 DEFMETHOD (__event_manager_register_documentation__, interp, args, ,
672 if (args.length () >= 1)
673 file = args(0).string_value();
680 DEFMETHOD (__event_manager_unregister_documentation__, interp, args, ,
688 if (args.length () >= 1)
689 file = args(0).string_value();
696 DEFMETHOD (__event_manager_show_file_browser__, interp, , ,
709 DEFMETHOD (__event_manager_show_command_history__, interp, , ,
722 DEFMETHOD (__event_manager_show_workspace__, interp, , ,
735 DEFMETHOD (__event_manager_show_community_news__, interp, , ,
748 DEFMETHOD (__event_manager_show_release_notes__, interp, , ,
761 DEFMETHOD (__event_manager_gui_status_update__, interp, args, ,
780 if (args.length () < 2)
781 error (
"__event_manager_gui_status_update__: two parameters required");
782 if (! (args(0).is_string ()))
783 error (
"__event_manager_gui_status_update__: FEATURE must be a string");
784 if (! (args(1).is_string ()))
785 error (
"__event_manager_gui_status_update__: STATUS must be a string");
787 feature = args(0).string_value ();
788 status = args(1).string_value ();
795 DEFMETHOD (__event_manager_update_gui_lexer__, interp, , ,
806 DEFMETHOD (__event_manager_copy_image_to_clipboard__, interp, args, ,
814 if (args.length () >= 1)
815 file = args(0).string_value();
822 DEFMETHOD (commandhistory, interp, args, ,
829 if (args.length () != 0)
837 DEFMETHOD (commandwindow, interp, args, ,
844 if (args.length () != 0)
859 if (args.length () != 0)
874 if (args.length () != 0)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns(void) const
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
Array< std::string > cellstr_value(void) const
static bool is_gui_running(void)
static void add_event_hook(event_hook_fcn f)
static string_vector list(int=-1, bool=false)
Vector representing the dimensions (size) of an Array.
Provides threadsafe access to octave.
void show_workspace(void)
bool show_documentation(const std::string &file)
OCTINTERP_API void connect_link(const std::shared_ptr< interpreter_events > &obj)
bool edit_variable(const std::string &name, const octave_value &val)
void push_event_queue(void)
void file_renamed(bool load_new)
virtual void focus_window(const std::string win_name)
OCTINTERP_API void set_workspace(void)
std::list< std::string > input_dialog(const std::list< std::string > &prompt, const std::string &title, const std::list< float > &nr, const std::list< float > &nc, const std::list< std::string > &defaults)
bool show_preferences(void)
bool register_documentation(const std::string &file)
bool have_dialogs(void) const
OCTINTERP_API event_manager(interpreter &interp)
std::string question_dialog(const std::string &msg, const std::string &title, const std::string &btn1, const std::string &btn2, const std::string &btn3, const std::string &btndef)
bool unregister_documentation(const std::string &file)
std::shared_ptr< interpreter_events > m_instance
bool update_gui_lexer(void)
uint8NDArray get_named_icon(const std::string &icon_name)
void pop_event_queue(void)
std::list< std::pair< std::string, std::string > > filter_list
OCTINTERP_API void set_history(void)
void file_remove(const std::string &old_name, const std::string &new_name)
OCTINTERP_API void process_events(bool disable=false)
bool copy_image_to_clipboard(const std::string &file)
bool prompt_new_edit_file(const std::string &file)
OCTINTERP_API void discard_events(void)
OCTINTERP_API bool enable(void)
std::pair< std::list< int >, int > list_dialog(const std::list< std::string > &list, const std::string &mode, int width, int height, const std::list< int > &initial_value, const std::string &name, const std::list< std::string > &prompt, const std::string &ok_string, const std::string &cancel_string)
mutex * m_event_queue_mutex
void show_command_history(void)
void start_gui(bool gui_app=false)
bool gui_status_update(const std::string &feature, const std::string &status)
std::list< std::string > file_dialog(const filter_list &filter, const std::string &title, const std::string &filename, const std::string &dirname, const std::string &multimode)
OCTINTERP_API void post_event(const fcn_callback &fcn)
std::string gui_preference(const std::string &key, const std::string &value)
void show_release_notes(void)
interpreter & m_interpreter
std::stack< std::shared_ptr< event_queue > > m_gui_event_queue
void show_community_news(int serial=-1)
void show_terminal_window(void)
bool apply_preferences(void)
virtual ~event_manager(void)
bool edit_file(const std::string &file)
void show_file_browser(void)
virtual void display_exception(const execution_exception &ee, bool beep)
tree_evaluator & get_evaluator(void)
OCTINTERP_API std::string xstring_value(const char *fmt,...) const
bool is_undefined(void) const
symbol_info_list get_symbol_info(void)
bool at_top_level(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void warning(const char *fmt,...)
void error(const char *fmt,...)
static int readline_event_hook(void)
std::function< void(void)> fcn_callback
std::function< void(interpreter &)> meth_callback
event_manager & __get_event_manager__(void)
bool is_true(const std::string &s)
OCTAVE_EXPORT octave_value_list Fisguirunning(const octave_value_list &args, int)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.