在GUI scilab中显示文件地址,为什么uicontrol返回undefined

时间:2018-05-23 02:54:26

标签: user-interface scilab

强文我正在编写SciLab的GUI程序。 我遇到了问题。 我想在选择文件时练习,该文件的地址将自动显示在GUI窗口中。

xdel(winsid());
clear;
clc;

//FileInformation=uigetfile(["*.txt"]);
//golbal window parameters
global margin_x margin_y;
global frame_w frame_h plot_w plot_h;
//window parameter initialization
frame_w=300;
frame_h=500;//frame width and height
plot_w=600;
plot_h=frame_h;//plot width and height
margin_x=15;
margin_y=15;//horizontal and vertical margin for elements
defaultfont="arial";
axes_w=3*margin_x+frame_w+plot_w; //axis width
axes_h=2*margin_y+frame_h;
demo=scf(100001);//create window with id=100001 and make it the current one
demo.background=-2;
demo.figure_position=[100 100];
demo.figure_name=gettext("profile prcessing");
demo.axes_size=[axes_w axes_h];
///////////////////////////////////////
//create menu
//remove menus and toolbars
delmenu(demo.figure_id, gettext("&File"));
delmenu(demo.figure_id, gettext("&Tools"));
delmenu(demo.figure_id, gettext("&Edit"));
delmenu(demo.figure_id, gettext("&?"));
toolbar(demo.figure_id,"off");
//new menu/////////////////////////////////////////////////////////////////
*h1=uimenu("parent",demo,"label",gettext...                           /////
("openfile"),"callback","information=uigetfile()");*                  /////
////////////////////////////////////////////////////////////////////////////
h2=uimenu("parent",demo,"label",gettext("About"),"callback","About();");

///
function About()
    msg=msprintf(gettext("this program is developed for wear depth...
    measurement. any unclear please contact ben XU"));
    messagebox(msg,gettext("About"),"info","modal");
endfunction
///
//creating a frame
my_frame=uicontrol("parent",demo,"relief","groove","style","frame",...
"units","pixels","position",[margin_x margin_y frame_w frame_h],...
"horizontalalignment","center","background",[1 1 1],"tag","frame control");
//title of frame
my_frame_title=uicontrol("parent",demo,"style","text","string",...
"address of file","units","pixels","position",[30+margin_x ...
 margin_y+frame_h-10 frame_w-60 20],...
 "fontname",defaultfont,"fontsize",16,"horizontalalignment",...
 "center","backgroun",[1 1 1],"tag","title_frame_control");
//
uicontrol("parent",demo,"style","text","string","address",...
"position",[20,240, 180, ...
20],"horizontalalignment","left","fontsize",14,"background",[1 1 1]);
////////////////////////////////////////////////////////////////////////////
*uicontrol("parent",demo,"style","edit","string",information,"position",...
[20,240,180,20],"horizontalalignment","left","fontsize",14,"background",...
[0.9 0.9 0.9],"tag","edi");*
////////////////////////////////////////////////////////////////////////////

我标记为" /"广场。  问题是信息,为什么没有定义?为什么?我该怎么办呢?

提前感谢你们。

2 个答案:

答案 0 :(得分:0)

回调是在自己的环境中执行的。

虽然它们继承了环境中定义的所有变量的值,但这些代码的代码实际上是在启动回调时执行的,但对这些变量的更改或新定义的变量在回调环境中是本地的。

您可以在两种环境中(在脚本的开头以及回调字符串的开头)声明全局变量(在您的情况下为变量“信息”)(添加“全局信息;”)。在调用环境中也可以更改其值的回调代码。

或者您可以使用用于触发呼叫的UI元素的“ userdata”属性。 在回调中,您可以通过gcbo对其进行寻址,这是调用元素的句柄。 “ set(gcbo,” userdata“,uigetfile());”应该可以。 由于h1是您可以在调用环境中触发回调的UI元素的句柄,因此可以在h1.userdata中找到有关用户选择的文件的信息。您将使用“ information = h1.userdata;”。或“ information = get(h1,“ userdata”);“。

答案 1 :(得分:0)

如果您创建菜单,菜单项并像这样编辑小部件

h1 = uimenu("parent",demo,"label",gettext("file"))
uimenu("parent",h1,"label",gettext("openfile"),"callback","h3.string=uigetfile()");
// ...
h3 = uicontrol("parent",demo,"style","edit","string","","position",...
[20,240,180,20],"horizontalalignment","left","fontsize",14,"background",...
[0.9 0.9 0.9],"tag","edi");

那你应该没事。