[Scilab-users] GUI help

classic Classic list List threaded Threaded
38 messages Options
12
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] GUI help

Hi there

I'm trying to build a GUI. For simplicity on the forum, I've built a really simple example of what I'm trying to do. How can I make the "conditional" GUI output work and not have it inside the calc function? ... or, how would you do it? Thanks.

Best regards, Claus.

// GUI_EXAMPLE.SCE
//
// Demo of how to build a simple GUI in Scilab.
// Real simple, with two input variables and one output.
// The example uses the basic mechanical example of a mass and a spring as
// input parameters and calculates the resonance frequency of the mechanical
// system.

// Initialize variables
m = 1; // Moving mass 'm' (kilogram)
k = 1; // Stiffness, spring constant 'k' (Newton per meter)
fres = 1; // Resonance frequency (Hertz)
show_result = %f;

function calc()
    m = evstr(get(ge_m,"string")); // get content in uicontrol ge_m
    k = evstr(get(ge_k,"string")); // get content in uicontrol ge_k
    fres = sqrt(m * k);
    // putting GUI updates inside the calculation routine is not pretty code.
    uicontrol("style","text","string","Result     :","position", ..
              [10 as(2)-110 80 20]);
    uicontrol("style","text","string",string(fres), ..
              "position",[100 as(2)-110 80 20]);
    uicontrol("style","text","string"," Hz ","position", ..
              [200 as(2)-110 30 20]);
    show_result = %t;
    // update global variables
    [m,k,fres,show_result]=return(m,k,fres,show_result);
endfunction

function goodbye()
    close(ge); // Close GUI window
    printf("Resulting fres: %f Hertz\n",fres);
    abort // Print result in console (e.g. for copy/paste), then kill the app
endfunction

ge = scf(); // GUI Example, Initialize and 'set current figure'
as = ge.axes_size; // read size of window, as = [width height]
ge.figure_name = "GUI Example"; // Change window header

uicontrol("style","text","string","Moving mass :","position", ..
          [10 as(2)-35 80 20],"background",[1 1 1]); // white background
          // position properties has four parameters = x,y,width,height
          // y-position counts from lower left corner, so we subtract from 'as'
ge_m = uicontrol("style","edit","string",string(m), ..
          "position",[100 as(2)-35 80 20]);
uicontrol("style","text","string"," kg ","position", ..
          [200 as(2)-35 30 20],"background",[1 1 1]);

uicontrol("style","text","string","Stiffness   :","position", ..
          [10 as(2)-60 80 20],"background",[1 1 1]);
ge_k = uicontrol("style","edit","string",string(k), ..
          "position",[100 as(2)-60 80 20]);
uicontrol("style","text","string"," N/m ","position", ..
          [200 as(2)-60 30 20],"background",[1 1 1]);

uicontrol("style","pushbutton","string","Calculate", ..
          "position",[10 as(2)-85 80 20],"callback","calc");

// How do I make this "conditional" output show up in my GUI?
if show_result then // If "Calculate" button was pushed at least once ...
    uicontrol("style","text","string","Result     :","position", ..
              [10 as(2)-110 80 20]);
    uicontrol("style","text","string",string(fres), ..
              "position",[100 as(2)-110 80 20]);
    uicontrol("style","text","string"," Hz ","position", ..
              [200 as(2)-110 30 20]);
end

uicontrol("style","pushbutton","string","Exit", ..
          "position",[10 as(2)-135 80 20],"callback","goodbye");

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? GUI help

Hello Claus,

I've been playing a bit with GUIs for teaching, so maybe I can help.
The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
Do not hesitate to rephrase your issue, I'll try a more focused answer.

Anywya, here is how I think your code could be improved:

(1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
(2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
(3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
(4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).

I attached a small gui I use to illustrate optical anti-reflection coating.
It is far from perfect (I did not implement a proper model-view-controler for example).
But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.

Hope it helps,

Antoine

Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:

> Hi there
>
> I'm trying to build a GUI. For simplicity on the forum, I've built a
> really simple example of what I'm trying to do. How can I make the
> "conditional" GUI output work and not have it inside the calc function?
> ... or, how would you do it? Thanks.
>
> Best regards, Claus.
>
> // GUI_EXAMPLE.SCE
> //
> // Demo of how to build a simple GUI in Scilab.
> // Real simple, with two input variables and one output.
> // The example uses the basic mechanical example of a mass and a spring as
> // input parameters and calculates the resonance frequency of the mechanical
> // system.
>
> // Initialize variables
> m  =  1;  // Moving mass 'm'(kilogram)
> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
> fres  =  1;  // Resonance frequency (Hertz)
> show_result  =  %f;
>
> function  calc()
>      m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
>      k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
>      fres  =  sqrt(m  *  k);
>      // putting GUI updates inside the calculation routine is not pretty code.
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
>      show_result  =  %t;
>      // update global variables
>      [m,k,fres,show_result]=return(m,k,fres,show_result);
> endfunction
>
> function  goodbye()
>      close(ge);  // Close GUI window
>      printf("Resulting fres: %f Hertz\n",fres);
>      abort  // Print result in console (e.g. for copy/paste), then kill the app
> endfunction
>
> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
> as  =  ge.axes_size;  // read size of window, as = [width height]
> ge.figure_name  =  "GUI Example";  // Change window header
>
> uicontrol("style","text","string","Moving mass :","position",  ..
>            [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
>            // position properties has four parameters = x,y,width,height
>            // y-position counts from lower left corner, so we subtract from 'as'
> ge_m  =  uicontrol("style","edit","string",string(m),  ..
>            "position",[100  as(2)-35  80  20]);
> uicontrol("style","text","string","kg ","position",  ..
>            [200  as(2)-35  30  20],"background",[1  1  1]);
>
> uicontrol("style","text","string","Stiffness :","position",  ..
>            [10  as(2)-60  80  20],"background",[1  1  1]);
> ge_k  =  uicontrol("style","edit","string",string(k),  ..
>            "position",[100  as(2)-60  80  20]);
> uicontrol("style","text","string","N/m ","position",  ..
>            [200  as(2)-60  30  20],"background",[1  1  1]);
>
> uicontrol("style","pushbutton","string","Calculate",  ..
>            "position",[10  as(2)-85  80  20],"callback","calc");
>
> // How do I make this "conditional"output show up in my GUI?
> if  show_result  then  // If "Calculate"button was pushed at least once ...
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
> end
>
> uicontrol("style","pushbutton","string","Exit",  ..
>            "position",[10  as(2)-135  80  20],"callback","goodbye");
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

ar_gui.sce (13K) Download Attachment
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? GUI help

Hallo Claus,

from what I understand the question is: How can GUI updated outside of the function "calc" ?

In other words:
right now "calc" updates the GUI.
I guess the aim is that "calc" only returns output values, which will be used to update the GUI .

Way 1:
Use global variables, which can be used in every function of the GUI.
The return value of the function will change this global variable.

Way 2
Give the calc() function output variables, such as:
function [out_var1, out_var2] = calc(arg1, arg2)
    out_var1 = arg1 + ...
    out_var2 = arg2 +....
endfunction
With this it should be possible to update the GUI outside of a callback function.

Way 3.....similar to way 1...and the way I did in the past
use a single global variable, called: handles

handles is more a structure, than a single variable.
It contains all uicontrols aswell as all variables necessary to update the GUI.
e.g.:

handles.f1 = figure(....)      // that would be the main GUI
handles.f2 = figure(....)      // that would be a sub GUI
handles.pb1 = uicontrol()   // that would be a push button of the GUI
handles.var1 = ....             // that would be a variable, necessary to keep available to all uicontrols
handles.var2 = ....             // that would be another variable, necessary to keep available to all uicontrols


When definig the callback function it would look like this:

function calc(handles)
  locVar1 = handles.var1
  locVar2 = handles.var2
  //...do the calculations...to change locVar1, locVar2
  //...update the handle variable(s)
  handles.var1 = locVar1
  handles.var2 = locVar2
  handles = resume(handles)
endfunction
 
one would call the function just as:     calc(handles)


A general note:
It helps to put all callback functions into a separate subfolder
The main function (that only defines the GUI) will call and load all callback functions from that subfolder.

I give callback function scripts the extension:  *.sci
I give the main GUI script the extension: *.sce
This is all not mandatory, but increases the overview.

To create the global variable "handles" I define a separate function:

function handles = Init(handles)
  handles.var1 = 0  // init value of var1
  handles.var2 = 0  // init value of var2
  handles.cmap = graycolormap(255)  // init GUI colormap
  handles.statusSlider = 0    // can be a status variable for a slider..if it has been used or not
  handles.statusPB = 0       // can be a status variable for a push bitton ..such as: has been pressed or not
  // etc...

  handles = resume(handles)
endfunction

sorry for the long Mail,
Best regards,
Philipp









Am Do., 28. Nov. 2019 um 08:57 Uhr schrieb Antoine Monmayrant <[hidden email]>:
Hello Claus,

I've been playing a bit with GUIs for teaching, so maybe I can help.
The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
Do not hesitate to rephrase your issue, I'll try a more focused answer.

Anywya, here is how I think your code could be improved:

(1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
(2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
(3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
(4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).

I attached a small gui I use to illustrate optical anti-reflection coating.
It is far from perfect (I did not implement a proper model-view-controler for example).
But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.

Hope it helps,

Antoine

Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:

> Hi there
>
> I'm trying to build a GUI. For simplicity on the forum, I've built a
> really simple example of what I'm trying to do. How can I make the
> "conditional" GUI output work and not have it inside the calc function?
> ... or, how would you do it? Thanks.
>
> Best regards, Claus.
>
> // GUI_EXAMPLE.SCE
> //
> // Demo of how to build a simple GUI in Scilab.
> // Real simple, with two input variables and one output.
> // The example uses the basic mechanical example of a mass and a spring as
> // input parameters and calculates the resonance frequency of the mechanical
> // system.
>
> // Initialize variables
> m  =  1;  // Moving mass 'm'(kilogram)
> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
> fres  =  1;  // Resonance frequency (Hertz)
> show_result  =  %f;
>
> function  calc()
>      m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
>      k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
>      fres  =  sqrt(m  *  k);
>      // putting GUI updates inside the calculation routine is not pretty code.
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
>      show_result  =  %t;
>      // update global variables
>      [m,k,fres,show_result]=return(m,k,fres,show_result);
> endfunction
>
> function  goodbye()
>      close(ge);  // Close GUI window
>      printf("Resulting fres: %f Hertz\n",fres);
>      abort  // Print result in console (e.g. for copy/paste), then kill the app
> endfunction
>
> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
> as  =  ge.axes_size;  // read size of window, as = [width height]
> ge.figure_name  =  "GUI Example";  // Change window header
>
> uicontrol("style","text","string","Moving mass :","position",  ..
>            [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
>            // position properties has four parameters = x,y,width,height
>            // y-position counts from lower left corner, so we subtract from 'as'
> ge_m  =  uicontrol("style","edit","string",string(m),  ..
>            "position",[100  as(2)-35  80  20]);
> uicontrol("style","text","string","kg ","position",  ..
>            [200  as(2)-35  30  20],"background",[1  1  1]);
>
> uicontrol("style","text","string","Stiffness :","position",  ..
>            [10  as(2)-60  80  20],"background",[1  1  1]);
> ge_k  =  uicontrol("style","edit","string",string(k),  ..
>            "position",[100  as(2)-60  80  20]);
> uicontrol("style","text","string","N/m ","position",  ..
>            [200  as(2)-60  30  20],"background",[1  1  1]);
>
> uicontrol("style","pushbutton","string","Calculate",  ..
>            "position",[10  as(2)-85  80  20],"callback","calc");
>
> // How do I make this "conditional"output show up in my GUI?
> if  show_result  then  // If "Calculate"button was pushed at least once ...
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
> end
>
> uicontrol("style","pushbutton","string","Exit",  ..
>            "position",[10  as(2)-135  80  20],"callback","goodbye");
>
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? GUI help

In reply to this post by amonmayr
Hi Antoine, et al.

Your reply is very helpful, so I think you got the right question :-)

1) Good point that I can use callback on every uicontrol. This would be suitable for a simple example (like gui_example.sce) ... but for heavy calculations, it might be more practical with a CALC button. P.S. The correct equation for the resonance frequency is fres = sqrt(k / m)/(2*%pi);

2) I see what you mean, so not having an empty space, but "show" the whole she-bang from the beginning. I didn't want to do that (just deleting the IF-statement), but it could be the best solution in the end (rather than the inline GUI updates), if nothing better shows up. This was somehow the "core" of my question. Maybe I ask for too much.

3) I will look into this. Thanks for the tip.

4) I will also look into this. My problem is the steep learning curve. If you look at the Scilab tutorials you have the good-old Openeering LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial using the Model-Viewer-Controller approach? - Maybe the Model-Viewer-Controller could be presented in a _simple_ tutorial - is it possible?

I appreciate gui_example.sce with just about 70 lines of code, two inputs and one output. I think something like it could help a lot of people ... and it's not 250 lines of code to get a GUI up and running, if you know what I mean. The gui_example shows a few differences, like white versus grey background, editable boxes, etc. In the outputs, because of the default grey background, you can see the dimensions of the grid / text-boxes, and gui_example has two buttons. It looks operational and easy to expand for new users.

Cheers,
Claus

On 28.11.2019 08:57, Antoine Monmayrant wrote:
Hello Claus,

I've been playing a bit with GUIs for teaching, so maybe I can help.
The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
Do not hesitate to rephrase your issue, I'll try a more focused answer.

Anywya, here is how I think your code could be improved:

(1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
(2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
(3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
(4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).

I attached a small gui I use to illustrate optical anti-reflection coating.
It is far from perfect (I did not implement a proper model-view-controler for example).
But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.

Hope it helps,

Antoine
 
Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup [hidden email] a écrit: 
 
Hi there

I'm trying to build a GUI. For simplicity on the forum, I've built a 
really simple example of what I'm trying to do. How can I make the 
"conditional" GUI output work and not have it inside the calc function? 
... or, how would you do it? Thanks.

Best regards, Claus.

// GUI_EXAMPLE.SCE
//
// Demo of how to build a simple GUI in Scilab.
// Real simple, with two input variables and one output.
// The example uses the basic mechanical example of a mass and a spring as
// input parameters and calculates the resonance frequency of the mechanical
// system.

// Initialize variables
m  =  1;  // Moving mass 'm'(kilogram)
k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
fres  =  1;  // Resonance frequency (Hertz)
show_result  =  %f;

function  calc()
     m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
     k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
     fres  =  sqrt(m  *  k);
     // putting GUI updates inside the calculation routine is not pretty code.
     uicontrol("style","text","string","Result :","position",  ..
               [10  as(2)-110  80  20]);
     uicontrol("style","text","string",string(fres),  ..
               "position",[100  as(2)-110  80  20]);
     uicontrol("style","text","string","Hz ","position",  ..
               [200  as(2)-110  30  20]);
     show_result  =  %t;
     // update global variables
     [m,k,fres,show_result]=return(m,k,fres,show_result);
endfunction

function  goodbye()
     close(ge);  // Close GUI window
     printf("Resulting fres: %f Hertz\n",fres);
     abort  // Print result in console (e.g. for copy/paste), then kill the app
endfunction

ge  =  scf();  // GUI Example, Initialize and 'set current figure'
as  =  ge.axes_size;  // read size of window, as = [width height]
ge.figure_name  =  "GUI Example";  // Change window header

uicontrol("style","text","string","Moving mass :","position",  ..
           [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
           // position properties has four parameters = x,y,width,height
           // y-position counts from lower left corner, so we subtract from 'as'
ge_m  =  uicontrol("style","edit","string",string(m),  ..
           "position",[100  as(2)-35  80  20]);
uicontrol("style","text","string","kg ","position",  ..
           [200  as(2)-35  30  20],"background",[1  1  1]);

uicontrol("style","text","string","Stiffness :","position",  ..
           [10  as(2)-60  80  20],"background",[1  1  1]);
ge_k  =  uicontrol("style","edit","string",string(k),  ..
           "position",[100  as(2)-60  80  20]);
uicontrol("style","text","string","N/m ","position",  ..
           [200  as(2)-60  30  20],"background",[1  1  1]);

uicontrol("style","pushbutton","string","Calculate",  ..
           "position",[10  as(2)-85  80  20],"callback","calc");

// How do I make this "conditional"output show up in my GUI?
if  show_result  then  // If "Calculate"button was pushed at least once ...
     uicontrol("style","text","string","Result :","position",  ..
               [10  as(2)-110  80  20]);
     uicontrol("style","text","string",string(fres),  ..
               "position",[100  as(2)-110  80  20]);
     uicontrol("style","text","string","Hz ","position",  ..
               [200  as(2)-110  30  20]);
end

uicontrol("style","pushbutton","string","Exit",  ..
           "position",[10  as(2)-135  80  20],"callback","goodbye");


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? GUI help

In reply to this post by der_Phil
Hi Philipp, et al.

Thanks for the (long) email. I appreciate it.

Way 1 - I already do.
Way 2 - Yes, the established part of the GUI updates, no problem. The big question was if I could turn certain parts of the GUI on (and maybe off again)?
Way 3 - interesting idea, to use a "handles" container for all variables. I'll think about it. Is this "only" an easy way to pass around lots of variables, or is there something more internal with the GUI that is smart with this solution?

Best regards,
Claus

On 28.11.2019 10:53, P M wrote:
Hallo Claus,

from what I understand the question is: How can GUI updated outside of the function "calc" ?

In other words:
right now "calc" updates the GUI.
I guess the aim is that "calc" only returns output values, which will be used to update the GUI .

Way 1:
Use global variables, which can be used in every function of the GUI.
The return value of the function will change this global variable.

Way 2
Give the calc() function output variables, such as:
function [out_var1, out_var2] = calc(arg1, arg2)
    out_var1 = arg1 + ...
    out_var2 = arg2 +....
endfunction
With this it should be possible to update the GUI outside of a callback function.

Way 3.....similar to way 1...and the way I did in the past
use a single global variable, called: handles

handles is more a structure, than a single variable.
It contains all uicontrols aswell as all variables necessary to update the GUI.
e.g.:

handles.f1 = figure(....)      // that would be the main GUI
handles.f2 = figure(....)      // that would be a sub GUI
handles.pb1 = uicontrol()   // that would be a push button of the GUI
handles.var1 = ....             // that would be a variable, necessary to keep available to all uicontrols
handles.var2 = ....             // that would be another variable, necessary to keep available to all uicontrols


When definig the callback function it would look like this:

function calc(handles)
  locVar1 = handles.var1
  locVar2 = handles.var2
  //...do the calculations...to change locVar1, locVar2
  //...update the handle variable(s)
  handles.var1 = locVar1
  handles.var2 = locVar2
  handles = resume(handles)
endfunction
 
one would call the function just as:     calc(handles)


A general note:
It helps to put all callback functions into a separate subfolder
The main function (that only defines the GUI) will call and load all callback functions from that subfolder.

I give callback function scripts the extension:  *.sci
I give the main GUI script the extension: *.sce
This is all not mandatory, but increases the overview.

To create the global variable "handles" I define a separate function:

function handles = Init(handles)
  handles.var1 = 0  // init value of var1
  handles.var2 = 0  // init value of var2
  handles.cmap = graycolormap(255)  // init GUI colormap
  handles.statusSlider = 0    // can be a status variable for a slider..if it has been used or not
  handles.statusPB = 0       // can be a status variable for a push bitton ..such as: has been pressed or not
  // etc...

  handles = resume(handles)
endfunction

sorry for the long Mail,
Best regards,
Philipp









Am Do., 28. Nov. 2019 um 08:57 Uhr schrieb Antoine Monmayrant <[hidden email]>:
Hello Claus,

I've been playing a bit with GUIs for teaching, so maybe I can help.
The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
Do not hesitate to rephrase your issue, I'll try a more focused answer.

Anywya, here is how I think your code could be improved:

(1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
(2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
(3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
(4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).

I attached a small gui I use to illustrate optical anti-reflection coating.
It is far from perfect (I did not implement a proper model-view-controler for example).
But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.

Hope it helps,

Antoine

Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:

> Hi there
>
> I'm trying to build a GUI. For simplicity on the forum, I've built a
> really simple example of what I'm trying to do. How can I make the
> "conditional" GUI output work and not have it inside the calc function?
> ... or, how would you do it? Thanks.
>
> Best regards, Claus.
>
> // GUI_EXAMPLE.SCE
> //
> // Demo of how to build a simple GUI in Scilab.
> // Real simple, with two input variables and one output.
> // The example uses the basic mechanical example of a mass and a spring as
> // input parameters and calculates the resonance frequency of the mechanical
> // system.
>
> // Initialize variables
> m  =  1;  // Moving mass 'm'(kilogram)
> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
> fres  =  1;  // Resonance frequency (Hertz)
> show_result  =  %f;
>
> function  calc()
>      m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
>      k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
>      fres  =  sqrt(m  *  k);
>      // putting GUI updates inside the calculation routine is not pretty code.
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
>      show_result  =  %t;
>      // update global variables
>      [m,k,fres,show_result]=return(m,k,fres,show_result);
> endfunction
>
> function  goodbye()
>      close(ge);  // Close GUI window
>      printf("Resulting fres: %f Hertz\n",fres);
>      abort  // Print result in console (e.g. for copy/paste), then kill the app
> endfunction
>
> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
> as  =  ge.axes_size;  // read size of window, as = [width height]
> ge.figure_name  =  "GUI Example";  // Change window header
>
> uicontrol("style","text","string","Moving mass :","position",  ..
>            [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
>            // position properties has four parameters = x,y,width,height
>            // y-position counts from lower left corner, so we subtract from 'as'
> ge_m  =  uicontrol("style","edit","string",string(m),  ..
>            "position",[100  as(2)-35  80  20]);
> uicontrol("style","text","string","kg ","position",  ..
>            [200  as(2)-35  30  20],"background",[1  1  1]);
>
> uicontrol("style","text","string","Stiffness :","position",  ..
>            [10  as(2)-60  80  20],"background",[1  1  1]);
> ge_k  =  uicontrol("style","edit","string",string(k),  ..
>            "position",[100  as(2)-60  80  20]);
> uicontrol("style","text","string","N/m ","position",  ..
>            [200  as(2)-60  30  20],"background",[1  1  1]);
>
> uicontrol("style","pushbutton","string","Calculate",  ..
>            "position",[10  as(2)-85  80  20],"callback","calc");
>
> // How do I make this "conditional"output show up in my GUI?
> if  show_result  then  // If "Calculate"button was pushed at least once ...
>      uicontrol("style","text","string","Result :","position",  ..
>                [10  as(2)-110  80  20]);
>      uicontrol("style","text","string",string(fres),  ..
>                "position",[100  as(2)-110  80  20]);
>      uicontrol("style","text","string","Hz ","position",  ..
>                [200  as(2)-110  30  20]);
> end
>
> uicontrol("style","pushbutton","string","Exit",  ..
>            "position",[10  as(2)-135  80  20],"callback","goodbye");
>
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel

In reply to this post by Claus Futtrup
Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup <[hidden email]> a écrit:
 
> Hi Antoine, et al.
>
> Your reply is very helpful, so I think you got the right question :-)
>
> 1) Good point that I can use callback on every uicontrol. This would be
> suitable for a simple example (like gui_example.sce) ... but for heavy
> calculations, it might be more practical with a CALC button. P.S. The
> correct equation for the resonance frequency is fres=sqrt(k/m)/(2*%pi);

You are right.
Also, the trick to disable the callback function/ reenable it is key for sliders that tend to generate an avalanche of call to the function when one moves the cursor.

>
> 2) I see what you mean, so not having an empty space, but "show" the
> whole she-bang from the beginning. I didn't want to do that (just
> deleting the IF-statement), but it could be the best solution in the end
> (rather than the inline GUI updates), if nothing better shows up. This
> was somehow the "core" of my question. Maybe I ask for too much.

I think you can achieve what you want by setting ".visible='off'" for all the uicontrols you don't want to show initialy. You can then set  ".visible='on'" after the first call to the callback (or at each call if you are lazy).

>
> 3) I will look into this. Thanks for the tip.

Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
I have found that this latter syntax is causing a lot of bug if your callback get called really often. I still don't know why.

>
> 4) I will also look into this. My problem is the steep learning curve.
> If you look at the Scilab tutorials you have the good-old Openeering
> LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial
> using the Model-Viewer-Controller approach? - Maybe the
> Model-Viewer-Controller could be presented in a _simple_ tutorial - is
> it possible?

Hmm, that would be a good idea.
I'll see whether I can put something together.
The thing is, MVC approach looks rather silly and overengineered on a small example.

>
> I appreciate gui_example.sce with just about 70 lines of code, two
> inputs and one output. I think something like it could help a lot of
> people ... and it's not 250 lines of code to get a GUI up and running,
> if you know what I mean. The gui_example shows a few differences, like
> white versus grey background, editable boxes, etc. In the outputs,
> because of the default grey background, you can see the dimensions of
> the grid / text-boxes, and gui_example has two buttons. It looks
> operational and easy to expand for new users.
>
> Cheers,
> Claus
>
> On 28.11.2019 08:57, Antoine Monmayrant wrote:
> > Hello Claus,
> >
> > I've been playing a bit with GUIs for teaching, so maybe I can help.
> > The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
> > Do not hesitate to rephrase your issue, I'll try a more focused answer.
> >
> > Anywya, here is how I think your code could be improved:
> >
> > (1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
> > (2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
> > (3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
> > (4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).
> >
> > I attached a small gui I use to illustrate optical anti-reflection coating.
> > It is far from perfect (I did not implement a proper model-view-controler for example).
> > But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.
> >
> > Hope it helps,
> >
> > Antoine
> >  
> > Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:
> >  
> >> Hi there
> >>
> >> I'm trying to build a GUI. For simplicity on the forum, I've built a
> >> really simple example of what I'm trying to do. How can I make the
> >> "conditional" GUI output work and not have it inside the calc function?
> >> ... or, how would you do it? Thanks.
> >>
> >> Best regards, Claus.
> >>
> >> // GUI_EXAMPLE.SCE
> >> //
> >> // Demo of how to build a simple GUI in Scilab.
> >> // Real simple, with two input variables and one output.
> >> // The example uses the basic mechanical example of a mass and a spring as
> >> // input parameters and calculates the resonance frequency of the mechanical
> >> // system.
> >>
> >> // Initialize variables
> >> m  =  1;  // Moving mass 'm'(kilogram)
> >> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
> >> fres  =  1;  // Resonance frequency (Hertz)
> >> show_result  =  %f;
> >>
> >> function  calc()
> >>       m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
> >>       k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
> >>       fres  =  sqrt(m  *  k);
> >>       // putting GUI updates inside the calculation routine is not pretty code.
> >>       uicontrol("style","text","string","Result :","position",  ..
> >>                 [10  as(2)-110  80  20]);
> >>       uicontrol("style","text","string",string(fres),  ..
> >>                 "position",[100  as(2)-110  80  20]);
> >>       uicontrol("style","text","string","Hz ","position",  ..
> >>                 [200  as(2)-110  30  20]);
> >>       show_result  =  %t;
> >>       // update global variables
> >>       [m,k,fres,show_result]=return(m,k,fres,show_result);
> >> endfunction
> >>
> >> function  goodbye()
> >>       close(ge);  // Close GUI window
> >>       printf("Resulting fres: %f Hertz\n",fres);
> >>       abort  // Print result in console (e.g. for copy/paste), then kill the app
> >> endfunction
> >>
> >> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
> >> as  =  ge.axes_size;  // read size of window, as = [width height]
> >> ge.figure_name  =  "GUI Example";  // Change window header
> >>
> >> uicontrol("style","text","string","Moving mass :","position",  ..
> >>             [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
> >>             // position properties has four parameters = x,y,width,height
> >>             // y-position counts from lower left corner, so we subtract from 'as'
> >> ge_m  =  uicontrol("style","edit","string",string(m),  ..
> >>             "position",[100  as(2)-35  80  20]);
> >> uicontrol("style","text","string","kg ","position",  ..
> >>             [200  as(2)-35  30  20],"background",[1  1  1]);
> >>
> >> uicontrol("style","text","string","Stiffness :","position",  ..
> >>             [10  as(2)-60  80  20],"background",[1  1  1]);
> >> ge_k  =  uicontrol("style","edit","string",string(k),  ..
> >>             "position",[100  as(2)-60  80  20]);
> >> uicontrol("style","text","string","N/m ","position",  ..
> >>             [200  as(2)-60  30  20],"background",[1  1  1]);
> >>
> >> uicontrol("style","pushbutton","string","Calculate",  ..
> >>             "position",[10  as(2)-85  80  20],"callback","calc");
> >>
> >> // How do I make this "conditional"output show up in my GUI?
> >> if  show_result  then  // If "Calculate"button was pushed at least once ...
> >>       uicontrol("style","text","string","Result :","position",  ..
> >>                 [10  as(2)-110  80  20]);
> >>       uicontrol("style","text","string",string(fres),  ..
> >>                 "position",[100  as(2)-110  80  20]);
> >>       uicontrol("style","text","string","Hz ","position",  ..
> >>                 [200  as(2)-110  30  20]);
> >> end
> >>
> >> uicontrol("style","pushbutton","string","Exit",  ..
> >>             "position",[10  as(2)-135  80  20],"callback","goodbye");
> >>
> >>
> >> _______________________________________________
> >> users mailing list
> >> [hidden email]
> >> http://lists.scilab.org/mailman/listinfo/users
>
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Stefan Du Rietz Stefan Du Rietz
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

> Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup <[hidden email]> a écrit:
>  
> I think you can achieve what you want by setting ".visible='off'" for all the uicontrols you don't want to show initialy. You can then set  ".visible='on'" after the first call to the callback (or at each call if you are lazy).

I do that and it is very convenient. I also save my GUI data in a
struct() in the "user_data" of the parent figure of the GUI. Then I
don't need global variables or even findobj().

Regards
Stefan
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

Hi Antoine and Stefan

Thanks for the tip using visible='off' ... it looks like a better way.

Regards,
Claus

On 28.11.2019 18:54, Stefan Du Rietz wrote:

>> Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup
>> <[hidden email]> a écrit:
>>   I think you can achieve what you want by setting ".visible='off'"
>> for all the uicontrols you don't want to show initialy. You can then
>> set  ".visible='on'" after the first call to the callback (or at each
>> call if you are lazy).
>
> I do that and it is very convenient. I also save my GUI data in a
> struct() in the "user_data" of the parent figure of the GUI. Then I
> don't need global variables or even findobj().
>
> Regards
> Stefan
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by Stefan Du Rietz
Hi Stefan

 >save my GUI data in a struct() in the "user_data"

I don't understand. Can you show me an example to explain this?

Best regards,
Claus

On 28.11.2019 18:54, Stefan Du Rietz wrote:

>> Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup
>> <[hidden email]> a écrit:
>>   I think you can achieve what you want by setting ".visible='off'"
>> for all the uicontrols you don't want to show initialy. You can then
>> set  ".visible='on'" after the first call to the callback (or at each
>> call if you are lazy).
>
> I do that and it is very convenient. I also save my GUI data in a
> struct() in the "user_data" of the parent figure of the GUI. Then I
> don't need global variables or even findobj().
>
> Regards
> Stefan
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by amonmayr
Hi Antoine

Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.


I see what you mean. I just now had trouble turning visibility on/off,
but using set(), it works fine. Thanks for the tip.

Best regards,
Claus

On 28.11.2019 17:47, Antoine Monmayrant wrote:

> Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup <[hidden email]> a écrit:
>  
>> Hi Antoine, et al.
>>
>> Your reply is very helpful, so I think you got the right question :-)
>>
>> 1) Good point that I can use callback on every uicontrol. This would be
>> suitable for a simple example (like gui_example.sce) ... but for heavy
>> calculations, it might be more practical with a CALC button. P.S. The
>> correct equation for the resonance frequency is fres=sqrt(k/m)/(2*%pi);
> You are right.
> Also, the trick to disable the callback function/ reenable it is key for sliders that tend to generate an avalanche of call to the function when one moves the cursor.
>
>> 2) I see what you mean, so not having an empty space, but "show" the
>> whole she-bang from the beginning. I didn't want to do that (just
>> deleting the IF-statement), but it could be the best solution in the end
>> (rather than the inline GUI updates), if nothing better shows up. This
>> was somehow the "core" of my question. Maybe I ask for too much.
> I think you can achieve what you want by setting ".visible='off'" for all the uicontrols you don't want to show initialy. You can then set  ".visible='on'" after the first call to the callback (or at each call if you are lazy).
>
>> 3) I will look into this. Thanks for the tip.
> Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
> I have found that this latter syntax is causing a lot of bug if your callback get called really often. I still don't know why.
>
>> 4) I will also look into this. My problem is the steep learning curve.
>> If you look at the Scilab tutorials you have the good-old Openeering
>> LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial
>> using the Model-Viewer-Controller approach? - Maybe the
>> Model-Viewer-Controller could be presented in a _simple_ tutorial - is
>> it possible?
> Hmm, that would be a good idea.
> I'll see whether I can put something together.
> The thing is, MVC approach looks rather silly and overengineered on a small example.
>
>> I appreciate gui_example.sce with just about 70 lines of code, two
>> inputs and one output. I think something like it could help a lot of
>> people ... and it's not 250 lines of code to get a GUI up and running,
>> if you know what I mean. The gui_example shows a few differences, like
>> white versus grey background, editable boxes, etc. In the outputs,
>> because of the default grey background, you can see the dimensions of
>> the grid / text-boxes, and gui_example has two buttons. It looks
>> operational and easy to expand for new users.
>>
>> Cheers,
>> Claus
>>
>> On 28.11.2019 08:57, Antoine Monmayrant wrote:
>>> Hello Claus,
>>>
>>> I've been playing a bit with GUIs for teaching, so maybe I can help.
>>> The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
>>> Do not hesitate to rephrase your issue, I'll try a more focused answer.
>>>
>>> Anywya, here is how I think your code could be improved:
>>>
>>> (1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
>>> (2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
>>> (3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
>>> (4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).
>>>
>>> I attached a small gui I use to illustrate optical anti-reflection coating.
>>> It is far from perfect (I did not implement a proper model-view-controler for example).
>>> But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.
>>>
>>> Hope it helps,
>>>
>>> Antoine
>>>    
>>> Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:
>>>    
>>>> Hi there
>>>>
>>>> I'm trying to build a GUI. For simplicity on the forum, I've built a
>>>> really simple example of what I'm trying to do. How can I make the
>>>> "conditional" GUI output work and not have it inside the calc function?
>>>> ... or, how would you do it? Thanks.
>>>>
>>>> Best regards, Claus.
>>>>
>>>> // GUI_EXAMPLE.SCE
>>>> //
>>>> // Demo of how to build a simple GUI in Scilab.
>>>> // Real simple, with two input variables and one output.
>>>> // The example uses the basic mechanical example of a mass and a spring as
>>>> // input parameters and calculates the resonance frequency of the mechanical
>>>> // system.
>>>>
>>>> // Initialize variables
>>>> m  =  1;  // Moving mass 'm'(kilogram)
>>>> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
>>>> fres  =  1;  // Resonance frequency (Hertz)
>>>> show_result  =  %f;
>>>>
>>>> function  calc()
>>>>        m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
>>>>        k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
>>>>        fres  =  sqrt(m  *  k);
>>>>        // putting GUI updates inside the calculation routine is not pretty code.
>>>>        uicontrol("style","text","string","Result :","position",  ..
>>>>                  [10  as(2)-110  80  20]);
>>>>        uicontrol("style","text","string",string(fres),  ..
>>>>                  "position",[100  as(2)-110  80  20]);
>>>>        uicontrol("style","text","string","Hz ","position",  ..
>>>>                  [200  as(2)-110  30  20]);
>>>>        show_result  =  %t;
>>>>        // update global variables
>>>>        [m,k,fres,show_result]=return(m,k,fres,show_result);
>>>> endfunction
>>>>
>>>> function  goodbye()
>>>>        close(ge);  // Close GUI window
>>>>        printf("Resulting fres: %f Hertz\n",fres);
>>>>        abort  // Print result in console (e.g. for copy/paste), then kill the app
>>>> endfunction
>>>>
>>>> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
>>>> as  =  ge.axes_size;  // read size of window, as = [width height]
>>>> ge.figure_name  =  "GUI Example";  // Change window header
>>>>
>>>> uicontrol("style","text","string","Moving mass :","position",  ..
>>>>              [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
>>>>              // position properties has four parameters = x,y,width,height
>>>>              // y-position counts from lower left corner, so we subtract from 'as'
>>>> ge_m  =  uicontrol("style","edit","string",string(m),  ..
>>>>              "position",[100  as(2)-35  80  20]);
>>>> uicontrol("style","text","string","kg ","position",  ..
>>>>              [200  as(2)-35  30  20],"background",[1  1  1]);
>>>>
>>>> uicontrol("style","text","string","Stiffness :","position",  ..
>>>>              [10  as(2)-60  80  20],"background",[1  1  1]);
>>>> ge_k  =  uicontrol("style","edit","string",string(k),  ..
>>>>              "position",[100  as(2)-60  80  20]);
>>>> uicontrol("style","text","string","N/m ","position",  ..
>>>>              [200  as(2)-60  30  20],"background",[1  1  1]);
>>>>
>>>> uicontrol("style","pushbutton","string","Calculate",  ..
>>>>              "position",[10  as(2)-85  80  20],"callback","calc");
>>>>
>>>> // How do I make this "conditional"output show up in my GUI?
>>>> if  show_result  then  // If "Calculate"button was pushed at least once ...
>>>>        uicontrol("style","text","string","Result :","position",  ..
>>>>                  [10  as(2)-110  80  20]);
>>>>        uicontrol("style","text","string",string(fres),  ..
>>>>                  "position",[100  as(2)-110  80  20]);
>>>>        uicontrol("style","text","string","Hz ","position",  ..
>>>>                  [200  as(2)-110  30  20]);
>>>> end
>>>>
>>>> uicontrol("style","pushbutton","string","Exit",  ..
>>>>              "position",[10  as(2)-135  80  20],"callback","goodbye");
>>>>
>>>>
>>>> _______________________________________________
>>>> users mailing list
>>>> [hidden email]
>>>> http://lists.scilab.org/mailman/listinfo/users
>>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

Le 28/11/2019 à 19:40, Claus Futtrup a écrit :
> Hi Antoine
>
> Also, you should better use get(a, 'propertyName') or set(a,
> 'propertyName', value) instead of a.propertyName and
> a.propertyName=value in your callbacks.


Why? It should be strictly equivalent, doesn't it?

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by Stefan Du Rietz
Le 28/11/2019 à 18:54, Stefan Du Rietz a écrit :
>
> I do that and it is very convenient. I also save my GUI data in a
> struct() in the "user_data" of the parent figure of the GUI. Then I
> don't need global variables or even findobj().

If the stored data are not handles, this could be a bit risky or buggy:
The graphics may be updated in the meantime, unlike the stored data...
that then get outdated.

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? GUI help

In reply to this post by amonmayr
Le 28/11/2019 à 08:57, Antoine Monmayrant a écrit :
Hello Claus,

I've been playing a bit with GUIs for teaching, so maybe I can help.
The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
Do not hesitate to rephrase your issue, I'll try a more focused answer.

Anywya, here is how I think your code could be improved:

(1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
(2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
(3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.


get() and set() can now use a tagsPath, that might be less ambiguate than using findobj(), that returns the first component with a matching tag (unless only unique tags are defined). The documentation of set() is being overhauled. You may have a look to it there. The same work on the get()'s page  is pending.


.../...
I attached a small gui I use to illustrate optical anti-reflection coating.

There won't never be too much physics on FileExchange, you know :-)


A physicist



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by amonmayr
Le 28/11/2019 à 17:47, Antoine Monmayrant a écrit :
> .../...
> Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
> I have found that this latter syntax is causing a lot of bug if your callback get called really often. I still don't know why.


OK. Now i remember, indeed, that some handle.prop access are badly
parsed as reading or defining a structure instead of reading or setting
the (expectedly) defined handle...


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by Stefan Du Rietz
Hello,

Le 28/11/2019 à 18:54, Stefan Du Rietz a écrit :
>> Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup
>> <[hidden email]> a écrit:
>>   I think you can achieve what you want by setting ".visible='off'"
>> for all the uicontrols you don't want to show initialy. You can then
>> set  ".visible='on'" after the first call to the callback (or at each
>> call if you are lazy).
>
> I do that and it is very convenient. I also save my GUI data in a
> struct() in the "user_data" of the parent figure of the GUI.
So do I. Definitively the most handy way of  doing.
> Then I don't need global variables or even findobj().
>
> Regards
> Stefan
> _______________________________________________
> users mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users 
>

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Stefan Du Rietz Stefan Du Rietz
Reply | Threaded
Open this post in threaded view
|

Re: ?= GUI hel

In reply to this post by Samuel GOUGEON

On 2019-11-28 20:55, Samuel Gougeon wrote:

> Le 28/11/2019 à 17:47, Antoine Monmayrant a écrit :
>> .../...
>> Also, you should better use get(a, 'propertyName') or set(a,
>> 'propertyName', value) instead of a.propertyName and
>> a.propertyName=value in your callbacks.
>> I have found that this latter syntax is causing a lot of bug if your
>> callback get called really often. I still don't know why.
>
>
> OK. Now i remember, indeed, that some handle.prop access are badly
> parsed as reading or defining a structure instead of reading or setting
> the (expectedly) defined handle...
>
>
I have also noticed all that.

But at last I managed to get it working. ;-)

I had to
1. copy the structure from user_data
2. edit the copied structure
3. set user_data to the edited structure


To Samuel 20:35:

My GUI data.are handles exept a few things I update simultaneously when
I change them..

Stefan

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel

In reply to this post by Claus Futtrup
Le Jeudi, Novembre 28, 2019 19:40 CET, Claus Futtrup <[hidden email]> a écrit:
 
> Hi Antoine
>
> Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
>
>
> I see what you mean. I just now had trouble turning visibility on/off,
> but using set(), it works fine. Thanks for the tip.

It's something quite weird, maybe a race condition.
I've seen it when using 'a.prop' or 'a.prop=value' syntax in either a callback function or in a for loop.
When you repeatedly use this syntax, scilab tends to forget that 'a' exists and that it's a handle with different properties.
The initial bug report is here: http://bugzilla.scilab.org/show_bug.cgi?id=15786
Not much progress because I never managed to get a minimal working example (it's an Heisenbug).

Antoine

>
> Best regards,
> Claus
>
> On 28.11.2019 17:47, Antoine Monmayrant wrote:
> > Le Jeudi, Novembre 28, 2019 17:05 CET, Claus Futtrup <[hidden email]> a écrit:
> >  
> >> Hi Antoine, et al.
> >>
> >> Your reply is very helpful, so I think you got the right question :-)
> >>
> >> 1) Good point that I can use callback on every uicontrol. This would be
> >> suitable for a simple example (like gui_example.sce) ... but for heavy
> >> calculations, it might be more practical with a CALC button. P.S. The
> >> correct equation for the resonance frequency is fres=sqrt(k/m)/(2*%pi);
> > You are right.
> > Also, the trick to disable the callback function/ reenable it is key for sliders that tend to generate an avalanche of call to the function when one moves the cursor.
> >
> >> 2) I see what you mean, so not having an empty space, but "show" the
> >> whole she-bang from the beginning. I didn't want to do that (just
> >> deleting the IF-statement), but it could be the best solution in the end
> >> (rather than the inline GUI updates), if nothing better shows up. This
> >> was somehow the "core" of my question. Maybe I ask for too much.
> > I think you can achieve what you want by setting ".visible='off'" for all the uicontrols you don't want to show initialy. You can then set  ".visible='on'" after the first call to the callback (or at each call if you are lazy).
> >
> >> 3) I will look into this. Thanks for the tip.
> > Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
> > I have found that this latter syntax is causing a lot of bug if your callback get called really often. I still don't know why.
> >
> >> 4) I will also look into this. My problem is the steep learning curve.
> >> If you look at the Scilab tutorials you have the good-old Openeering
> >> LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial
> >> using the Model-Viewer-Controller approach? - Maybe the
> >> Model-Viewer-Controller could be presented in a _simple_ tutorial - is
> >> it possible?
> > Hmm, that would be a good idea.
> > I'll see whether I can put something together.
> > The thing is, MVC approach looks rather silly and overengineered on a small example.
> >
> >> I appreciate gui_example.sce with just about 70 lines of code, two
> >> inputs and one output. I think something like it could help a lot of
> >> people ... and it's not 250 lines of code to get a GUI up and running,
> >> if you know what I mean. The gui_example shows a few differences, like
> >> white versus grey background, editable boxes, etc. In the outputs,
> >> because of the default grey background, you can see the dimensions of
> >> the grid / text-boxes, and gui_example has two buttons. It looks
> >> operational and easy to expand for new users.
> >>
> >> Cheers,
> >> Claus
> >>
> >> On 28.11.2019 08:57, Antoine Monmayrant wrote:
> >>> Hello Claus,
> >>>
> >>> I've been playing a bit with GUIs for teaching, so maybe I can help.
> >>> The issue is that I don't get what your problem is exactly here, so I my answer might be a bit off-topic.
> >>> Do not hesitate to rephrase your issue, I'll try a more focused answer.
> >>>
> >>> Anywya, here is how I think your code could be improved:
> >>>
> >>> (1) You can use 'calc' as the callback for all of the editable text field so that your result gets shown right away, without having to press a button.
> >>> (2) You should populate all the uicontrols of your gui first, then only update the displayed values, the visibility of the uicontrols, etc inside your calc function. (ie no more creating a uicontrol inside a callback)
> >>> (3) The 'tag' property of any uicontrol together with 'findobj()' are really nice to get/set the properties of each existing uicontrol.
> >>> (4) You can rely on a proper Model-View-Controler approach (or any other well established method to avoid mixing gui stuff with calculation stuff).
> >>>
> >>> I attached a small gui I use to illustrate optical anti-reflection coating.
> >>> It is far from perfect (I did not implement a proper model-view-controler for example).
> >>> But you can see how I tried to separate the different parts of the code an how I use findobj/tag/get/set,  etc.
> >>>
> >>> Hope it helps,
> >>>
> >>> Antoine
> >>>    
> >>> Le Mercredi, Novembre 27, 2019 19:21 CET, Claus Futtrup <[hidden email]> a écrit:
> >>>    
> >>>> Hi there
> >>>>
> >>>> I'm trying to build a GUI. For simplicity on the forum, I've built a
> >>>> really simple example of what I'm trying to do. How can I make the
> >>>> "conditional" GUI output work and not have it inside the calc function?
> >>>> ... or, how would you do it? Thanks.
> >>>>
> >>>> Best regards, Claus.
> >>>>
> >>>> // GUI_EXAMPLE.SCE
> >>>> //
> >>>> // Demo of how to build a simple GUI in Scilab.
> >>>> // Real simple, with two input variables and one output.
> >>>> // The example uses the basic mechanical example of a mass and a spring as
> >>>> // input parameters and calculates the resonance frequency of the mechanical
> >>>> // system.
> >>>>
> >>>> // Initialize variables
> >>>> m  =  1;  // Moving mass 'm'(kilogram)
> >>>> k  =  1;  // Stiffness, spring constant 'k'(Newton per meter)
> >>>> fres  =  1;  // Resonance frequency (Hertz)
> >>>> show_result  =  %f;
> >>>>
> >>>> function  calc()
> >>>>        m  =  evstr(get(ge_m,"string"));  // get content in uicontrol ge_m
> >>>>        k  =  evstr(get(ge_k,"string"));  // get content in uicontrol ge_k
> >>>>        fres  =  sqrt(m  *  k);
> >>>>        // putting GUI updates inside the calculation routine is not pretty code.
> >>>>        uicontrol("style","text","string","Result :","position",  ..
> >>>>                  [10  as(2)-110  80  20]);
> >>>>        uicontrol("style","text","string",string(fres),  ..
> >>>>                  "position",[100  as(2)-110  80  20]);
> >>>>        uicontrol("style","text","string","Hz ","position",  ..
> >>>>                  [200  as(2)-110  30  20]);
> >>>>        show_result  =  %t;
> >>>>        // update global variables
> >>>>        [m,k,fres,show_result]=return(m,k,fres,show_result);
> >>>> endfunction
> >>>>
> >>>> function  goodbye()
> >>>>        close(ge);  // Close GUI window
> >>>>        printf("Resulting fres: %f Hertz\n",fres);
> >>>>        abort  // Print result in console (e.g. for copy/paste), then kill the app
> >>>> endfunction
> >>>>
> >>>> ge  =  scf();  // GUI Example, Initialize and 'set current figure'
> >>>> as  =  ge.axes_size;  // read size of window, as = [width height]
> >>>> ge.figure_name  =  "GUI Example";  // Change window header
> >>>>
> >>>> uicontrol("style","text","string","Moving mass :","position",  ..
> >>>>              [10  as(2)-35  80  20],"background",[1  1  1]);  // white background
> >>>>              // position properties has four parameters = x,y,width,height
> >>>>              // y-position counts from lower left corner, so we subtract from 'as'
> >>>> ge_m  =  uicontrol("style","edit","string",string(m),  ..
> >>>>              "position",[100  as(2)-35  80  20]);
> >>>> uicontrol("style","text","string","kg ","position",  ..
> >>>>              [200  as(2)-35  30  20],"background",[1  1  1]);
> >>>>
> >>>> uicontrol("style","text","string","Stiffness :","position",  ..
> >>>>              [10  as(2)-60  80  20],"background",[1  1  1]);
> >>>> ge_k  =  uicontrol("style","edit","string",string(k),  ..
> >>>>              "position",[100  as(2)-60  80  20]);
> >>>> uicontrol("style","text","string","N/m ","position",  ..
> >>>>              [200  as(2)-60  30  20],"background",[1  1  1]);
> >>>>
> >>>> uicontrol("style","pushbutton","string","Calculate",  ..
> >>>>              "position",[10  as(2)-85  80  20],"callback","calc");
> >>>>
> >>>> // How do I make this "conditional"output show up in my GUI?
> >>>> if  show_result  then  // If "Calculate"button was pushed at least once ...
> >>>>        uicontrol("style","text","string","Result :","position",  ..
> >>>>                  [10  as(2)-110  80  20]);
> >>>>        uicontrol("style","text","string",string(fres),  ..
> >>>>                  "position",[100  as(2)-110  80  20]);
> >>>>        uicontrol("style","text","string","Hz ","position",  ..
> >>>>                  [200  as(2)-110  30  20]);
> >>>> end
> >>>>
> >>>> uicontrol("style","pushbutton","string","Exit",  ..
> >>>>              "position",[10  as(2)-135  80  20],"callback","goodbye");
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> users mailing list
> >>>> [hidden email]
> >>>> http://lists.scilab.org/mailman/listinfo/users
> >>
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.scilab.org/mailman/listinfo/users
>
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel

In reply to this post by Samuel GOUGEON
Le Jeudi, Novembre 28, 2019 20:55 CET, Samuel Gougeon <[hidden email]> a écrit:
 
> Le 28/11/2019 à 17:47, Antoine Monmayrant a écrit :
> > .../...
> > Also, you should better use get(a, 'propertyName') or set(a, 'propertyName', value) instead of a.propertyName and a.propertyName=value in your callbacks.
> > I have found that this latter syntax is causing a lot of bug if your callback get called really often. I still don't know why.
>
>
> OK. Now i remember, indeed, that some handle.prop access are badly
> parsed as reading or defining a structure instead of reading or setting
> the (expectedly) defined handle...

Yes, I spent some time to get a minimum working example, but without any success.
Even with big gui scripts, I only faced issues 1 out 10 times.
I faced the same kind of issues when creating complex plots with a big for loop to scan across "h.children.children" and set attributes.

Antoine


>
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel

In reply to this post by Samuel GOUGEON
> get() and set() can now use a tagsPath, that might be less ambiguate
> than using findobj(), that returns the first component with a matching
> tag (unless only unique tags are defined). The documentation of set() is
> being overhauled <http://bugzilla.scilab.org/show_bug.cgi?id=15414>. You
> may have a look to it there
> <http://bugzilla.scilab.org/attachment.cgi?id=4997>. The same work on
> the get()'s page is pending
> <http://bugzilla.scilab.org/show_bug.cgi?id=15226>.

I tried to use your syntax in a callback and it does not work.
The values returned are not the same than when using findobj and the old syntax (I always get the initial value for the uicontrol, not the updated ones).
I'll try to get a minimal working example...

Antoine

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= GUI hel

In reply to this post by amonmayr
> > 4) I will also look into this. My problem is the steep learning curve.
> > If you look at the Scilab tutorials you have the good-old Openeering
> > LHY_Tutorial - it's incredibly complicated and long. Is LHY_Tutorial
> > using the Model-Viewer-Controller approach? - Maybe the
> > Model-Viewer-Controller could be presented in a _simple_ tutorial - is
> > it possible?
>
> Hmm, that would be a good idea.
> I'll see whether I can put something together.
> The thing is, MVC approach looks rather silly and overengineered on a small example.

I have not tried to follow a MWC approach, but here is my attempt at making a really simple GUI to just show the basics (see below).
It take numbers from two different types of uicontrols (a slider and an edit) and display the sum in a text uicontrol.
To keep things simple, I positioned and sized the uicontrols manually instead of using a gridbag.
I also tried to use the fancy syntax for get() and set() that do not require calling findobj(), as suggested by Samuel.

Hope it helps,

Antoine


f=figure();

/* ---------------- First number from slider ----------------  */
//values
nmin=-5;
nmax=10;
nini=7;
nsmallstep=1;
nsbigstep=2;
//slider position and size
x=10;
y=20;
w=100;
h=25;
//slider uicontrol creation in figure f
hslider=uicontrol(f, ...
    "style", "slider", ...
    "tag", "slider1", ...
    "backgroundcolor", [1 1 1], ...
    "position", [x y w h], ...
    "value", nini, ...
    "min", nmin, ...
    "max", nmax, ...
    "sliderstep", [nsmallstep, nsbigstep], ...
    "callback", "update_values");

/* ------------- Second number from an editable text -------------  */
// initial value
editini="3.14";
//edit position and size
x2=x;
y2=y+h+5;
w2=w;
h2=h;
//edit uicontrol creation in figure f
hedit=uicontrol(f, ...
    "style", "edit", ...
    "tag", "edit2", ...
    "backgroundcolor", [1 1 1], ...
    "position", [x2 y2 w2 h2], ...
    "string", editini, ...
    "callback", "update_values");
   
/* ------------- Sum displayed in a text uicontrol -------------  */
// initial value
textini="Nothing"
//edit position and size
x3=x+w+5;
y3=y;
w3=w;
h3=2*h+5;
//slider uicontrol creation
htext=uicontrol(f, ...
    "style", "text", ...
    "tag", "text3", ...
    "backgroundcolor", [1 1 1], ...
    "position", [x3 y3 w3 h3], ...
    "string", textini);

/* -------- callback function for slider and edit uicontrols --------  */
//Whenever user interacts with the slider or the edit uicontrols
//  show the sum of both numbers in the text field
function update_values()
    //temporarily deactivate the callback (don't want callback calls to stack up while processing the current one
    set(gcbo,"callback_type",-1);
    /*
      Using the unique tag chosen at the creation time of the uicontrols
      to set/get the uicontrol properties
    */
    //get both numbers from the slider and the edit uicontrols
    number1=get("slider1", "value");
    string2=get("edit2", "string");
    //do your maths & conversion
    string3=string(number1+evstr(string2));
    //change the string displayed in the text uicontrol
    set("text3", "string", string3);
    //reactivate callback
    set(gcbo,"callback_type",0);
endfunction

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
12