Utilisation des callbacks sur Scilab

Fermé
ecgbuilder - 8 févr. 2011 à 11:48
 ecgbuilder - 19 avril 2011 à 11:07
Bonjour,

J'ai un problème d'utilisation de paramètres avec les callbacks des uicontrol sur Scilab (5.2.2).
Pour résumer, je veux passer des informations que j'ai entré dans un champ texte, d'une fenêtre à l'autre, en cliquant sur un bouton.

Voici les fichiers que j'utilise successivement :

fichier essai1.sce :

h1 = figure();
h1.Position = [0 0 200 150];
htext1=uicontrol(h1,"style","edit");
htext1.Position = [0 80 100 20];
htext1.String = "";
htext1.BackgroundColor=[1 1 1];

hbutton1=uicontrol(h1,"style","pushbutton");
hbutton1.Position = [0 0 50 30];
hbutton1.String = "OK";
hbutton1.Callback = "OK1(htext1)";



function OK1(htext1)
  global NOM;
  NOM=htext1.String;
  exec('essai2.sce')
  close(h1)
endfunction


fichier essai2.sce :

global NOM;
h2 = figure();
h2.Position = [0 0 200 150];
hlabel2=uicontrol(h2,"style","text");
hlabel2.Position = [0 120 100 20];
hlabel2.String = NOM;
htext2=uicontrol(h2,"style","edit");
htext2.Position = [0 80 100 20];
htext2.String = "";
htext2.BackgroundColor=[1 1 1];

hbutton2=uicontrol(h2,"style","pushbutton");
hbutton2.Position = [0 0 50 30];
hbutton2.String = "OK";
hbutton2.Callback = "OK2(htext2)";


function OK2(htext2)
  global PRENOM;
  PRENOM=htext2.String;
  exec('essai3.sce')
  close(h2)
endfunction


fichier essai3.sce :

global NOM PRENOM;
h3 = figure();
h3.Position = [0 0 200 150];
hnom=uicontrol(h3,"style","text");
hnom.Position = [0 120 100 20];
hnom.String = NOM;
hprenom=uicontrol(h2,"style","text");
hprenom.Position = [0 80 100 20];
hprenom.String = PRENOM;


Je voudrais donc entrer mon nom dans la première fenêtre, entrer mon prénom dans la deuxième fenêtre, et afficher mon nom et mon prénom dans la troisième.
J'ai une erreur pour passer de la 2è à la 3è fenêtre, donc en utilisant la fonction OK2 :

 !--error 4 
Variable non définie: htext2

at line       3 of function OK2 called by :  
exists("gcbo") then %oldgcbo = gcbo; end;gcbo = getcallbackobject(17);OK2;if exists("%oldgcbo") then gcbo = %oldgcbo; else clear gcbo; end
while executing a callback


Je ne comprends pas pourquoi ça ne marche pas au 2è bouton alors que ça marche pour le premier...
Merci d'avance pour votre aide.

2 réponses

J'ai trouvé la réponse à mon problème. Il faut modifier une propriété des callbacks :

hbutton1.Callback_Type=2
1
Here is a working solution for the first button, you can easily generalize


h1 = figure();
h1.Position = [0 0 200 150];
htext1=uicontrol(h1,"style","edit");
htext1.Position = [0 80 100 20];
htext1.String = "";
htext1.BackgroundColor=[1 1 1];

hbutton1=uicontrol(h1,"style","pushbutton");
hbutton1.Position = [0 0 50 30];
hbutton1.String = "OK";
hbutton1.Callback = "OK1()";
set(hbutton1,'user_data',htext1); //store the edit uicontrol handle in the button user data



function OK1()
htext1=gcbo.user_data; //gco is the handle of the calling uicontrol
global NOM;
NOM=htext1.String;
disp(NOM)
//exec('essai2.sce')
close(h1)
endfunction
0