From f9b539584c371c92be45cb84f922d674d6a5c471 Mon Sep 17 00:00:00 2001 From: Mus M Date: Thu, 19 Jan 2017 16:50:18 -0500 Subject: [PATCH 1/2] Clean up show/hide/and get visibility methods on Windows --- README.md | 18 ++++++++++++++++-- src/MATLAB.jl | 7 +++++-- src/engine.jl | 27 +++++++++++++++++---------- src/init.jl | 3 ++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6781604..f6e3ebb 100644 --- a/README.md +++ b/README.md @@ -311,12 +311,26 @@ xx, yy = mxcall(:meshgrid, 2, x, y) ``mxcall`` puts the input arguments to the MATLAB workspace (using mangled names), evaluates the function call in MATLAB, and retrievs the variable from the MATLAB session. This function is mainly provided for convenience. However, you should keep in mind that it may incur considerable overhead due to the communication between MATLAB and Julia domain. -#### Viewing the MATLAB Session +#### Viewing the MATLAB Session (Windows only) -To open an interactive window for the MATLAB session, use the command `show_msession()`. To hide the window, use `hide_msession()`. Note that closing this window will result in an error, so it is advised that one uses the `hide_msession()` command instead. +To open an interactive window for the MATLAB session, use the command `show_msession()`. To hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or worse result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.* Note that this feature only works on Windows. +```julia +# default +show_msession() # open the default MATLAB session interactive window +get_msession_visiblity() # get the session's visibility state +hide_msession() # hide the default MATLAB session interactive window + +# similarily +s = MSession() +show_msession(s) +get_msession_visiblity(a) +hide_msession(s) +``` + + #### Advanced use of MATLAB Engines This package provides a series of functions for users to control the communication with MATLAB sessions. diff --git a/src/MATLAB.jl b/src/MATLAB.jl index 6b4b233..878fd45 100644 --- a/src/MATLAB.jl +++ b/src/MATLAB.jl @@ -31,9 +31,11 @@ export MSession, MatFile, eval_string, get_mvariable, get_variable, put_variable, put_variables, variable_names, read_matfile, write_matfile, mxcall, - @mput, @mget, @matlab, @mat_str, - show_msession, hide_msession + @mput, @mget, @matlab, @mat_str +if is_windows() + export show_msession, hide_msession, get_msession_visiblity +end # exceptions type MEngineError <: Exception @@ -65,6 +67,7 @@ function __init__() eng_open[] = engfunc(:engOpen) eng_close[] = engfunc(:engClose) eng_set_visible[] = engfunc(:engSetVisible) + eng_get_visible[] = engfunc(:engGetVisible) eng_output_buffer[] = engfunc(:engOutputBuffer) eng_eval_string[] = engfunc(:engEvalString) eng_put_variable[] = engfunc(:engPutVariable) diff --git a/src/engine.jl b/src/engine.jl index 1a4e6a4..de1f1fb 100644 --- a/src/engine.jl +++ b/src/engine.jl @@ -90,18 +90,25 @@ function close_default_msession() return nothing end -function show_msession(m::MSession = get_default_msession()) - ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1) - ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)")) - return nothing -end +if is_windows() + function show_msession(m::MSession = get_default_msession()) + ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1) + ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)")) + return nothing + end -function hide_msession(m::MSession = get_default_msession()) - ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0) - ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)")) - return nothing -end + function hide_msession(m::MSession = get_default_msession()) + ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0) + ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)")) + return nothing + end + function get_msession_visiblity(m::MSession = get_default_msession()) + vis = Ref{Cint}(true) + ccall(eng_get_visible[], Int, (Ptr{Void}, Ptr{Cint}), m, vis) + return vis[] == 1 ? true : false + end +end ########################################################### # diff --git a/src/init.jl b/src/init.jl index 8e9c584..919b257 100644 --- a/src/init.jl +++ b/src/init.jl @@ -9,6 +9,7 @@ const libmat = Ref{Ptr{Void}}() const eng_open = Ref{Ptr{Void}}() const eng_close = Ref{Ptr{Void}}() const eng_set_visible = Ref{Ptr{Void}}() +const eng_get_visible = Ref{Ptr{Void}}() const eng_output_buffer = Ref{Ptr{Void}}() const eng_eval_string = Ref{Ptr{Void}}() const eng_put_variable = Ref{Ptr{Void}}() @@ -84,7 +85,7 @@ const mx_set_field = Ref{Ptr{Void}}() const mx_get_field_bynum = Ref{Ptr{Void}}() const mx_get_fieldname = Ref{Ptr{Void}}() -const mx_get_string = Ref{Ptr{Void}}(0) +const mx_get_string = Ref{Ptr{Void}}() # load I/O mat functions From a2a4f2b5be956220835bf4c6bdadf8214290abcf Mon Sep 17 00:00:00 2001 From: Mus M Date: Sat, 28 Jan 2017 13:06:03 -0700 Subject: [PATCH 2/2] Tweak wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6e3ebb..1721534 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ xx, yy = mxcall(:meshgrid, 2, x, y) #### Viewing the MATLAB Session (Windows only) -To open an interactive window for the MATLAB session, use the command `show_msession()`. To hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or worse result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.* +To open an interactive window for the MATLAB session, use the command `show_msession()` and to hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.* Note that this feature only works on Windows.