Home > marsbar > @mardo > ui_et_edit.m

ui_et_edit

PURPOSE ^

method to edit invidual event types in design

SYNOPSIS ^

function [D, ic] = ui_et_edit(D, ic)

DESCRIPTION ^

 method to edit invidual event types in design
 FORMAT [D, ic] = ui_et_edit(D, ic)
 
 D         - design object
 ic        - index identifying event type to edit (or edited)
 
 In this case, the return of an empty ic means that the routine was
 cancelled, as this makes no sense otherwise.
 
 The object method idea here is rather a hack, because the passed object is
 used only to pull in the object methods for the callback.

 We first collect all the events from the design, and their names.  The
 event passed, that are IN, get attached to the top (IN) panel, and the
 rest go to the bottom (OUT) panel.  Event names and definitions
 (session, event number pairs) are always sorted according to the
 current sort mode, which is set from the GUI.
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [D, ic] = ui_et_edit(D, ic)
0002 % method to edit invidual event types in design
0003 % FORMAT [D, ic] = ui_et_edit(D, ic)
0004 %
0005 % D         - design object
0006 % ic        - index identifying event type to edit (or edited)
0007 %
0008 % In this case, the return of an empty ic means that the routine was
0009 % cancelled, as this makes no sense otherwise.
0010 %
0011 % The object method idea here is rather a hack, because the passed object is
0012 % used only to pull in the object methods for the callback.
0013 %
0014 % We first collect all the events from the design, and their names.  The
0015 % event passed, that are IN, get attached to the top (IN) panel, and the
0016 % rest go to the bottom (OUT) panel.  Event names and definitions
0017 % (session, event number pairs) are always sorted according to the
0018 % current sort mode, which is set from the GUI.
0019 %
0020 % $Id$
0021 
0022 et = event_types(D);
0023 len_et = prod(size(et));
0024 if nargin < 2
0025   if len_et > 1
0026     error('Need event number to edit');
0027   end
0028   if len_et
0029     ic = 1;
0030   else
0031     ic = Inf;
0032   end
0033 end
0034 if prod(size(ic)) > 1
0035   error('Can only edit one event');
0036 end
0037 if ~isfinite(ic)  % New
0038   my_event =  struct('name', 'New event', ...
0039              'e_spec', []);
0040   ic = len_et + 1;
0041 elseif ic < 0 | ic > len_et
0042   error('Event number is out of range');
0043 else
0044   my_event = et(ic);
0045 end
0046 
0047 % Put up window and initialize callbacks
0048 [F hDone hListIN hName] = sf_start_edit_window(D, my_event);
0049 
0050 % Wait for OK, Cancel, figure cleared.
0051 waitfor(hDone,'UserData')
0052 
0053 % Get what was pressed, assume cancel if window has died
0054 if ~ishandle(hDone)
0055   status = 0;
0056   ic = [];
0057 else
0058   status = get(hDone, 'UserData');
0059   if status % OK
0060     my_event.name   = get(hName, 'String');
0061     e_vals          = get(hListIN, 'UserData');
0062     my_event.e_spec = mars_struct('getifthere', e_vals, 'e_spec');
0063     if isempty(et), et = my_event; else et(ic) = my_event; end
0064     D               = event_types(D, et);
0065   else
0066     ic = [];
0067   end
0068   close(F);
0069 end
0070 
0071 return
0072 
0073 function [F, hDone, hListIN, hName] = sf_start_edit_window(D, my_event)
0074 % Put up window and set up callbacks
0075 
0076 % Window tag
0077 w_tag = 'ui_et_edit';
0078   
0079 % Close any et_edit windows currently open
0080 close(findobj('Tag', w_tag))
0081   
0082 %-Generic CallBack code to get embedded object
0083 cb = ['ete_D = get(findobj(''Tag'', ''' w_tag '''),''UserData''); '];
0084 
0085 % Get events IN and events OUT
0086 [all_es ev_names] = event_specs(D);
0087 n_evs = size(all_es, 2);
0088 ev_names = cellstr([char(ev_names) ...     % add session names
0089         repmat(': session ', n_evs, 1) ...
0090         num2str(all_es(1, :)')]);
0091 if isempty(my_event.e_spec)
0092   in_cols = logical(zeros(n_evs, 1));
0093 else
0094   in_cols = ismember(all_es', my_event.e_spec', 'rows');
0095 end
0096 IN_evs = pr_sort_evs(struct('names', {ev_names(in_cols)},...
0097                 'e_spec', all_es(:, in_cols)), ...
0098              'session');
0099 OUT_evs = pr_sort_evs(struct('names', {ev_names(~in_cols)},...
0100                  'e_spec', all_es(:, ~in_cols)),...
0101               'session');
0102 
0103 %-Create window, compute scaling for screen size
0104 %-----------------------------------------------------------------------
0105 WS = spm('WinScale');                %-Window scaling factors
0106 FS = spm('FontSizes');                %-Scaled font sizes
0107 PF = spm_platform('fonts');            %-Font names (for this platform)
0108 S0 = get(0,'ScreenSize');            %-Screen size
0109 
0110 % Window size, button size, positions, in WS units
0111 win_sz      = [400 500];
0112 b_ratio     = (1 + sqrt(5))/1.5;
0113 border_x    = 12;
0114 border_y    = 12;
0115 text_sz     = 12;
0116 button_sz_x = 80;
0117 button_sz_y = button_sz_x / b_ratio;
0118 button_sz   = [button_sz_x button_sz_y];
0119 
0120 % Text sizes, locations
0121 label_gap    = 4;   % y gap between label and control it refers to
0122 label_sz_y   = text_sz *1.5;
0123 control_gap  = 14;   % default y gap between controls
0124 text_box_sz  = label_sz_y * 1.5;
0125 
0126 % Sizes, positions for stuff on LHS
0127 OUT_list_y   = border_y;
0128 name_label_y = win_sz(2)-border_y-label_sz_y;
0129 name_box_y   = name_label_y - label_gap - text_box_sz;
0130 IN_label_y   = name_box_y - control_gap - label_sz_y;
0131 IN_list_top  = IN_label_y - label_gap;
0132 
0133 list_sz_y    = (IN_list_top - OUT_list_y ...
0134     - control_gap - label_sz_y - label_gap)/2;
0135 
0136 IN_list_y    = IN_list_top - list_sz_y;
0137 OUT_label_y  = IN_list_y - control_gap - label_sz_y;
0138 OUT_list_top = OUT_label_y - label_gap;
0139 
0140 % Sizes, positions for stuff on RHS
0141 n_buttons   = 4; % buttons (sizes) to spread out across list size
0142 button_x    = win_sz(1) - button_sz_x - border_x;
0143 gap_b       = (list_sz_y - button_sz_y) / (n_buttons-1);
0144 buttons_y   = [OUT_list_y:gap_b:OUT_list_top ...
0145            IN_list_y:gap_b:IN_list_top];
0146 sort_box_y  = buttons_y(6);
0147 sort_label_y = sort_box_y + button_sz_y + label_gap;
0148 
0149 % Sort out x sizes for LHS
0150 list_sz_x   = button_x - border_x*2;
0151 list_sz     = [list_sz_x list_sz_y];
0152 
0153 % Figure
0154 F = figure('IntegerHandle','off',...
0155        'Tag', w_tag,...
0156        'UserData', D, ...
0157        'Name','Event type edit', ...
0158        'NumberTitle','off',...
0159        'Position',[S0(3)/2,S0(4)/2,0,0] + [-250,-200, win_sz].*WS,...
0160        'Resize','off',...
0161        'Color',[1 1 1]*.7,...
0162        'MenuBar','none',...
0163        'DefaultTextColor','k',...
0164        'DefaultTextFontName',PF.helvetica,...
0165        'DefaultTextFontSize',FS(text_sz),...
0166        'DefaultAxesFontName',PF.helvetica,...
0167        'DefaultUicontrolBackgroundColor',[1 1 1]*.7,...
0168        'DefaultUicontrolFontName',PF.helvetica,...
0169        'DefaultUicontrolFontSize',FS(text_sz),...
0170        'DefaultUicontrolInterruptible','on',...
0171        'Colormap',gray(64),...
0172        'Renderer','painters',...
0173        'Visible','on');
0174 
0175 % OK
0176 hDone = uicontrol(F,...
0177           'Style','Pushbutton','String','OK',...
0178           'ToolTipString','OK - press after selecting events to include',...
0179           'ForegroundColor','k',...
0180           'Tag','ui_et_done', ...
0181           'Callback',[cb 'ui_et_edit_cb(ete_D, ''OK'')'] ,...
0182           'Interruptible','off','BusyAction','Cancel',...
0183           'Position',[button_x buttons_y(1) button_sz].*WS);
0184 
0185 % Cancel
0186 uicontrol(F,...
0187       'Style','Pushbutton','String','Cancel',...
0188       'ToolTipString','Cancel UI and return without changing event type',...
0189       'ForegroundColor','k',...
0190       'Tag','ui_et_cancel',...
0191       'Callback',[cb 'ui_et_edit_cb(ete_D, ''Cancel'')'] ,...
0192       'Interruptible','off','BusyAction','Cancel',...
0193       'Position',[button_x buttons_y(2) button_sz].*WS);
0194 
0195 % Add
0196 uicontrol(F,...
0197       'Style','Pushbutton','String','Add',...
0198       'ToolTipString','Add events to event type',...
0199       'ForegroundColor','k',...
0200       'Tag','ui_et_add',...
0201       'Callback',[cb 'ui_et_edit_cb(ete_D, ''Add'')'] ,...
0202       'Interruptible','off','BusyAction','Cancel',...
0203       'Position',[button_x buttons_y(4) button_sz].*WS);
0204 
0205 % Remove
0206 uicontrol(F,...
0207       'Style','Pushbutton','String','Remove',...
0208       'ToolTipString','Remove events to event type',...
0209       'ForegroundColor','k',...
0210       'Tag','ui_et_remove',...
0211       'Callback',[cb 'ui_et_edit_cb(ete_D, ''Remove'')'] ,...
0212       'Interruptible','off','BusyAction','Cancel',...
0213       'Position',[button_x buttons_y(8) button_sz].*WS);
0214 
0215 % Sort box
0216 uicontrol(F,...
0217       'Style','PopUp', ...
0218       'String',strvcat('Session no', 'Event no', 'Event name'),...
0219       'ToolTipString','Sort events by...',...
0220       'ForegroundColor','k',...
0221       'Tag','ui_et_sort',...
0222       'Callback',[cb 'ui_et_edit_cb(ete_D, ''Sort'')'] ,...
0223       'Interruptible','off','BusyAction','Cancel',...
0224       'Position',[button_x sort_box_y button_sz].*WS);
0225 
0226 % Sort box label
0227 uicontrol(F,'Style','Text',...
0228       'String','Sort by...',...
0229       'FontWeight','Bold',...
0230       'ForegroundColor','k',...
0231       'HorizontalAlignment','Center',...
0232       'Position',[button_x sort_label_y button_sz_x label_sz_y].*WS);
0233 
0234 % Name box
0235 hName = uicontrol(F,'Style','Edit','Tag','ui_et_name',...
0236           'ToolTipString','enter name for event type',...
0237           'String', my_event.name,...
0238           'UserData', my_event.name,... % to check for change
0239           'HorizontalAlignment','Left',...
0240           'Interruptible','off',...
0241           'BackgroundColor','w',...
0242           'Position',[border_x name_box_y list_sz_x ...
0243             text_box_sz].*WS);
0244 
0245 % Name box label
0246 uicontrol(F,'Style','Text',...
0247       'String','Event type name',...
0248       'FontWeight','Bold',...
0249       'ForegroundColor','k',...
0250       'HorizontalAlignment','Left',...
0251       'Position',[border_x name_label_y list_sz_x label_sz_y].*WS);
0252 
0253 % IN list
0254 hListIN = uicontrol(F,'Style','ListBox','Tag','ui_et_IN',...
0255             'ToolTipString',['Select events(s) - drag/shift-click',...
0256             '/ctrl-click to select multiple events'],...
0257             'UserData', IN_evs,...
0258             'String', IN_evs.names,...
0259             'Max',2,...
0260             'CallBack', '' ,...
0261             'Interruptible','off','BusyAction','Queue',...
0262             'BackgroundColor','w',...
0263             'Position',[border_x IN_list_y list_sz].*WS);
0264 
0265 % IN label
0266 uicontrol(F,'Style','Text',...
0267       'String','Events IN event type',...
0268       'FontWeight','Bold',...
0269       'ForegroundColor','k',...
0270       'HorizontalAlignment','Left',...
0271       'Position',[border_x IN_label_y list_sz_x label_sz_y].*WS);
0272 
0273 % Events that are OUT list
0274 uicontrol(F,'Style','ListBox','Tag','ui_et_OUT',...
0275       'ToolTipString',['Select events(s) - drag/shift-click',...
0276             '/ctrl-click to select multiple events'],...
0277       'UserData', OUT_evs,...
0278       'String', OUT_evs.names,...
0279       'Max',2,...
0280       'CallBack', '' ,...
0281       'Interruptible','off','BusyAction','Queue',...
0282       'BackgroundColor','w',...
0283       'Position',[border_x OUT_list_y, list_sz].*WS);
0284 
0285 % OUT label
0286 uicontrol(F,'Style','Text',...
0287       'String','Events NOT IN event type',...
0288       'FontWeight','Bold',...
0289       'ForegroundColor','k',...
0290       'HorizontalAlignment','Left',...
0291       'Position',[border_x OUT_label_y list_sz_x label_sz_y].*WS);
0292 
0293 return

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019