[Scilab-users] How to keep figure active with x_mdialog window open?

Rafael Guerra jrafaelbguerra at hotmail.com
Tue Jul 24 09:12:54 CEST 2018


After studying some past threads by Serge Steer on this callback topic, the following approach seems more appropriate.
One may discard the too-simple function save_exit() in code snippet at the bottom and rewrite the section:

        // Exit application
        h0=uicontrol(f0, "Position", [15 15 160 25],...
        "Style", "pushbutton",...
        "String", gettext("SAVE & EXIT"),...
        "FontSize", 11,...
        "Callback", "gcbo.userdata.hlist= h_list;");

Within my major Scilab script loop, I have put this command:
        input("Select items and then ENTER to continue","string");
        nh0 = h0.userdata.hlist.value; 

Which again works fine for standalone and in major loop issues error:
"Attempt to reference field of non-structure array."

However both typeof(h0.userdata.hlist.value) and typeof(nh0) are constant ...
And I see some hope in this as now, h0.userdata.hlist.value has the correct array of integer values

Any clues please?

Regards,
Rafael

-----Original Message-----
From: users <users-bounces at lists.scilab.org> On Behalf Of Rafael Guerra
Sent: Monday, July 23, 2018 10:42 PM
To: Users mailing list for Scilab <users at lists.scilab.org>
Subject: Re: [Scilab-users] How to keep figure active with x_mdialog window open?

Hi Izabela and Samuel,

I have followed Samuel's awesome offline advice to try using the gcbo() function to retrieve the lost callback handle. The improved code below now seems to work like a charm, regardless of where I place it within a larger Scilab program/loop.

// START OF CODE
stringmat = ["ITEM1";"ITEM2";"ITEM3";"ITEM4"];

function nn=save_exit()
    nn = gcbo().Userdata.hlist.value;
    delete(get("SELECT MULTIPLE ITEMS"));
endfunction

w = 300; // width and height in pixels
h = 900;
max0 = max(size(stringmat));
stringmat = string((1:max0)') + repmat(" - ",max0,1) + stringmat;

// Create a figure
f = figure("figure_name", gettext("SELECT MULTIPLE ITEMS"),...
"infobar_visible", "off",...
"toolbar_visible", "off",...
"dockable", "off",...
"menubar", "none",...
"default_axes", "off", ...
"Position",[100 100 w h],...
"resize", "off",...
"BackgroundColor", [0.9 0.9 0.9],...
"Tag", "SELECT MULTIPLE ITEMS");

// display list
h_list = uicontrol(f, "Position", [15 45 w-20 h-50],.. // -20 to allow space for scroll bar
"Style", "listbox",...
"FontSize", 11,...
"String",  stringmat,...
"BackgroundColor", [1 1 1],...
"Max", max0,... //if Max>1 then allowed multiple selection
"Tag", "colors_listbox");


// Exit application
h0=uicontrol(f, "Position", [15 15 160 25],...
"Style", "pushbutton",...
"String", gettext("SAVE & EXIT"),...
"FontSize", 11,...
"Callback", "h0.Userdata.hlist=h_list; nn=save_exit();");
// END OF CODE

Thanks a lot Samuel, this is a really useful functionality.

Kind regards,
Rafael




More information about the users mailing list