source: trunk/src/activate.m @ 980

Last change on this file since 980 was 977, checked in by g7moreau, 4 years ago
  • Update Copyright 2008-2017 notice
File size: 3.7 KB
Line 
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
9% Position=[x y] coordinates set for the mouse relative to the object (default =[] corresponds to the centre [0.5 0.5]
10% Value: value set to the element, for instance string to select on a menu
11
12%=======================================================================
13% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
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
30function activate(FigTag,PanelTag,ObjectTag,Position,Value)
31hFig=findobj(allchild(0),'tag',FigTag);
32set(0,'CurrentFigure',hFig)
33% xx=double(get(hFig,'CurrentCharacter')); %get the keyboard character
34% if isequal(xx,27) % key escape
35%     pause
36% end
37handles=guidata(hFig);
38unit_0=get(0,'Unit');
39unit=get(hFig,'Unit');
40set(hFig,'Unit',unit_0)
41FramePos=get(hFig,'Position');% position of the figure
42set(hFig,'Unit',unit)
43if isempty(PanelTag)
44    hPanel=hFig;
45    hObject=handles.(ObjectTag);
46else
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)
52end
53if ~exist('Position','var')
54    Position=[];
55end
56if isempty(Position)
57    Position=[0.5 0.5];
58end
59if ~exist('Value','var')
60    Value=[];
61end
62hObject=handles.(ObjectTag);
63if isempty(hObject)
64    disp(['Object' ObjectTag ' not found'])
65else
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);
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
79    end
80    unit=get(hObject,'Unit');
81    set(hObject,'Unit',unit_0);
82    Pos=get(hObject,'Position');
83    set(hObject,'Unit',unit)
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)) 
87    for ipos=1:10
88        set(0,'PointerLocation',CurrentPointerLoc+0.1*ipos*(NewPointerLoc-CurrentPointerLoc))
89        pause(0.2)
90    end
91    if strcmp(get(hObject,'Type'),'axes')
92        mouse_down(hFig,[])
93        pause(2)
94        mouse_up(hFig,[])
95        drawnow
96    else
97    BackgroundColor=get(hObject,'BackgroundColor');
98    set(hObject,'BackgroundColor',[1 1 0])% mark activation of the object
99    drawnow
100    feval(FigTag,[ObjectTag '_Callback'],hObject,[],handles);
101        pause(2)
102    set(hObject,'BackgroundColor',BackgroundColor)
103    end
104end
105%%%%text display
106if isempty(Value)
107disp(['mouse select ' ObjectTag ' in ' FigTag ' ' PanelTag])
108else
109    disp(['set ' Value ' in ' FigTag ' ' PanelTag ' ' ObjectTag])
110end
Note: See TracBrowser for help on using the repository browser.