Ignore:
Timestamp:
Apr 9, 2013, 8:20:00 PM (8 years ago)
Author:
sommeria
Message:

various bugs corrected after tests with Windows OS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r606 r609  
    44%
    55% OUTPUT:
    6 % hfig: handles of the browser fig, the selected file name is obtained as File=get(hfig,'UserData')
     6% fileinput: detected file name, including path
    77%
    88% INPUT:
    9 % option: ='file browser': usual browser, 'series status': display advancement of a series calculation
     9% title: = displayed title, 'status': display advancement of a series calculation
    1010% InputDir: directory to browse at first display
    1111
    12 
    13 function hfig=uigetfile_uvmat(option,InputDir)
    14 if ~exist(InputDir,'dir')
    15     InputDir=pwd;
    16 end
    17 hfig=findobj(allchild(0),'name',option);
     12function fileinput=uigetfile_uvmat(title,InputName)
     13fileinput=''; %default file selection
     14if strcmp(title,'status')
     15    option='status';
     16else
     17    option='browser';
     18end
     19if exist(InputName,'file')||exist(InputName,'dir')
     20    [InputDir,InputFileName,Ext]=fileparts(InputName);
     21    InputFileName=[InputFileName Ext];
     22    if isdir(InputName)
     23        InputFileName=['+/' InputFileName];
     24    end
     25else
     26    InputDir=pwd;%look in the current work directory if the input file does not exist
     27    InputFileName='';
     28end
     29hfig=findobj(allchild(0),'tag',option);
    1830if isempty(hfig)
     31    set(0,'Unit','points')
    1932    ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
    20     hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Position',[ScreenSize(3)-600 ScreenSize(4)-640 560 600],'DeleteFcn',@stop_status,'UserData',InputDir);
    21     uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @(src,event)view_file(option,src,event),'tag','list','FontSize',12);
    22     uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',InputDir,'FontSize',12,'FontWeight','bold');
    23     uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@stop_status);
    24     uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.1 0.01 0.2 0.07],'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@refresh_GUI);
     33    Width=350;% fig width in points (1/72 inch)
     34    Height=min(0.8*ScreenSize(4),500);
     35    Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
     36    Bottom=ScreenSize(4)-Height-40; %put fig at top right
     37    hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir);
     38    uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @(src,event)view_file(option,src,event),'tag','list',...
     39        'FontUnits','points','FontSize',12);
     40    uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,...
     41        'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold');
     42    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'Callback',@(src,event)close(option,src,event),...
     43        'String','Close','FontWeight','bold','FontUnits','points','FontSize',12);
     44    uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.1 0.01 0.2 0.07],'Callback',@refresh_GUI,...
     45        'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12);
    2546    %set(hrefresh,'UserData',StatusData)
    26     if strcmp(option,'series status') %put a run advancement display
     47    if strcmp(option,'status') %put a run advancement display
     48        set(hfig,'DeleteFcn',@stop_status)
    2749        uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.81 0.01 0.05],'BackgroundColor',[1 0 0],'tag','waitbar');
    2850        uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
    29     else  %put a title
    30         uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.81 0.9 0.03],'String','select an input file:',...
    31             'FontSize',14,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
    32         uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.01 0.2 0.07],'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir);
     51    else  %put a title and additional pushbuttons
     52        uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.81 0.8 0.03],...
     53            'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
     54        uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.8 0.1 0.07],...
     55            'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward);
     56        uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.01 0.2 0.07],...
     57            'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir);
    3358    end
    3459    drawnow
    3560end
    36 refresh_GUI(hfig)
    37    
    38 %------------------------------------------------------------------------   
    39 % --- launched by selecting a file on the list
     61refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName) 
     62if ~strcmp(option,'status') 
     63    uiwait(hfig)
     64end
     65fileinput=get(hfig,'UserData');% retrieve the input file selection
     66delete(hfig)
     67
     68%------------------------------------------------------------------------   
     69% --- launched by selecting an item on the file list
    4070function view_file(option,hObject,event)
    4171%------------------------------------------------------------------------
    4272list=get(hObject,'String');
    4373index=get(hObject,'Value');
    44 hfig=get(hObject,'parent');
    45 DirName=get(get(hObject,'parent'),'UserData');
    46 SelectName=regexprep(list{index},'^/','');% remove the / used to mark dir
    47 if strcmp(SelectName,'..')
     74hfig=get(hObject,'parent');%handle of the fig
     75DirName=get(hfig,'UserData');
     76SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir
     77if strcmp(SelectName,'..')% the upward dir option has been selected
    4878    FullSelectName=fileparts(DirName);
    4979else
    50 %ind_dot=regexp(SelectName,'\.\.\.');
    51 % if ~isempty(ind_dot)
    52 %     SelectName=SelectName(1:ind_dot-1);
    53 % end
    54 FullSelectName=fullfile(DirName,SelectName);
     80    %ind_dot=regexp(SelectName,'\.\.\.');
     81    % if ~isempty(ind_dot)
     82    %     SelectName=SelectName(1:ind_dot-1);
     83    % end
     84    FullSelectName=fullfile(DirName,SelectName);
    5585end
    5686if exist(FullSelectName,'dir')% a directory has been selected
     
    6595%         FullSelectName=fileparts(fileparts(FullSelectName));
    6696%     end
     97    hbackward=findobj(hfig,'Tag','backward');
     98    set(hbackward,'UserData',DirName); %store the current dir for future backward action
    6799    ListFiles=list_files(FullSelectName);
    68100    set(hObject,'Value',1)
     
    82114        %uvmat(FullSelectName);
    83115        switch option
    84             case 'file browser'
     116            case 'browser'
    85117        hfig=get(hObject,'parent');
    86118        set(hfig,'UserData',FullSelectName);
    87119        uiresume(hfig)
    88             case 'series status'
     120            case 'status'
    89121           uvmat(FullSelectName);
    90122        end
    91     end
    92     set(gcbo,'Value',1)
     123        set(gcbo,'Value',1)
     124    end
    93125end
    94126
     
    96128% --- launched by selecting home
    97129function home_dir(hObject,event)
     130%------------------------------------------------------------------------
    98131DirName=pwd;
    99 
    100132ListFiles=list_files(DirName);% list the directory content
    101133hfig=get(hObject,'parent');
     
    108140
    109141%------------------------------------------------------------------------   
     142% --- launched by pressing the backward (<--) button
     143function backward(hObject,event)
     144%------------------------------------------------------------------------
     145PrevDir=get(hObject,'UserData');
     146if ~isempty(PrevDir)
     147hfig=get(hObject,'parent');
     148set(hfig,'UserData',PrevDir)
     149htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name
     150set(htitlebox,'String',PrevDir)
     151refresh_GUI(findobj(hfig,'Tag','refresh'))
     152end
     153
     154%------------------------------------------------------------------------
     155
     156%------------------------------------------------------------------------   
    110157% --- launched by refreshing the display figure
    111 function refresh_GUI(hfig,event)
    112 %------------------------------------------------------------------------
     158function refresh_GUI(hObject,InputFileName)
     159%------------------------------------------------------------------------
     160if ~exist('InputFileName','var')
     161    InputFileName='';
     162end
     163hfig=get(hObject,'parent');
    113164DirName=get(hfig,'UserData');
    114165ListFiles=list_files(DirName);% list the directory content
    115166hlist=findobj(hfig,'tag','list');% find the list object
    116167set(hlist,'String',ListFiles)
     168Value=[];
     169if ~isempty(InputFileName)
     170    Value=find(strcmp(InputFileName,ListFiles));
     171end
     172if isempty(Value)
     173    Value=1;
     174end
     175set(hlist,'Value',Value)
    117176return
    118177
     
    188247ListFiles=ListCells(1,:);%list of file names
    189248check_dir=cell2mat(ListCells(4,:));% check directories
    190 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','/$0');% put '/' in front of dir name display
     249ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    191250[tild,index_sort]=sort(check_dir,2,'descend');% sort
    192251ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file
    193 cell_remove=regexp(ListFiles,'^(-|\.|/\.)');% remove strings beginning by '/.',';' or '-'
    194 check_remove=cellfun('isempty',cell_remove);
    195 ListFiles=[{'/..'} ListFiles(check_remove)];
     252cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     253check_keep=cellfun('isempty', cell_remove);               
     254ListFiles=[{'+/..'} ListFiles(check_keep)];
    196255
    197256%-------------------------------------------------------------------------   
    198 % launched by deleting the status figure
    199 function stop_status(hObject, eventdata)
     257% launched by deleting the status figure (only used in mode series status')
     258function close(option,hObject, eventdata)
    200259%-------------------------------------------------------------------------
    201 hciv=findobj(allchild(0),'tag','series');
    202 hhciv=guidata(hciv);
    203 set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
    204 set(hhciv.status,'BackgroundColor',[0 1 0])
     260if strcmp(option,'status')
     261    hseries=findobj(allchild(0),'tag','series');
     262    hstatus=findobj(hfig,'Tag','status');
     263    set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
     264    set(hhciv.status,'BackgroundColor',[0 1 0])
     265end
    205266delete(gcbf)
    206267
Note: See TracChangeset for help on using the changeset viewer.