spm_Menu.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. function Fmenu = spm_Menu(action, varargin)
  2. % SPM Menu window
  3. % FORMAT Fmenu = spm_Menu('Create',Vis)
  4. % Create the SPM Menu window (tag property set to 'Menu')
  5. % Vis - visibility: {'on'} or 'off'
  6. % Fmenu - handle of figure created
  7. %
  8. % FORMAT Fmenu = spm_Menu('Switch',Modality)
  9. % Switch the SPM Menu window to the specified modality
  10. %
  11. % FORMAT spm_Menu('Close')
  12. % Close the SPM Menu window
  13. %_________________________________________________________________________
  14. % Copyright (C) 2018 Wellcome Trust Centre for Neuroimaging
  15. % Guillaume Flandin
  16. % $Id: spm_Menu.m 7432 2018-09-28 14:35:27Z guillaume $
  17. if nargin < 1, action = 'Create'; end
  18. switch lower(action)
  19. case 'create'
  20. spm_Menu('Close');
  21. Fmenu = create_menu(varargin{1:end});
  22. case 'switch'
  23. Fmenu = spm_figure('FindWin','Menu');
  24. [Modality,ModNum] = spm('CheckModality',varargin{1});
  25. if ~isempty(Fmenu)
  26. if strcmpi(Modality,'PET')
  27. set(findobj(Fmenu, '-regexp', 'Tag', 'FMRI'), 'Visible', 'off');
  28. set(findobj(Fmenu, '-regexp', 'Tag', 'EEG'), 'Visible', 'off');
  29. set(findobj(Fmenu, '-regexp', 'Tag', 'PET'), 'Visible', 'on' );
  30. elseif strcmpi(Modality,'FMRI')
  31. set(findobj(Fmenu, '-regexp', 'Tag', 'EEG'), 'Visible', 'off');
  32. set(findobj(Fmenu, '-regexp', 'Tag', 'PET'), 'Visible', 'off');
  33. set(findobj(Fmenu, '-regexp', 'Tag', 'FMRI'), 'Visible', 'on' );
  34. else
  35. set(findobj(Fmenu, '-regexp', 'Tag', 'PET'), 'Visible', 'off');
  36. set(findobj(Fmenu, '-regexp', 'Tag', 'FMRI'), 'Visible', 'off');
  37. set(findobj(Fmenu, '-regexp', 'Tag', 'EEG'), 'Visible', 'on' );
  38. end
  39. set(findobj(Fmenu,'Tag','Modality'),'Value',ModNum,'UserData',ModNum);
  40. else
  41. warning('SPM Menu window not found.');
  42. end
  43. case 'close'
  44. Fmenu = spm_figure('FindWin','Menu');
  45. delete(Fmenu);
  46. otherwise
  47. error('Unknown action ''%s''.',action);
  48. end
  49. %==========================================================================
  50. %-function Fmenu = create_menu(Vis)
  51. %==========================================================================
  52. function Fmenu = create_menu(Vis)
  53. if ~nargin, Vis = 'on'; end
  54. %-Get size and scalings
  55. %--------------------------------------------------------------------------
  56. PF = spm_platform('fonts'); %-Font names (for this platform)
  57. FS = spm('FontSizes'); %-Scaled font sizes
  58. WS = spm('WinScale'); %-Window scaling factors
  59. Rect0 = spm('WinSize','0',1);
  60. RectM = spm('WinSize','Menu',1).*WS; %-Menu window rectangle: 400x445
  61. Pos = [Rect0(1) Rect0(2) 0 0] + RectM;
  62. %-Create Menu window
  63. %--------------------------------------------------------------------------
  64. if ~isempty(which('openfig'))
  65. Fmenu = openfig(fullfile(spm('Dir'),'spm_Menu.fig'),'new','invisible');
  66. else
  67. fprintf('\nFunction openfig.m is missing. Download it from:\n');
  68. fprintf(' https://savannah.gnu.org/bugs/download.php?file_id=33499\n');
  69. Fmenu = [];
  70. end
  71. set(Fmenu,'Name',[spm('Version') ': Menu']);
  72. set(Fmenu,'Units','pixels', 'Position',Pos);
  73. set(Fmenu,'Color',[1 1 1]*.8);
  74. % Fmenu = figure('Tag','Menu',...
  75. % 'Name',[spm('Version') ': Menu'],...
  76. % 'IntegerHandle','off',...
  77. % 'NumberTitle','off',...
  78. % 'Units','pixels',...
  79. % 'Position',Pos,...
  80. % 'Resize','on',...
  81. % 'Pointer','arrow',...
  82. % 'Color',[1 1 1]*.8,...
  83. % 'MenuBar','none',...
  84. % 'DockControls','off',...
  85. % 'CloseRequestFcn','spm(''Quit'')',...
  86. % 'HandleVisibility','off',...
  87. % 'DefaultUicontrolFontName',PF.helvetica,...
  88. % 'Visible','off');
  89. %-Set SPM colour
  90. %--------------------------------------------------------------------------
  91. set(findobj(Fmenu,'Tag', 'frame'),'BackgroundColor',spm('colour'));
  92. if ismac
  93. set(findobj(Fmenu,'UserData','LABEL'),'Visible','off','Tag','');
  94. end
  95. %-Set Utils
  96. %--------------------------------------------------------------------------
  97. set(findobj(Fmenu,'Tag', 'Utils'), 'String',{'Utils...',...
  98. 'CD',...
  99. 'PWD',...
  100. 'Run M-file',...
  101. 'Load MAT-file',...
  102. 'Save MAT-file',...
  103. 'Delete files',...
  104. 'Show SPM',...
  105. 'Show MATLAB'});
  106. set(findobj(Fmenu,'Tag', 'Utils'), 'UserData',{...
  107. ['spm(''FnBanner'',''CD'');' ...
  108. 'cd(spm_select(1,''dir'',''Select new working directory''));' ...
  109. 'spm(''alert"'',{''New working directory:'',['' '',pwd]},''CD'',1);'],...
  110. ['spm(''FnBanner'',''PWD'');' ...
  111. 'spm(''alert"'',{''Present working directory:'',['' '',pwd]},''PWD'',1);'],...
  112. ['spm(''FnBanner'',''Run M-file'');' ...
  113. 'spm(''Run'');' ...
  114. 'fprintf(''%-40s: %30s\n'',''Completed'',spm(''time''));'],...
  115. ['spm(''FnBanner'',''Load MAT-file'');' ...
  116. 'load(spm_select(1,''mat'',''Select MAT-file''));'],...
  117. ['spm(''FnBanner'',''Save MAT-file'');' ...
  118. 'save(spm_input(''Output filename'',1,''s''), spm_get_defaults(''mat.format''));'],...
  119. ['spm(''FnBanner'',''Delete files'');' ...
  120. 'spm(''Delete'');'],...
  121. ['spm(''FnBanner'',''Show SPM'');' ...
  122. 'spm(''Show'');'],...
  123. ['spm(''FnBanner'',''Show Command Window'');' ...
  124. 'commandwindow;']});
  125. %-Set Toolboxes
  126. %--------------------------------------------------------------------------
  127. xTB = spm('tbs');
  128. if ~isempty(xTB)
  129. set(findobj(Fmenu,'Tag', 'Toolbox'),'String',{'Toolbox:' xTB.name });
  130. set(findobj(Fmenu,'Tag', 'Toolbox'),'UserData',xTB);
  131. else
  132. set(findobj(Fmenu,'Tag', 'Toolbox'),'Visible','off')
  133. end
  134. set(Fmenu,'Visible',Vis);