[620] | 1 | % 'activate': emulate the mouse selection of a GUI element, for demo |
---|
| 2 | %----------------------------------------------------------------------- |
---|
| 3 | % function activate(FigTag,PanelTag,ObjectTag,Value) |
---|
| 4 | % |
---|
| 5 | % INPUT: |
---|
| 6 | % FigTag: tag name of the GUI figure (e.g; 'uvmat') |
---|
| 7 | % PanelTag: tag name of a uipanel containing the element, =[] if no panel |
---|
| 8 | % ObjectTag: tag name of the element |
---|
[627] | 9 | % Position=[x y] coordinates set for the mouse relative to the object (default =[] corresponds to the centre [0.5 0.5] |
---|
[620] | 10 | % Value: value set to the element, for instance string to select on a menu |
---|
| 11 | |
---|
[627] | 12 | function activate(FigTag,PanelTag,ObjectTag,Position,Value) |
---|
[620] | 13 | hFig=findobj(allchild(0),'tag',FigTag); |
---|
| 14 | set(0,'CurrentFigure',hFig) |
---|
[627] | 15 | % xx=double(get(hFig,'CurrentCharacter')); %get the keyboard character |
---|
| 16 | % if isequal(xx,27) % key escape |
---|
| 17 | % pause |
---|
| 18 | % end |
---|
[620] | 19 | handles=guidata(hFig); |
---|
| 20 | unit_0=get(0,'Unit'); |
---|
| 21 | unit=get(hFig,'Unit'); |
---|
| 22 | set(hFig,'Unit',unit_0) |
---|
[627] | 23 | FramePos=get(hFig,'Position');% position of the figure |
---|
[620] | 24 | set(hFig,'Unit',unit) |
---|
| 25 | if isempty(PanelTag) |
---|
| 26 | hPanel=hFig; |
---|
| 27 | hObject=handles.(ObjectTag); |
---|
| 28 | else |
---|
| 29 | hPanel=findobj(hFig,'tag',PanelTag); |
---|
| 30 | unit=get(hPanel,'Unit'); |
---|
| 31 | set(hPanel,'Unit',unit_0) |
---|
| 32 | FramePos=FramePos+get(hPanel,'Position'); |
---|
| 33 | set(hPanel,'Unit',unit) |
---|
| 34 | end |
---|
[627] | 35 | if ~exist('Position','var') |
---|
| 36 | Position=[]; |
---|
| 37 | end |
---|
| 38 | if isempty(Position) |
---|
| 39 | Position=[0.5 0.5]; |
---|
| 40 | end |
---|
| 41 | if ~exist('Value','var') |
---|
| 42 | Value=[]; |
---|
| 43 | end |
---|
[620] | 44 | hObject=handles.(ObjectTag); |
---|
| 45 | if isempty(hObject) |
---|
| 46 | disp(['Object' ObjectTag ' not found']) |
---|
| 47 | else |
---|
| 48 | if exist('Value','var') |
---|
| 49 | if isempty(PanelTag) |
---|
| 50 | Param.(ObjectTag)=Value; |
---|
| 51 | else |
---|
| 52 | Param.(PanelTag).(ObjectTag)=Value; |
---|
| 53 | end |
---|
| 54 | errormsg=fill_GUI(Param,hFig); |
---|
[627] | 55 | if ~isempty(errormsg) |
---|
| 56 | disp(errormsg) |
---|
| 57 | end |
---|
| 58 | % if isequal(get(handles.(ObjectTag),'Style'),'pushbutton') |
---|
| 59 | % set(handles.(ObjectTag),'Value',Value) |
---|
| 60 | % end |
---|
[620] | 61 | end |
---|
| 62 | unit=get(hObject,'Unit'); |
---|
| 63 | set(hObject,'Unit',unit_0); |
---|
| 64 | Pos=get(hObject,'Position'); |
---|
| 65 | set(hObject,'Unit',unit) |
---|
[627] | 66 | CurrentPointerLoc=get(0,'PointerLocation'); |
---|
| 67 | NewPointerLoc=FramePos(1:2)+Pos(1:2)+Position.*Pos(3:4); |
---|
| 68 | set(0,'PointerLocation',FramePos(1:2)+Pos(1:2)+Position.*Pos(3:4)) |
---|
[620] | 69 | for ipos=1:10 |
---|
[627] | 70 | set(0,'PointerLocation',CurrentPointerLoc+0.1*ipos*(NewPointerLoc-CurrentPointerLoc)) |
---|
[620] | 71 | pause(0.2) |
---|
| 72 | end |
---|
[660] | 73 | if strcmp(get(hObject,'Type'),'axes') |
---|
[627] | 74 | mouse_down(hFig,[]) |
---|
[660] | 75 | pause(2) |
---|
[627] | 76 | mouse_up(hFig,[]) |
---|
[660] | 77 | drawnow |
---|
[627] | 78 | else |
---|
| 79 | BackgroundColor=get(hObject,'BackgroundColor'); |
---|
| 80 | set(hObject,'BackgroundColor',[1 1 0])% mark activation of the object |
---|
| 81 | drawnow |
---|
[620] | 82 | feval(FigTag,[ObjectTag '_Callback'],hObject,[],handles); |
---|
[627] | 83 | pause(2) |
---|
[620] | 84 | set(hObject,'BackgroundColor',BackgroundColor) |
---|
[627] | 85 | end |
---|
[620] | 86 | end |
---|
[627] | 87 | %%%%text display |
---|
| 88 | if isempty(Value) |
---|
| 89 | disp(['mouse select ' ObjectTag ' in ' FigTag ' ' PanelTag]) |
---|
| 90 | else |
---|
| 91 | disp(['set ' Value ' in ' FigTag ' ' PanelTag ' ' ObjectTag]) |
---|
| 92 | end |
---|