Ignore:
Timestamp:
May 19, 2013, 11:37:49 PM (8 years ago)
Author:
sommeria
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r620 r635  
    6767    %set(hrefresh,'UserData',StatusData)
    6868    if strcmp(option,'status_display') %put a run advancement display
    69         set(hfig,'DeleteFcn',@stop_status)
    70         uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.81 0.01 0.05],'BackgroundColor',[1 0 0],'tag','waitbar');
    71         uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
     69        set(hfig,'DeleteFcn',@(src,event)close(option,src,event))
     70              uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.85 0.9 0.04]);
     71        uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar');
     72
    7273    else  %put a title and additional pushbuttons
    7374        uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.75 0.6 0.03],'BackgroundColor',BackgroundColor,...
     
    109110DirName=get(htitlebox,'String');
    110111hsort_option=findobj(hfig,'tag','sort_option');
    111 sort_option='name';
    112 if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
    113     sort_option='date';
    114 end
    115 hcheck_date=findobj(hfig,'tag','check_date');
    116 ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content
    117 
    118 set(hlist,'String',ListFiles)
    119 Value=[];
    120 if ~isempty(InputFileName)
    121     Value=find(strcmp(InputFileName,ListFiles));
    122 end
    123 if isempty(Value)
    124     Value=1;
    125 end
    126 set(hlist,'Value',Value)
    127 set(hlist,'BackgroundColor',[0.7 0.7 0.7])
    128 if strcmp(get(hfig,'Tag'),'status_display')
     112if strcmp(get(hfig,'Tag'),'status_display')
    129113    hseries=findobj(allchild(0),'tag','series');
    130     hstatus=findobj(hseries,'tag','status_display');
     114    hstatus=findobj(hseries,'tag','status');
    131115    StatusData=get(hstatus,'UserData');
    132116    TimeStart=0;
    133117    if isfield(StatusData,'TimeStart')
    134118        TimeStart=StatusData.TimeStart;
    135     end 
     119    end
    136120    hlist=findobj(hfig,'tag','list');
    137     testrecent=0;
    138     datnum=zeros(numel(ListDisplay),1);
    139     for ilist=1:numel(ListDisplay)
    140         ListDisplay{ilist}=ListFiles(ilist).name;
    141         if ListFiles(ilist).isdir
    142             ListDisplay{ilist}=['/' ListDisplay{ilist}];
    143         elseif isfield(ListFiles(ilist),'datenum')
    144             datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions
    145             testrecent=1;
    146             if datnum(ilist)<TimeStart
    147                 ListDisplay{ilist}=[ListDisplay{ilist} '  --OLD--'];
    148             end
    149         end
    150     end
    151    
    152     %% Look at date of creation
    153     ListDisplay=ListDisplay(datnum~=0);
    154     datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
    155    
     121    testrecent=0;   
    156122    NbOutputFile=[];
    157     if isempty(datnum)
    158         if testrecent
    159             message='no result created yet';
    160         else
    161             message='';
    162         end
    163     else
    164         [first,indfirst]=min(datnum);
    165         [last,indlast]=max(datnum);
    166         NbOutputFile_str='?';
    167         if isfield(StatusData,'NbOutputFile')
    168             NbOutputFile=StatusData.NbOutputFile;
    169             NbOutputFile_str=num2str(NbOutputFile);
    170         end
    171         message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification:  ' ListDisplay{indfirst} ' : ' datestr(first)];...
    172             ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
    173     end
    174     set(htitlebox,'String', [DirName{1};message])
     123    if isfield(StatusData,'NbOutputFile')
     124        NbOutputFile=StatusData.NbOutputFile;
     125        NbOutputFile_str=num2str(NbOutputFile);
     126    end
     127    [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content
    175128   
    176129    %% update the waitbar
     
    178131    if ~isempty(NbOutputFile)
    179132        BarPosition=get(hwaitbar,'Position');
    180         BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
     133        BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead
    181134        set(hwaitbar,'Position',BarPosition)
    182135    end
    183 end
    184 
     136else
     137    sort_option='name';
     138    if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     139        sort_option='date';
     140    end
     141    hcheck_date=findobj(hfig,'tag','check_date');
     142    [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content
     143end
     144
     145set(hlist,'String',ListFiles)
     146Value=[];
     147if ~isempty(InputFileName)
     148    Value=find(strcmp(InputFileName,ListFiles));
     149end
     150if isempty(Value)
     151    Value=1;
     152end
     153set(hlist,'Value',Value)
     154set(hlist,'BackgroundColor',[0.7 0.7 0.7])
    185155%------------------------------------------------------------------------   
    186156% --- launched by selecting an item on the file list
     
    272242%-------------------------------------------------------------------------   
    273243% list the content of a directory
    274 function ListFiles=list_files(DirName,check_date,sort_option)
     244function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option)
    275245%-------------------------------------------------------------------------
    276246ListStruct=dir(DirName);% get structure of the current directory
     247NumFiles=0; %default
    277248if numel(ListStruct)<1  % case of empty dir
    278249    ListFiles={};
     
    283254check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    284255ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    285 if strcmp(sort_option,'date')
    286     ListDates=cell2mat(ListCells(5,:));%list of numerical dates
    287     ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
     256ListDates=cell2mat(ListCells(5,:));%list of numerical dates
     257if isnumeric(sort_option)
     258    check_old=ListDates<sort_option-1;% -1 is put to account for a 1 s delay in the record of starting time
     259    NumFiles=numel(find(~check_old&~check_dir));
     260end
     261if ~isempty(find(~check_dir))
     262ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
     263end
     264if isnumeric(sort_option)|| strcmp(sort_option,'date')
    288265    [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list
    289266else
     
    295272ListFiles=[{'+/..'} ListFiles(check_keep)];
    296273if check_date
    297 ListDateString=ListCells(2,:);%list of file dates
    298 ListDateString(check_dir)={''};
    299 ListDateString=ListDateString(index_sort);% sort the corresponding dates
    300 ListDateString=[{''} ListDateString(check_keep)];
    301 ListFiles=[ListFiles; ListDateString];
    302 ListFiles=cell2tab(ListFiles','...');
     274    ListDateString=ListCells(2,:);%list of file dates
     275    if isnumeric(sort_option)
     276        ListDateString(check_old)={'--OLD--'};
     277    end
     278    ListDateString(check_dir)={''};
     279    ListDateString=ListDateString(index_sort);% sort the corresponding dates
     280    ListDateString=[{''} ListDateString(check_keep)];
     281    ListFiles=[ListFiles; ListDateString];
     282    ListFiles=cell2tab(ListFiles','...');
    303283end
    304284
     
    343323%-------------------------------------------------------------------------
    344324if strcmp(option,'status_display')
    345     hseries=findobj(allchild(0),'tag','series');
    346     hstatus=findobj(hfig,'Tag','status_display');
    347     set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
    348     set(hhciv.status,'BackgroundColor',[0 1 0])
     325    hseries=findobj(allchild(0),'Tag','series');
     326    hstatus=findobj(hseries,'Tag','status');
     327    set(hstatus,'value',0) %reset the status uicontrol in the GUI series
     328    set(hstatus,'BackgroundColor',[0 1 0])
    349329end
    350330delete(gcbf)
Note: See TracChangeset for help on using the changeset viewer.