Ignore:
Timestamp:
Jun 25, 2013, 12:48:10 AM (11 years ago)
Author:
sommeria
Message:

various bugs corrected. Introduction of campaign lists in Open menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r648 r651  
    1515%          'image': any image or movie
    1616%          '.ext': display only files with extension '.ext'
     17%          'uigetdir'; browser used to select a directory (like the matlab browser 'uigetdir')
    1718
    1819function fileinput=uigetfile_uvmat(title,InputName,FilterExt)
     
    5253    Width=350;% fig width in points (1/72 inch)
    5354    Height=min(0.8*ScreenSize(4),500);
    54     Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 
     55    Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
    5556    Bottom=ScreenSize(4)-Height-40; %put fig at top right
    5657    hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir);
    5758    BackgroundColor=get(hfig,'Color');
    58     uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.97 0.5 0.03],'BackgroundColor',BackgroundColor,...
    59             'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
    60     uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.89 0.9 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,...
    61         'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold');
    62     uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.75 0.1 0.07],...
    63             'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward);
    64     uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.75 0.2 0.04],'tag','check_date','Callback',@dates_Callback,...
    65             'String','dates','FontUnits','points','FontSize',12,'FontWeight','bold');
    66     uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...
    67             'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');
    68     uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',...
    69             'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold');   
    70     uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option,FilterExt,src,event),'tag','list',...
    71         'FontUnits','points','FontSize',12);
    72     uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),...
     59    path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',...
     60        'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
     61    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,...
     62        'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path');
     63    uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],...
     64        'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward');
     65    home_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.35 0.005 0.3 0.07],...
     66        'String','Work dir','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir,'TooltipString','reach the current Matlab working directory');
     67   
     68    uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.75 0.23 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',...
     69        'String',{'sort name';'sort date'},'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''sort_option'': sort the files by names or dates');
     70    uicontrol('Style','listbox','Units','normalized', 'Position',[0.02 0.08 0.96 0.66], 'Callback', @(src,event)list_Callback(option,FilterExt,src,event),'tag','list',...
     71        'FontUnits','points','FontSize',12,'TooltipString','''list'':current list of directories, marked by +/, and files');
     72    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.78 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),...
    7373        'String','Close','FontWeight','bold','FontUnits','points','FontSize',12);
    74     uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.1 0.005 0.2 0.07],'Callback',@refresh_GUI,...
     74    uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.02 0.005 0.2 0.07],'Callback',@refresh_GUI,...
    7575        'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12);
     76    OK_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.75 0.81 0.23 0.07],'BackgroundColor',[0 1 0],...
     77        'String','OK','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@(src,event)OK_Callback(option,FilterExt,src,event));
    7678    %set(hrefresh,'UserData',StatusData)
    7779    if strcmp(option,'status_display') %put a run advancement display
    7880        set(hfig,'DeleteFcn',@(src,event)close(option,src,event))
    79               uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.85 0.9 0.04]);
    80         uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar');
    81 
     81        uicontrol('Style','frame','Units','normalized', 'Position', [0.02 0.85 0.9 0.04]);
     82        uicontrol('Style','frame','Units','normalized', 'Position',[0.02 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar');
     83        %             uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...
     84        %             'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');
     85        delete(home_button)
     86        set(OK_button,'String','OPEN')
     87    elseif strcmp(FilterExt,'uigetdir') %pick a  directory
     88        set(path_title,'String',title); %show the input title for path (directory)
    8289    else  %put a title and additional pushbuttons
    83         uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.75 0.6 0.03],'BackgroundColor',BackgroundColor,...
     90        uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.74 0.6 0.03],'BackgroundColor',BackgroundColor,...
    8491            'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
    85 
    86         uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.005 0.2 0.07],...
    87             'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir);
     92        uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,...
     93            'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates');
     94%         uicontrol('Style','text','Units','normalized', 'Position', [0.37 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...
     95%             'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');
     96       
    8897    end
    8998    drawnow
    9099end
    91 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 
    92 if ~strcmp(option,'status_display') 
     100refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir
     101if ~strcmp(option,'status_display')
    93102    uiwait(hfig)
    94103    if ishandle(hfig)
    95     htitlebox=findobj(hfig,'Tag','titlebox');
    96     fileinput=get(htitlebox,'String');% retrieve the input file selection
    97     delete(hfig)
     104        htitlebox=findobj(hfig,'Tag','titlebox');
     105        fileinput=get(htitlebox,'String');% retrieve the input file selection
     106        delete(hfig)
    98107    end
    99108end
     
    101110%------------------------------------------------------------------------   
    102111% --- launched by refreshing the display figure
     112%------------------------------------------------------------------------
    103113function titlebox_Callback(hObject,event)
    104114refresh_GUI(hObject)
    105 %------------------------------------------------------------------------
     115
     116%------------------------------------------------------------------------   
     117% --- launched by selecting OK (relevant for FilterExt='uigetdir')
     118%------------------------------------------------------------------------
     119function OK_Callback(option,filter_ext,hObject,event)
     120hfig=get(hObject,'parent');%handle of the fig
     121% if ~strcmp(get(hfig,'SelectionType'),'open')
     122%     return %select double click
     123% end
     124%set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action
     125%     drawnow
     126htitlebox=findobj(hfig,'tag','titlebox');  % display the current dir name 
     127DirName=get(htitlebox,'String');
     128
     129if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir
     130    hlist=findobj(hfig,'Tag','list');
     131    list=get(hlist,'String');
     132    index=get(hlist,'Value');
     133    SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir
     134    ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond  '...'
     135    if ~isempty(ind_dot)
     136        SelectName=SelectName(1:ind_dot-1);
     137    end
     138    % if strcmp(SelectName,'..')% the upward dir option has been selected
     139    %     FullSelectName=fileparts(DirName);
     140    % else
     141    FullSelectName=fullfile(DirName,SelectName);
     142    % end
     143    if exist(FullSelectName,'file')
     144        switch option
     145            case 'browser'
     146                set(htitlebox,'String',FullSelectName);
     147                uiresume(hfig)
     148            case 'status_display'
     149                FileType=get_file_type(FullSelectName);
     150                if strcmp(FileType,'txt')
     151                    edit(FullSelectName)
     152                elseif strcmp(FileType,'xml')
     153                    editxml(FullSelectName)
     154                elseif strcmp(FileType,'figure')
     155                    open(FullSelectName)
     156                else
     157                    uvmat(FullSelectName);
     158                end
     159        end
     160    end
     161end
     162%set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end
     163
     164uiresume(get(hObject,'parent'))
    106165
    107166%------------------------------------------------------------------------   
     
    113172end
    114173if ~exist('FilterExt','var')
     174    FilterExt='*';
     175end
     176if strcmp(FilterExt,'uigetdir')
    115177    FilterExt='*';
    116178end
     
    165227set(hlist,'Value',Value)
    166228set(hlist,'BackgroundColor',[0.7 0.7 0.7])
     229
    167230%------------------------------------------------------------------------   
    168231% --- launched by selecting an item on the file list
     232%------------------------------------------------------------------------
    169233function dates_Callback(hObject,event)
    170 %------------------------------------------------------------------------
     234
    171235hfig=get(hObject,'parent');
    172236hsort_option=findobj(hfig,'tag','sort_option');
     
    178242end
    179243refresh_GUI(hObject,[])
     244
    180245
    181246%------------------------------------------------------------------------   
     
    205270end
    206271if exist(FullSelectName,'dir')% a directory has been selected
    207     %     ListFiles=dir(FullSelectName);
    208     %     ListDisplay=cell(numel(ListFiles),1);
    209     %     for ilist=2:numel(ListDisplay)% suppress the first line '.'
    210     %         ListDisplay{ilist-1}=ListFiles(ilist).name;
    211     %     end
    212     %     set(hObject,'Value',1)
    213     %     set(hObject,'String',ListDisplay)
    214     %     if strcmp(selectname,'..')
    215     %         FullSelectName=fileparts(fileparts(FullSelectName));
    216     %     end
    217272    set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action
    218273    drawnow
     
    231286    set(hObject,'BackgroundColor',[0.7 0.7 0.7])
    232287    set(htitlebox,'String',FullSelectName)% record the new dir name
    233 elseif exist(FullSelectName,'file')%visualise the field if it exists 
    234     switch option
    235         case 'browser'
    236             set(htitlebox,'String',FullSelectName);
    237             uiresume(hfig)
    238         case 'status_display'
    239             FileType=get_file_type(FullSelectName);
    240             if strcmp(FileType,'txt')
    241                 edit(FullSelectName)
    242             elseif strcmp(FileType,'xml')
    243                 editxml(FullSelectName)
    244             elseif strcmp(FileType,'figure')
    245                 open(FullSelectName)
    246             else
    247                 uvmat(FullSelectName);
    248             end
    249     end
    250288end
    251289set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end
     
    265303check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    266304ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    267 if exist('filter_ext','var') && ~strcmp(filter_ext,'*')
     305if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir')
    268306    if strcmp(filter_ext,'image')
    269307        check_keep=cellfun(@isimage,ListFiles) ;
     
    277315    check_dir=check_dir(check_keep);
    278316end
     317check_emptydate=cellfun('isempty',ListCells(5,:));% = 1 if datenum undefined
     318ListCells(5,find(check_emptydate))={0}; %set to 0 the empty dates
    279319ListDates=cell2mat(ListCells(5,:));%list of numerical dates
    280320if isnumeric(sort_option)
Note: See TracChangeset for help on using the changeset viewer.