| 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 |
## the informational palettes |
| 7 |
|
| 8 |
|
| 9 |
## $group_title_## |
| 10 |
sub update_titles { |
| 11 |
my $group = $_[0]; |
| 12 |
|
| 13 |
}; |
| 14 |
|
| 15 |
sub raise_palette { |
| 16 |
($update->state() eq "normal") ? $update->raise : $update->deiconify && $update->raise; |
| 17 |
$notebook->raise($_[0]); |
| 18 |
}; |
| 19 |
|
| 20 |
|
| 21 |
sub setup_data { |
| 22 |
#my $this = $_[0] || $groups{$current}->{file}; |
| 23 |
my $this = $groups{$current}->{file}; |
| 24 |
Echo('No data!'), return unless ($this); |
| 25 |
Echo("The Default Parameters have no associated data"), return if ($this eq "Default Parameters"); |
| 26 |
Echo("The current group has no associated file"), return unless (-e $this); |
| 27 |
if (Ifeffit::Files->is_record($this)) { |
| 28 |
Error("This data is from a project file and may not be edited via the data palette."); |
| 29 |
$notes{data} -> insert('end', 'This data is from a project file and may not be edited this way.', "text"); |
| 30 |
$update->deiconify; |
| 31 |
$notebook->raise('data'); |
| 32 |
$top->update; |
| 33 |
return; |
| 34 |
}; |
| 35 |
$update->deiconify; |
| 36 |
$notebook->raise('data'); |
| 37 |
$current_file = $this; |
| 38 |
#my $file = $_[0] || $groups{$current}->{file}; |
| 39 |
my $file = $groups{$current}->{file}; |
| 40 |
open F, $file or die "Could not open $file\n"; |
| 41 |
$notes{data} -> configure(-state=>'normal'); |
| 42 |
$notes{data} -> delete(qw/1.0 end/); |
| 43 |
while (<F>) { |
| 44 |
s/\r//; |
| 45 |
$notes{data} -> insert('end', $_, "text"); |
| 46 |
}; |
| 47 |
## this was a stab at putting the view at the beginning of the |
| 48 |
## data. it cause Athena to crash in certain situations. that |
| 49 |
## doesn't seem like a good idea... |
| 50 |
|
| 51 |
# if ($_[0]) { |
| 52 |
## my $comm = Ifeffit::get_string('$commentchar'); |
| 53 |
## my $lab = (split(" ",Ifeffit::get_string('$column_label')))[0]; |
| 54 |
## my $regex = "^[ \\t$comm]*$lab"; |
| 55 |
## ##print $regex, $/; |
| 56 |
## my $index = $notes{data} -> search('-regexp', $regex, '1.0', 'end'); |
| 57 |
## $index = $notes{data} -> index($index); |
| 58 |
## my @parts = split(/\./, $index); |
| 59 |
## $index = $parts[0] - 2; |
| 60 |
## $index .= ".$parts[1]"; |
| 61 |
## $notes{data} -> yview($index); |
| 62 |
## $top -> update; |
| 63 |
# }; |
| 64 |
close F; |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
## what about records and chi data? |
| 69 |
sub save_and_reload { |
| 70 |
Echo("Cannot save and reload, \"$groups{$current}->{label}\" is frozen."), return if ($groups{$current}->{frozen}); |
| 71 |
Echo("Save and reload does not yet work for records"), return if $groups{$current}->{is_rec}; |
| 72 |
my $how = $_[0]; |
| 73 |
my $n = 3; |
| 74 |
my $tmp = "." x $n . "athena.tmp"; # this will eventually find an |
| 75 |
while (-f $tmp) { # unused temporary file name |
| 76 |
++$n; |
| 77 |
$tmp = "." x $n . "athena.tmp"; |
| 78 |
}; |
| 79 |
my $file = $tmp; |
| 80 |
if ($how) { |
| 81 |
#local $Tk::FBox::a; |
| 82 |
#local $Tk::FBox::b; |
| 83 |
my $path = $current_data_dir || Cwd::cwd; |
| 84 |
my $f = basename($groups{$current}->{file}); |
| 85 |
my $types = [['All Files', '*'], ['Data Files', '.dat']]; |
| 86 |
$file = $top -> getSaveFile(-filetypes=>$types, |
| 87 |
#(not $is_windows) ? |
| 88 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 89 |
-initialdir=>$path, |
| 90 |
-initialfile=>$f, |
| 91 |
-title => "Athena: Save edited data"); |
| 92 |
return unless ($file and (-e $file)); |
| 93 |
&push_mru($file, 1); |
| 94 |
}; |
| 95 |
open D, '>'.$file or do { |
| 96 |
Error("You cannot write to \"$file\"."); return |
| 97 |
}; |
| 98 |
print D $notes{data} -> get(qw/1.0 end/); |
| 99 |
close D; |
| 100 |
my ($e, $x) = ($groups{$current}->{en_str}, $groups{$current}->{mu_str}); |
| 101 |
$groups{$current} -> dispose("read_data(file=\"$file\", group=$current)\n", $dmode); |
| 102 |
SWITCH: { |
| 103 |
$groups{$current}->{is_xmu} and do { |
| 104 |
$groups{$current} -> dispose("set($current.energy = $e, $current.xmu = $x)\n", $dmode); |
| 105 |
$groups{$current} -> make(update_bkg=>1); |
| 106 |
$groups{$current} -> plotE('emz',$dmode,\%plot_features, \@indicator); |
| 107 |
$last_plot = 'e'; |
| 108 |
$last_plot_params = [$current, 'group', 'e', 'emz']; |
| 109 |
last SWITCH; |
| 110 |
}; |
| 111 |
$groups{$current}->{is_chi} and do { |
| 112 |
$groups{$current} -> dispose("set($current.k = $e, $current.chi = $x)\n", $dmode); |
| 113 |
$groups{$current} -> make(update_chi=>1); |
| 114 |
$groups{$current} -> plotk('kw',$dmode,\%plot_features, \@indicator); |
| 115 |
$last_plot = 'k'; |
| 116 |
$last_plot_params = [$current, 'group', 'k', 'kw']; |
| 117 |
last SWITCH; |
| 118 |
}; |
| 119 |
## rsp? qsp? |
| 120 |
}; |
| 121 |
if ($how) { |
| 122 |
$groups{$current} -> make(file=>$file); |
| 123 |
} else { |
| 124 |
unlink $file; |
| 125 |
}; |
| 126 |
}; |
| 127 |
|
| 128 |
## END OF PALETTES SUBSECTION |
| 129 |
########################################################################################## |