[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 | |
---|
[809] | 12 | %======================================================================= |
---|
[1071] | 13 | % Copyright 2008-2020, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 14 | % http://www.legi.grenoble-inp.fr |
---|
| 15 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 16 | % |
---|
| 17 | % This file is part of the toolbox UVMAT. |
---|
| 18 | % |
---|
| 19 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 20 | % it under the terms of the GNU General Public License as published |
---|
| 21 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 22 | % or (at your option) any later version. |
---|
| 23 | % |
---|
| 24 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 27 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 28 | %======================================================================= |
---|
| 29 | |
---|
[627] | 30 | function activate(FigTag,PanelTag,ObjectTag,Position,Value) |
---|
[620] | 31 | hFig=findobj(allchild(0),'tag',FigTag); |
---|
| 32 | set(0,'CurrentFigure',hFig) |
---|
[627] | 33 | % xx=double(get(hFig,'CurrentCharacter')); %get the keyboard character |
---|
| 34 | % if isequal(xx,27) % key escape |
---|
| 35 | % pause |
---|
| 36 | % end |
---|
[620] | 37 | handles=guidata(hFig); |
---|
| 38 | unit_0=get(0,'Unit'); |
---|
| 39 | unit=get(hFig,'Unit'); |
---|
| 40 | set(hFig,'Unit',unit_0) |
---|
[627] | 41 | FramePos=get(hFig,'Position');% position of the figure |
---|
[620] | 42 | set(hFig,'Unit',unit) |
---|
| 43 | if isempty(PanelTag) |
---|
| 44 | hPanel=hFig; |
---|
| 45 | hObject=handles.(ObjectTag); |
---|
| 46 | else |
---|
| 47 | hPanel=findobj(hFig,'tag',PanelTag); |
---|
| 48 | unit=get(hPanel,'Unit'); |
---|
| 49 | set(hPanel,'Unit',unit_0) |
---|
| 50 | FramePos=FramePos+get(hPanel,'Position'); |
---|
| 51 | set(hPanel,'Unit',unit) |
---|
| 52 | end |
---|
[627] | 53 | if ~exist('Position','var') |
---|
| 54 | Position=[]; |
---|
| 55 | end |
---|
| 56 | if isempty(Position) |
---|
| 57 | Position=[0.5 0.5]; |
---|
| 58 | end |
---|
| 59 | if ~exist('Value','var') |
---|
| 60 | Value=[]; |
---|
| 61 | end |
---|
[620] | 62 | hObject=handles.(ObjectTag); |
---|
| 63 | if isempty(hObject) |
---|
| 64 | disp(['Object' ObjectTag ' not found']) |
---|
| 65 | else |
---|
| 66 | if exist('Value','var') |
---|
| 67 | if isempty(PanelTag) |
---|
| 68 | Param.(ObjectTag)=Value; |
---|
| 69 | else |
---|
| 70 | Param.(PanelTag).(ObjectTag)=Value; |
---|
| 71 | end |
---|
| 72 | errormsg=fill_GUI(Param,hFig); |
---|
[627] | 73 | if ~isempty(errormsg) |
---|
| 74 | disp(errormsg) |
---|
| 75 | end |
---|
| 76 | % if isequal(get(handles.(ObjectTag),'Style'),'pushbutton') |
---|
| 77 | % set(handles.(ObjectTag),'Value',Value) |
---|
| 78 | % end |
---|
[620] | 79 | end |
---|
| 80 | unit=get(hObject,'Unit'); |
---|
| 81 | set(hObject,'Unit',unit_0); |
---|
| 82 | Pos=get(hObject,'Position'); |
---|
| 83 | set(hObject,'Unit',unit) |
---|
[627] | 84 | CurrentPointerLoc=get(0,'PointerLocation'); |
---|
| 85 | NewPointerLoc=FramePos(1:2)+Pos(1:2)+Position.*Pos(3:4); |
---|
| 86 | set(0,'PointerLocation',FramePos(1:2)+Pos(1:2)+Position.*Pos(3:4)) |
---|
[620] | 87 | for ipos=1:10 |
---|
[627] | 88 | set(0,'PointerLocation',CurrentPointerLoc+0.1*ipos*(NewPointerLoc-CurrentPointerLoc)) |
---|
[620] | 89 | pause(0.2) |
---|
| 90 | end |
---|
[660] | 91 | if strcmp(get(hObject,'Type'),'axes') |
---|
[627] | 92 | mouse_down(hFig,[]) |
---|
[660] | 93 | pause(2) |
---|
[627] | 94 | mouse_up(hFig,[]) |
---|
[660] | 95 | drawnow |
---|
[627] | 96 | else |
---|
| 97 | BackgroundColor=get(hObject,'BackgroundColor'); |
---|
| 98 | set(hObject,'BackgroundColor',[1 1 0])% mark activation of the object |
---|
| 99 | drawnow |
---|
[620] | 100 | feval(FigTag,[ObjectTag '_Callback'],hObject,[],handles); |
---|
[627] | 101 | pause(2) |
---|
[620] | 102 | set(hObject,'BackgroundColor',BackgroundColor) |
---|
[627] | 103 | end |
---|
[620] | 104 | end |
---|
[627] | 105 | %%%%text display |
---|
| 106 | if isempty(Value) |
---|
| 107 | disp(['mouse select ' ObjectTag ' in ' FigTag ' ' PanelTag]) |
---|
| 108 | else |
---|
| 109 | disp(['set ' Value ' in ' FigTag ' ' PanelTag ' ' ObjectTag]) |
---|
| 110 | end |
---|