Mercurial > hg > ltpda
comparison m-toolbox/m/gui/quicklook/ltpdaquicklook.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function varargout = ltpdaquicklook(varargin) | |
2 | |
3 % LTPDAQUICKLOOK allows the user to quicklook LTPDA objects. | |
4 % | |
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
6 % | |
7 % DESCRIPTION: LTPDAQUICKLOOK allows the user to quicklook LTPDA objects. | |
8 % | |
9 % CALL: ltpdaquicklook | |
10 % | |
11 % | |
12 % VERSION: $Id: ltpdaquicklook.m,v 1.5 2009/01/15 16:09:28 ingo Exp $ | |
13 % | |
14 % HISTORY: 07-03-08 M Hewitson | |
15 % Creation | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 | |
20 %% Check if I exist already | |
21 hs = findall(0); | |
22 found = -1; | |
23 for j=1:length(hs) | |
24 h = hs(j); | |
25 if strcmp(get(h, 'Tag'), 'LTPDAquicklook') | |
26 found = h; | |
27 end | |
28 end | |
29 if found ~= -1 | |
30 figure(found); | |
31 return | |
32 end | |
33 | |
34 % id = findobj('Tag', 'LTPDAquicklook'); | |
35 % if ~isempty(id) | |
36 % figure(id) | |
37 % return | |
38 % end | |
39 | |
40 %% Some initial setup | |
41 | |
42 Gproperties.Gcol = [240 240 240]/255; | |
43 Gproperties.Gwidth = 600; | |
44 Gproperties.Gheight = 400; | |
45 Gproperties.Gborder = 10; | |
46 fontsize = 12; | |
47 | |
48 Gproperties.Screen = get(0,'screensize'); | |
49 Gproperties.Gposition = [150 ... | |
50 100 ... | |
51 Gproperties.Gwidth... | |
52 Gproperties.Gheight]; | |
53 | |
54 % Initialize and hide the GUI as it is being constructed. | |
55 mainfig = figure('Name', 'LTPDA Quicklook',... | |
56 'NumberTitle', 'off',... | |
57 'Visible','off',... | |
58 'Position',Gproperties.Gposition,... | |
59 'Color', Gproperties.Gcol,... | |
60 'Toolbar', 'none',... | |
61 'MenuBar', 'none',... | |
62 'Resize', 'off',... | |
63 'HandleVisibility', 'callback', ... | |
64 'Tag', 'LTPDAquicklook'); | |
65 | |
66 % Set mainfig callbacks | |
67 set(mainfig, 'CloseRequestFcn', {@ltpda_quicklook_close, mainfig}); | |
68 | |
69 % Set Application data | |
70 setappdata(mainfig, 'Gproperties', Gproperties); | |
71 | |
72 | |
73 %% GUI Parts | |
74 | |
75 % Objects list | |
76 objs = getWorkspaceObjs(); | |
77 setappdata(mainfig, 'objs', objs); | |
78 | |
79 lbh = uicontrol(mainfig,'Style','listbox',... | |
80 'String',{' '},... | |
81 'Value',1,... | |
82 'BackgroundColor', 'w',... | |
83 'Fontsize', fontsize,... | |
84 'Max', 1000,... | |
85 'Position',[10 90 150 300],... | |
86 'Tag', 'LTPDA_quicklook_objlist'); | |
87 | |
88 % Set callback | |
89 set(lbh, 'Callback', {@objList, mainfig}); | |
90 | |
91 setWorkspaceObjsList(objs) | |
92 | |
93 % Refresh button | |
94 pbh = uicontrol(mainfig,'Style','pushbutton',... | |
95 'String','Refresh',... | |
96 'Callback', {@refresh, mainfig}, ... | |
97 'Position',[10 70 60 25]); | |
98 | |
99 | |
100 % Object display | |
101 sth = uicontrol(mainfig,'Style','text',... | |
102 'String','',... | |
103 'BackgroundColor', 'w', ... | |
104 'ForegroundColor', 'b', ... | |
105 'HorizontalAlignment', 'left', ... | |
106 'Tag', 'LTPDA_quicklook_display', ... | |
107 'Position',[170 90 420 300]); | |
108 | |
109 % Plot button | |
110 pbh = uicontrol(mainfig,'Style','pushbutton',... | |
111 'String','iplot',... | |
112 'Callback', {@call_iplot, mainfig}, ... | |
113 'Position',[10 10 60 25]); | |
114 | |
115 % history plot | |
116 pbh = uicontrol(mainfig,'Style','pushbutton',... | |
117 'String','plot history',... | |
118 'Callback', {@call_histplot, mainfig}, ... | |
119 'Position',[80 10 80 25]); | |
120 | |
121 | |
122 %% Start the GUI | |
123 | |
124 % Make the GUI visible. | |
125 set(mainfig,'Visible','on') | |
126 | |
127 %% Callbacks | |
128 | |
129 %---------------- history plot | |
130 function call_histplot(varargin) | |
131 | |
132 mainfig = varargin{end}; | |
133 objs = getappdata(mainfig, 'objs'); | |
134 | |
135 % get selection | |
136 olh = findobj(mainfig, 'Tag', 'LTPDA_quicklook_objlist'); | |
137 idx = get(olh, 'Value'); | |
138 | |
139 cmd = sprintf('obj = evalin(''base'', ''%s'');', objs(idx).name); | |
140 eval(cmd); | |
141 | |
142 plot(obj.hist); | |
143 | |
144 | |
145 %---------------- iplot | |
146 function call_iplot(varargin) | |
147 | |
148 mainfig = varargin{end}; | |
149 objs = getappdata(mainfig, 'objs'); | |
150 | |
151 % get selection | |
152 olh = findobj(mainfig, 'Tag', 'LTPDA_quicklook_objlist'); | |
153 idx = get(olh, 'Value'); | |
154 | |
155 cmd = sprintf('obj = evalin(''base'', ''%s'');', objs(idx).name); | |
156 eval(cmd); | |
157 | |
158 iplot(obj); | |
159 | |
160 %---------------- refresh | |
161 function refresh(varargin) | |
162 | |
163 mainfig = varargin{end}; | |
164 objs = getWorkspaceObjs(); | |
165 setWorkspaceObjsList(objs) | |
166 setappdata(mainfig, 'objs', objs); | |
167 | |
168 %---------------- Close function | |
169 function ltpda_quicklook_close(varargin) | |
170 % Callback executed when the GUI is closed | |
171 | |
172 disp('* Goodbye from the LTPDA Quicklook GUI *') | |
173 delete(varargin{1}) | |
174 | |
175 | |
176 %---------------- Get a list of LTPDA objects in the MATLAB workspace | |
177 function objs = getWorkspaceObjs() | |
178 | |
179 % get base workspace variables | |
180 ws_vars = evalin('base','whos'); | |
181 | |
182 objs = []; | |
183 for j=1:length(ws_vars) | |
184 cmd = sprintf('obj = evalin(''base'', ''%s'');', ws_vars(j).name); | |
185 eval(cmd) | |
186 if isa(obj, 'ltpda_uo') | |
187 objs = [objs ws_vars(j)]; | |
188 end | |
189 end | |
190 | |
191 | |
192 %---------------- Callback for list selection | |
193 function objList(varargin) | |
194 | |
195 mainfig = varargin{end}; | |
196 objs = getappdata(mainfig, 'objs'); | |
197 | |
198 % get selection | |
199 olh = findobj(mainfig, 'Tag', 'LTPDA_quicklook_objlist'); | |
200 idx = get(olh, 'Value'); | |
201 | |
202 cmd = sprintf('obj = evalin(''base'', ''%s'');', objs(idx).name); | |
203 eval(cmd); | |
204 | |
205 txt = display(obj); | |
206 | |
207 dh = findobj(mainfig, 'Tag', 'LTPDA_quicklook_display'); | |
208 set(dh, 'String', txt); | |
209 | |
210 | |
211 %---------------- Fill the workspace object list | |
212 function setWorkspaceObjsList(objs) | |
213 | |
214 id = findobj('Tag', 'LTPDA_quicklook_objlist'); | |
215 | |
216 objlist = []; | |
217 for j=1:length(objs) | |
218 obj = objs(j); | |
219 str = sprintf('%s\t\t(%s)', obj.name, obj.class); | |
220 objlist = [objlist cellstr(str)]; | |
221 end | |
222 | |
223 set(id, 'Value', 1); | |
224 set(id, 'String', objlist); | |
225 | |
226 |