Popup Menu Using Guide

12 views (last 30 days)
Brandon Walker
Brandon Walker on 3 Jun 2019
Commented: Geoff Hayes on 3 Jun 2019
Hello, I am new to using matlab. I am trying to create a program that utilizes two push buttons and a drop down menu. I want to be able to pick an option from the menu and then click check in (start) and then click check out (stop) and have the elapsed time displayed. I also want the program after clicking the check out button to return to the state in which it waits for a user to select a choice again. Lastly I also want to be able to select another option from the drop down and check that one in while the other one is still running. I currently have a drop down and two push buttons that display the current time when pressed by the user but I do not know how to program it so that after clicking check out the program will retunr to the beginning state or allow me to choose multiple choices while another is running. I have attached the code I have so far. Any help would be appreciated, thank you.
function varargout = Popup(varargin)
% POPUP MATLAB code for Popup.fig
% POPUP, by itself, creates a new POPUP or raises the existing
% singleton*.
%
% H = POPUP returns the handle to a new POPUP or the handle to
% the existing singleton*.
%
% POPUP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in POPUP.M with the given input arguments.
%
% POPUP('Property','Value',...) creates a new POPUP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Popup_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Popup_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Popup
% Last Modified by GUIDE v2.5 03-Jun-2019 10:14:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Popup_OpeningFcn, ...
'gui_OutputFcn', @Popup_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Popup is made visible.
function Popup_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Popup (see VARARGIN)
set(handles.pushbutton2,'Enable','off');
% Choose default command line output for Popup
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Popup wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Popup_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
updateDisplay(handles)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function updateDisplay(handles)
contents = cellstr(get(handles.popupmenu1,'String'));
userchoice = contents{get(handles.popupmenu1,'Value')}
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
set(handles.pushbutton2,'Enable','on');
set(handles.pushbutton1,'Enable','off');
handles.startTime = char(datestr(now,'mm-dd-yyyy hh:MM:ss'));
startTime = handles.startTime
m2 = msgbox(startTime);
guidata(hObject,handles);
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
set(handles.pushbutton1,'Enable','on');
handles.stopTime = char(datestr(now,'mm-dd-yyyy hh:MM:ss'));
stopTime = handles.stopTime
m2 = msgbox(handles.stopTime);
elapsedTime = handles.stopTime - handles.startTime
guidata(hObject, handles);
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
  1 Comment
Geoff Hayes
Geoff Hayes on 3 Jun 2019
Brandon - what does the "beginning state" mean to you? Should the start button be enabled and the stop button disabled? Please also clarify I also want to be able to select another option from the drop down and check that one in. What is being "checked in"? Besides calling updateDisplay when the popup menu selection changes, I don't see what happens with that selection.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!