0

I would like to run a script which asks the user to give an input value. To choose the value the user is assumed to look at the current result represented graphically. It is practically impossible to foreseen which part of the graph has decisive information for choosing the parameter, so that the user is assumed to be able to move along the graph and rescale it if necessary until the decision is taken. In my script it looks as following:

...
scf(f1);plot2d(x,y,1);
w=evstr(x_dialog('Value of the parameter ?','3.1415926'));
...

However in this implementation the graphic window appears to be locked and no operations with it are possible until the input to dialog box is given.

I would appreciate any hint how to overcome this problem.

EDIT: I have found the following temporary solution:

...
scf(f1);plot2d(x,y,1);
disp('Choose the parameter value and type ''resume'' to continue.');
pause;
w=evstr(x_dialog('Value of the parameter ?','3.1415926'));
...

But I still hope for a better solution, such as pressing a keyboard button instead of typing 'resume'. To my sorry xclick() does not work, as again prevents working with the graphical window.

user
  • 101
  • 2

1 Answers1

1

The x_dialog will not return until one of the two button has been clicked, so you won't be able to find a better solution if you keep x_dialog.

Using callback may answer your problem but it's not a "better" solution as you will need to produce a gui (see uicontrol), a callback to run the simulation once the user inputed the value.

A first try :

clc
clear
xdel(winsid())

function callback()
  // get the value, and check if its a constant
  val=msscanf(get(findobj('tag_edit'),'string'),'%e')
  if val==[] then
    error('The input could not be read as a constant.')
  end
    // Call the main function/script here
    // like 'main(val)'
    // or 'exec('main.sce')' 
endfunction

function xdialog_alt(text,default)
  f=gdf(); // get the default value
  // so the dialog will be placed next to it on the right
  fig=figure('layout','gridbag','dockable','off','infobar_visible','off','menubar_visible','off','toolbar_visible','off','figure_size',[400,70],'figure_position',f.figure_position+[f.figure_size(1),0])

  // Create the text uicontrol to explain what to enter
  c = createConstraints("gridbag",[1, 1, 1, 1], [1, 1], "both");
  uicontrol(fig,'style','text','string',text,'constraints',c)

  // Create the edit uicontrol to recieve an user inputed value
  c = createConstraints("gridbag",[2, 1, 1, 1], [1, 1], "both");
  uicontrol(fig,'style','edit','string',default,'constraints',c,'tag','tag_edit')
  // create a button to launch further computation with the inputed value
  c = createConstraints("gridbag",[3, 1, 1, 1], [1, 1], "both");
  uicontrol(fig,'style','pushbutton','string','Confirm','constraints',c,'callback','callback')
endfunction

x=0:0.3:3
y = sin(x)
plot2d(x,y,1);
xdialog_alt('Value of the parameter ?','3.1415');
// End of the script. nothing below this will be aware of the value written in xdialog_alt

this gives hands back on the graph

PTRK
  • 899
  • 1
  • 5
  • 18
  • Thank you for the answer, but I did not get the point, how the main program (function) gets access to the input value. – user Mar 21 '18 at 08:48
  • It can't. You should put further calculation inside the callback function – PTRK Mar 21 '18 at 12:40
  • This is of course not quite satisfactory. Frankly speaking, I do not understand why it is needed to block other windows until user gives the input into `x_dialog`. It would be much more convenient to give the user a possibility to look around. I personally have decided to use the `input` command instead of `x_dialog`. The only problem is that the input values are stored in history and one should leaf through all of them. – user Mar 21 '18 at 14:37
  • `x=input('Enter the parameter : -->')` . Why do you say you have to leaf through them ? – PTRK Mar 21 '18 at 15:32
  • I mean that after execution of my function all values which I have entered after the (multiple) prompt remain in the history. – user Mar 21 '18 at 15:56
  • Why does it bother you ? It's normal for the history to record your input. – PTRK Mar 21 '18 at 16:02
  • While normally I would like to return back to the previous call and now I should press the "Up" key ten times more. :) But in fact it is just a minor inconvenience... Much more interesting is the question how to "repair" `x_dialog`. For developers it should not be a problem... – user Mar 21 '18 at 16:26