Ignore:
Timestamp:
Apr 14, 2013, 9:37:42 AM (8 years ago)
Author:
sommeria
Message:

various bugs fixed after tests under widows
introduce uigetfile_uvmat for series/status (some problems need to be solved)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r609 r610  
    1212function fileinput=uigetfile_uvmat(title,InputName)
    1313fileinput=''; %default file selection
    14 if strcmp(title,'status')
    15     option='status';
     14if strcmp(title,'status_display')
     15    option='status_display';
    1616else
    1717    option='browser';
    1818end
    19 if exist(InputName,'file')||exist(InputName,'dir')
     19if exist(InputName,'dir')
     20    InputDir=InputName;
     21      InputFileName='';
     22elseif exist(InputName,'file')
    2023    [InputDir,InputFileName,Ext]=fileparts(InputName);
    21     InputFileName=[InputFileName Ext];
     24    if isempty(InputFileName)% if InputName is already the root
     25        InputFileName=InputDir;
     26        if  ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems
     27            InputDir=[InputDir '\'];% append '\' for a correct action of dir
     28            InputFileName=[InputFileName '\'];
     29        end
     30    end
    2231    if isdir(InputName)
    23         InputFileName=['+/' InputFileName];
     32        InputFileName=['+/' InputFileName Ext];
    2433    end
    2534else
     
    4554        'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12);
    4655    %set(hrefresh,'UserData',StatusData)
    47     if strcmp(option,'status') %put a run advancement display
     56    if strcmp(option,'status_display') %put a run advancement display
    4857        set(hfig,'DeleteFcn',@stop_status)
    4958        uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.81 0.01 0.05],'BackgroundColor',[1 0 0],'tag','waitbar');
     
    5968    drawnow
    6069end
    61 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName) 
    62 if ~strcmp(option,'status') 
     70refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName)% refresh the list of content of the current dir 
     71if ~strcmp(option,'status_display') 
    6372    uiwait(hfig)
    64 end
    65 fileinput=get(hfig,'UserData');% retrieve the input file selection
    66 delete(hfig)
     73    fileinput=get(hfig,'UserData');% retrieve the input file selection
     74    delete(hfig)
     75end
     76
     77
     78
     79%------------------------------------------------------------------------   
     80% --- launched by refreshing the display figure
     81function refresh_GUI(hObject,InputFileName)
     82%------------------------------------------------------------------------
     83if ~exist('InputFileName','var')
     84    InputFileName='';
     85end
     86hfig=get(hObject,'parent');
     87DirName=get(hfig,'UserData');
     88ListFiles=list_files(DirName);% list the directory content
     89hlist=findobj(hfig,'tag','list');% find the list object
     90set(hlist,'String',ListFiles)
     91Value=[];
     92if ~isempty(InputFileName)
     93    Value=find(strcmp(InputFileName,ListFiles));
     94end
     95if isempty(Value)
     96    Value=1;
     97end
     98set(hlist,'Value',Value)
     99
     100if strcmp(get(hfig,'Tag'),'status_display')
     101   
     102    hseries=findobj(allchild(0),'tag','series');
     103    hstatus=findobj(hseries,'tag','status_display');
     104    StatusData=get(hstatus,'UserData');
     105    TimeStart=0;
     106    if isfield(StatusData,'TimeStart')
     107        TimeStart=StatusData.TimeStart;
     108    end
     109   
     110   
     111    htitlebox=findobj(hfig,'tag','titlebox');
     112    hlist=findobj(hfig,'tag','list');
     113    OutputDir=get(hfig,'UserData');
     114   
     115    testrecent=0;
     116    datnum=zeros(numel(ListDisplay),1);
     117    for ilist=1:numel(ListDisplay)
     118        ListDisplay{ilist}=ListFiles(ilist).name;
     119        if ListFiles(ilist).isdir
     120            ListDisplay{ilist}=['/' ListDisplay{ilist}];
     121        elseif isfield(ListFiles(ilist),'datenum')
     122            datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions
     123            testrecent=1;
     124            if datnum(ilist)<TimeStart
     125                ListDisplay{ilist}=[ListDisplay{ilist} '  --OLD--'];
     126            end
     127        end
     128    end
     129   
     130    %% Look at date of creation
     131    ListDisplay=ListDisplay(datnum~=0);
     132    datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
     133   
     134    NbOutputFile=[];
     135    if isempty(datnum)
     136        if testrecent
     137            message='no result created yet';
     138        else
     139            message='';
     140        end
     141    else
     142        [first,indfirst]=min(datnum);
     143        [last,indlast]=max(datnum);
     144        NbOutputFile_str='?';
     145        if isfield(StatusData,'NbOutputFile')
     146            NbOutputFile=StatusData.NbOutputFile;
     147            NbOutputFile_str=num2str(NbOutputFile);
     148        end
     149        message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification:  ' ListDisplay{indfirst} ' : ' datestr(first)];...
     150            ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
     151    end
     152    set(htitlebox,'String', [DirName{1};message])
     153   
     154    %% update the waitbar
     155    hwaitbar=findobj(hfig,'tag','waitbar');
     156    if ~isempty(NbOutputFile)
     157        BarPosition=get(hwaitbar,'Position');
     158        BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
     159        set(hwaitbar,'Position',BarPosition)
     160    end
     161end
    67162
    68163%------------------------------------------------------------------------   
     
    118213        set(hfig,'UserData',FullSelectName);
    119214        uiresume(hfig)
    120             case 'status'
     215            case 'status_display'
    121216           uvmat(FullSelectName);
    122217        end
    123218        set(gcbo,'Value',1)
    124219    end
    125 end
    126 
    127 %------------------------------------------------------------------------   
    128 % --- launched by selecting home
    129 function home_dir(hObject,event)
    130 %------------------------------------------------------------------------
    131 DirName=pwd;
    132 ListFiles=list_files(DirName);% list the directory content
    133 hfig=get(hObject,'parent');
    134     set(hfig,'UserData',DirName)% record the new dir name
    135     htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name 
    136     set(htitlebox,'String',DirName)
    137     hlist=findobj(hfig,'tag','list');% find the list object
    138 set(hlist,'String',ListFiles)
    139 %------------------------------------------------------------------------
    140 
    141 %------------------------------------------------------------------------   
    142 % --- launched by pressing the backward (<--) button
    143 function backward(hObject,event)
    144 %------------------------------------------------------------------------
    145 PrevDir=get(hObject,'UserData');
    146 if ~isempty(PrevDir)
    147 hfig=get(hObject,'parent');
    148 set(hfig,'UserData',PrevDir)
    149 htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name
    150 set(htitlebox,'String',PrevDir)
    151 refresh_GUI(findobj(hfig,'Tag','refresh'))
    152 end
    153 
    154 %------------------------------------------------------------------------
    155 
    156 %------------------------------------------------------------------------   
    157 % --- launched by refreshing the display figure
    158 function refresh_GUI(hObject,InputFileName)
    159 %------------------------------------------------------------------------
    160 if ~exist('InputFileName','var')
    161     InputFileName='';
    162 end
    163 hfig=get(hObject,'parent');
    164 DirName=get(hfig,'UserData');
    165 ListFiles=list_files(DirName);% list the directory content
    166 hlist=findobj(hfig,'tag','list');% find the list object
    167 set(hlist,'String',ListFiles)
    168 Value=[];
    169 if ~isempty(InputFileName)
    170     Value=find(strcmp(InputFileName,ListFiles));
    171 end
    172 if isempty(Value)
    173     Value=1;
    174 end
    175 set(hlist,'Value',Value)
    176 return
    177 
    178 %TODO adapt to series status
    179 hseries=findobj(allchild(0),'tag','series');
    180 hstatus=findobj(hseries,'tag','status');
    181 StatusData=get(hstatus,'UserData');
    182 TimeStart=0;
    183 if isfield(StatusData,'TimeStart')
    184     TimeStart=StatusData.TimeStart;
    185 end
    186 % testrecent=0;
    187 % datnum=zeros(numel(ListDisplay),1);
    188 % for ilist=1:numel(ListDisplay)
    189 %     ListDisplay{ilist}=ListFiles(ilist).name;
    190 %     if ListFiles(ilist).isdir
    191 %         ListDisplay{ilist}=['/' ListDisplay{ilist}];   
    192 %     elseif isfield(ListFiles(ilist),'datenum')
    193 %         datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions
    194 %         testrecent=1;
    195 %         if datnum(ilist)<TimeStart
    196 %             ListDisplay{ilist}=[ListDisplay{ilist} '  --OLD--'];
    197 %         end
    198 %     end
    199 % end
    200 
    201 
    202 %% Look at date of creation
    203 ListDisplay=ListDisplay(datnum~=0);
    204 datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
    205 
    206 NbOutputFile=[];
    207 if isempty(datnum)
    208     if testrecent
    209         message='no result created yet';
    210     else
    211         message='';
    212     end
    213 else
    214     [first,indfirst]=min(datnum);
    215     [last,indlast]=max(datnum);
    216     NbOutputFile_str='?';
    217     if isfield(StatusData,'NbOutputFile')
    218         NbOutputFile=StatusData.NbOutputFile;
    219         NbOutputFile_str=num2str(NbOutputFile);
    220     end
    221     message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification:  ' ListDisplay{indfirst} ' : ' datestr(first)];...
    222         ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
    223 end
    224 set(htitlebox,'String', [DirName{1};message])
    225 
    226 %% update the waitbar
    227 hwaitbar=findobj(hfig,'tag','waitbar');
    228 if ~isempty(NbOutputFile)
    229     BarPosition=get(hwaitbar,'Position');
    230     BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
    231     set(hwaitbar,'Position',BarPosition)
    232220end
    233221
     
    236224function ListFiles=list_files(DirName)
    237225%-------------------------------------------------------------------------
    238 ListStruct=dir(DirName);
     226ListStruct=dir(DirName);% get structure of the current directory
    239227if numel(ListStruct)<1
    240228    ListFiles={};
     
    254242ListFiles=[{'+/..'} ListFiles(check_keep)];
    255243
     244%------------------------------------------------------------------------   
     245% --- launched by selecting home
     246function home_dir(hObject,event)
     247%------------------------------------------------------------------------
     248DirName=pwd;
     249ListFiles=list_files(DirName);% list the directory content
     250hfig=get(hObject,'parent');
     251    set(hfig,'UserData',DirName)% record the new dir name
     252    htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name 
     253    set(htitlebox,'String',DirName)
     254    hlist=findobj(hfig,'tag','list');% find the list object
     255set(hlist,'String',ListFiles)
     256%------------------------------------------------------------------------
     257
     258%------------------------------------------------------------------------   
     259% --- launched by pressing the backward (<--) button
     260function backward(hObject,event)
     261%------------------------------------------------------------------------
     262PrevDir=get(hObject,'UserData');
     263if ~isempty(PrevDir)
     264hfig=get(hObject,'parent');
     265set(hfig,'UserData',PrevDir)
     266htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name
     267set(htitlebox,'String',PrevDir)
     268refresh_GUI(findobj(hfig,'Tag','refresh'))
     269end
     270
    256271%-------------------------------------------------------------------------   
    257272% launched by deleting the status figure (only used in mode series status')
    258273function close(option,hObject, eventdata)
    259274%-------------------------------------------------------------------------
    260 if strcmp(option,'status')
     275if strcmp(option,'status_display')
    261276    hseries=findobj(allchild(0),'tag','series');
    262     hstatus=findobj(hfig,'Tag','status');
     277    hstatus=findobj(hfig,'Tag','status_display');
    263278    set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
    264279    set(hhciv.status,'BackgroundColor',[0 1 0])
Note: See TracChangeset for help on using the changeset viewer.