help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Function handle with arguments for GUI callback


From: Arnaud Miege
Subject: Function handle with arguments for GUI callback
Date: Mon, 11 Mar 2013 16:21:49 +0000

Hi,

I am trying to develop a GUI (using Octave 3.6.2 with Qt graphics toolkit on Windows). The whole of the code is in a single function file, with a number of nested functions. I have used MATLAB for more than 10 years so I am used to the nested functions having access to the workspace of the calling function. Now, I understand that the decision was made for Octave to not support this behaviour, and that's fine, everybody's entitled to their opinion, I am not going to discuss the benefits of using either approach. It just means that I have to pass arguments to the callback functions, which is fine, or at least should be in theory.

My question really is what is the best way to use a function handle *with arguments* as a callback to a uicontrol?

Here's what my code looks like:

function my_top_level_GUI()

  function gui = create_interface()
  % some code to create the uicontrols
  % gui is a struct

   % Add pop-up menus for dimension choice of each input
   strings = {'Nominal dimensions|Measurement file'};
   width = [0.5 0.5 0.5];
   gui.dim_choices = cell(size(gui.inputs_txt)); % cell of dim (3,1)
  for k=1:length(gui.inputs_txt)
  gui.dim_choices{k} = uicontrol('Style','popupmenu','String',strings,...
      'Units','normalized','Position',[0.23 y_pos(k) width(k) 0.1],...
      'BackgroundColor','w','Parent',gui.inputs_panel,'Callback',...
  @(gui,k)update_browse_btn);
  end

   end % end create_interface

   function update_browse_btn(gui,k)
  % Called when user activates popup menu 
   val = get(gui.dim_choices{k},'Value');
   if val == 2
      set(gui.browse_btns{k},'Enable','on');
   end
   end % end update_browse_btn

end

This gives me the error message:

>> error: `gui' undefined near line 184 column 11
error: evaluating argument list element number 1
error: called from:
error:   <path_to_my_GUI_file> at line 184, colu
mn 5

Any suggestions on how to make this work?

Many thanks in advance,

Arnaud

reply via email to

[Prev in Thread] Current Thread [Next in Thread]