Debian Codegraph @

athena_parts/prefs.pl

raw
1 ## -*- cperl -*-
2 ##
3 ## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel
4 ##
5 ## This section of the code contains subroutines associated with
6 ## Athena's preferences dialog
7
8
9 sub prefs {
10
11 my %prefs_params = ();
12 &read_config(\%prefs_params);
13
14 #$Data::Dumper::Indent = 2;
15 #print Data::Dumper->Dump([\%prefs_params], [qw/prefs_params/]);
16 #$Data::Dumper::Indent = 0;
17
18
19
20 $fat_showing = 'prefs';
21 $hash_pointer = \%prefs_params;
22 map {$_ -> configure(-state=>'disabled')}
23 ($data_menu, $merge_menu, $anal_menu, $settings_menu);
24 $fat -> packForget;
25 my $prefs = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3)
26 -> pack(-fill=>'both', -expand=>1);
27 #$prefs -> packPropagate(0);
28 $which_showing = $prefs;
29
30 $prefs_params{save} = 0;
31 $prefs -> Label(-text=>"Edit Preferences",
32 -font=>$config{fonts}{large},
33 -foreground=>$config{colors}{activehighlightcolor})
34 -> pack(-side=>'top', -fill=>'x', -anchor=>'w');
35
36 my $labframe = $prefs -> LabFrame(-label=>'All parameters',
37 -foreground=>$config{colors}{activehighlightcolor},
38 -labelside=>'acrosstop')
39 -> pack(-side=>'left', -expand=>1, -fill=>'both');
40 my $tree;
41 $tree = $labframe -> Scrolled('Tree',
42 -scrollbars => 'se',
43 -width => 15,
44 -background => $config{colors}{hlist},
45 -browsecmd => sub{&browse_variable($tree, \%prefs_params)},
46 )
47 -> pack(-expand=>1, -fill=>'both');
48 $tree->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background},
49 ($is_windows) ? () : (-width=>8));
50 $tree->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background},
51 ($is_windows) ? () : (-width=>8));
52
53 $prefs -> Button(-text=>'Return to the main window', @button_list,
54 -background=>$config{colors}{background2},
55 -activebackground=>$config{colors}{activebackground2},
56 -command=>sub{
57 my $response = 'No';
58 if ($prefs_params{save}) {
59 my $message = ($prefs_params{save} eq -1) ?
60 "You have applied the preferences, but have not saved them for future sessions. Would you like to save your new preference selections?" :
61 "Would you like to apply and save your new preference selections?";
62 my $dialog =
63 $top -> Dialog(-bitmap => 'questhead',
64 -text => $message,
65 -title => 'Athena: preferences...',
66 -buttons => ["Apply", "Apply and save", "Return"],
67 -default_button => 'Return');
68 $response = $dialog->Show(-popover => 'cursor');
69 }
70 &prefs_apply(\%prefs_params) if ($response =~ /Apply/);
71 &prefs_save(\%prefs_params) if ($response =~ /Save/);
72 &reset_window($prefs, "preferences", 0);
73 Echo("Your preferences were applied and saved to $personal_rcfile")
74 if ($response =~ /(Apply|Save)/);
75 })
76 -> pack(-side=>'bottom', -fill=>'x');
77 $prefs_params{future} = $prefs -> Button(-text=>'Save changes for future sessions', @button_list,
78 -state=>'disabled',
79 -command=>sub{
80 &prefs_apply(\%prefs_params); &prefs_save(\%prefs_params);
81 $prefs_params{apply} ->configure(-state=>'disabled');
82 $prefs_params{future}->configure(-state=>'disabled');
83 } )
84 -> pack(-side=>'bottom', -fill=>'x');
85 $widget{prefs_future} = $prefs_params{future};
86 $prefs_params{apply} = $prefs -> Button(-text=>'Apply changes to this session', @button_list,
87 -state=>'disabled',
88 -command=>sub{
89 &prefs_apply(\%prefs_params);
90 $prefs_params{apply} ->configure(-state=>'disabled');
91 } )
92 -> pack(-side=>'bottom', -fill=>'x');
93 $widget{prefs_apply} = $prefs_params{apply};
94
95
96
97 my $frame = $prefs -> Frame(-relief=>'flat')
98 -> pack(-side=>'right', -expand=>1, -fill=>'both');
99
100 $prefs_params{parameter_label} = $frame -> Label(-text=>'Parameter: ',
101 -font=>$config{fonts}{small},
102 -justify=>'right',
103 -foreground=>$config{colors}{activehighlightcolor})
104 -> grid(-row=>0, -column=>0, -sticky=>'e');
105 $prefs_params{parameter} = $frame -> Label(-text=>'',
106 -font=>$config{fonts}{small},
107 -justify=>'left')
108 -> grid(-row=>0, -column=>1, -sticky=>'ew');
109 $frame -> Label(-text=>'Type: ',
110 -font=>$config{fonts}{small},
111 -justify=>'right',
112 -foreground=>$config{colors}{activehighlightcolor})
113 -> grid(-row=>1, -column=>0, -sticky=>'e');
114 $prefs_params{type} = $frame -> Label(-text=>'',
115 -font=>$config{fonts}{small},
116 -width=>1,
117 -justify=>'left')
118 -> grid(-row=>1, -column=>1, -sticky=>'ew');
119 $frame -> Label(-text=>"Athena's Default: ",
120 -font=>$config{fonts}{small},
121 -justify=>'right',
122 -foreground=>$config{colors}{activehighlightcolor})
123 -> grid(-row=>2, -column=>0, -sticky=>'e');
124 $prefs_params{default} = $frame -> Label(-text=>'',
125 -font=>$config{fonts}{small},
126 -justify=>'left')
127 -> grid(-row=>2, -column=>1, -sticky=>'ew');
128 $frame -> Label(-text=>'Value: ',
129 -justify=>'right',
130 -foreground=>$config{colors}{activehighlightcolor})
131 -> grid(-row=>3, -column=>0, -sticky=>'e');
132 $prefs_params{values} = $frame -> Label(-text=>'',
133 -font=>$config{fonts}{small},
134 -justify=>'left')
135 -> grid(-row=>3, -column=>1, -sticky=>'ew');
136 $labframe = $frame -> LabFrame(-label=>'Description',
137 -foreground=>$config{colors}{activehighlightcolor},
138 -labelside=>'acrosstop')
139 -> grid(-row=>4, -column=>0, -columnspan=>2, -sticky=>'nsew',);
140
141 $prefs_params{description} = $labframe -> Scrolled('ROText', -scrollbars=>'oe',
142 -wrap=>'word',
143 -font=>$config{fonts}{small},
144 -width=>1, -height=>18)
145 -> pack(-expand=>1, -fill=>'both');
146 $prefs_params{description} ->
147 Subwidget("yscrollbar") ->
148 configure(-background=>$config{colors}{background},
149 ($is_windows) ? () : (-width=>8));
150 $widget{prefs_all} =
151 $frame -> Button(-text=>"Set ALL params to Athena's defaults", @button_list,
152 -command=>[\&prefs_restore_all, \%prefs_params, $tree])
153 -> grid(-row=>5, -column=>0, -columnspan=>2, -sticky=>'ew');
154 disable_mouse3($prefs_params{description}->Subwidget('rotext'));
155 $prefs_params{description} -> tagConfigure('descr', -rmargin=>2, -spacing1=>1,
156 -lmargin1=>2, -lmargin2=>2,);
157 $prefs_params{description} -> tagConfigure('warn', -rmargin=>2, -spacing1=>1,
158 -lmargin1=>2, -lmargin2=>2,
159 -foreground=>'red3',);
160 $prefs_params{description} -> tagConfigure('units', -rmargin=>2, -spacing1=>1,
161 -lmargin1=>2, -lmargin2=>2,
162 -foreground=>'green4',);
163 $prefs_params{description} -> tagConfigure('restart', -rmargin=>2, -spacing1=>1,
164 -lmargin1=>2, -lmargin2=>2,
165 -foreground=>'darkviolet',);
166
167 foreach my $s (@{$prefs_params{order}}) {
168 $tree -> add($s, -text=>$s);
169 foreach my $v (@{$prefs_params{$s}{order}}) {
170 my $this = $s.".".$v;
171 $tree -> add($this, -text=>$v);
172 $tree -> setmode($this, 'none');
173 $prefs_params{$s}{$v}{new} = $config{$s}{$v};
174 };
175 $tree -> setmode($s, 'close');
176 $tree -> close($s);
177
178 };
179 $tree->autosetmode();
180
181 ## save, so it can be unbound if changed (this is the global variable)
182 $user_key = $config{general}{user_key};
183
184 $top -> update;
185 };
186
187
188 sub browse_variable {
189 my ($tree, $rhash) = @_;
190 my $this = $tree->infoAnchor;
191 return unless $this;
192 my ($s, $v) = split(/\./, $this);
193
194 my $frame = $$rhash{values}->parent;
195 return unless $s;
196 unless ($v) {
197 $$rhash{parameter_label} -> configure(-text=>"Section: ");
198 $$rhash{parameter} -> configure(-text=>$s);
199 $$rhash{type} -> configure(-text=>"");
200 $$rhash{default} -> configure(-text=>"");
201 $$rhash{description} -> delete(qw(1.0 end));
202 $$rhash{description} -> insert('end', $$rhash{$s}{description}, 'descr');
203 $$rhash{default} -> gridForget();
204 $$rhash{default} = $frame -> Label(-text=>'', -justify=>'left')
205 -> grid(-row=>2, -column=>1, -padx=>2, -sticky=>'ew');
206 $$rhash{values} -> gridForget();
207 $$rhash{values} = $frame -> Label(-text=>'',)
208 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
209 #$tree -> open($this) if ($tree->getmode($this) eq 'open');
210 return;
211 };
212
213 $$rhash{values} -> gridForget();
214 ##$$rhash{values} -> bind('<Any-KeyPress>');
215 $$rhash{parameter_label} -> configure(-text=>"Parameter: ");
216 $$rhash{parameter} -> configure(-text=>$v);
217 $$rhash{type} -> configure(-text=>$$rhash{$s}{$v}{type});
218 $$rhash{default} -> gridForget();
219 $$rhash{default} = $frame -> Button(-text=>"", -borderwidth=>1,
220 -command=>sub{
221 ## restore the default value
222 $$rhash{$s}{$v}{new} = $$rhash{$s}{$v}{default};
223 $$rhash{$s}{$v}{new} = $$rhash{$s}{$v}{windows}
224 if (exists $$rhash{$s}{$v}{windows} and $is_windows);
225 if ($$rhash{$s}{$v}{type} eq 'boolean') {
226 $$rhash{$s}{$v}{new} = ($$rhash{$s}{$v}{new} eq 'true') ? $$rhash{$s}{$v}{onvalue} : 0;
227 } elsif ($$rhash{$s}{$v}{type} eq 'keypress') {
228 $$rhash{values} -> delete(0, 'end');
229 $$rhash{values} -> insert('end', $$rhash{$s}{$v}{new});
230 };
231 $$rhash{save} = 1;
232 $$rhash{apply} ->configure(-state=>'normal');
233 $$rhash{future}->configure(-state=>'normal');
234 ## and make sure it is displayed properly
235 $tree -> KeyboardBrowse;
236 })
237 -> grid(-row=>2, -column=>1, -padx=>2, -sticky=>'ew');
238 if (exists $$rhash{$s}{$v}{windows} and $is_windows) {
239 $$rhash{default} -> configure(-text=>$$rhash{$s}{$v}{windows});
240 } else {
241 $$rhash{default} -> configure(-text=>$$rhash{$s}{$v}{default});
242 };
243 #$$rhash{parameter} -> configure(-text=>$v);
244 $$rhash{description} -> delete(qw(1.0 end));
245 $$rhash{description} -> insert('end', $$rhash{$s}{$v}{description}, 'descr');
246 if ($s eq 'fonts') {
247 my $rcfile = $groups{"Default Parameters"} -> find('athena', 'rc_personal');
248 $$rhash{description} -> insert('end', "\n\nFonts cannot currently be changed interactively. You will need to edit $rcfile by hand.", 'warn');
249 } elsif ($$rhash{$s}{$v}{type} eq 'color') {
250 $$rhash{description} -> insert('end', "\n\nPress the colored \"Value\" button to change this color.", 'descr');
251 } elsif ($$rhash{$s}{$v}{type} eq 'regex') {
252 $$rhash{description} -> insert('end', "\n\nThis parameter must be a valid Perl regular expression.", 'warn');
253 };
254
255 ##$$rhash{description} -> insert('end', "\n\nMost color changes (with the exception of the \"current\" color) do not take effect until the next time Athena is started. That will be fixed in a future version of Athena.", 'descr')
256 ## if ($s eq 'colors');
257
258 $$rhash{description} -> insert('end', "\n\nThe units of this parameter are $$rhash{$s}{$v}{units}.", 'units')
259 if (exists $$rhash{$s}{$v}{units});
260 $$rhash{description} -> insert('end', "\n\nYou must restart Athena to see the effect of changing this parameter.", 'restart')
261 if (exists $$rhash{$s}{$v}{restart} and (not (($s eq 'fonts') or ($$rhash{$s}{$v}{type} eq 'font'))));
262
263 $$rhash{description} -> insert('end', "\n\nPress the \"Default\" button to restore Athena's default value for this variable.", 'descr');
264
265 SWITCH: {
266 ($$rhash{$s}{$v}{type} eq 'string') and do {
267 $$rhash{values} = $frame -> Entry(-width=>12, -validate=>'key',
268 -validatecommand=>[\&prefs_string, join(".", $s,$v), $rhash])
269 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
270 $$rhash{values} -> configure(-validate=>'none');
271 $$rhash{values} -> insert('end', $$rhash{$s}{$v}{new});
272 $$rhash{values} -> configure(-validate=>'key');
273 last SWITCH;
274 };
275 ($$rhash{$s}{$v}{type} eq 'regex') and do {
276 $$rhash{values} = $frame -> Entry(-width=>12, -validate=>'key',
277 -validatecommand=>[\&prefs_string, join(".", $s,$v), $rhash])
278 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
279 $$rhash{values} -> configure(-validate=>'none');
280 $$rhash{values} -> insert('end', $$rhash{$s}{$v}{new});
281 $$rhash{values} -> configure(-validate=>'key');
282 last SWITCH;
283 };
284 ($$rhash{$s}{$v}{type} eq 'real') and do {
285 $$rhash{values} = $frame -> Entry(-width=>12, -validate=>'key',
286 -validatecommand=>[\&prefs_real, join(".", $s,$v), $rhash])
287 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
288 $$rhash{values} -> configure(-validate=>'none');
289 $$rhash{values} -> insert('end', $$rhash{$s}{$v}{new});
290 $$rhash{values} -> configure(-validate=>'key');
291 last SWITCH;
292 };
293 ## need to set the save flag
294 ($$rhash{$s}{$v}{type} eq 'positive integer') and do {
295 $$rhash{values} = $frame -> NumEntry(-width => 4,
296 -orient => 'horizontal',
297 -foreground => $config{colors}{foreground},
298 -textvariable => \$$rhash{$s}{$v}{new},
299 -minvalue => $$rhash{$s}{$v}{minint}||0,
300 -maxvalue => $$rhash{$s}{$v}{maxint},
301 -browsecmd => [\&prefs_modified, $rhash],
302 -command => [\&prefs_modified, $rhash],
303 )
304 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'w');
305 $$rhash{values} -> configure( -value=>$$rhash{$s}{$v}{new});
306 ## crufty solution to the lack of a callback for NumEntry
307 $$rhash{apply} -> configure(-state=>'normal');
308 $$rhash{future} -> configure(-state=>'normal');
309 last SWITCH;
310 };
311 ($$rhash{$s}{$v}{type} eq 'list') and do {
312 my @vals = split(" ", $$rhash{$s}{$v}{values});
313 $$rhash{values} = $frame -> Optionmenu(-font=>$config{fonts}{small},
314 -borderwidth=>1,
315 -textvariable=>\$$rhash{$s}{$v}{new}
316 )
317 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
318 foreach my $vl (@vals) {
319 $$rhash{values} -> command(-label => $vl,
320 -command=>sub{$$rhash{$s}{$v}{new}=$vl;
321 $$rhash{save} = 1;
322 $$rhash{apply} ->configure(-state=>'normal');
323 $$rhash{future}->configure(-state=>'normal');
324 } );
325 };
326 last SWITCH;
327 };
328 ($$rhash{$s}{$v}{type} eq 'boolean') and do {
329 $$rhash{values} = $frame -> Checkbutton(-text=>$v,
330 -onvalue=>$$rhash{$s}{$v}{onvalue},
331 -offvalue=>$$rhash{$s}{$v}{offvalue}||0,
332 -selectcolor=> $config{colors}{single},
333 -variable=>\$$rhash{$s}{$v}{new},
334 -command=>
335 sub{
336 $$rhash{apply} ->configure(-state=>'normal');
337 $$rhash{future}->configure(-state=>'normal');
338 $$rhash{save} = 1;
339 })
340 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
341 last SWITCH;
342 };
343 ($$rhash{$s}{$v}{type} eq 'keypress') and do {
344 $$rhash{values} = $frame -> Entry(-width=>12, -justify=>'center')
345 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
346 $$rhash{values} -> insert('end', $$rhash{$s}{$v}{new});
347 $$rhash{values} -> bind('<Any-KeyPress>' => sub
348 {
349 my($c) = @_;
350 my $e = $c->XEvent;
351 my $keysym = $e->K;
352 $$rhash{$s}{$v}{new} = $keysym;
353 $$rhash{values} -> delete(0, 'end');
354 $$rhash{values} -> insert('end', $keysym);
355 $$rhash{save} = 1;
356 $$rhash{apply} ->configure(-state=>'normal');
357 $$rhash{future}->configure(-state=>'normal');
358 });
359 last SWITCH;
360 };
361 ($$rhash{$s}{$v}{type} eq 'color') and do {
362 my $color = $$rhash{$s}{$v}{new};
363 my ($r, $g, $b) = $frame -> rgb($color);
364 #print join(" ", $color, $r, $g, $b), $/;
365 my $acolor = sprintf("#%4.4x%4.4x%4.4x", int($r*0.85), int($g*0.85), int($b*0.85));
366 ($acolor = "#300030003000") if ($acolor eq "#000000000000");
367 #print $acolor, $/;
368 $$rhash{values} = $frame -> Button(-background=>$color,
369 -activebackground=>$acolor,
370 -borderwidth=>1,
371 -command=>sub{
372 my $color = "";
373 #$top->Busy(-recurse=>1);
374 $color = $$rhash{values}->chooseColor(-initialcolor=>$$rhash{$s}{$v}{new});
375 #$top->Unbusy;
376 return unless defined($color);
377 $$rhash{values}->configure(-background=>$color,
378 -activebackground=>$color);
379 $$rhash{$s}{$v}{new}=$color;
380 $$rhash{save} = 1;
381 $$rhash{apply} ->configure(-state=>'normal');
382 $$rhash{future}->configure(-state=>'normal');
383 })
384 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
385 last SWITCH;
386 };
387 ($$rhash{$s}{$v}{type} eq 'font') and do {
388 $$rhash{values} = $frame -> Button(-foreground=>'black',
389 -borderwidth=>1,
390 -text=>'abc ABC 123',
391 -font=>$$rhash{$s}{$v}{new},
392 -command=>sub{Error("Changing fonts interactively is not yet supported. You can edit ".$groups{'Default Parameters'} -> find('athena', 'rc_personal')." by hand.")})
393 -> grid(-row=>3, -column=>1, -padx=>2, -sticky=>'ew');
394 last SWITCH;
395 };
396
397 };
398 };
399
400
401 ## validate command for a string type variable (no restrictions)
402 sub prefs_string {
403 my ($k, $hash, $entry) = (shift, shift, shift);
404 my ($s, $v) = split(/\./, $k);
405 $$hash{$s}{$v}{new} = $entry;
406 $$hash{save} = 1;
407 $$hash{apply} ->configure(-state=>'normal');
408 $$hash{future}->configure(-state=>'normal');
409 #print join(" ", ">>>", $s, $v, $$hash{save}, $$hash{$s}{$v}, $/);
410 return 1;
411 };
412 sub prefs_modified {
413 my $hash = shift;
414 $$hash{save} = 1;
415 $$hash{apply} ->configure(-state=>'normal');
416 $$hash{future}->configure(-state=>'normal');
417 return 1;
418 };
419
420 ## validate command for a real type variable (must be a +/-real)
421 sub prefs_real {
422 my ($k, $hash, $entry) = (shift, shift, shift);
423 my ($s, $v) = split(/\./, $k);
424 #print join(" ", $s, $v, $entry, $hash, $/);
425 ($entry =~ /^\s*$/) and ($entry = 0); # error checking ...
426 ($entry =~ /^\s*-$/) and return 1; # error checking ...
427 ($entry =~ /^\s*-?(\d+\.?\d*|\.\d+)\s*$/) or return 0;
428 $$hash{$s}{$v}{new} = $entry;
429 $$hash{save} = 1;
430 $$hash{apply} ->configure(-state=>'normal');
431 $$hash{future}->configure(-state=>'normal');
432 #print join(" ", ">>>", $s, $v, $$hash{save}, $$hash{$s}{$v}, $/);
433 return 1;
434 };
435
436 sub prefs_restore_all {
437 my ($rhash, $tree) = @_;
438
439 my $message = "Are you sure that you wish to restore ALL the default values, overwriting any configuration you may have already made to Athena? Doing so will only restore them within this dialog. You will then need to click the buttons below to apply or save the default values.";
440 my $dialog =
441 $top -> Dialog(-bitmap => 'questhead',
442 -text => $message,
443 -title => 'Athena: preferences...',
444 -buttons => [qw/Yes No/],
445 -default_button => 'Yes');
446 my $response = $dialog->Show();
447 unless ($response eq 'Yes') {
448 return;
449 };
450 foreach my $s (@{$$rhash{order}}) {
451 foreach my $v (@{$$rhash{$s}{order}}) {
452 $$rhash{$s}{$v}{new} = $$rhash{$s}{$v}{default};
453 $$rhash{$s}{$v}{new} = $$rhash{$s}{$v}{windows}
454 if (exists $$rhash{$s}{$v}{windows} and $is_windows);
455 if ($$rhash{$s}{$v}{type} eq 'boolean') {
456 $$rhash{$s}{$v}{new} = ($$rhash{$s}{$v}{new} eq 'true') ? $$rhash{$s}{$v}{onvalue} : 0;
457 };
458 };
459 };
460 $$rhash{save} = 1;
461 $$rhash{apply} ->configure(-state=>'normal');
462 $$rhash{future}->configure(-state=>'normal');
463 ## and make sure it is displayed properly
464 $tree -> KeyboardBrowse;
465 Echo("Restored ALL parameter defaults. Click the apply or save buttons to use these defaults.");
466 };
467
468
469 sub prefs_apply {
470 my $rhash = $_[0];
471
472 my %old = (charsize => $config{plot}{charsize},
473 charfont => $config{plot}{charfont},
474 mru_display => $config{general}{mru_display},
475 );
476
477 foreach my $s (@{$$rhash{order}}) {
478 foreach my $v (@{$$rhash{$s}{order}}) {
479 $config{$s}{$v} = $$rhash{$s}{$v}{new};
480 };
481 };
482 $$rhash{save} = -1;
483
484 ## certain parameters need to take effect immediately and so require
485 ## some special care
486
487 ## set various plotting defaults
488 my @fclist;
489 map {push @fclist, "color".$_, $config{plot}{'c'.$_}} (0 ..9);
490 my $screen = ", fg=$config{plot}{fg}, bg=$config{plot}{bg}, ";
491 $screen .= ($config{plot}{showgrid}) ? "grid, gridcolor=\"$config{plot}{grid}\"" : "nogrid";
492 $setup -> SetDefault(screen=>$screen,
493 @fclist,
494 'showmarkers', $config{plot}{showmarkers},
495 'marker', $config{plot}{marker},
496 'markersize', $config{plot}{markersize},
497 'markercolor', $config{plot}{markercolor},
498 #'indicator', $config{plot}{indicator},
499 'indicatorcolor', $config{plot}{indicatorcolor},
500 'indicatorline', $config{plot}{indicatorline},
501 'bordercolor', $config{plot}{bordercolor},
502 'borderline', $config{plot}{borderline},
503 'linetypes', $config{plot}{linetypes},
504 'interp', $config{general}{interp},);
505 &set_key_params;
506 ## set default analysis parameter values
507 $setup -> SetDefault(bkg_kw => $config{bkg}{kw},
508 bkg_rbkg => $config{bkg}{rbkg},
509 bkg_pre1 => $config{bkg}{pre1},
510 bkg_pre2 => $config{bkg}{pre2},
511 bkg_nor1 => $config{bkg}{nor1},
512 bkg_nor2 => $config{bkg}{nor2},
513 bkg_nnorm => $config{bkg}{nnorm},
514 bkg_spl1 => $config{bkg}{spl1},
515 bkg_spl2 => $config{bkg}{spl2},
516 bkg_nclamp => $config{bkg}{nclamp},
517 bkg_clamp1 => $config{bkg}{clamp1},
518 bkg_clamp2 => $config{bkg}{clamp2},
519 fft_arbkw => $config{fft}{arbkw},
520 fft_dk => $config{fft}{dk},
521 fft_win => $config{fft}{win},
522 fft_kmin => $config{fft}{kmin},
523 fft_kmax => $config{fft}{kmax},
524 fft_pc => $config{fft}{pc},
525 bft_dr => $config{bft}{dr},
526 bft_win => $config{bft}{win},
527 bft_rmin => $config{bft}{rmin},
528 bft_rmax => $config{bft}{rmax},
529 );
530 ## handle general.listside parameter
531 &swap_panels unless
532 (grep {$_ eq $config{general}{listside}} ($skinny -> packInfo()));
533 ## deal with the toggle in the Merge menu
534 $merge_weight = ($config{merge}{merge_weight} eq 'u') ? 'Weight by importance' : 'Weight by chi_noise';
535 ## turn on/off the dispersive data conversion
536 $data_menu -> menu -> entryconfigure(3, -state=>($config{pixel}{do_pixel_check}) ?
537 'normal' : 'disabled');
538 ## handle general.projectbar parameter
539 #if ($config{general}{projectbar} eq 'none') {
540 # $projectbar -> packForget;
541 #} elsif ($config{general}{projectbar} eq 'file') {
542 # $project_label -> configure(-textvariable=>\$project_name);
543 # $projectbar -> pack(-side=>"top", -anchor=>'nw', -fill=>'x', -after=>$menubar)
544 #};
545
546 ## bring the edge step widget up to date
547 $widget{bkg_step} -> configure(-increment=>$config{bkg}{step_increment});
548
549 ## make sure that the default plot style is up to date
550 foreach my $k (keys %plot_features) {
551 next unless ($k =~ /^[ekqr](_|ma|mi)/);
552 $plot_styles{default}{$k} = $plot_features{$k};
553 };
554 tied(%plot_styles) -> WriteConfig($groups{"Default Parameters"} -> find('athena', 'plotstyles'));
555 $plot_features{smoothderiv} =$config{plot}{smoothderiv};
556
557
558 ## user configured, user defined key sequences (yikes!)
559 my $this_key = "<Control-" . $config{general}{user_key} . ">";
560 my $old_key = "<Control-" . $user_key . ">";
561 $top -> bind($old_key, "");
562 $top -> bind($this_key => [\&keys_dispatch, 'control']);
563 $this_key = "<Meta-" . $config{general}{user_key} . ">";
564 $old_key = "<Meta-" . $user_key . ">";
565 $top -> bind($old_key, "");
566 $top -> bind($this_key => [\&keys_dispatch, 'meta']);
567 $this_key = "<Alt-" . $config{general}{user_key} . ">";
568 $old_key = "<Alt-" . $user_key . ">";
569 $top -> bind($old_key, "");
570 $top -> bind($this_key => [\&keys_dispatch, 'meta']);
571
572 &set_recent_menu if ($old{mru_display} ne $config{general}{mru_display});
573
574 ## add any special handling of configuration parameters here
575 $Ifeffit::Group::rmax_out = $config{fft}{rmax_out};
576 $groups{"Default Parameters"} -> dispose("plot(charsize=$config{plot}{charsize}, charfont=$config{plot}{charfont})", $dmode)
577 if (($old{charsize} != $config{plot}{charsize}) or ($old{charfont} != $config{plot}{charfont}));
578
579 foreach (qw(slight weak medium strong rigid)) {
580 $groups{"Default Parameters"} -> set_clamp(ucfirst($_), $config{clamp}{$_});
581 };
582
583 Echo("Applied new preferences to current session.");
584 };
585
586 sub prefs_save {
587 my $rhash = $_[0];
588 rename $personal_rcfile, $personal_rcfile.".bak";
589 my $config_ref = tied %config;
590 $config_ref -> WriteConfig($personal_rcfile);
591 $$rhash{save} = 0;
592 Echo("Saved preferences to \"$personal_rcfile\"");
593 };
594
595
596 sub read_config {
597 my $rhash = $_[0];
598 my $config_file = $groups{"Default Parameters"} -> find('athena', 'config');
599 ##$config_file = "Ifeffit/lib/athena.config";
600 return -1 unless (-e $config_file);
601
602 $$rhash{order} = [];
603 my ($current_section, $current_variable) = ("", "");
604 Echo("Reading master configuration file ...");
605 open C, $config_file or die "could not open $config_file for reading\n";
606 while (<C>) {
607 next if (/^\s*$/); # blank line
608 next if (/^\s*\#/); # comment line
609 chomp;
610 SWITCH: {
611 ## recognize a new section of variables
612 (/^section=/) and do {
613 my @line = split(/=/, $_);
614 push @{$$rhash{order}}, $line[1];
615 $$rhash{$line[1]} = {};
616 $current_section = $line[1];
617 last SWITCH;
618 };
619 ## read the description of the current section of variables
620 (/^section_description/) and do {
621 $$rhash{$current_section}{description} = "";
622 my $next = <C>;
623 while ($next !~ /^\s*$/) {
624 chomp $next;
625 $$rhash{$current_section}{description} .= substr($next, 1);
626 $next = <C>;
627 };
628 $$rhash{$current_section}{description} =
629 substr($$rhash{$current_section}{description}, 1);
630 last SWITCH;
631 };
632 ## recognize a new variable
633 (/^variable=/) and do {
634 my @line = split(/=/, $_);
635 push @{$$rhash{$current_section}{order}}, $line[1];
636 $$rhash{$current_section}{$line[1]} = {};
637 $current_variable = $line[1];
638 last SWITCH;
639 };
640 ## read the description of the current variable
641 (/^description/) and do {
642 $$rhash{$current_section}{$current_variable}{description} = "";
643 my $next = <C>;
644 while ($next !~ /^\s*$/) {
645 chomp $next;
646 $next =~ s/^ *\.\s*$/\n\n\n/;
647 $next =~ s/^ *\./\n\n /;
648 $$rhash{$current_section}{$current_variable}{description} .= substr($next, 1);
649 $next = <C>;
650 };
651 $$rhash{$current_section}{$current_variable}{description} =
652 substr($$rhash{$current_section}{$current_variable}{description}, 1);
653 last SWITCH;
654 };
655 ## the type (i.e. string, boolean, etc) of the current variable
656 (/^type=/) and do {
657 my @line = split(/=/, $_);
658 ($line[1] = " ") if ($line[1] eq '""');
659 $$rhash{$current_section}{$current_variable}{type} = $line[1];
660 last SWITCH;
661 };
662 ## default value
663 (/^default=/) and do {
664 my @line = split(/=/, $_);
665 ($line[1] = " ") if ($line[1] eq '""');
666 $$rhash{$current_section}{$current_variable}{default} = $line[1];
667 last SWITCH;
668 };
669 ## list values
670 (/^values=/) and do {
671 my @line = split(/=/, $_);
672 ($line[1] = " ") if ($line[1] eq '""');
673 $$rhash{$current_section}{$current_variable}{values} = $line[1];
674 last SWITCH;
675 };
676 ## special treatment for windows
677 (/^windows=/) and do {
678 my @line = split(/=/, $_);
679 ($line[1] = " ") if ($line[1] eq '""');
680 $$rhash{$current_section}{$current_variable}{windows} = $line[1];
681 last SWITCH;
682 };
683 ## max value for a positive integer
684 (/^maxint=/) and do {
685 my @line = split(/=/, $_);
686 ($line[1] = " ") if ($line[1] eq '""');
687 $$rhash{$current_section}{$current_variable}{maxint} = $line[1];
688 last SWITCH;
689 };
690 ## min value for a positive integer
691 (/^minint=/) and do {
692 my @line = split(/=/, $_);
693 ($line[1] = " ") if ($line[1] eq '""');
694 $$rhash{$current_section}{$current_variable}{minint} = $line[1];
695 last SWITCH;
696 };
697 ## boolean for whether a font may be variable width
698 (/^variable_width=/) and do {
699 my @line = split(/=/, $_);
700 ($line[1] = " ") if ($line[1] eq '""');
701 $$rhash{$current_section}{$current_variable}{variable_width} = $line[1];
702 last SWITCH;
703 };
704 ## value for boolean true
705 (/^onvalue=/) and do {
706 my @line = split(/=/, $_);
707 ($line[1] = " ") if ($line[1] eq '""');
708 $$rhash{$current_section}{$current_variable}{onvalue} = $line[1];
709 last SWITCH;
710 };
711 ## value for boolean false if not 0
712 (/^offvalue=/) and do {
713 my @line = split(/=/, $_);
714 ($line[1] = " ") if ($line[1] eq '""');
715 $$rhash{$current_section}{$current_variable}{offvalue} = $line[1];
716 last SWITCH;
717 };
718 ## restart required
719 (/^restart=/) and do {
720 my @line = split(/=/, $_);
721 ($line[1] = 0) if ($line[1] eq '""');
722 $$rhash{$current_section}{$current_variable}{restart} = $line[1];
723 last SWITCH;
724 };
725 ## parameter units
726 (/^units=/) and do {
727 my @line = split(/=/, $_);
728 ($line[1] = " ") if ($line[1] eq '""');
729 $$rhash{$current_section}{$current_variable}{units} = $line[1];
730 last SWITCH;
731 };
732 ## callback string for list or boolean
733 (/^callback=/) and do {
734 my @line = split(/=/, $_);
735 ($line[1] = " ") if ($line[1] eq '""');
736 $$rhash{$current_section}{$current_variable}{callback} = $line[1];
737 last SWITCH;
738 };
739 };
740 };
741
742 close C;
743 Echo("Reading master configuration file ... done!");
744
745 };