-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtrack_editpreferences.m
346 lines (297 loc) · 18.3 KB
/
dtrack_editpreferences.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
342
343
344
345
346
function outpara = dtrack_editpreferences(para)
%DTRACK_EDITPREFERENCES creates a gui for the user to change DTrack preferences.
% By pressing the Default button, the preferences are saved to the Matlab preferences directory (from where they are loaded whenever a new project
% is created). Pressing the "Revert" button resets all values to what they were when the Preferences window was opened.
%
% Call sequence: GUI (File -> Preferences, or Toolbar button) -> dtrack_action -> dtrack_editpreferences
% Uses: None
% See also: dtrack_action
%% init variables
inpara = para; %for restore
gui = [];
editcb = @sub_callback;
outpara = [];
%create
sub_creategui;
sub_setdef;
%% set figure to modal late after you know there are no errors
%set(gui.fig, 'windowStyle', 'modal');
%% handle Return/Escape/Figure close, redraw to remove wrong previews and finish
try
uiwait(gui.fig);
delete(gui.fig);
catch anyerror
delete(gui.fig); %delete the modal figure, otherwise we'll be stuck in it forever
rethrow(anyerror);
end
%%%%%%%%%%%%%%%%%%%
%% Nested functions for callbacks, writing/drawing and panel creation
function sub_OK(varargin)
% OK: ok button callback, returns the changed para and finishes execution
outpara = para;
uiresume;
end
function sub_cancel(varargin)
% CANCEL: cancel button callback, returns unchanged para and finishes execution
uiresume;
end
function sub_revert(varargin)
% REVERT: revert to original
para = inpara;
sub_setdef;
end
function sub_default(varargin)
% DEFAULT: save current values as new default
clear savepara;
savepara.paths.movdef = para.paths.movdef;
savepara.paths.resdef = para.paths.resdef;
savepara.paths.vlcpath = para.paths.vlcpath;
savepara.gui.fig1pos = para.gui.fig1pos;
savepara.showcurr = para.showcurr;
savepara.showlast = para.showlast;
savepara.showlastrange = para.showlastrange;
savepara.maxrecent = para.maxrecent;
savepara.gui.stepsize = para.gui.stepsize;
savepara.gui.tab_title_spacing = para.gui.tab_title_spacing;
savepara.defaultz = para.defaultz;
savepara.autoforw = para.autoforw;
savepara.gui.navitoolbar = para.gui.navitoolbar;
savepara.gui.infopanel = para.gui.infopanel;
savepara.gui.infopanel_points = para.gui.infopanel_points;
savepara.gui.infopanel_mani = para.gui.infopanel_mani;
savepara.gui.minimap = para.gui.minimap;
save(fullfile(prefdir, 'dtrack_pref.dtp'), 'savepara', '-mat');
disp('Local preferences saved to preferences directory.');
end
function sub_close(varargin)
% CLOSE: close button callback
button = questdlg('Do you want to save the changed values?', 'Save changes', 'Save', 'Don''t save', 'Cancel', 'Don''t save');
switch button
case 'Save'
sub_OK();
case 'Don''t save'
sub_cancel();
end
end
function sub_callback(src, varargin)
switch get(src, 'tag')
case 'editpref_movdef'
if exist(get(src, 'string'), 'file')
para.paths.movdef = get(src, 'string');
else
errordlg('Invalid directory path', 'Invalid entry', 'modal');
set(src, 'string', para.paths.movdef);
end
case 'editpref_movdefbutton'
dirname = uigetdir(para.paths.movdef);
if dirname~=0
para.paths.movdef = dirname;
set(gui.panel1.movdef, 'string', dirname);
end
case 'editpref_resdef'
if exist(get(src, 'string'), 'file')
para.paths.resdef = get(src, 'string');
else
errordlg('Invalid directory path', 'Invalid entry', 'modal');
set(src, 'string', para.paths.resdef);
end
case 'editpref_resdefbutton'
dirname = uigetdir(para.paths.resdef);
if dirname~=0
para.paths.resdef=dirname;
set(gui.panel1.resdef, 'string', dirname);
end
case 'editpref_vlcpath'
if exist(get(src, 'string'), 'file')
para.paths.vlcpath=get(src, 'string');
else
errordlg('Invalid directory path', 'Invalid entry', 'modal');
set(src, 'string', para.paths.resdef);
end
case 'editpref_vlcpathbutton'
[filename, pathname] = uigetfile('vlc.exe', 'Please enter the location of vlc.exe', para.paths.vlcpath);
if filename~=0
para.paths.vlcpath = fullfile(pathname, filename);
set(gui.panel1.vlcpath, 'string', fullfile(pathname, filename));
end
case 'editpref_maxrecent'
temp=round(str2double(get(src, 'string')));
if temp>0
para.maxrecent = temp;
else
set(src, 'string', num2str(para.maxrecent));
errordlg('Invalid entry', 'Invalid entry', 'modal');
end
case 'editpref_fig1pos'
temp = get(src, 'string');
itemname = temp(get(src, 'value'), :);
switch itemname
case 'Fullscreen'
para.gui.fig1pos = [];
otherwise
resolution = textscan(itemname, '%dx%d');
para.gui.fig1pos = [1 1 resolution{1} resolution{2}];
end
case 'editpref_showcurr'
para.showcurr = get(src, 'value');
case 'editpref_showlast'
para.showlast = get(src, 'value');
case 'editpref_showlastrange'
temp = round(str2double(get(src, 'string')));
if temp>0
para.showlastrange = temp;
else
set(src, 'string', num2str(para.showlastrange));
errordlg('Invalid entry', 'Invalid entry', 'modal');
end
case 'editpref_stepsize'
temp = round(str2double(get(src, 'string')));
if temp>0
para.gui.stepsize = temp;
else
set(src, 'string', num2str(para.gui.stepsize));
errordlg('Invalid entry', 'Invalid entry', 'modal');
end
case 'editpref_guispace'
temp = str2double(get(src, 'string'));
if ~isnan(temp)
temp = min([max([temp 0]) 0.1]);
para.gui.tab_title_spacing = temp;
set(src, 'string', num2str(para.gui.tab_title_spacing));
else
set(src, 'string', num2str(para.gui.tab_title_spacing));
errordlg('Invalid entry', 'Invalid entry', 'modal');
end
case 'editpref_defaultz'
temp = str2double(get(src, 'string'));
if ~isnan(temp)
para.defaultz = temp;
else
set(src, 'string', num2str(para.defaultz));
errordlg('Invalid entry', 'Invalid entry', 'modal');
end
case 'editpref_autoforw'
para.autoforw = get(src, 'value')-1;
case 'editpref_navitoolbar'
para.gui.navitoolbar = get(src, 'value');
case 'editpref_infopanel'
para.gui.infopanel = get(src, 'value');
case 'editpref_info_points'
para.gui.infopanel_points = get(src, 'value');
case 'editpref_info_mani'
para.gui.infopanel_mani = get(src, 'value');
case 'editpref_minimap'
para.gui.minimap = get(src, 'value');
otherwise
error(['Internal error: unknown field ' get(src, 'tag') ' calling main callback']);
end
end
function sub_creategui
screen = get(0, 'screensize');
figsize = [600 500];
figpos = [screen(3)/2-figsize(1)/2 screen(4)/2-figsize(2)/2 figsize(1) figsize(2)];
%set up the figure
gui.fig = figure(777); clf;
set(gui.fig, 'outerposition', figpos, 'name', '', 'numbertitle', 'off', 'menubar', 'none',...
'interruptible', 'off', 'pointer', 'arrow', 'CloseRequestFcn', @sub_close);
%% panels
uicontrol(gui.fig, 'style', 'text', 'string', [para.theme.name ' preferences'], 'units', 'normalized', 'position', [.02 .91 .96 .07], 'backgroundcolor', get(gui.fig, 'color'), 'fontsize', 15, 'fontweight', 'bold');
gui.panel1.panel = uipanel(gui.fig, 'position', [.02 .74 .96 .15]);
gui.panel2.panel = uipanel(gui.fig, 'position', [.02 .57 .96 .15]);
gui.panel3.panel = uipanel(gui.fig, 'position', [.02 .12 .47 .43]);
gui.panel4.panel = uipanel(gui.fig, 'position', [.51 .12 .47 .43]);
%% panel 1
opts = {'units', 'normalized', 'callback', editcb};
uicontrol(gui.panel1.panel, opts{:}, 'position', [.01 .69 .18 .31], 'style', 'text', 'string', {'Default movie path:'}, 'HorizontalAlignment', 'left');
gui.panel1.movdef = uicontrol(gui.panel1.panel, opts{:}, 'position', [.20 .69 .699 .31], 'style', 'edit', 'HorizontalAlignment', 'left', 'tag', 'editpref_movdef', 'tooltipstring', 'Please enter the default path to start searching for data files.');
gui.panel1.movdefbutton = uicontrol(gui.panel1.panel, opts{:}, 'position', [.90 .69 .099 .31], 'style', 'pushbutton', 'string', 'Browse...', 'tag', 'editpref_movdefbutton');
uicontrol(gui.panel1.panel, opts{:}, 'position', [.01 .35 .18 .31], 'style', 'text', 'string', {'Default results path:'}, 'HorizontalAlignment', 'left');
gui.panel1.resdef = uicontrol(gui.panel1.panel, opts{:}, 'position', [.20 .35 .699 .31], 'style', 'edit', 'HorizontalAlignment', 'left', 'tag', 'editpref_resdef', 'tooltipstring', 'Please enter the default path to start searching for results files.');
gui.panel1.resdefbutton = uicontrol(gui.panel1.panel, opts{:}, 'position', [.90 .35 .099 .31], 'style', 'pushbutton', 'string', 'Browse...', 'tag', 'editpref_resdefbutton');
uicontrol(gui.panel1.panel, opts{:}, 'position', [.01 .02 .18 .31], 'style', 'text', 'string', {'VLC path:'}, 'HorizontalAlignment', 'left');
gui.panel1.vlcpath = uicontrol(gui.panel1.panel, opts{:}, 'position', [.20 .02 .699 .31], 'style', 'edit', 'HorizontalAlignment', 'left', 'tag', 'editpref_vlcpath', 'tooltipstring', 'To enable viewing videos in VLC, please enter the path of vlc.exe on your system (Windows only).');
gui.panel1.vlcpathbutton = uicontrol(gui.panel1.panel, opts{:}, 'position', [.90 .02 .099 .31], 'style', 'pushbutton', 'string', 'Browse...', 'tag', 'editpref_vlcpathbutton');
%% panel 2
reslist = 'Fullscreen|640x480|800x600|1024x768|1280x1024|1440x900|1680x1050|1920x1080|1920x1200';
uicontrol(gui.panel2.panel, opts{:}, 'position', [.01 .52 .48 .31], 'style', 'text', 'string', {'Default resolution:'}, 'HorizontalAlignment', 'right');
gui.panel2.fig1pos = uicontrol(gui.panel2.panel, opts{:}, 'position', [.50 .52 .20 .37], 'style', 'popupmenu', 'string', reslist, 'tag', 'editpref_fig1pos');
uicontrol(gui.panel2.panel, opts{:}, 'position', [.01 .19 .48 .31], 'style', 'text', 'string', {'Maximum recent files to show in start dialog:'}, 'HorizontalAlignment', 'right');
gui.panel2.maxrecent = uicontrol(gui.panel2.panel, opts{:}, 'position', [.50 .19 .10 .31], 'style', 'edit', 'tag', 'editpref_maxrecent');
%% panel 3
gui.panel3.showcurr = uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .87 .9 .1], 'style', 'checkbox', 'string', 'Highlight current object', 'tag', 'editpref_showcurr');
gui.panel3.showlast = uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .75 .9 .1], 'style', 'checkbox', 'string', 'Show previous position for current object,', 'tag', 'editpref_showlast');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .63 .5 .09], 'style', 'text', 'string', 'if it was marked in the last', 'HorizontalAlignment', 'left');
gui.panel3.showlastrange = uicontrol(gui.panel3.panel, opts{:}, 'position', [.55 .63 .1 .1], 'style', 'edit', 'tag', 'editpref_showlastrange');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.67 .63 .3 .09], 'style', 'text', 'string', 'frames.', 'HorizontalAlignment', 'left');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .43 .39 .1], 'style', 'text', 'string', 'Large step:', 'HorizontalAlignment', 'left');
gui.panel3.stepsize = uicontrol(gui.panel3.panel, opts{:}, 'position', [.5 .45 .4 .1], 'style', 'edit', 'tag', 'editpref_stepsize', 'tooltipstring', 'Select number of frames to jump in a large step (by default done with left/right arrow)');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .3 .39 .1], 'style', 'text', 'string', 'Autoforward mode:', 'HorizontalAlignment', 'left');
gui.panel3.autoforw = uicontrol(gui.panel3.panel, opts{:}, 'position', [.5 .32 .4 .1], 'style', 'popupmenu', 'string', 'nothing|small step|large step', 'tag', 'editpref_autoforw', 'tooltipstring', 'What to do after all objects in a frame are marked?');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .17 .39 .1], 'style', 'text', 'string', 'Default z-position:', 'HorizontalAlignment', 'left');
gui.panel3.defaultz = uicontrol(gui.panel3.panel, opts{:}, 'position', [.5 .19 .4 .1], 'style', 'edit', 'tag', 'editpref_defaultz', 'tooltipstring', 'For 3D-tracking, use this z-value to plot points with untracked z-depth.');
uicontrol(gui.panel3.panel, opts{:}, 'position', [.05 .04 .44 .1], 'style', 'text', 'string', 'Panel spacing (0-0.1):', 'HorizontalAlignment', 'left');
gui.panel3.guispace = uicontrol(gui.panel3.panel, opts{:}, 'position', [.5 .06 .4 .1], 'style', 'edit', 'tag', 'editpref_guispace', 'tooltipstring', 'An extra spacing value for each each tab. Use to unclutter the panels on the right of the screen.');
%% panel 4
uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .87 .5 .12], 'style', 'text', 'string', 'Show by default:', 'HorizontalAlignment', 'left');
gui.panel4.navitoolbar = uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .74 .9 .12], 'style', 'checkbox', 'string', 'File and navigation toolbar', 'tag', 'editpref_navitoolbar');
gui.panel4.infopanel = uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .61 .9 .12], 'style', 'checkbox', 'string', 'Info panel', 'tag', 'editpref_infopanel');
gui.panel4.info_points = uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .48 .9 .12], 'style', 'checkbox', 'string', 'Object panel', 'tag', 'editpref_info_points');
gui.panel4.info_mani = uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .22 .9 .12], 'style', 'checkbox', 'string', 'Image manipulation panel', 'tag', 'editpref_info_mani');
gui.panel4.minimap = uicontrol(gui.panel4.panel, opts{:}, 'position', [.05 .09 .9 .12], 'style', 'checkbox', 'string', 'Miniplot window', 'tag', 'editpref_minimap');
%% Control buttons
uicontrol(gui.fig, 'style', 'pushbutton', 'string', 'Revert', 'callback', @sub_revert, ...
'units', 'normalized', 'position', [.1 .02 .19 .07], 'backgroundcolor', [.7 .7 .7], 'Fontweight', 'bold', 'tag', 'editpref_ok');
uicontrol(gui.fig, 'style', 'pushbutton', 'string', 'Save as default', 'callback', @sub_default, ...
'units', 'normalized', 'position', [.3 .02 .19 .07], 'backgroundcolor', [.7 .7 .7], 'Fontweight', 'bold', 'tag', 'editpref_cancel');
uicontrol(gui.fig, 'style', 'pushbutton', 'string', 'OK', 'callback', @sub_OK, ...
'units', 'normalized', 'position', [.5 .02 .19 .07], 'backgroundcolor', [.7 .7 .7], 'Fontweight', 'bold', 'tag', 'editpref_ok');
uicontrol(gui.fig, 'style', 'pushbutton', 'string', 'Cancel', 'callback', @sub_cancel, ...
'units', 'normalized', 'position', [.7 .02 .19 .07], 'backgroundcolor', [.7 .7 .7], 'Fontweight', 'bold', 'tag', 'editpref_cancel');
end
function sub_setdef
%% set defaults
% panel 1
set(gui.panel1.movdef, 'string', para.paths.movdef);
set(gui.panel1.resdef, 'string', para.paths.resdef);
set(gui.panel1.vlcpath, 'string', para.paths.vlcpath);
% panel 2
if isempty(para.gui.fig1pos) || length(para.gui.fig1pos)<4 %Fullscreen
set(gui.panel2.fig1pos, 'value', 1);
para.gui.fig1pos=[];
elseif all(para.gui.fig1pos(3:4)==[640 480])
set(gui.panel2.fig1pos, 'value', 2);
elseif all(para.gui.fig1pos(3:4)==[800 600])
set(gui.panel2.fig1pos, 'value', 3);
elseif all(para.gui.fig1pos(3:4)==[1024 768])
set(gui.panel2.fig1pos, 'value', 4);
elseif all(para.gui.fig1pos(3:4)==[1280 1024])
set(gui.panel2.fig1pos, 'value', 5);
elseif all(para.gui.fig1pos(3:4)==[1440 900])
set(gui.panel2.fig1pos, 'value', 6);
elseif all(para.gui.fig1pos(3:4)==[1680 1050])
set(gui.panel2.fig1pos, 'value', 7);
elseif all(para.gui.fig1pos(3:4)==[1920 1080])
set(gui.panel2.fig1pos, 'value', 8);
elseif all(para.gui.fig1pos(3:4)==[1920 1200])
set(gui.panel2.fig1pos, 'value', 9);
else
%do nothing, it'll just set it to full screen
para.gui.fig1pos=[];
end
set(gui.panel2.maxrecent, 'string', num2str(para.maxrecent));
% panel 3
set(gui.panel3.showcurr, 'value', para.showcurr);
set(gui.panel3.showlast, 'value', para.showlast);
set(gui.panel3.showlastrange, 'string', num2str(para.showlastrange));
set(gui.panel3.stepsize, 'string', num2str(para.gui.stepsize));
set(gui.panel3.guispace, 'string', num2str(para.gui.tab_title_spacing));
set(gui.panel3.defaultz, 'string', num2str(para.defaultz));
set(gui.panel3.autoforw, 'value', para.autoforw+1);
% panel 4
set(gui.panel4.navitoolbar, 'value', para.gui.navitoolbar);
set(gui.panel4.infopanel, 'value', para.gui.infopanel);
set(gui.panel4.info_points, 'value', para.gui.infopanel_points);
set(gui.panel4.info_mani, 'value', para.gui.infopanel_mani);
set(gui.panel4.minimap, 'value', para.gui.minimap);
end
end