File: Config.pm

package info (click to toggle)
horae 066-3
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 17,272 kB
  • ctags: 1,656
  • sloc: perl: 64,718; lisp: 744; sh: 82; makefile: 67; ansic: 35
file content (658 lines) | stat: -rwxr-xr-x 22,555 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/usr/bin/perl -w
######################################################################
## TkAtoms configuration module for Atoms 3.0beta9
##                                     copyright (c) 1999 Bruce Ravel
##                                          ravel@phys.washington.edu
##                            http://feff.phys.washington.edu/~ravel/
##
##	  The latest version of Atoms can always be found at
##	    http://feff.phys.washington.edu/~ravel/atoms/
##
## -------------------------------------------------------------------
##     All rights reserved. This program is free software; you can
##     redistribute it and/or modify it under the same terms as Perl
##     itself.
##
##     This program is distributed in the hope that it will be useful,
##     but WITHOUT ANY WARRANTY; without even the implied warranty of
##     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##     Artistic License for more details.
## -------------------------------------------------------------------
######################################################################

package Xray::Tk::Config;
use strict;
use vars qw($VERSION $cvs_info @ISA @EXPORT @EXPORT_OK);

require Exporter;

@ISA = qw(Exporter AutoLoader);
@EXPORT_OK = qw(atoms_config);
$cvs_info = '$Id: Config.pm,v 1.7 2001/09/20 17:54:19 bruce Exp $ ';
$VERSION = (split(' ', $cvs_info))[2] || 'pre_release';

use Tk;
use Tk::widgets qw/ColorEditor/;
my $is_windows = (($^O eq 'MSWin32') or ($^O eq 'cygwin'));

my (%values, %initial);
my @variables = (		## variables
		 ['write_to_pwd',      'boolean'],
		 ['prefer_feff_eight', 'boolean'],
		 ['always_write_feff', 'boolean'],
		 ['display_balloons',  'boolean'],
		 ['no_crystal_warnings',  'boolean'],
		 ['one_frame',         'boolean'],
		 #['convolve_dafs',     'boolean'],
		 ['never_ask_to_save', 'boolean'],
		 ['atoms_language',    'list', \&Xray::Atoms::available_languages],
		 ['absorption_tables', 'list', \&Xray::Absorption::available],
		 ['dafs_default',      'list', \&Xray::Absorption::scattering],
		 ['unused_modifier',   'list',
		  sub{return ('Shift', 'Alt', 'Control', 'Meta')}],
		 ['default_filepath',  'directory'],
		 #['plotting_hook',     'string'],
		 ['ADB_location',      'string'],
				## colors
		 ['foreground',      'colors'],
		 ['background',      'colors'],
		 ['trough',          'colors'],
		 ['entry',           'colors'],
		 ['label',           'colors'],
		 ['balloon',         'colors'],
		 ['button',          'colors'],
		 ['buttonActive',    'colors'],
		 ['radio',           'colors'],
		 ['sgbActive',       'colors'],
		 ['sgbGroup',        'colors'],
		 #['done',            'colors'],
		 ['todo',            'colors'],
		 ['plot',            'colors'],
				## fonts
		 ['f_balloon',         'fonts'],
		 ['f_label',           'fonts'],
		 ['f_menu',            'fonts'],
		 ['f_button',          'fonts'],
		 ['f_header',          'fonts'],
		 ['f_entry',           'fonts'],
		 ['f_sgb',             'fonts'],
		);


my @label_args = ('-justify', 'left', '-width', 17, '-anchor', 'w',
		  '-foreground', $::colors{label},
		  '-font', $::fonts{label}, );
my @menu_args = (-foreground=>$::colors{label},
		 -activeforeground=>$::colors{label},
		 -font=>$::fonts{menu}, );
my @entry_args  = (-background=>$::colors{entry},
		   -font=>$::fonts{entry},
		   -insertbackground=>$::colors{foreground}, );
my @button_args = (-foreground => $::colors{entry},
		   -background => $::colors{button},
		   -activeforeground => $::colors{entry},
		   -activebackground => $::colors{buttonActive},
		   -font=>$::fonts{button},);

my ($count_colors, $count_variables) = (0,0);
my $force_restore = 0;
my ($top, $notebook, $ce);	# some widgets
my %color_button;
my $max_var_rows = 7;

sub atoms_config {
  my $parent = $_[0];
  ##   if ($^O eq 'MSWin32') {
  ##     my $dialog = $parent -> DialogBox(-title=>'TkAtoms: warning',
  ## 				      -buttons=>['OK'],);
  ##     $dialog -> add("Label", qw/-padx .25c -pady .25c -text/,
  ## 		   "The preferences selector has a high probability of$/" .
  ## 		   "hanging Windows 95 and 98, so it is currently disabled.$/" .
  ## 		   "on all Windows platforms.  Sorry.  Something to$/" .
  ## 		   "look forward to...")
  ##       -> pack(-side=>'left');
  ##     $dialog -> Show;
  ##     return;
  ##   };
  if (not Exists $top) {
    $top = $parent -> Toplevel(-class=>'horae');
    $top -> iconbitmap('@'.File::Spec->catfile($Xray::Atoms::lib_dir, "tkatoms3.xbm"))
      unless $is_windows;
    $top ->resizable(0,0);
    $notebook = $top -> NoteBook(-backpagecolor=>$::colors{background},
				 -inactivebackground=>$::colors{background},);
    $top -> bind('<Control-d>' => \&dump_values);
    my %pages;
    ($count_colors, $count_variables) = (0,0);
    my @note_args = (-anchor=>'center',);
    foreach my $f0 ('variables', 'colors', 'fonts') {
      $pages{$f0}  = $notebook -> add($f0, -label=>$$::config{$f0}, @note_args);
    };
    $notebook->pack(-expand => 'y', -side => 'top');

    my $button_frame = $top -> Frame(-relief=>'ridge', '-border'=>2)
      -> pack(-side=>'bottom', -fill=>'x');
    my $save_button = $button_frame
      -> Button(-text=>$$::config{'save_values'}, @button_args,
		-command=>\&write_new_rcfile)
	-> pack(-side=>'left', -fill=>'x', -padx=>2, -pady=>2, );
    &::manage($save_button, "button");
    exists ($$::config{'save_values_help'}) and
      $::balloon -> attach($save_button, -msg=>$$::config{'save_values_help'});
    my $dismiss_button = $button_frame -> Button(-text=>$$::config{dismiss},
						 @button_args,
						 -command=>sub{
						   $top->withdraw})
      -> pack(-side=>'right', -fill=>'x', -padx=>2, -pady=>2);
    &::manage($dismiss_button, "button");
    exists ($$::config{'dismiss_help'}) and
      $::balloon -> attach($dismiss_button, -msg=>$$::config{'dismiss_help'});

    ## ----- set up page of colors ---------------------------------------
    my $top_frame = $pages{'colors'} ->
      Frame(-border=>2, -relief=>'ridge') ->
	pack(-side=>'top',-fill=>'x', -expand=>1);
    my $palette_button = $top_frame ->
      Button(-text=>$$::config{'set_palette'},
	     @button_args,
	     -command=>[\&atoms_set_palette,$parent])
	-> pack(-side=>'left');
    &::manage($palette_button, "button");
    exists ($$::config{'set_palette_help'}) and
      $::balloon -> attach($palette_button, -msg=>$$::config{'set_palette_help'});
    my $restore_button = $top_frame ->
      Button(-text=>$$::config{'restore'},
	     @button_args,
	     -command=>[\&reset_values,'colors'])
	-> pack(-side=>'left');
    &::manage($restore_button, "button");
    exists ($$::config{'restore_palette_help'}) and
      $::balloon -> attach($restore_button,
			   -msg=>$$::config{'restore_palette_help'});
    my $color_explain = $top_frame ->
      Label(#-width=>100,
	    -foreground=>$::colors{label},
	    -text=>$$::config{'explain_colors'}) ->
	      pack(-side=>'left');
    &::manage($color_explain, "label");
    my $color_frame = $pages{'colors'} -> Frame() -> pack(-side=>'right');
    $ce = $color_frame -> ColorSelect() -> pack();
    ## yipes!!!  Rearrange some stuff in the color selector
    ##push @::all_menus, (($ce->children())[3]->children())[0]->children();
    ($ce->children())[1] -> configure('-width'=>18);
    unless ($^O eq 'MSWin32') {
      ($ce->children())[5] -> configure('-length'=>'4c');
      ($ce->children())[7] -> configure('-length'=>'4c');
      ($ce->children())[9] -> configure('-length'=>'4c');
      ((($ce->children())[3]->children())[0]->children())[0]
	-> invoke('RGB color space');
    };
    ## need to load color selector widgets into all_ arrays (ugh!)
    my $color_list_frame = $pages{'colors'} ->
      Frame(-border=>1, -relief=>'groove') ->
	pack(-side=>'left');

    ## ----- set up page of variables ------------------------------------
    $top_frame = $pages{'variables'} ->
      Frame(-border=>2, -relief=>'ridge') ->
	pack(-side=>'top',-fill=>'x', -expand=>1, -anchor=>'n');
    my $variables_frame = $pages{'variables'} ->
      Frame(-border=>2, -relief=>'groove') ->
      pack(-side=>'left', -padx=>2, -pady=>2, -fill=>'y');

    my $set_button = $top_frame ->
      Button(-text=>$$::config{'set_variables'}, @button_args,
	     -command=>[\&::set_variables, \%values])
	-> pack(-side=>'left');
    &::manage($set_button, "button");
    exists ($$::config{'set_variables_help'}) and
      $::balloon -> attach($set_button, -msg=>$$::config{'set_variables_help'});

    $restore_button = $top_frame ->
      Button(-text=>$$::config{'restore'},
	     @button_args,
	     -command=>[\&reset_values,'variables'])
	-> pack(-side=>'left');
    &::manage($restore_button, "button");
    exists ($$::config{'restore_variables_help'}) and
      $::balloon -> attach($restore_button,
			   -msg=>$$::config{'restore_variables_help'});

    foreach my $v (@variables) {
      if ($v->[1] eq 'colors') {
	&add_color($color_list_frame, $v->[0]);
      } elsif ($v->[1] eq 'fonts') {
	&add_font($pages{'fonts'}, $v->[0]);
      } elsif ($v->[1] eq 'boolean') {
	&add_boolean($variables_frame, $v->[0]);
	++$count_variables;
      } elsif ($v->[1] eq 'directory') {
	&add_directory($variables_frame, $v->[0]);
	++$count_variables;
      } elsif ($v->[1] eq 'string') {
	&add_string($variables_frame, $v->[0]);
	++$count_variables;
      } elsif ($v->[1] eq 'list') {
	&add_list($variables_frame, $v->[0], $v->[2]);
	++$count_variables;
      };
    };


    ## ----- set up page of fonts ----------------------------------------
    my $label = $pages{'fonts'} ->
      Label(-text=>'Sorry.  No font configuration yet.')
	->pack();
    &::manage($label, "label");

    $top -> title($$::config{config_title});
    $top -> iconname($$::config{config_title});
    $top -> bind('<Control-q>' => sub{$top->destroy});
  } else {
    $top->deiconify;
    $top->raise;
  }
  foreach my $k (keys %values) {
    $initial{$k} = $values{$k};
  };
  return ($top, $notebook);
};


######################################################################
## subroutines for filling configuration notecards

sub display_name {
  my $name = $_[0];
  my @name = split(/_/, $name);
  ($name[0] =~ /^[fc]$/i) and shift @name;
  @name = map {ucfirst($_)} @name;
  return join(" ", @name);
};

sub add_list {
  my ($parent, $name, $r_function) = @_;
  my $this_row = $count_variables % $max_var_rows;
  my $col_add  = int($count_variables / $max_var_rows);
  $col_add &&= $col_add*3+1;
  my $current = $::meta{$name};
  $current = ucfirst($current);
  ($current eq 'Cl') and $current = 'CL';
  ($current eq 'Mcmaster') and $current = 'McMaster';
  $values{$name}  = $current;
  my $space = $parent -> Label(-text=>' ') ->
    grid(-row=>$this_row, -column=>0+$col_add, -sticky=>'w');
  my $label = $parent -> Label(-text=>&display_name($name), @label_args) ->
    grid(-row=>$this_row, -column=>1+$col_add, -sticky=>'w');
  &::manage($label, "label");
  exists ($$::config{$name}) and
    $::balloon -> attach($label, -msg=>$$::config{$name});
  my $menu = $parent
    -> Optionmenu(-textvariable     => \$current,
		  -background       => $::colors{entry},
		  -activeforeground => $::colors{label},
		  -activebackground => $::colors{entry},
		  -width=>10, -font=>$::fonts{label},
		  -relief=>'groove')
      -> grid(-row=>$this_row, -column=>2+$col_add, -sticky=>'we');
  &::manage($menu, "menu");
  foreach my $s (&$r_function) {
    my $this = $menu -> command(-label => $s, @menu_args,
				-command=>sub{$values{$name}=$s; $current=$s});
    &::manage($menu, "menu");
  };
};


sub add_string {
  my ($parent, $name) = @_;
  my $this_row = $count_variables % $max_var_rows;
  my $col_add  = int($count_variables / $max_var_rows);
  $col_add &&= $col_add*3+1;
  my $current = $::meta{$name};
  $values{$name}  = $current;
  my $space = $parent -> Label(-text=>' ') ->
    grid(-row=>$this_row, -column=>0+$col_add, -sticky=>'w');
  my $label = $parent -> Label(-text=>&display_name($name), @label_args)
    -> grid(-row=>$this_row, -column=>1+$col_add, -sticky=>'w');
  &::manage($label, "label");
  exists ($$::config{$name}) and
    $::balloon -> attach($label, -msg=>$$::config{$name});
  my $entry = $parent -> Entry(-textvariable=>\$values{$name}, @entry_args)
    -> grid(-row=>$this_row, -column=>2+$col_add);
  #$entry -> delete(qw/0 end/);
  #$entry -> insert(0,$current);
  &::manage($entry, "entry");
};

sub add_directory {
  my ($parent, $name) = @_;
  my $this_row = $count_variables % $max_var_rows;
  my $col_add  = int($count_variables / $max_var_rows);
  $col_add &&= $col_add*3+1;
  my $current = $::meta{$name};
  $values{$name}  = $current;
  my $space = $parent -> Label(-text=>' ') ->
    grid(-row=>$this_row, -column=>0+$col_add, -sticky=>'w');
  my $label = $parent -> Label(-text=>&display_name($name), @label_args)
    -> grid(-row=>$this_row, -column=>1+$col_add, -sticky=>'w');
  &::manage($label, "label");
  exists ($$::config{$name}) and
    $::balloon -> attach($label, -msg=>$$::config{$name});
  my $entry = $parent -> Entry(-textvariable=>$current, @entry_args)
    -> grid(-row=>$this_row, -column=>2+$col_add);
  &::manage($entry, "entry");
  my $home;
  eval '$home = $ENV{"HOME"} || $ENV{"LOGDIR"} || (getpwuid($<))[7];'
    or $home = "";
  my $button = $parent ->
    Button(-text=>$$::config{'browse'},
	   @button_args,
	   -command=>sub{
	     local $Tk::FBox::a;
	     local $Tk::FBox::b;
	     my $types = [['All Files', '*'],];
	     my $path = $::meta{default_filepath} || Cwd::cwd();
	     $current = $top ->
	       getOpenFile(-defaultextension=>'inp',
			   -filetypes=>$types,
			   #(not $is_windows) ?
		  	   #  (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : (),
			   -initialdir=>$path,
			   -title => "Configure TkAtoms");
	     $values{$name}=$current;
	     $entry -> delete(0,'end');
	     $entry -> insert(0,$current);
	     return 0;
	   })
      -> grid(-row=>$this_row, -column=>3+$col_add, -padx=>2, -sticky=>'w');
  exists ($$::config{browse_help}) and
    $::balloon -> attach($button, -msg=>$$::config{browse_help});
  &::manage($button, "button");
}

sub add_boolean {
  my ($parent, $name) = @_;
  my @args = qw/-offvalue 0 -onvalue 1/;
  my $this_row = $count_variables % $max_var_rows;
  my $col_add  = int($count_variables / $max_var_rows);
  $col_add &&= $col_add*3+1;
  my $current = $::meta{$name};
  $values{$name}  = $current;
  my $space = $parent -> Label(-text=>' ') ->
    grid(-row=>$this_row, -column=>0+$col_add, -sticky=>'w');
  my $button = $parent -> Checkbutton(@args, -text=>&display_name($name),
				      -selectcolor=>$::colors{radio},
				      -variable=>\$current, @label_args,
				      -command=>sub{$values{$name}=$current} )
    -> grid(-row=>$this_row, -column=>1+$col_add, -sticky=>'w');
  &::manage($button, "check");
  exists ($$::config{$name}) and
    $::balloon -> attach($button, -msg=>$$::config{$name});
};

sub add_color {
  my ($parent, $name) = @_;
  my $frame = $parent -> Frame(-borderwidth=>1, -relief=>'sunken')
    -> grid(-column=>($count_colors%2), -row=>int($count_colors/2));
  ++$count_colors;
  my $current = $::colors{$name};
  $values{$name}  = $current;
  $color_button{$name} = $frame -> Label(-text=>'   ', -background=>$current,
			      -borderwidth=>1, -relief=>'raised')
    -> pack(-side=>'left', -padx=>4);
  my $label = $frame -> Label(-text=>&display_name($name),
			      -width=>12, @label_args)
    -> pack(-side=>'left');
  &::manage($label, "label");
  exists ($$::config{$name}) and
    $::balloon -> attach($label, -msg=>$$::config{$name});
  my $button = $frame ->
    Button(-text=>$$::config{'set'},
	   @button_args,
	   -command=>sub{
	     $current = ($ce->children())[11] -> get();
	     $values{$name} = $current;
	     $color_button{$name} -> configure(-background=>$current);
	   })
      -> pack(-side=>'left');
  &::manage($button, "button");
  exists ($$::config{set_color_help}) and
    $::balloon -> attach($button, -msg=>$$::config{set_color_help});
}

sub add_font {
  my ($parent, $name) = @_;
  my $n = substr($name, 2);
  my $current = $::fonts{$n};
  $values{$name}  = $current;
  1;
}

sub reset_values {
  my $which = $_[0];
  $force_restore = 1;
  foreach my $k (keys %values) {
    if ( (($which eq 'colors') or ($which eq 'all'))
	 and
	 ($k =~ /^c_/) ) {
      $values{$k} = $initial{$k};
      $color_button{$k} -> configure(-background=>$values{$k});
    };
    if ( (($which eq 'variables') or ($which eq 'all'))
	 and
	 ($k !~ /^[cf]_/) ) {
      $values{$k} = $initial{$k};
      eval "\$$k = $values{$k};";
    };
    ## fonts
  };
};


sub atoms_set_palette {
  my @palette = (background  => $values{background},
 		 foreground  => $values{foreground},
		 troughColor => $values{trough},);
  ## set $colors hash to its new values for future widgets
  my $noisy = 0;

  ## set overall palette stuff (if necessary)
  my $do_palette = ( $force_restore
		     or
		     (lc($values{background}) ne lc($initial{background}))
		     or
		     (lc($values{foreground}) ne lc($initial{foreground}))
		     or
		     (lc($values{trough})     ne lc($initial{trough}))
		   );
  $do_palette and $::top -> setPalette(@palette);
  $force_restore = 0;
  ## balloon colors
  $::balloon -> configure(-background=>$values{balloon},
			  -foreground=>$values{balloon});

  ## labels
  $noisy and print "labels\n";
  foreach my $w (@::all_labels) {
    next unless (Exists($w));
    $w -> configure(-foreground => $values{label});
  };
  ## buttons
  $noisy and print "buttons\n";
  foreach my $w (@::all_buttons) {
    next unless (Exists($w));
    $w -> configure(-foreground => $values{entry},
		    -background => $values{button},
		    -activeforeground => $values{entry},
		    -activebackground => $values{buttonActive},);
  };
  ## entries
  $noisy and print "entries\n";
  foreach my $w (@::all_entries) {
    next unless (Exists($w));
    $w -> configure(-background=>$values{entry},
		    #-font=>$values{f_entry},
		    -insertbackground=>$values{foreground},);
  };
  ## radio buttons (menu)
  $noisy and print "radio\n";
  foreach my $w (@::all_radio) {
    #next unless (Exists($w));
    $w -> configure(-selectcolor => $values{button},
		    -foreground=>$values{label},
		    -activeforeground=>$values{label},
		    -activebackground => $values{entry},
		   );
  };
  ## check buttons (label)
  $noisy and print "check\n";
  foreach my $w (@::all_check) {
    next unless (Exists($w));
    $w -> configure(-selectcolor => $values{button},
		    -foreground => $values{label}
		   );
  };
  ## headers
  $noisy and print "headers\n";
  foreach my $w (@::all_headers) {
    next unless (Exists($w));
    $w -> configure(-foreground=>$values{button},
		    #-font=>$values{f_header},
		    );
  };
  ## menu buttons and entries
  $noisy and print "menus\n";
  foreach my $w (@::all_menus) {
    ## next unless (("$w" !~ /cascade|command/i) and Exists($w));
    $w -> configure(-foreground	      => $values{label},
		    -activeforeground => $values{label},
		    -activebackground => $values{entry},
		    -background       => $values{background},
		    ##-font=>$$fonts{menu},
		   );
    ($w =~ /Option/) and
      $w -> configure(-background       => $values{background},
		      -activebackground => $values{entry},);
    ($w =~ /Menu::[CR]/) and
      $w -> configure(-background       => $values{background},
		      -activebackground => $values{entry},);
  };
  ## separators
  ## $noisy and print "separators\n";
  ## foreach my $w (@::all_separators) {
  ##   print $w -> configure(), $/; #-background => $values{background});
  ## };
  ## LabFrames
  $noisy and print "labframes\n";
  foreach my $w (@::all_labframes) {
    next unless (Exists($w));
    $w -> configure(-foreground=>$values{label});
  };
  ## scales
  $noisy and print "scales\n";
  foreach my $w (@::all_scales) {
    next unless (Exists($w));
    $w -> configure(-foreground=>$values{label});
  };
  ## canvases
  $noisy and print "canvases\n";
  foreach my $w (@::all_canvas) {
    next unless (Exists($w));
    $w -> configure(-background=>$values{todo});
  };
  my @toss = @::all_progress;
  while (@toss) {
    my $w = shift(@toss);
    next unless (Exists($w));
    my $id = shift(@toss);
    $w -> itemconfigure($id, -fill=>$values{done});
  };

  ## set $::colors hash to this set of values
  foreach my $c (qw/foreground background trough entry label
		 balloon button buttonActive sgbActive
		 sgbGroup done todo plot/) {
    my $t = substr($c, 2);
    $::colors{$t} = $values{$c};
  };
  &::set_arg_arrays;

};


sub write_new_rcfile {
  my $file = &Xray::Atoms::rcfile_name;
  die "could not determine config file\n", return if ($file =~ /\?/);
  if (-e $file) { rename ($file, $file.".bak") or die $!; };
  open RC, ">".$file or die $!;
  print RC <<EOH
## -*- mode: perl -*-
## This atomsrc file was generated automatically by TkAtoms $Xray::Atoms::VERSION
## using Tk/Config.pm $VERSION

EOH
  ;

  print RC $/, '[meta]', $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if (($v->[1] ne 'colors') and ($v->[1] ne 'fonts')) {
      printf RC "   %-20s = %s$/", $key, $values{$key};
    };
  };
  print RC $/, '[colors]', $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if ($v->[1] eq 'colors') {
      printf RC "   %-20s = %s$/", $key, $values{$key};
    };
  };
  print RC $/, '[fonts]', $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if ($v->[1] eq 'fonts') {
      printf RC "   %-20s = %s$/", substr($key,2), $values{$key};
    };
  };
  close RC;
  my $text = "Saved configurations to $file.
Saved old rcfile to $file.bak.";
  &main::tkatoms_text_dialog (\$top, $text, 'left');
  $top->update;
};

sub dump_values {
  my $string =  <<EOH
## This is what your atomsrc file would like if you were to push the
## "Save values" button now.

EOH
  ;

  $string .= $/ . '[meta]' . $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if (($v->[1] ne 'colors') and ($v->[1] ne 'fonts')) {
      $string .= sprintf("   %-20s = %s$/", $key, $values{$key});
    };
  };
  $string .= $/ . '[colors]' . $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if ($v->[1] eq 'colors') {
      $string .= sprintf("   %-20s = %s$/", $key, $values{$key});
    };
  };
  $string .= $/ . '[fonts]' . $/;
  foreach my $v (@variables) {
    my $key = $v->[0];
    if ($v->[1] eq 'fonts') {
      $string .= sprintf("   %-20s = %s$/", substr($key,2), $values{$key});
    };
  };
  &::display_in_frame($top, \$string,);
};

1;
__END__