GUI Examples #19:Explore popup selection determination and manipulation

February 14, 2010 by Matt Fig · Leave a Comment
Filed under: GUI, Tutorials 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Similar to GUI_18, except that the editbox is allowed to select a value from the popup.  The editbox may also add an item to the popup.

function [] = GUI_19()
% Demonstrate how to get selection from a popup to an edit box & vis versa.
% This is an expansion of GUI_17.  Here we will not enforce a specific list
% of choices so that any text the user enters into the editbox will be
% added to the popup list if it is not already there.
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 300 110],...
 'menubar','none',...
 'name','GUI_19',...
 'numbertitle','off',...
 'resize','off');
S.pop = uicontrol('style','pop',...
 'units','pixels',...
 'position',[20 10 260 40],...
 'string',{'one','two','three','four'});
S.ed = uicontrol('style','edit',...
 'units','pix',...
 'position',[20 60 260 30],...
 'fontsize',16,'string','one');
 
set([S.pop,S.ed],{'callback'},{{@pp_call,S};{@ed_call,S}});
 
function [] = pp_call(varargin)
% Callback for the popup.
S = varargin{3}% Get the structure.
P = get(S.pop,{'string','val'})% Get the users choice.
set(S.ed,'string',P{1}{P{2}})% Assign the user's choice to the edit.
 
function [] = ed_call(varargin)
% Callback for the edit.
S = varargin{3}% Get the structure.
E = get(S.ed,'string')% Get the string from the edit.
P = get(S.pop,{'string','value'})% Get the users choice.
% Check if edit string is found in pop-up list.
tmp = strmatch(E,P{1});
 
if ~isempty(tmp)
 set(S.pop,'value',tmp)  % Set the pop-up to match the edit.
else
 % We could add the new element to the popup string at either the top or
 % the bottom.  Both methods are shown below.  Only uncomment one of
 % these at a time!
 set(S.pop,'string',{P{1}{:},E},'value',length(P{1})+1) % Bottom
%     set(S.pop,'string',{E,P{1}{:}},'value',1) % Top   
end
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 1% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

GUI Examples #18:Explore popup selection determination

February 14, 2010 by Matt Fig · Leave a Comment
Filed under: GUI, Tutorials 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Explore popup selection determination and manipulation.  Similar to GUI_17, except that the editbox is allowed to select a value  from the popup.

function [] = GUI_18()
% Demonstrate how to get selection from a popup to an edit box & vis versa.
% This is an expansion of GUI_17.  Here we will enforce a specific list of
% choices so that any text the user enters into the editbox which is not a
% choice in the popup will be overwritten.
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 300 110],...
 'menubar','none',...
 'name','GUI_18',...
 'numbertitle','off',...
 'resize','off');
S.pop = uicontrol('style','pop',...
 'units','pixels',...
 'position',[20 10 260 40],...
 'string',{'one','two','three','four'});
S.ed = uicontrol('style','edit',...
 'units','pix',...
 'position',[20 60 260 30],...
 'fontsize',16,...
 'string','one');
 
set([S.pop,S.ed],{'callback'},{{@pop_call,S};{@ed_call,S}}); % Set callback
 
function [] = pop_call(varargin)
% Callback for the popup.
S = varargin{3}% Get the structure.
P = get(S.pop,{'string','val'})% Get the users choice.
set(S.ed,'string',P{1}{P{2}})% Assign the user's choice to the edit.
 
function [] = ed_call(varargin)
% Callback for the edit.
S = varargin{3}% Get the structure.
E = get(S.ed,'string')% Get the string from the edit.
P = get(S.pop,{'string','value'})% Get the users choice.
% Check if edit string is found in pop-up list.
tmp = strmatch(E,P{1});
 
if ~isempty(tmp)
 set(S.pop,'value',tmp)  % Set the pop-up to match the edit.
else
 set(S.ed,'string',P{1}{P{2}}) % Set the edit to current pop-up.
end
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 1% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

GUI Examples #17:Explore popup selection determination

February 7, 2010 by Matt Fig · Leave a Comment
Filed under: GUI, Tutorials 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Choosing an item from the popup causes the editbox to display the choice.

function [] = GUI_17()
% Demonstrate how to get the chosen string from a popup.  
% Creates a popup and an editbox.  When the user selects a choice from the
% popup, this choice will appear in the editbox.
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 300 110],...
 'menubar','none',...
 'name','GUI_17',...
 'numbertitle','off',...
 'resize','off');
S.pp = uicontrol('style','pop',...
 'units','pixels',...
 'position',[20 10 260 40],...
 'string',{'one','two','three','four'});
S.ed = uicontrol('style','edit',...
 'units','pix',...
 'position',[20 60 260 30],...
 'fontsize',16,'string','one');
 
set(S.pp,'callback',{@pp_call,S})% Set the callback.
 
function [] = pp_call(varargin)
% Callback for the popup.
S = varargin{3}% Get the structure.
P = get(S.pp,{'string','val'})% Get the user's choice.
set(S.ed,'string',P{1}{P{2}})% Assign the user's choice to the edit.
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 2% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

GUI Examples #7: Explore selection determination and counting

November 15, 2009 by Matt Fig · Leave a Comment
Filed under: GUI, Tutorials 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Selecting an item from the popup causes the textbox to display the number of times the item has been selected

GUIExample7

function [] = GUI_7()
% Demonstrate how to store choice counters for multiple user choices.  
% Creates a popup with two choices and a textbox to display the number of 
% times each choice has been made.  
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 300 100],...
 'menubar','none',...
 'name','GUI_7',...
 'numbertitle','off',...
 'resize','off');
S.tx = uicontrol('style','tex',...
 'unit','pix',...
 'position',[10 15 280 20],...
 'backgroundcolor',get(S.fh,'color'),...
 'fontsize',12,'fontweight','bold',... 
 'string','OPTION 1:  0      OPTION 2:  0');
S.pp = uicontrol('style','pop',...
 'unit','pix',...
 'position',[10 60 280 20],...
 'backgroundc',get(S.fh,'color'),...
 'fontsize',12,'fontweight','bold',... 
 'string',{'option 1';'option 2'},'value',1);
S.CNT = [0 0]% Holds the number of times each option has been called.
set(S.pp,'callback',{@pp_call,S})% Set the callback.             
 
function [] = pp_call(varargin)
% Callback for popupmenu.
S = varargin{3}% Get the structure.
P = get(S.pp,'val'); % Get the users choice from the popup.
S.CNT(P) = S.CNT(P) + 1% Increment the counter.
set(S.tx, 'string', sprintf('OPTION 1:  %i     OPTION 2:  %i', S.CNT));
set(S.pp,'callback',{@pp_call,S})% Save the new count.

Download full list of examples

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 1% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS