Re: [Scilab-users] Executing scripts with functions from GUI

2016-04-18 Thread Jan Åge Langeland



On 18.04.2016 21:05, Samuel Gougeon wrote:
afun() is defined in sel(), and so is local to sel(). It is cleared 
when leaving sel(). To prevent this, you may return it as "afun" in 
the environment calling sel() with:

afun = return(afun)
at the end of sel(), before leaving it.

https://help.scilab.org/docs/5.5.2/en_US/return.html

HTH
Samuel 
Thanks a lot, works fine, although it is a bit sensitive to changes in 
the executed scripts.


Brgds
Jan Å
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Executing scripts with functions from GUI

2016-04-18 Thread Samuel Gougeon

Le 18/04/2016 12:14, JLan a écrit :

I wonder if someone can give me a hint here.

I am trying to make a menu GUI that can start different scripts.

This does not work properly when the scripts contain functions.

A simple example. I have a script called
aaa.sce :
//---
disp('Script aaa')
function afun(aa)
 if aa=='-a'  then
 disp('AFUN')
 end
endfunction
//---
After executing this from the console:
*-->exec('aaa.sce', -1)*
I can obviously do:
*
1

Script aaa
  
-->afun -a
  
AFUN

*
I then clear afun and try to start this from my GUI
maingui.sce:
//--
clear afun
function sel(al)
 disp(al);
 if al==1 then
   
 exec('aaa.sce',-1)

 end
 if al==2 then
  exec('bbb.sce',-1)
 end
 if al==3 then
  disp('D_Spare')
 end
 set(hl, 'value', []);
endfunction

ctrw=figure(...
'figure_position',[-1,-1],...
'figure_size', [620,400],...
'figure_name', '',...
'menubar_visible','off',...
'toolbar_visible','off');
ht1=uicontrol(ctrw,...
'style','text',...
'position', [10 310 100 30],...
'string',' MAIN MENU');
hl=uicontrol(ctrw,'style','listbox', ...
'position', [10 10 550 280],...
'callback','sel(get(hl,''value''))');

set(hl, 'string',"...
 Run aaa|...
 Run bbb|...
 spare");
//-

When running
*-->exec('maingui.sce', -1)*
  then clicking aaa and trying to run afun I get:
*
   
 1.
  
  Script aaa


-->afun -a
   !--error 4
Undefined variable: afun*

I have tried to define afun as global, it has an effect but I still don't
get the same response.
afun() is defined in sel(), and so is local to sel(). It is cleared when 
leaving sel(). To prevent this, you may return it as "afun" in the 
environment calling sel() with:

afun = return(afun)
at the end of sel(), before leaving it.

https://help.scilab.org/docs/5.5.2/en_US/return.html

HTH
Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] Executing scripts with functions from GUI

2016-04-18 Thread JLan
I wonder if someone can give me a hint here.

I am trying to make a menu GUI that can start different scripts.  

This does not work properly when the scripts contain functions.

A simple example. I have a script called 
aaa.sce :
//---
disp('Script aaa')
function afun(aa)
if aa=='-a'  then
disp('AFUN')
end
endfunction
//---
After executing this from the console:
*-->exec('aaa.sce', -1)* 
I can obviously do:
*
1

Script aaa
 
-->afun -a
 
AFUN   
*
I then clear afun and try to start this from my GUI 
maingui.sce:
//--
clear afun   
function sel(al)
disp(al);
if al==1 then
  
exec('aaa.sce',-1)
end
if al==2 then
 exec('bbb.sce',-1)
end
if al==3 then
 disp('D_Spare')
end
set(hl, 'value', []);
endfunction

ctrw=figure(...
   'figure_position',[-1,-1],...
   'figure_size', [620,400],...
   'figure_name', '',...
   'menubar_visible','off',...
   'toolbar_visible','off');
ht1=uicontrol(ctrw,...
   'style','text',...
   'position', [10 310 100 30],...
   'string',' MAIN MENU');
hl=uicontrol(ctrw,'style','listbox', ...
   'position', [10 10 550 280],...
   'callback','sel(get(hl,''value''))');

set(hl, 'string',"...
Run aaa|...
Run bbb|...
spare");
//-

When running
*-->exec('maingui.sce', -1)*
 then clicking aaa and trying to run afun I get:
*
  
1.  
 
 Script aaa

-->afun -a
  !--error 4 
Undefined variable: afun*

I have tried to define afun as global, it has an effect but I still don't
get the same response.

Jan Å






--
View this message in context: 
http://mailinglists.scilab.org/Executing-scripts-with-functions-from-GUI-tp4033997.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at 
Nabble.com.
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users