Debian Codegraph @

athena_parts/demo.pl

raw
1
2 ## -*- cperl -*-
3 ##
4 ## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel
5 ##
6 ## This file demonstrates how to add a new analysis feature to Athena
7
8
9 ## 0. Write all the subroutines needed to perform this chore.
10 ## Typically the sub that presents the view in the main window is
11 ## in the same file as all the subs that are needed to perform
12 ## the chore. Add your new file to the file list used to build
13 ## athena.pl from its parts in Makefile.PL and in the mkathena
14 ## utility.
15
16 ## 1. Follow the example in this file for preparing your page.
17 ## Populate it with widgets as desired. Try to maintain some
18 ## visual consistency with other views, unless, of course, you
19 ## have a beter idea
20
21 ## 2. Make an entry in the appropriate menu. if you add to the Data
22 ## or File menus, you will need to take care with the indeces
23 ## used to enable/disable menu items. this is mostly done in the
24 ## first part of set_properties
25
26 ## 3. Add an entry to the FAT block at the end of set_properties
27 ## that will correctly handle any chores that need doing whenever
28 ## the current group changes
29
30 ## 4. You should try to make use of the current and marked groups as
31 ## a way of selecting groups for analysis. from a UI perspective
32 ## it is a bad idea to make special ways of incorporating data
33 ## into the analysis. the one exception is the use of an
34 ## optionmenu to define the "standard" for the analysis chore
35
36 ## 5. Add a section to athena.config with any configuration
37 ## variables that your users might need. feel free to add new
38 ## colors or fonts to athena.config, but do try to reuse the ones
39 ## that are already there
40
41 ## 6. If any of the configuration parameters require special
42 ## handling at the time they are reconfigured, add that to the
43 ## end of the prefs_apply subroutine
44
45 ## 7. Add key binding data to the set_key_data subroutine following
46 ## the commented out example. at the very least, you should add
47 ## your top level function so that the view can be accessed from
48 ## the keyboard. it would be best to provide bindings to every
49 ## button click on your page
50
51 ## 8. If you add this function to the Analysis or Data menus, you
52 ## should add a help balloon hint. this is done in head.pl near
53 ## the menubutton_attach subroutine
54
55 ## 9. Write a document section and add a link to it in athena.pod.
56 ## Also add a menu entry to your new pod in the document sections
57 ## cascade in the $help_menu
58
59 ## 10. It is ok to add new parameters to the Group object which have
60 ## to do with this analysis chore. This can usually be done
61 ## without harming any other part of the code. It would be a
62 ## good idea to follow a naming scheme for your new object
63 ## parameters -- something like 'foobar_spiffyparam'. It is
64 ## probably not necessary to initialize these new parameters in
65 ## Group.pm, however you may need to add some code to the file
66 ## reading or group initializing code to deal with those
67 ## parameters. Cerrtainly it is ok to modify other object
68 ## parameters in your analysis functions.
69
70
71 sub foobaricate {
72
73 ## generally, we do not change modes unless there is data.
74 ## exceptions include things like the prefernces and key bindings,
75 ## which are data-independent
76 Echo("No data!"), return unless $current;
77 Echo("No data!"), return if ($current eq "Default Parameters");
78
79 ## this is a way of testing the current list of data groups for some
80 ## necessary property. for the demo, this will just be the list of
81 ## groups
82 # my @keys = ();
83 # foreach my $k (&sorted_group_list) {
84 # ($groups{$k}->{is_xmu}) and push @keys, $k;
85 # };
86 # Echo("You need two or more xmu groups to foobar"), return unless ($#keys >= 1);
87 my @keys = &sorted_group_list;
88
89 ## you must define a hash which will contain the parameters needed
90 ## to perform the task. the hash_pointer global variable will point
91 ## to this hash for use in set_properties. you might draw these
92 ## values from configuration parameters, as in the commented out
93 ## example
94 my %foobar_params;
95 $foobar_params{string} = "Hi mom!";
96 $foobar_params{boolean} = 1;
97 ## $foobar_params{blah} = $config{foobar}{blah};
98
99 ## let's just assume the first group is the standard and the second
100 ## is the unknown
101 $foobar_params{standard} = $keys[0];
102 $foobar_params{standard_lab} = $groups{$keys[0]}->{label};
103
104 ## you probably do not want the standard and the unknown to be the
105 ## same group
106 set_properties(1, $keys[1], 0) if ($current eq $keys[0]);
107 $foobar_params{unknown} = $current;
108
109 ## you may wish to provide a better guess for which should be the
110 ## standard and which the unknown. you may also want to adjust the
111 ## view of the groups list to show the unknown -- the following
112 ## works...
113 my $here = ($list->bbox($groups{$current}->{text}))[1] - 5 || 0;
114 ($here < 0) and ($here = 0);
115 my $full = ($list->bbox(@skinny_list))[3] + 5;
116 $list -> yview('moveto', $here/$full);
117
118
119 ## The Athena standard for analysis chores that need a specialized
120 ## plotting range is to save the plotting range from the main view
121 ## and restore it when the main view is restored
122 # my @save = ($plot_features{emin}, $plot_features{emax});
123 # $plot_features{emin} = $config{foobar}{emin};
124 # $plot_features{emax} = $config{foobar}{emax};
125
126 ## these two global variables must be set before this view is
127 ## displayed. these are used at the level of set_properties to
128 ## perform chores appropriate to this dialog when changing the
129 ## current group
130 $fat_showing = 'demo';
131 $hash_pointer = \%foobar_params;
132
133 ## disable many menus. this makes the chore of managing the views
134 ## much easier. the idea is that the main view is "home base". if
135 ## you want to do a different analysis chore, you must first return
136 ## to the main view
137 map {$_ -> configure(-state=>'disabled')}
138 ($data_menu, $merge_menu, $anal_menu, $settings_menu);
139
140 ## this removes the currently displayed view without destroying its
141 ## contents
142 $fat -> packForget;
143
144 ## define the parent Frame for this analysis chore and pack it in
145 ## the correct location
146 my $foobar = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3)
147 -> pack(-fill=>'both', -expand=>1);
148 #$foobar -> packPropagate(0);
149 ## global variable identifying which Frame is showing
150 $which_showing = $foobar;
151
152 ## the standard label along the top identifying this analysis chore
153 $foobar -> Label(-text=>"Foobaricate your data",
154 -font=>$config{fonts}{large},
155 -foreground=>$config{colors}{activehighlightcolor})
156 -> pack(-side=>'top', -fill=>'x', -anchor=>'w');
157
158 ## at this point it is common to make an optionmenu defining the
159 ## standard for this data analysis chore and a label identifying
160 ## which data group is currently being work on (i.e. the one
161 ## highlighted in orange in the groups list)
162
163 ## a good solution to organizing widgets is to stack frames, so
164 ## let's make a frame for the standard and the other. note that the
165 ## "labels" are actually flat buttons which display hints in the
166 ## echo area
167 my $frame = $foobar -> Frame(-borderwidth=>2, -relief=>'sunken')
168 -> pack(-side=>'top', -fill=>'x');
169 $frame -> Button(-text=>"Standard: ", @label_button,
170 -foreground=>$config{colors}{activehighlightcolor},
171 -activeforeground=>$config{colors}{activehighlightcolor},
172 -command=>[\&Echo, "The spectrum serving as the foobarication standard."]
173 )
174 -> grid(-row=>0, -column=>0, -sticky=>'e', -ipady=>2);
175 my $menu = $frame -> Optionmenu(-textvariable => \$foobar_params{standard_lab},
176 -borderwidth=>1, )
177 -> grid(-row=>0, -column=>1, -sticky=>'w');
178 foreach my $s (@keys) {
179 $menu -> command(-label => $groups{$s}->{label},
180 -command=>sub{$foobar_params{standard}=$s;
181 $foobar_params{standard_lab}=$groups{$s}->{label};
182 ## do the analysis chore
183 });
184 };
185
186 ## the group for alignment is the current group in the group list.
187 ## note that the key for the %widget hash identifies the analysis
188 ## chore. this will make searches through this hash much easier in
189 ## other parts Athena -- it's a good convention to stick to
190 $frame -> Button(-text=>"Other: ",
191 -foreground=>$config{colors}{activehighlightcolor},
192 -activeforeground=>$config{colors}{activehighlightcolor},
193 @label_button,
194 -command=>[\&Echo, "The group currently selected for foobarication."]
195 )
196 -> grid(-row=>1, -column=>0, -sticky=>'e', -ipady=>2);
197 $widget{foobar_unknown} = $frame -> Label(-text=>$groups{$current}->{label},
198 -foreground=>$config{colors}{button})
199 -> grid(-row=>1, -column=>1, -sticky=>'w', -pady=>2, -padx=>2);
200
201
202
203 ## this is a spacer frame which pushes all the widgets to the top
204 $foobar -> Frame(-background=>$config{colors}{darkbackground})
205 -> pack(-side=>'bottom', -expand=>1, -fill=>'both');
206
207 ## at the bottom of the frame, there are full width buttons for
208 ## returning to the main view and for going to the appropriate
209 ## document section
210 $foobar -> Button(-text=>'Return to the main window', @button_list,
211 -background=>$config{colors}{background2},
212 -activebackground=>$config{colors}{activebackground2},
213 -command=>sub{## clean-up chores, for instance you
214 ## may need to toggle update_bkg or
215 ## one of the others
216
217 ## restore the plot ranges is they
218 ## were changed
219 ## finally restore the main view
220 &reset_window($foobar, "foobarication", 0);
221 #&reset_window($foobar, "foobarication", \@save);
222 })
223 -> pack(-side=>'bottom', -fill=>'x');
224 ## help button
225 $foobar -> Button(-text=>'Document section: foobaricating data', @button_list,
226 -command=>sub{Echo("Display this document section");
227 ## get rid of the preceding line
228 ## and uncomment the next line
229 ## pod_display("process::foobar.pod");
230 })
231 -> pack(-side=>'bottom', -fill=>'x', -pady=>4);
232
233
234 ## now begin setting up the widgets you need for your new analysis
235 ## feature
236
237 ## now a new frame for our two dummy widgets
238 $frame = $foobar -> Frame(-borderwidth=>2, -relief=>'sunken')
239 -> pack(-side=>'top', -fill=>'x');
240 $widget{foobar_string} = $frame -> Entry(-width=>20,
241 -textvariable=>\$foobar_params{string})
242 -> pack(-side=>'top');
243 $widget{foobar_boolean} = $frame -> Checkbutton(-text=>"Do super foobarication",
244 -variable=>\$foobar_params{boolean})
245 -> pack(-side=>'bottom');
246
247
248
249 ## do you need to run one of your analysis subroutines immediately?
250 ## now is a good time...
251
252 ## and finally....
253 $top -> update;
254
255 };
256
257
258 ## END OF DEMO SUBSECTION
259 ##########################################################################################