[Scilab-users] Help write simple GUI

Antoine ELIAS antoine.elias at scilab-enterprises.com
Sun Jun 1 11:41:24 CEST 2014


Hi Claus,

For small dialogs to ask inputs, use *x_mdialog* function ( http://help.scilab.org/docs/5.5.0/fr_FR/x_mdialog.html )

function result = compute_voltage()
    txt = ['Power (Watt)';'Impedance (ohm)'];
    values = *x_mdialog*('System values',txt,['100';'8'])
    if values <> [] then
        w = values(1);
        o = values(2);
        w = eval(w);
        o = eval(o);

        if typeof(w) <> "constant" | int(w) <> w | typeof(o) <> "constant" | int(o) <> o then
            error("bad value, integer values expected");
        end

        result = sqrt(w * o);
    else
        result = [];
    end
endfunction

voltage = compute_voltage()

Antoine


Le 31/05/2014 22:01, Claus Futtrup a écrit :
> Hi there
>
> I hope someone can help me make a simple GUI front end to my script, preferably without using GUI Builder or guimaker, because I think I'll understand better without using additional tools.
>
> The GUI - a window containing two variable input:
> 1. text + input box + text
>    Again the input is a number, typically an integer (as in "system power : 100 Watt"). 100 being the user variable input.
> 2. text + input box + text
>    A number, typically an intereger (as in "impedance : 8 ohm"). 8 being the user variable input.
>
> The script will then based on 100 Watt into 8 ohm calculate the voltage = sqrt(100*8). I will round the number to one decimal, convert it to a string and create an answer, like "Input level : 28.3
> Volt".
>
> The GUI should contain two buttons, e.g. an OK + a QUIT button. The OK button runs the calculations. The quit button quits the script (may as well quit Scilab).
>
> I've studied the GUI controls in Scilab already and I understand the the old way of making a new window is:
>
> f = figure();
>
> but it seems there's a new command in Scilab 5.5.0:
>
> f = createWindow();
>
> The new method probably has its advantages, but the Scilab manual doesn't really explain... can anybody explain to me?
>
> Can you use the same uicontrol commands with both methods? (can I use examples found on the internet using "figure" and just replace figure with createWindow?). It seems to me that the examples in
> the createWindow gives uicontrol some inputs named "units" - "normalized" - etc. - which are not present when looking at old figure() examples.
>
> My next question will be, how do I create a uicontrol which accepts a string input (as I need 2 of those). The uicontrol documentation says the "Edit" style will do that. Funny, but also a bit
> strange, that you can find all sorts of examples for using uicontrol with checboxes, listboxes, radiobuttons, pushbuttons, tables etc. - but no examples are provided with this most useful editable
> string input ... (???)
>
> ... hereafter I expect to evaluate the two strings (or if they're returned as numbers, that's fine of course, I just don't need the script to crash if something is not right). Then execute my code.
>
> Best regards,
> Claus
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users


-- 
Antoine ELIAS
Software developer
-----------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles
Phone: 01.80.77.04.70
http://www.scilab-enterprises.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140601/14cd5ec3/attachment.htm>


More information about the users mailing list