Ignore:
Timestamp:
Mar 23, 2025, 11:13:38 AM (4 weeks ago)
Author:
sommeria
Message:

a few bug repairs and cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r1144 r1179  
    4141fileinput=''; %default file selection
    4242if strcmp(title,'status_display')
    43     option='status_display';
    44 else
    45     option='browser';
     43    option='status_display';% use with the button 'Status Display' from the GUI 'series'
     44else
     45    option='browser';% usual browser
    4646end
    4747InputDir=pwd;%look in the current work directory if the input file does not exist
    4848InputFileName='';%default
    4949if ischar(InputName)
    50     if isempty(regexp(InputName,'^http://'))%usual files
     50    if isempty(regexp(InputName,'^http://', 'once'))%usual files
    5151        if exist(InputName,'dir')
    5252            InputDir=InputName;
     
    6868            InputDir=[InputDir '\'];% append '\' for a correct action of dir
    6969        end
    70     else
    71         [InputDir,InputFileName,Ext]=fileparts(InputName);
    72     end
    73 end
    74 
     70    else % files accessed on the web by Opendap
     71        [InputDir,InputFileName]=fileparts(InputName);
     72    end
     73end
     74
     75%% Display the browser figure
    7576hfig=findobj(allchild(0),'tag',option);%look for existing browser fig
    7677if isempty(hfig)% create the browser fig if it does not exist
     
    8384    hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir);
    8485    BackgroundColor=get(hfig,'Color');
     86    % text title
    8587    path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',...
    8688        'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
    87     htitlebox=uicontrol('Style','edit','Units','normalized', 'Position', [0.02 0.89 0.96 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,...
     89    % edit box for the current folder name
     90    uicontrol('Style','edit','Units','normalized', 'Position', [0.02 0.89 0.96 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,...
    8891        'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path');
     92    % button for backward move in the directory tree
    8993    uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],...
    9094        'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward');
     
    118122        uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,...
    119123            'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates');
    120 %         uicontrol('Style','text','Units','normalized', 'Position', [0.37 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...
    121 %             'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');
    122124         set(OK_button,'String','Open')
    123125         set(close_button,'String','Cancel')   
     
    126128end
    127129refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir
    128 if ~strcmp(option,'status_display')
     130if ~strcmp(option,'status_display') && strcmp(get(hfig,'Type'),'figure')
    129131    uiwait(hfig)
    130132    if ishandle(hfig)
     
    140142function titlebox_Callback(hObject,event)
    141143refresh_GUI(hObject)
     144
     145
     146%------------------------------------------------------------------------
     147% --- launched by refreshing the display figure
     148function refresh_GUI(hObject,InputFileName,FilterExt)
     149%------------------------------------------------------------------------
     150if ~exist('InputFileName','var')
     151    InputFileName='';
     152end
     153if ~exist('FilterExt','var')
     154    FilterExt='*';
     155end
     156if strcmp(FilterExt,'uigetdir')
     157    FilterExt='*';
     158end
     159hfig=get(hObject,'parent');
     160hlist=findobj(hfig,'tag','list');% find the list object
     161set(hlist,'BackgroundColor',[1 1 0])
     162drawnow
     163htitlebox=findobj(hfig,'tag','titlebox');
     164DirName=get(htitlebox,'String');
     165hsort_option=findobj(hfig,'tag','sort_option');
     166
     167%% case of file browser opened by Status Display in the GUI series
     168if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series
     169    hseries=findobj(allchild(0),'tag','series');
     170    hstatus=findobj(hseries,'tag','status');
     171    StatusData=get(hstatus,'UserData');
     172    TimeStart=0;
     173    if isfield(StatusData,'TimeStart')
     174        TimeStart=StatusData.TimeStart;
     175    end
     176    hlist=findobj(hfig,'tag','list');
     177    NbOutputFile=[];
     178    if isfield(StatusData,'NbOutputFile')
     179        NbOutputFile=StatusData.NbOutputFile;
     180    end
     181    [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content
     182   
     183    % update the waitbar
     184    hwaitbar=findobj(hfig,'tag','waitbar');
     185    if ~isempty(NbOutputFile)
     186        BarPosition=get(hwaitbar,'Position');
     187        BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead
     188        set(hwaitbar,'Position',BarPosition)
     189    end
     190%% case of usual browser
     191else  %use as usual browser
     192    sort_option='name';
     193    if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     194        sort_option='date';
     195    end
     196    hcheck_date=findobj(hfig,'tag','check_date');
     197    ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content
     198end
     199if ~isempty(DirName) && isempty(ListFiles)
     200    if isempty(regexp(DirName,'^http://', 'once'))%usual files
     201        ListFiles='empty folder';
     202    else
     203        ListFiles='address http:// not found';
     204    end
     205end
     206set(hlist,'String',ListFiles)
     207Value=[];
     208if ~isempty(InputFileName)
     209    Value=find(strcmp(InputFileName,ListFiles));
     210end
     211if isempty(Value)
     212    Value=1;
     213end
     214set(hlist,'Value',Value)
     215set(hlist,'BackgroundColor',[0.7 0.7 0.7])
    142216
    143217%------------------------------------------------------------------------   
     
    158232    list=get(hlist,'String');
    159233    index=get(hlist,'Value');
    160     if ~isempty(regexp(list{index},'^\+/'))
     234    if ~isempty(regexp(list{index},'^\+/', 'once'))
    161235        return % quit if a dir has been opened
    162236    end
     
    167241        SelectName=SelectName(1:ind_dot-1);
    168242    end
    169     if isempty(regexp(DirName,'^http://'))% if the input dir is not a web site (begins by http://)
     243    if isempty(regexp(DirName,'^http://', 'once'))% if the input dir is not a web site (begins by http://)
    170244        FullSelectName=fullfile(DirName,SelectName);
    171245        check_exist=exist(FullSelectName,'file');
     
    201275end
    202276
    203 %------------------------------------------------------------------------
    204 % --- launched by refreshing the display figure
    205 function refresh_GUI(hObject,InputFileName,FilterExt)
    206 %------------------------------------------------------------------------
    207 if ~exist('InputFileName','var')
    208     InputFileName='';
    209 end
    210 if ~exist('FilterExt','var')
    211     FilterExt='*';
    212 end
    213 if strcmp(FilterExt,'uigetdir')
    214     FilterExt='*';
    215 end
    216 hfig=get(hObject,'parent');
    217 hlist=findobj(hfig,'tag','list');% find the list object
    218 set(hlist,'BackgroundColor',[1 1 0])
    219 drawnow
    220 htitlebox=findobj(hfig,'tag','titlebox');
    221 DirName=get(htitlebox,'String');
    222 hsort_option=findobj(hfig,'tag','sort_option');
    223 % use with GUI series
    224 if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series
    225     hseries=findobj(allchild(0),'tag','series');
    226     hstatus=findobj(hseries,'tag','status');
    227     StatusData=get(hstatus,'UserData');
    228     TimeStart=0;
    229     if isfield(StatusData,'TimeStart')
    230         TimeStart=StatusData.TimeStart;
    231     end
    232     hlist=findobj(hfig,'tag','list');
    233     testrecent=0;
    234     NbOutputFile=[];
    235     if isfield(StatusData,'NbOutputFile')
    236         NbOutputFile=StatusData.NbOutputFile;
    237         NbOutputFile_str=num2str(NbOutputFile);
    238     end
    239     [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content
    240    
    241     % update the waitbar
    242     hwaitbar=findobj(hfig,'tag','waitbar');
    243     if ~isempty(NbOutputFile)
    244         BarPosition=get(hwaitbar,'Position');
    245         BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead
    246         set(hwaitbar,'Position',BarPosition)
    247     end
    248 else  %use as usual browser
    249     sort_option='name';
    250     if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
    251         sort_option='date';
    252     end
    253     hcheck_date=findobj(hfig,'tag','check_date');
    254     [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content
    255 end
    256 
    257 set(hlist,'String',ListFiles)
    258 Value=[];
    259 if ~isempty(InputFileName)
    260     Value=find(strcmp(InputFileName,ListFiles));
    261 end
    262 if isempty(Value)
    263     Value=1;
    264 end
    265 set(hlist,'Value',Value)
    266 set(hlist,'BackgroundColor',[0.7 0.7 0.7])
    267 
    268 %------------------------------------------------------------------------   
     277
     278%------------------------------------------------------------------------
    269279% --- launched by selecting an item on the file list
    270280%------------------------------------------------------------------------
     
    282292
    283293
    284 %------------------------------------------------------------------------   
     294%------------------------------------------------------------------------
    285295% --- launched by selecting an item on the file list
    286296function list_Callback(option,filter_ext,hObject,event)
     
    288298hfig=get(hObject,'parent');%handle of the fig
    289299set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action
    290     drawnow
     300drawnow
    291301list=get(hObject,'String');
    292302index=get(hObject,'Value');
    293303
    294 htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name 
     304htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name
    295305DirName=get(htitlebox,'String');
    296 CheckSubDir=~isempty(regexp(list{index},'^\+'));
     306CheckSubDir=~isempty(regexp(list{index},'^\+', 'once'));
    297307SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir
    298308ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond  '...'
     
    303313    FullSelectName=fileparts(DirName);
    304314else
    305     if isempty(regexp(DirName,'^http://'))% usual files
     315    if isempty(regexp(DirName,'^http://', 'once'))% usual files
    306316        FullSelectName=fullfile(DirName,SelectName);
    307317    else
     
    321331    end
    322332    hcheck_date=findobj(hfig,'tag','check_date');
    323    
     333
    324334    ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content
    325335    set(hObject,'Value',1)
     
    330340set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end
    331341
    332 %-------------------------------------------------------------------------   
     342%-------------------------------------------------------------------------
    333343% list the content of a directory
    334344function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext)
    335345%-------------------------------------------------------------------------
     346ListFiles={};%default
     347NumFiles=0;
    336348ListStruct=dir_uvmat(DirName);% get structure of the current directory
    337349if ~isstruct(ListStruct)
    338350    return
    339351end
    340    
     352
    341353date_index=find(strcmp('datenum',fieldnames(ListStruct)));% find the index of the date displayin the list of fields
    342 NumFiles=0; %default
    343354if numel(ListStruct)<1  % case of empty dir
    344     ListFiles={};
    345355    return
    346356end
    347357ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
    348358ListFiles=ListCells(1,:);%list of file names
    349 index_dir=find(strcmp('isdir',fieldnames(ListStruct)));
     359index_dir=strcmp('isdir',fieldnames(ListStruct));
    350360check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files
    351361ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     
    362372    check_dir=check_dir(check_keep);
    363373end
    364 check_emptydate=cellfun('isempty',ListCells(date_index,:));% = 1 if datenum undefined 
    365 ListCells(date_index,find(check_emptydate))={0}; %set to 0 the empty dates
     374check_emptydate=cellfun('isempty',ListCells(date_index,:));% = 1 if datenum undefined
     375ListCells(date_index,check_emptydate)={0}; %set to 0 the empty dates
    366376ListDates=cell2mat(ListCells(date_index,:));%list of numerical dates
    367377if isnumeric(sort_option)
     
    369379    NumFiles=numel(find(~check_old&~check_dir));
    370380end
    371 if ~isempty(find(~check_dir))
    372 ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
     381if ~isempty(find(~check_dir, 1))
     382    ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
    373383end
    374384
    375385if isnumeric(sort_option)|| strcmp(sort_option,'date')
    376     [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list
    377 else
    378     [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list
     386    [~,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list
     387else
     388    [~,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list
    379389end
    380390ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file
     
    447457function CheckImage=isimage(filename)
    448458
    449 [pp,name,ext]=fileparts(filename);
     459[~,~,ext]=fileparts(filename);
    450460CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.','')));
Note: See TracChangeset for help on using the changeset viewer.