-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProjectStartupApp.m
341 lines (287 loc) · 12.7 KB
/
ProjectStartupApp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
classdef ProjectStartupApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
StartUpAppUIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
WelcomeTab matlab.ui.container.Tab
Image matlab.ui.control.Image
READMEButton matlab.ui.control.Button
ReviewUsButton matlab.ui.control.Button
MainMenuButton matlab.ui.control.Button
WelcomeTitle matlab.ui.control.Label
TabReview matlab.ui.container.Tab
OtherButton matlab.ui.control.Button
StudentButton matlab.ui.control.Button
FacultyButton matlab.ui.control.Button
Q1 matlab.ui.control.Label
ReviewTitle matlab.ui.control.Label
ReviewText matlab.ui.control.Label
end
properties (Access = private)
GitHubOrganization = "MathWorks-Teaching-Resources"; % Description
GitHubRepository = "Programming-Structuring-Code";
end
%% How to customize the app?
%{
This StartUp app is designed to be customized to your module. It
requires a minimum number of customization:
1. Change "Module Template" in app.WelcomeTitle by your module name
2. Change "Module Template" in app.ReviewTitle by your module name
3. Change the GitHubRepository (line 25) to the correct value
4. Change image in app.Image by the cover image you would like for your
module. This image should be located in rootFolder/Images
5. Create your MS Form:
a. Make a copy of the Faculty and the Student Template surveys
b. Customize the name of the survey to match the name of your
survey
c. Click on "Collect responses", select "Anyone can respond" and
copy the form link to SetupAppLinks (see step 6).
5. Create your MS Sway:
a. Go to MS Sway
b. Create a blank sway
c. Add the name of your module to the title box
d. Click "Share", Select "Anyone with a link", Select "View"
e. Copy the sway link to SetupAppLinks (see step 6).
6. Add the Survey and Sway link to Utilities/SurveyLinks using
SetupAppLinks.mlx in InternalFiles/RequiredFunctions/StartUpFcn
7. Save > Export to .m file and save the result as
Utilities/ProjectStartupApp.m
%}
methods (Access = private, Static)
function pingSway(app)
try
if ~ispref("MCCTEAM")
load Utilities\SurveyLinks.mat SwayLink
webread(SwayLink);
end
catch
end
end
function openStudentForm(app)
try
load Utilities\SurveyLinks.mat StudentFormLink
web(StudentFormLink);
catch
end
end
function openFacultyForm(app)
try
load Utilities\SurveyLinks.mat FacultyFormLink
web(FacultyFormLink);
catch
end
end
function saveSettings(isReviewed,numLoad)
try
save(fullfile("Utilities","ProjectSettings.mat"),"isReviewed","numLoad");
catch
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Switch tab to review if has not been reviewed yet
if isfile(fullfile("Utilities","ProjectSettings.mat"))
load(fullfile("Utilities","ProjectSettings.mat"),"isReviewed","numLoad");
numLoad = numLoad + 1; % Increment counter
else
isReviewed = false;
numLoad = 1; % Initialize counter
end
% Switch tab for review
if ~isReviewed && numLoad > 2
isReviewed = true;
app.TabGroup.SelectedTab = app.TabReview;
end
% Save new settings
app.saveSettings(isReviewed,numLoad)
% Download links to survey (should only work when module goes
% public on GitHub)
try
import matlab.net.*
import matlab.net.http.*
Request = RequestMessage;
Request.Method = 'GET';
Address = URI("http://api.github.com/repos/"+app.GitHubOrganization+...
"/"+app.GitHubRepository+"/contents/Utilities/SurveyLinks.mat");
Request.Header = HeaderField("X-GitHub-Api-Version","2022-11-28");
Request.Header(2) = HeaderField("Accept","application/vnd.github+json");
[Answer,~,~] = send(Request,Address);
websave(fullfile("Utilities/SurveyLinks.mat"),Answer.Body.Data.download_url);
catch
end
end
% Close request function: StartUpAppUIFigure
function StartUpAppUIFigureCloseRequest(app, event)
if event.Source == app.READMEButton
open README.mlx
elseif event.Source == app.MainMenuButton
open MainMenu.mlx
elseif event.Source == app.FacultyButton
open MainMenu.mlx
elseif event.Source == app.StudentButton
open MainMenu.mlx
elseif event.Source == app.OtherButton
open MainMenu.mlx
else
disp("Thank you for your time.")
end
delete(app)
end
% Button pushed function: MainMenuButton
function MainMenuButtonPushed(app, event)
StartUpAppUIFigureCloseRequest(app,event)
end
% Button pushed function: FacultyButton
function FacultyButtonPushed(app, event)
app.pingSway;
app.openFacultyForm;
StartUpAppUIFigureCloseRequest(app,event)
end
% Button pushed function: StudentButton
function StudentButtonPushed(app, event)
app.pingSway;
app.openStudentForm;
StartUpAppUIFigureCloseRequest(app,event)
end
% Button pushed function: OtherButton
function OtherButtonPushed(app, event)
app.pingSway;
app.openStudentForm;
StartUpAppUIFigureCloseRequest(app,event)
end
% Button pushed function: ReviewUsButton
function ReviewUsButtonPushed(app, event)
app.TabGroup.SelectedTab = app.TabReview;
end
% Button pushed function: READMEButton
function READMEButtonPushed(app, event)
StartUpAppUIFigureCloseRequest(app,event)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create StartUpAppUIFigure and hide until all components are created
app.StartUpAppUIFigure = uifigure('Visible', 'off');
app.StartUpAppUIFigure.AutoResizeChildren = 'off';
app.StartUpAppUIFigure.Position = [100 100 276 430];
app.StartUpAppUIFigure.Name = 'StartUp App';
app.StartUpAppUIFigure.Resize = 'off';
app.StartUpAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @StartUpAppUIFigureCloseRequest, true);
% Create TabGroup
app.TabGroup = uitabgroup(app.StartUpAppUIFigure);
app.TabGroup.AutoResizeChildren = 'off';
app.TabGroup.Position = [1 1 276 460];
% Create WelcomeTab
app.WelcomeTab = uitab(app.TabGroup);
app.WelcomeTab.AutoResizeChildren = 'off';
app.WelcomeTab.Title = 'Tab';
% Create WelcomeTitle
app.WelcomeTitle = uilabel(app.WelcomeTab);
app.WelcomeTitle.HorizontalAlignment = 'center';
app.WelcomeTitle.VerticalAlignment = 'top';
app.WelcomeTitle.WordWrap = 'on';
app.WelcomeTitle.FontSize = 24;
app.WelcomeTitle.FontWeight = 'bold';
app.WelcomeTitle.Position = [2 349 274 70];
app.WelcomeTitle.Text = 'Programming: Structuring Code';
% Create MainMenuButton
app.MainMenuButton = uibutton(app.WelcomeTab, 'push');
app.MainMenuButton.ButtonPushedFcn = createCallbackFcn(app, @MainMenuButtonPushed, true);
app.MainMenuButton.FontSize = 18;
app.MainMenuButton.Position = [59 96 161 35];
app.MainMenuButton.Text = 'Main Menu';
% Create ReviewUsButton
app.ReviewUsButton = uibutton(app.WelcomeTab, 'push');
app.ReviewUsButton.ButtonPushedFcn = createCallbackFcn(app, @ReviewUsButtonPushed, true);
app.ReviewUsButton.FontSize = 18;
app.ReviewUsButton.Position = [59 10 161 35];
app.ReviewUsButton.Text = 'Review Us';
% Create READMEButton
app.READMEButton = uibutton(app.WelcomeTab, 'push');
app.READMEButton.ButtonPushedFcn = createCallbackFcn(app, @READMEButtonPushed, true);
app.READMEButton.FontSize = 18;
app.READMEButton.Position = [59 53 161 35];
app.READMEButton.Text = 'README';
% Create Image
app.Image = uiimage(app.WelcomeTab);
app.Image.Position = [16 141 245 209];
app.Image.ImageSource = 'TurkeysColor.png';
% Create TabReview
app.TabReview = uitab(app.TabGroup);
app.TabReview.AutoResizeChildren = 'off';
app.TabReview.Title = 'Tab2';
app.TabReview.HandleVisibility = 'off';
% Create ReviewText
app.ReviewText = uilabel(app.TabReview);
app.ReviewText.HorizontalAlignment = 'center';
app.ReviewText.VerticalAlignment = 'top';
app.ReviewText.WordWrap = 'on';
app.ReviewText.FontSize = 18;
app.ReviewText.Position = [16 243 245 69];
app.ReviewText.Text = 'Please help us improve your experience by answering a few questions.';
% Create ReviewTitle
app.ReviewTitle = uilabel(app.TabReview);
app.ReviewTitle.HorizontalAlignment = 'center';
app.ReviewTitle.VerticalAlignment = 'top';
app.ReviewTitle.WordWrap = 'on';
app.ReviewTitle.FontSize = 24;
app.ReviewTitle.FontWeight = 'bold';
app.ReviewTitle.Position = [2 326 274 93];
app.ReviewTitle.Text = 'Programming: Structuring Code';
% Create Q1
app.Q1 = uilabel(app.TabReview);
app.Q1.HorizontalAlignment = 'center';
app.Q1.VerticalAlignment = 'top';
app.Q1.WordWrap = 'on';
app.Q1.FontSize = 18;
app.Q1.FontWeight = 'bold';
app.Q1.Position = [16 141 245 69];
app.Q1.Text = 'What describes you best?';
% Create FacultyButton
app.FacultyButton = uibutton(app.TabReview, 'push');
app.FacultyButton.ButtonPushedFcn = createCallbackFcn(app, @FacultyButtonPushed, true);
app.FacultyButton.FontSize = 18;
app.FacultyButton.Position = [64 127 150 40];
app.FacultyButton.Text = 'Faculty';
% Create StudentButton
app.StudentButton = uibutton(app.TabReview, 'push');
app.StudentButton.ButtonPushedFcn = createCallbackFcn(app, @StudentButtonPushed, true);
app.StudentButton.FontSize = 18;
app.StudentButton.Position = [64 80 150 40];
app.StudentButton.Text = 'Student';
% Create OtherButton
app.OtherButton = uibutton(app.TabReview, 'push');
app.OtherButton.ButtonPushedFcn = createCallbackFcn(app, @OtherButtonPushed, true);
app.OtherButton.FontSize = 18;
app.OtherButton.Position = [64 34 150 40];
app.OtherButton.Text = 'Other';
% Show the figure after all components are created
app.StartUpAppUIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ProjectStartupApp
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.StartUpAppUIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.StartUpAppUIFigure)
end
end
end