Commit d09bca97 authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.31.6

-- Some changes to configSettingsGUI.m to easily accommodate any number of parameters. Also changed how empty # (that is when nothing follows #) is parsed - for simplicity they are interpreted as edit boxes instead of read only parameters. Also you are now allowed to have empty or no value.
parent fab89a6c
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ classdef ConfigFileClass < FileClass
        % ----------------------------------------------------
        function obj = ConfigFileClass(filename0)
            obj.linestr = '';
            obj.sections = struct('name','','val','','param','');
            obj.sections = struct('name','','val',{{}},'param',{{}});
            obj.filename = '';
            
            % Error checks
@@ -333,10 +333,8 @@ classdef ConfigFileClass < FileClass
            while jj<length(obj.linestr) && (obj.linestr(jj)~=newline || obj.linestr(jj)~=sprintf('\r'))
                jj=jj+1;
            end
            if ii == jj && strcmp(obj.linestr(ii),'#')
                param = cell(1,1);
            elseif ii == jj
                param = [];
            if ii == jj
                param = {};
            else
                param = strtrim_improve(obj.linestr(ii:jj));
                param = split(param,', ');
+115 −190
Original line number Diff line number Diff line
@@ -3,175 +3,97 @@ function configSettingsGUI

cfgSet = ConfigFileClass();

    f = figure('NumberTitle','off');
    f.Name = 'App Setting Config GUI';
    set(f, 'MenuBar', 'none');
    set(f, 'ToolBar', 'none');
    
    param = cell(length(cfgSet.sections),1);
    for i = 1:length(cfgSet.sections)
        param{i} = cfgSet.sections(i).param;
    end
% Hardcode size of each parameter panel in char units
ysize = 5;
xsize = 50;


% Hardcode size of each buttons
ysizeBttn = 2;
xsizeBttn = 20;


    %Number of Parameters
% Gaps sizes between controls
ygapsize = 1;
xgapsize = 2;


% Calculate number of columns and rows needed to accomodate all the
% parameters
np = length(cfgSet.sections);
    %Number of Editable Parameters
    n = length(cfgSet.sections) - length(find(cellfun(@isempty,param)));
    
    nAdj = 1;               %Count for Editable Parameters
    p = cell(n,1);          %Panels
    c = cell(n,1);          %Parameters/User Inputs
    
    if n < 11
        if rem(n,2) ~= 0
            p{1} = uipanel('Title',cfgSet.sections(1).name,'FontSize',12,'Position',[0 1-(1/((n+1)/2)) 1 1/((n+1)/2)]);
            if isempty(cfgSet.sections(1).param)
                %Not editable?
                c{1} = uicontrol(p{1}, 'Style', 'text', 'FontSize', 15, 'Units', 'Normalized');
                c{1}.String = 'Not Editable';
                cfgSet.sections(1).val = [];
            elseif isempty(find(strcmp(cfgSet.sections(1).param,cfgSet.sections(1).val),1))
                c{1} = uicontrol(p{1}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(1).name);
                c{1}.String = cfgSet.sections(1).val;
                c{1}.Position = [0.125 0.25 0.75 0.5];
                c{nAdj}.Callback = @setVal;
                nAdj = nAdj + 1;
            else
                c{1} = uicontrol(p{1}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(1).name);
                c{1}.String = cfgSet.sections(1).param;
                c{1}.Value = find(strcmp(cfgSet.sections(1).param,cfgSet.sections(1).val));
                c{1}.Position = [0.125 0.25 0.75 0.5];
                c{nAdj}.Callback = @setVal;
                nAdj = nAdj + 1;
            end
            if n < 2
                %End
            else
                for i = 2:np
                    if isempty(cfgSet.sections(i).param)
                        %Not editable?
                        continue;
                    elseif isempty(find(strcmp(cfgSet.sections(i).param,cfgSet.sections(i).val),1))
                        p{nAdj} = uipanel('Title',cfgSet.sections(i).name,'FontSize',12,'Position',[0.5*rem(nAdj,2) 1-(floor(nAdj/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                        c{nAdj} = uicontrol(p{nAdj}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i).name);
                        c{nAdj}.String = cfgSet.sections(i).val{1};
                        c{nAdj}.Callback = @setVal;
                    else
                        p{nAdj} = uipanel('Title',cfgSet.sections(i).name,'FontSize',12,'Position',[0.5*rem(nAdj,2) 1-(floor(nAdj/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                        c{nAdj} = uicontrol(p{nAdj}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i).name);
                        c{nAdj}.String = cfgSet.sections(i).param;
                        c{nAdj}.Callback = @setVal;
                    end
                    c{nAdj}.Value = find(strcmp(cfgSet.sections(i).param,cfgSet.sections(i).val));
                    c{nAdj}.Position = [0.125 0.25 0.75 0.5];
                    nAdj = nAdj + 1;
                end
            end
        else
            if n == 0
                %Nothing
            else
                for i = 0:(np-1)
                    if i == 0
                        if isempty(cfgSet.sections(i+1).param)
                            %Not editable?
                            continue;
                        elseif isempty(find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val),1))
                            p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[0.5*rem(nAdj-1,2) 1-(floor((nAdj-1)/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                            c{nAdj} = uicontrol(p{nAdj}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                            c{nAdj}.String = cfgSet.sections(i+1).val{1};
                            c{nAdj}.Callback = @setVal;
                        else
                            p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[0.5*rem(nAdj-1,2) 1-(floor((nAdj-1)/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                            c{nAdj} = uicontrol(p{nAdj}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                            c{nAdj}.String = cfgSet.sections(i+1).param;
                            c{nAdj}.Callback = @setVal;
                        end
                        c{nAdj}.Value = find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val));
                        c{nAdj}.Position = [0.125 0.25 0.75 0.5];
                        nAdj = nAdj + 1;
                    else
                        if isempty(cfgSet.sections(i+1).param)
                            %Not editable?
                            continue;
                        elseif isempty(find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val),1))
                            p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[0.5*rem(nAdj-1,2) 1-(floor((nAdj-1)/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                            c{nAdj} = uicontrol(p{nAdj}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                            c{nAdj}.String = cfgSet.sections(i+1).val{1};
                            c{nAdj}.Callback = @setVal;
                        else
                            p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[0.5*rem(nAdj-1,2) 1-(floor((nAdj-1)/2)+1)*(1/(n/2+1)) 0.5 1/(n/2+1)]);
                            c{nAdj} = uicontrol(p{nAdj}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                            c{nAdj}.String = cfgSet.sections(i+1).param;
                            c{nAdj}.Callback = @setVal;
                        end
                        c{nAdj}.Value = find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val));
                        c{nAdj}.Position = [0.125 0.25 0.75 0.5];
                        nAdj = nAdj + 1;
                    end
                end
            end
        end
    else
        div = ceil(n/5);
        for i = 0:(np-1)
            if i == 0
                if isempty(cfgSet.sections(i+1).param)
                    %Not editable?
                    continue;
                elseif isempty(find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val),1))
                    p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[(1/div)*(rem(nAdj-1,div)) 1-(floor((nAdj-1)/div)+1)*(1/ceil(n/div)) 1/div 1/ceil(n/div)]);
                    c{nAdj} = uicontrol(p{i+1}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                    c{nAdj}.String = cfgSet.sections(i+1).val{1};
                    c{nAdj}.Callback = @setVal;
                else
                    p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[(1/div)*(rem(nAdj-1,div)) 1-(floor((nAdj-1)/div)+1)*(1/ceil(n/div)) 1/div 1/ceil(n/div)]);
                    c{nAdj} = uicontrol(p{i+1}, 'Style', 'edit', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                    c{nAdj}.String = cfgSet.sections(i+1).param;
                    c{nAdj}.Callback = @setVal;
nParamsPerCol = 8;
ncols = floor(np/nParamsPerCol)+1;
nrows = nParamsPerCol;


% Create figure and calculate it's size
hf = figure('name', 'App Setting Config GUI', 'NumberTitle','off', 'MenuBar','none', 'ToolBar','none', 'units','characters');
p0 = get(hf, 'position');
ysizeParamsGui = nrows * (ysize + ygapsize) + 2*ygapsize;
xsizeParamsGui = ncols * (xsize + xgapsize) + 2*xgapsize;
d = ysizeParamsGui - p0(4);
offset = 0;
if d>0
    offset = d;
end
ysizeGui = ysizeParamsGui+ysizeBttn+4*ygapsize;
xsizeGui = xsizeParamsGui;
set(hf, 'position', [p0(1), p0(2)-offset, xsizeGui, ysizeGui])


% Draw all param panels and their controls in the figure gui
fontsizeVals = 9;
posParam     = [.10,.10,.80,.80];
hp           = zeros(np,1);
for i = 1:ncols
    for j = 1:nrows
        % Figure out param panel position
        xpos    = (xsize+xgapsize)*(i-1) + xgapsize;
        ypos    = ysizeGui - 2*ygapsize - (ysize+ygapsize)*j;
        
        ip = nParamsPerCol*(i-1) + j;
        if ip>np
            break;
        end
                c{nAdj}.Value = find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val));
                c{nAdj}.Position = [0.125 0.25 0.75 0.5];
                nAdj = nAdj + 1;

        % Draw param panel
        posPanel = [xpos, ypos, xsize, ysize];
        hp(ip) = uipanel('Title',cfgSet.sections(ip).name, 'FontSize',10, 'fontweight','bold', 'foregroundcolor',[.6,.3,.1], ...
            'units','characters', 'Position',posPanel);
        
        % Draw param values control within panel. Note all controls have same relative position within panel 
        pval = '';
        if ~isempty(cfgSet.sections(ip).val)
            pval = cfgSet.sections(ip).val{1};
        end
        if isempty(cfgSet.sections(ip).param)
            hv = uicontrol(hp(ip), 'Style','edit', 'string',pval, 'FontSize',fontsizeVals, 'fontweight','bold', 'Tag',cfgSet.sections(ip).name, ...
                'units','normalized', 'position',posParam);
        else
                p{nAdj} = uipanel('Title',cfgSet.sections(i+1).name,'FontSize',12,'Position',[(1/div)*(rem(nAdj-1,div)) 1-(floor((nAdj-1)/div)+1)*(1/ceil(n/div)) 1/div 1/ceil(n/div)]);
                if isempty(cfgSet.sections(i+1).param)
                    %Not editable?
                    continue;
                elseif isempty(find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val),1))
                    c{nAdj} = uicontrol(p{i+1}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                    c{nAdj}.String = cfgSet.sections(i+1).val{1};
                    c{nAdj}.Callback = @setVal;
            hv = uicontrol(hp(ip), 'Style','popupmenu', 'string',cfgSet.sections(ip).param, ...
                'FontSize',fontsizeVals, 'fontweight','bold', 'Tag',cfgSet.sections(ip).name, ...
                'units','normalized', 'position',posParam);
            k = find(strcmp(cfgSet.sections(ip).param, pval));
            if isempty(k)
                set(hv, 'string',[{''}, cfgSet.sections(ip).param(:)']);
            else
                    c{nAdj} = uicontrol(p{i+1}, 'Style', 'popupmenu', 'FontSize', 15, 'Units', 'Normalized', 'Tag', cfgSet.sections(i+1).name);
                    c{nAdj}.String = cfgSet.sections(i+1).param;
                    c{nAdj}.Callback = @setVal;
                hv.Value = k;
            end
                c{nAdj}.Value = find(strcmp(cfgSet.sections(i+1).param,cfgSet.sections(i+1).val));
                c{nAdj}.Position = [0.125 0.25 0.75 0.5];
                nAdj = nAdj + 1;
        end
        hv.Callback = @setVal;
    end
end

    if n < 11
        if rem(n,2) ~= 0
            p{nAdj} = uipanel('FontSize',12,'Position',[0 0 1 1/((n+1)/2+1)]);
        else
            p{nAdj} = uipanel('FontSize',12,'Position',[0 0 1 1/(n/2+1)]);
        end
    else
        p{nAdj} = uipanel('FontSize',12,'Position',[0 0 1 1/ceil(n/div)]);
    end
    c{nAdj} = uicontrol(p{nAdj}, 'Style', 'pushbutton', 'FontSize', 15, 'Units', 'Normalized', 'String', 'Save',...
              'Position', [0.125 0.25 0.25 0.5]);
    c{nAdj}.Callback = @cfgSave;
    c{nAdj+1} = uicontrol(p{nAdj}, 'Style', 'pushbutton', 'FontSize', 15, 'Units', 'Normalized', 'String', 'Exit',...
              'Position', [0.625 0.25 0.25 0.5]);
    c{nAdj+1}.Callback = @cfgExit;

%     clear cfgSet
end
% Draw buttons
xoffset = xsizeGui/5;
hBttnSave = uicontrol('Style','pushbutton', 'FontSize',15, 'Units','characters', 'String','Save', ...
    'Position', [xoffset, ysizeGui-(ysizeParamsGui+ysize), xsizeBttn, ysizeBttn]);
hBttnSave.Callback = @cfgSave;
hBttnExit = uicontrol('Style','pushbutton', 'FontSize',15, 'Units','characters', 'String','Exit', ...
    'Position', [xsizeGui-(xsizeBttn+xoffset), ysizeGui-(ysizeParamsGui+ysize), xsizeBttn, ysizeBttn]);
hBttnExit.Callback = @cfgExit;



% -------------------------------------------------------------
function setVal(src,~)
@@ -181,17 +103,20 @@ end
else
    cfgSet.SetValue(src.Tag, src.String);
end
    end


% -------------------------------------------------------------
    function cfgSave(~,~)
function cfgSave(~,~) %#ok<*DEFNU>
global cfgSet
cfgSet.Save();
close;
    end


% -------------------------------------------------------------
function cfgExit(~,~)
close;
    end




+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ function vrnnum = getVernum()

vrnnum{1} = '1';   % Major version #
vrnnum{2} = '31';  % Major sub-version #
vrnnum{3} = '5';   % Minor version #
vrnnum{3} = '6';   % Minor version #
vrnnum{4} = '0';   % Minor sub-version # or patch #: 'p1', 'p2', etc