⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sptprefs.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 2 页
字号:
%    pf_pos - position in pixels of panel frame
%    fus,lbs,lw,lh,uw,uh - spacing and positioning information
% Outputs:
%    panelControls - cell array of handle vectors, one entry for each row
%       of prefs.controls

labelPos = [pf_pos(1)+fus pf_pos(2)+pf_pos(4)-lh/2+fus lw uh];
controlPos = [pf_pos(1)+fus+lbs+lw ...
       pf_pos(2)+pf_pos(4)-lh/2+fus uw uh];

N = size(prefs.controls,1);
% prefs.controls is a table containing the following columns:
%  Name  Description  type  radiogroup  number_of_lines popup_string ...
%      factory_value  help_string

panelControls = cell(1,N);
for i=1:N
    if i == 1
        labelPos = labelPos - [0 uh+fus 0 0];
    else
        labelPos = labelPos - [0 prefs.controls{i-1,5}*uh+fus 0 0];
    end
    controlPos = controlPos - [0 prefs.controls{i,5}*uh+fus 0 0];
    controlPos(4) = prefs.controls{i,5}*uh;
    switch prefs.controls{i,3}
    case 'edit'
        panelControls{i} = uicontrol('style','text',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'position',labelPos,...
            'string',prefs.controls{i,2},...
            'horizontalalignment','right');
        panelControls{i} = [ panelControls{i}  uicontrol('style','edit',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'backgroundcolor','w','string',prefs.currentValue{i},...
            'callback',['sbswitch(''sptprefs'',''change'',' num2str(i) ')'],...
            'userdata',prefs.controls{i,4},...
            'position',controlPos,...
            'horizontalalignment','left',...
            'max',prefs.controls{i,5})   ];    
    case 'popupmenu'
        panelControls{i} = uicontrol('style','text',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'position',labelPos,...
            'string',prefs.controls{i,2},...
            'horizontalalignment','right');
        panelControls{i} = [ panelControls{i}  uicontrol('style','popupmenu',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'string',prefs.controls{i,6},...
            'value',prefs.currentValue{i},...
            'callback',['sbswitch(''sptprefs'',''change'',' num2str(i) ')'],...
            'userdata',prefs.controls{i,4},...
            'position',controlPos)   ];    
    case 'radiobutton'
        panelControls{i} = uicontrol('style','radiobutton',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'position',labelPos,...
            'string',prefs.controls{i,2},...
            'value',prefs.currentValue{i},...
            'callback',['sbswitch(''sptprefs'',''change'',' num2str(i) ')'],...
            'userdata',prefs.controls{i,4});
        minwidthLeft(panelControls{i})

    case 'checkbox'
        panelControls{i} = uicontrol('style','checkbox',...
            'units','pixels',...
            'tag',['control' num2str(i)],...
            'position',labelPos,...
            'string',prefs.controls{i,2},...
            'value',prefs.currentValue{i},...
            'callback',['sbswitch(''sptprefs'',''change'',' num2str(i) ')'],...
            'userdata',prefs.controls{i,4});
        minwidthLeft(panelControls{i})
    end

end

function setPanel(panelControls,value)
%setPanel - set values of uicontrols
% Inputs:
%    panelControls - cell array of handle vectors for the current panel
%    value - cell array of values for each entry of panelControls

N = length(panelControls);
for i=1:N
    if length(panelControls{i}) == 1
        style = get(panelControls{i}(1),'style');
    else
        style = get(panelControls{i}(2),'style');
    end
    switch style
    case 'edit'
        set(panelControls{i}(2),'string',value{i})
    case 'popupmenu'
        set(panelControls{i}(2),'value',value{i})
    case {'radiobutton', 'checkbox'}
        set(panelControls{i}(1),'value',value{i})
    end
end

function values = getPanel(panelControls)
%getPanel - get values from uicontrols
% Inputs:
%    panelControls - cell array of handle vectors for the current panel
% Outputs:
%    value - cell array (column) of values for each entry of panelControls
   values = {};
   for i = 1:length(panelControls)
       if length(panelControls{i}) == 1
           style = get(panelControls{i}(1),'style');
       else
           style = get(panelControls{i}(2),'style');
       end
       switch style
       case 'edit'
           values = {values{:} ...
                get(panelControls{i}(2),'string')};
       case 'popupmenu'
           values = {values{:} ...
                get(panelControls{i}(2),'value')};
       case {'radiobutton','checkbox'}
           values = {values{:} ...
                get(panelControls{i}(1),'value')};
       end
   end
   values = values(:);

function setEnable(panelInd,prefs,panelControls,factory,revert)
% setEnable - sets enable property of factory and revert uicontrols

   values = getPanel(panelControls{panelInd});
   if isequal(values,prefs(panelInd).currentValue)
       set(revert,'enable','off')
   else
       set(revert,'enable','on')
   end
   if isequal(values,prefs(panelInd).controls(:,7))
       set(factory,'enable','off')
   else
       set(factory,'enable','on')
   end
   
function sptprefsHelp
% local function to go into help mode
    fig = gcf;
    ud = get(fig,'userdata');
    set(ud.helpButton,'String','Click for Help...')
    setptr(fig,'help')

    panelInd = get(ud.list,'value');
    
    uilist = findobj(fig,'type','uicontrol');
    saveenable = get(uilist,'enable');
    set(uilist,'enable','inactive',...
       'buttondownfcn',...
         'set(findobj(gcf,''tag'',''helpButton''),''userdata'',get(gcbo,''tag''))')

    set(ud.helpButton,'userdata',0)
    waitfor(ud.helpButton,'userdata')
    tag = get(ud.helpButton,'userdata');
    switch tag
    case 'helpButton'
        s = {
        'PREFERENCES DIALOG BOX'
        ' '
        'This window allows you to change certain settings of the SPTool'
        'and its clients that will be remembered between MATLAB sessions.'
        'The preferences are saved on disk in the MAT-file "sigprefs.mat".'
        ' '
        'To get help on any preference or on how to use the buttons, '
        'click "Help..." once, and then click on the item you would like'
        'more help on.'
        };
    case 'revertButton'
        s = {
        'REVERT PANEL BUTTON'
        ' '
        'Press this button to revert the preferences in the current '
        'panel to what they were when you opened the preferences window.'
        ' '
        'This button is enabled only if you have made a change to the'
        'preferences in the current panel.' 
        };
    case 'factoryButton'
        s = {
        'FACTORY SETTINGS BUTTON'
        ' '
        'Press this button to restore the preferences in the current panel'
        'to their "factory settings", that is, the settings at the time'
        'the software was first installed.'
        ' '
        'This button is enabled only when the preferences in the current'
        'panel are not the same as the factory settings.' 
        };
    case 'okButton'
        s = {
        'OK BUTTON'
        ' '
        'Press this button to apply your changes to the preferences and'
        'close the preferences window.'
        ' '
        'This button is only enabled when you have made some change to'
        'a preference.'
        ' '
        'If the file "sigprefs.mat" is not found, a dialog box will appear,'
        'asking you to find a place to save this file.  If this process '
        'happens repeatedly, then either you are saving the file somewhere'
        'not on your MATLAB path or current directory, or perhaps you are out of'
        'disk space or the directory is write-protected.'
        };
    case 'cancelButton'
        s = {
        'CANCEL BUTTON'
        ' '
        'Press this button to close the preferences window, ignoring any'
        'changes made while it was open.'
        };
    case 'listbox'
        s = {
        'PREFERENCE CATEGORY LIST'
        ' '
        'This is a list of all the categories of preferences that you'
        'can change for the SPTool.'
        ' '
        'By clicking on a category, the panel on the right changes to'
        'reflect the preferences for that category.'
        ' '
        'To get help on a category, change to that category first, and then'
        'click on "Help..." and click the question mark cursor on the'
        'category name at the top of the panel on the right.'
        };
    case {'panelLabel','panelFrame'}
        s = {
        ['Preferences for "' ud.prefs(panelInd).panelDescription '"'] ...
        ' ' ...
        ud.prefs(panelInd).panelHelp{:} ...
        };
    otherwise
        ind = findstr('control',tag);
        if ~isempty(ind)
            tag(1:7)=[];
            i = str2num(tag);
            s = {['You have clicked on preference "' ...
                     ud.prefs(panelInd).controls{i,2} '"'] ... 
                     ['in the category "' ...
                  ud.prefs(panelInd).panelDescription '".'] ...
                 ' ' ...
                 ud.prefs(panelInd).controls{i,8}{:} ...
                 };
        else
            s = {['this object has tag ' tag]};
        end
    end
    
    set(uilist,{'enable'},saveenable,'buttondownfcn','')
    set(ud.helpButton,'String','Help...')
    setptr(fig,'arrow')
    
    fp = get(fig,'position');
    sz = sptsizes;
    helpButtonPos = get(ud.helpButton,'position');
    sz.uh = helpButtonPos(4);

    saveVis = get(uilist,'visible');
    if strcmp(computer,'PCWIN')
        set(uilist,'visible','off')
    end

    f = uicontrol('style','frame',...
           'position',[sz.fus sz.fus fp(3)-2*sz.fus fp(4)-sz.fus-1],...
           'tag','prefhelp');
    tp = [2*sz.fus 4*sz.fus+sz.uh fp(3)-4*sz.fus fp(4)-(6*sz.fus+sz.uh)];
       % text position
    [fontname,fontsize]=fixedfont;
    t = uicontrol('style','listbox','position',tp,'string',s,'max',2,...
         'tag','prefhelp','horizontalalignment','left',...
         'backgroundcolor','w','fontname',fontname,'fontsize',fontsize);
    bp = [fp(3)/2-sz.bw/2 2*sz.fus sz.bw sz.uh];
    b = uicontrol('style','pushbutton','position',bp,...
         'tag','prefhelp','string','OK',...
         'callback','delete(findobj(gcf,''tag'',''prefhelp''))');
    waitfor(b)
    if all(ishandle(uilist))
        if strcmp(computer,'PCWIN')
            set(uilist,{'visible'},saveVis)
        end
    end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -