| 1 |
#!/usr/bin/perl |
| 2 |
###################################################################### |
| 3 |
## TkAtoms using Atoms version 3.0beta9 |
| 4 |
## copyright (c) 1998,1999 Bruce Ravel |
| 5 |
## [email protected] |
| 6 |
## http://feff.phys.washington.edu/~ravel/ |
| 7 |
## |
| 8 |
## The latest version of Atoms can always be found at |
| 9 |
## http://feff.phys.washington.edu/~ravel/atoms/ |
| 10 |
## |
| 11 |
## ------------------------------------------------------------------- |
| 12 |
## All rights reserved. This program is free software; you can |
| 13 |
## redistribute it and/or modify it under the same terms as Perl |
| 14 |
## itself. |
| 15 |
## |
| 16 |
## This program is distributed in the hope that it will be useful, |
| 17 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
## Artistic License for more details. |
| 20 |
## ------------------------------------------------------------------- |
| 21 |
###################################################################### |
| 22 |
## $Id: tkatoms.pl,v 1.24 2001/09/20 17:21:34 bruce Exp $ |
| 23 |
###################################################################### |
| 24 |
## This file is the main program for TkAtoms (graphical interface). |
| 25 |
## |
| 26 |
## This version of atoms is wrapped behind a GUI. All of the input |
| 27 |
## information is entered using various button and text widgets on the |
| 28 |
## screen, although it is also capable of loading crystallographic |
| 29 |
## data from input files or from a fast, portable database format. |
| 30 |
## |
| 31 |
## Hopefully, the use of this program is fairly self-explanatory to |
| 32 |
## anyone with a knowledge of crystallographic notation. To aid the |
| 33 |
## user, many widgets have help balloons attached. Let the mouse |
| 34 |
## linger for a half a second near certain widgets and an explanatory |
| 35 |
## balloon will pop up. |
| 36 |
###################################################################### |
| 37 |
## Code: |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
### > introduction |
| 42 |
|
| 43 |
BEGIN { |
| 44 |
##use lib '/usr/local/share/ifeffit/perl'; |
| 45 |
##(($^O eq 'MSWin32') or ($^O eq 'cygwin')) and |
| 46 |
#local $^W = 0; |
| 47 |
use lib $ENV{IFEFFIT_DIR} . "/share/perl"; |
| 48 |
use Tk; |
| 49 |
use Xray::Xtal; |
| 50 |
$Xray::Xtal::run_level = 1; |
| 51 |
use Xray::Atoms qw(number); |
| 52 |
use Xray::ATP; |
| 53 |
if (@ARGV and ($ARGV[0] =~ /^-{1,2}v(ersion)?$/)) { |
| 54 |
print &about_tkatoms; |
| 55 |
exit; |
| 56 |
}; |
| 57 |
sub about_tkatoms { |
| 58 |
eval ' |
| 59 |
local $^W = 0; |
| 60 |
require Xray::Tk::Atoms; |
| 61 |
require Xray::Tk::Absorption; |
| 62 |
require Xray::Tk::Dafs; |
| 63 |
require Xray::Tk::Powder; |
| 64 |
require Xray::Tk::Plotter; |
| 65 |
require Xray::Tk::Config; |
| 66 |
return " |
| 67 |
This is TkAtoms 3.0beta9 |
| 68 |
|
| 69 |
by Bruce Ravel copyright (c) 1999 |
| 70 |
ravel\@phys.washington.edu |
| 71 |
http://feff.phys.washington.edu/~ravel/software/atoms/ |
| 72 |
|
| 73 |
using: |
| 74 |
Atoms.pm $Xray::Atoms::module_version |
| 75 |
Xtal.pm $Xray::Xtal::VERSION with space groups database $Xray::Xtal::sg_version |
| 76 |
Absorption.pm $Xray::Absorption::cvs_version |
| 77 |
Tk/Atoms.pm $Xray::Tk::Atoms::VERSION |
| 78 |
Tk/Absorption.pm $Xray::Tk::Absorption::VERSION |
| 79 |
Tk/Dafs.pm $Xray::Tk::Dafs::VERSION |
| 80 |
Tk/Powder.pm $Xray::Tk::Powder::VERSION |
| 81 |
Tk/Plotter.pm $Xray::Tk::Plotter::VERSION |
| 82 |
Tk/Config.pm $Xray::Tk::Config::VERSION |
| 83 |
|
| 84 |
You are running perl $] and Tk $Tk::VERSION on $^O. |
| 85 |
"' |
| 86 |
}; |
| 87 |
}; |
| 88 |
## Tk/Molecule.pm $Xray::Tk::Molecule::VERSION |
| 89 |
|
| 90 |
require 5.004; |
| 91 |
use warnings; |
| 92 |
use strict; |
| 93 |
use constant EPSILON => 0.00001; |
| 94 |
#use diagnostics; |
| 95 |
|
| 96 |
use vars qw/$v/; |
| 97 |
$v = $Xray::Atoms::VERSION; |
| 98 |
|
| 99 |
use Tk::widgets qw(Table DialogBox LabFrame Balloon ErrorDialog |
| 100 |
Checkbutton Text Entry Button Optionmenu |
| 101 |
Radiobutton Scale Bitmap Photo Pod Pod/Text |
| 102 |
Pod/Search Pod/Tree Menubar More ROText Canvas Config); |
| 103 |
### wtf?!?! PerlApp needs these lines: |
| 104 |
use Tk::ErrorDialog; |
| 105 |
use Tk::Menubar; |
| 106 |
|
| 107 |
use Xray::Tk::SGB; |
| 108 |
use File::Basename qw(dirname basename); |
| 109 |
use Cwd; |
| 110 |
|
| 111 |
use vars qw($is_windows $ifeffit_exists $LWP_simple_exists); |
| 112 |
$is_windows = (($^O eq 'MSWin32') or ($^O eq 'cygwin')); |
| 113 |
$ifeffit_exists = (eval "require Ifeffit"); |
| 114 |
## $LWP_simple_exists = (eval "require LWP::Simple"); |
| 115 |
$LWP_simple_exists = 0; |
| 116 |
($is_windows) and ($LWP_simple_exists = 0); |
| 117 |
#WINDOWS# $ifeffit_exists = 1; |
| 118 |
#WINDOWS# use Ifeffit; |
| 119 |
my $plot_group; |
| 120 |
|
| 121 |
## -------------------------------------------------------------------- |
| 122 |
## rc file variables |
| 123 |
use vars qw(%meta %colors %fonts $titles $labels $help $dialogs $file_dialog |
| 124 |
$sgb $messages $config); |
| 125 |
## use vars qw($always_write_feff $atoms_language $write_to_pwd |
| 126 |
## $prefer_feff_eight $absorption_tables $dafs_default |
| 127 |
## $plotting_hook $default_filepath $unused_modifier |
| 128 |
## $display_balloons $no_crystal_warnings $one_frame $convolve_dafs |
| 129 |
## $never_ask_to_save $ADB_location); |
| 130 |
|
| 131 |
%meta = (ADB_location => "http://cars9.uchicago.edu/atomsdb/", |
| 132 |
absorption_tables => 'elam', |
| 133 |
always_write_feff => 0, |
| 134 |
atoms_language => 'english', |
| 135 |
convolve_dafs => 1, |
| 136 |
dafs_default => 'henke', |
| 137 |
default_filepath => cwd, |
| 138 |
display_balloons => 1, |
| 139 |
never_ask_to_save => 0, |
| 140 |
no_crystal_warnings => 0, |
| 141 |
one_frame => 1, |
| 142 |
plotting_hook => '', |
| 143 |
prefer_feff_eight => 0, |
| 144 |
unused_modifier => 'Shift', |
| 145 |
write_to_pwd => 1, |
| 146 |
); |
| 147 |
|
| 148 |
%colors = (foreground => 'black', |
| 149 |
background => 'cornsilk3', |
| 150 |
trough => 'cornsilk4', |
| 151 |
entry => 'ivory2', |
| 152 |
label => 'blue3', |
| 153 |
balloon => 'coral', |
| 154 |
button => 'red4', |
| 155 |
buttonActive => 'red3', |
| 156 |
radio => ($is_windows) ? 'red2' : 'red4', |
| 157 |
sgbActive => 'blue3', |
| 158 |
sgbGroup => 'darkviolet', |
| 159 |
todo => 'seashell', |
| 160 |
plot => 'blue', |
| 161 |
); |
| 162 |
|
| 163 |
%fonts = (balloon => "Arial 10 normal", # font for text in help ballons |
| 164 |
label => "Arial 12 normal", # font for text labels |
| 165 |
menu => "Arial 12 normal", # font for text labels |
| 166 |
button => "Arial 10 bold", # font for push buttons |
| 167 |
header => "Arial 14 bold", # font for text headers |
| 168 |
entry => "Arial 12 normal", # font for editable fields |
| 169 |
sgb => "Arial 12 normal", # font used in space group browser |
| 170 |
); |
| 171 |
|
| 172 |
|
| 173 |
## this sets the name and location of tkatoms.pod |
| 174 |
Tk::Pod->Dir($Xray::Atoms::lib_dir); |
| 175 |
my $pod_name = 'tkatoms.pod'; |
| 176 |
if ($is_windows) { |
| 177 |
Tk::Pod->Dir(File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray")); |
| 178 |
$pod_name = 'tkatoms.pod'; |
| 179 |
}; |
| 180 |
|
| 181 |
## read the system rc file then read the user's rc file |
| 182 |
use vars qw($xtal_dir $rcfile); |
| 183 |
$xtal_dir = ($is_windows) ? |
| 184 |
File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", 'lib') : |
| 185 |
$Xray::Atoms::lib_dir; |
| 186 |
$rcfile = ($is_windows) ? |
| 187 |
File::Spec->catfile($xtal_dir, 'tkatoms.ini') : |
| 188 |
File::Spec->catfile($xtal_dir, 'atomsrc'); |
| 189 |
(-e $rcfile) and &read_rc($rcfile); |
| 190 |
my $users_rc = &Xray::Atoms::rcfile_name; |
| 191 |
(-e $users_rc) and &read_rc($users_rc); |
| 192 |
|
| 193 |
$meta{absorption_tables} = lc($meta{absorption_tables}); |
| 194 |
Xray::Absorption -> load($meta{absorption_tables}); |
| 195 |
($meta{unused_modifier} =~ /Alt|Control|Meta|Shift/) or |
| 196 |
$meta{unused_modifier} = 'Shift'; |
| 197 |
$meta{unused_modifier} = ucfirst($meta{unused_modifier}); |
| 198 |
($meta{ADB_location} =~ /\/$/) or $meta{ADB_location} .= '/'; |
| 199 |
|
| 200 |
|
| 201 |
## ($colors or $fonts) and |
| 202 |
## warn " |
| 203 |
## As of alpha17 fonts and colors are no longer set in the |
| 204 |
## atomsrc file using anonymous hashes. See |
| 205 |
## $rcfile |
| 206 |
## for the new scheme. |
| 207 |
## |
| 208 |
## "; |
| 209 |
|
| 210 |
|
| 211 |
## ---------------------------------------------------------------------- |
| 212 |
## Internationalization: |
| 213 |
$meta{atoms_language} = lc($meta{atoms_language}); |
| 214 |
my $language_file = ""; |
| 215 |
## = "tkatomsrc." . $$Xray::Atoms::languages{$meta{atoms_language}}; |
| 216 |
## $language_file = (($^O eq 'MSWin32') or ($^O eq 'cygwin')) ? |
| 217 |
## File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", "lib", $language_file): |
| 218 |
## File::Spec->catfile($xtal_dir, $language_file); |
| 219 |
|
| 220 |
unless (-e $language_file) { |
| 221 |
$language_file = (($^O eq 'MSWin32') or ($^O eq 'cygwin')) ? |
| 222 |
File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", "lib", "tkatomsrc.en"): |
| 223 |
File::Spec->catfile($xtal_dir, "tkatomsrc.en"); |
| 224 |
}; |
| 225 |
eval "do '$language_file'"; # read strings |
| 226 |
(lc($meta{atoms_language}) eq 'english') or |
| 227 |
Xray::Xtal::set_language($meta{atoms_language}); |
| 228 |
## --------------------------------- handle a few specially ---------# |
| 229 |
$$help{'mol_core'} = $$help{'core'}; # |
| 230 |
$$help{'mol_elem'} = $$help{'elem'}; # |
| 231 |
$$labels{cancel} = $$file_dialog{-CancelButtonLabel}; # |
| 232 |
## ------------------------------------------------------------------# |
| 233 |
## ---------------------------warehouse for new text strings --------# |
| 234 |
$$labels{plotgif} = 'Save GIF image'; |
| 235 |
$$labels{plotps} = 'Save postscript image'; |
| 236 |
## ------------------------------------------------------------------# |
| 237 |
|
| 238 |
## ---------------------------------------------------------------------- |
| 239 |
## use vars qw($apt_program); |
| 240 |
## ($apt_program = $0) =~ s/tkatoms/apt/; |
| 241 |
## ($is_windows) and |
| 242 |
## ($apt_program = File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", "apt.pl")); |
| 243 |
|
| 244 |
## -------------------------------------------------------------------- |
| 245 |
## various global variables and variables used for the bottom panel |
| 246 |
my $nsites = 3; |
| 247 |
my $pnsites = $nsites+1; |
| 248 |
my $initial_sites = 4; |
| 249 |
my ($sites_list, $status); |
| 250 |
my %lattice = (); # hash of space group and lattice constant widgets |
| 251 |
my @unique_sites = (); # list of site widgets |
| 252 |
my @occupancy = (); |
| 253 |
use vars qw/%atoms_widgets/; |
| 254 |
%atoms_widgets = (); |
| 255 |
|
| 256 |
## -------------------------------------------------------------------- |
| 257 |
## fetch names of all available atp files |
| 258 |
## -- atpfiles is the list of all atp files found |
| 259 |
## -- atplist is the list for use with atoms |
| 260 |
my @atp_dir_list = (); |
| 261 |
my %atp_seen = (); |
| 262 |
my @found; |
| 263 |
use vars qw/@atpfiles @atplist/; |
| 264 |
my $atp_direc = ($is_windows) ? |
| 265 |
File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", "atp"): |
| 266 |
$Xray::Atoms::atp_dir; |
| 267 |
push @atp_dir_list, $atp_direc; |
| 268 |
push @atp_dir_list, Xray::Atoms::rcdirectory; |
| 269 |
|
| 270 |
foreach my $dir (@atp_dir_list) { |
| 271 |
next if ($dir eq '???'); |
| 272 |
$dir = File::Spec->canonpath($dir); |
| 273 |
next unless opendir (ATPDIR, $dir); |
| 274 |
## die "could not open directory $dir for reading$/"; |
| 275 |
push @found, grep /\.atp/, readdir ATPDIR; |
| 276 |
closedir ATPDIR; |
| 277 |
}; |
| 278 |
@found = sort( map {if ($_ =~ /(.+)\.atp$/) {$1}} @found ); |
| 279 |
foreach my $item (@found) { |
| 280 |
push(@atpfiles, $item) unless $atp_seen{$item}++; |
| 281 |
}; |
| 282 |
@atplist = ('feff', 'feff8'); |
| 283 |
foreach my $a (@atpfiles) { |
| 284 |
next if ($a =~ /^\s*$/); |
| 285 |
next if ($a =~ /absorption|atoms|test/); |
| 286 |
next if ($a =~ /^molec/); |
| 287 |
next if ($a =~ /^template/); |
| 288 |
next if ($a =~ /dafs/); |
| 289 |
unless ($a =~ /^feff8?$/) { |
| 290 |
push @atplist, $a; |
| 291 |
}; |
| 292 |
}; |
| 293 |
push @atplist, 'test'; |
| 294 |
|
| 295 |
## -------------------------------------------------------------------- |
| 296 |
## this is a hash of references to functions. The hash keys are the |
| 297 |
## same as the keys to the help and labels array from tkatomsrc.?? |
| 298 |
## This aids in algorithmic generation of chunks of screen real |
| 299 |
## estate. |
| 300 |
use vars qw/%function_refs/; |
| 301 |
%function_refs = ('quit_tkatoms' => \&quit_tkatoms, |
| 302 |
'atoms_validate' => \&Xray::Tk::Atoms::atoms_validate, |
| 303 |
'run_atoms' => \&Xray::Tk::Atoms::run_atoms, |
| 304 |
'run_absorption' => \&Xray::Tk::Absorption::run_absorption, |
| 305 |
'clear_atoms' => \&Xray::Tk::Atoms::clear_atoms, |
| 306 |
'clear_site' => \&clear_site, |
| 307 |
'clear_lattice' => \&clear_lattice, |
| 308 |
'remove' => \&remove_site, |
| 309 |
'add' => \&add_one_site, |
| 310 |
); |
| 311 |
## -------------------------------------------------------------------- |
| 312 |
|
| 313 |
## need to define the top before setting widget properties |
| 314 |
use vars qw/$top/; |
| 315 |
$top = MainWindow->new(-class=>'horae'); |
| 316 |
|
| 317 |
|
| 318 |
## -------------------------------------------------------------------- |
| 319 |
## define widget properties |
| 320 |
use vars qw/@button_args @label_args @header_args @entry_args @menu_args |
| 321 |
@sgb_args/; |
| 322 |
|
| 323 |
&set_arg_arrays; |
| 324 |
sub set_arg_arrays { |
| 325 |
@button_args = (-foreground => $colors{entry}, |
| 326 |
-background => $colors{button}, |
| 327 |
-activeforeground => $colors{entry}, |
| 328 |
-activebackground => $colors{buttonActive}, |
| 329 |
-font => $fonts{button},); |
| 330 |
@label_args = (-foreground => $colors{label}, |
| 331 |
-font => $fonts{label}, ); |
| 332 |
@entry_args = (-background => $colors{entry}, |
| 333 |
-font => $fonts{entry}, |
| 334 |
-insertbackground => $colors{foreground}, ); |
| 335 |
@header_args = (-foreground => $colors{button}, |
| 336 |
-font => $fonts{header}, ); |
| 337 |
@menu_args = (-foreground => $colors{label}, |
| 338 |
-activeforeground => $colors{label}, |
| 339 |
-font => $fonts{menu}, ); |
| 340 |
}; |
| 341 |
|
| 342 |
my @lattice_label_args = (-width=>6, -height=>1, @label_args,); |
| 343 |
|
| 344 |
my @lattice_entry_args = (-width=>10, @entry_args); |
| 345 |
|
| 346 |
my @sites_label_args = (-width=>17, -height=>1, @label_args,); |
| 347 |
|
| 348 |
my @sites_entry_args = (-width=>5, @entry_args); |
| 349 |
|
| 350 |
sub set_sgb_args { |
| 351 |
@sgb_args = (-sgbActive => $colors{'sgbActive'}, |
| 352 |
-sgbGroup => $colors{'sgbGroup'}, |
| 353 |
-button => $colors{'button'}, |
| 354 |
-buttonActive => $colors{'buttonActive'}, |
| 355 |
-buttonLabel => $colors{'entry'}, |
| 356 |
-buttonFont => $fonts{'button'}, |
| 357 |
-sgbFont => $fonts{'sgb'}, |
| 358 |
-dismiss => $$labels{'dismiss'}, |
| 359 |
-back => $$labels{'back'}, |
| 360 |
-restore => $$labels{'restore'}, |
| 361 |
); |
| 362 |
}; |
| 363 |
|
| 364 |
use vars qw/@file_menubutton/; |
| 365 |
@file_menubutton = (-text=>$$labels{file}, @menu_args,); |
| 366 |
use vars qw(@recent_files @recent_registry); |
| 367 |
my $recent_menu; |
| 368 |
@recent_files = (); |
| 369 |
@recent_registry = (); |
| 370 |
sub set_file_menu { |
| 371 |
my $menu = $_[0]; |
| 372 |
my $this = $menu |
| 373 |
-> command(-label=>$$::labels{'load_input'}, @::menu_args, |
| 374 |
-command=>\&load_input, |
| 375 |
-accelerator=>'Control+o', ); |
| 376 |
&::manage($this, "menu"); |
| 377 |
($LWP_simple_exists) and do { |
| 378 |
my $sep = $menu -> separator(); |
| 379 |
manage($sep, "separator"); |
| 380 |
$this = $menu |
| 381 |
-> command(-label=>$$::labels{'load_adb'}, @::menu_args, |
| 382 |
-command=>\&load_adb, ); |
| 383 |
&::manage($this, "menu"); |
| 384 |
#$this = $menu |
| 385 |
# -> command(-label=>$$::labels{'download_adb'}, @::menu_args, |
| 386 |
# -command=>\&download_adb, ); |
| 387 |
#&::manage($this, "menu"); |
| 388 |
}; |
| 389 |
my $sep = $menu -> separator(); |
| 390 |
manage($sep, "separator"); |
| 391 |
$this = $menu |
| 392 |
-> command(-label=>$$::labels{'save_input'}, @::menu_args, |
| 393 |
-command=>\&save_input, |
| 394 |
-accelerator=>'Control+s', ); |
| 395 |
&::manage($this, "menu"); |
| 396 |
unless ($_[1]) { |
| 397 |
$this = $menu |
| 398 |
-> command(-label=>$$::labels{'quit'}, @::menu_args, |
| 399 |
-command=>\&quit_tkatoms, #sub{exit}, |
| 400 |
-accelerator=>'Control+q', ); |
| 401 |
&::manage($this, "menu"); |
| 402 |
}; |
| 403 |
}; |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
## $$dialogs{'no_molecule_data'} = 'You have not read in any molecule data.'; |
| 408 |
## $$dialogs{'no_absorption'} = |
| 409 |
## 'Absorption calculations are unreliable for very low energies. |
| 410 |
## They cannot be made for your chosen edge and central atom.'; |
| 411 |
use vars qw/@pref_menubutton/; |
| 412 |
@pref_menubutton = (-text=>$$labels{pref_menu}, @menu_args,); |
| 413 |
sub set_pref_menu { |
| 414 |
my $menu = $_[0]; |
| 415 |
my $this = $menu |
| 416 |
-> command(-label=>$$labels{'pref_var'}, @menu_args, |
| 417 |
-command=> |
| 418 |
sub{require Xray::Tk::Config; |
| 419 |
my ($cwin,$cnote) = &Xray::Tk::Config::atoms_config($top); |
| 420 |
($^O eq "MSWin32") or $cnote -> raise('variables'); }, ); |
| 421 |
&::manage($this, "menu"); |
| 422 |
$this = $menu |
| 423 |
-> command(-label=>$$labels{'pref_col'}, @menu_args, |
| 424 |
-command=> |
| 425 |
sub{require Xray::Tk::Config; |
| 426 |
my ($cwin,$cnote) = &Xray::Tk::Config::atoms_config($top); |
| 427 |
($^O eq "MSWin32") or $cnote -> raise('colors'); }, ); |
| 428 |
&::manage($this, "menu"); |
| 429 |
$this = $menu |
| 430 |
-> command(-label=>$$labels{'pref_fon'}, @menu_args, |
| 431 |
-command=> |
| 432 |
sub{require Xray::Tk::Config; |
| 433 |
my ($cwin,$cnote) = &Xray::Tk::Config::atoms_config($top); |
| 434 |
($^O eq "MSWin32") or $cnote -> raise('fonts'); }, ); |
| 435 |
&::manage($this, "menu"); |
| 436 |
}; |
| 437 |
|
| 438 |
## use vars qw/@apt_args/; |
| 439 |
## @apt_args = |
| 440 |
## (-label => "Periodic Table", |
| 441 |
## #-borderwidth => 0, # hackery to get the words aligned |
| 442 |
## #-relief=>"raised", |
| 443 |
## -command=> |
| 444 |
## sub{ local $^W = 0; |
| 445 |
## unless (my $return = do $::apt_program) { |
| 446 |
## die "couldn't parse $::apt_program: $@" if $@; |
| 447 |
## die "couldn't do $::apt_program: $!" unless defined $return; |
| 448 |
## die "couldn't run $::apt_program:" unless $return; |
| 449 |
## }}, |
| 450 |
## @::menu_args); |
| 451 |
|
| 452 |
|
| 453 |
use vars qw/@help_menubutton/; |
| 454 |
@help_menubutton = (-text=>$$labels{help_menu}, @menu_args,); |
| 455 |
sub set_help_menu { |
| 456 |
my $menu = $_[0]; |
| 457 |
my $this = $menu |
| 458 |
-> command(-label=>$$labels{'help_atoms'}, @menu_args, |
| 459 |
-command=>sub{ |
| 460 |
#if ($^O eq 'MSWin32') { |
| 461 |
# my $dialog = $top -> DialogBox(-title=>'Windows warning', |
| 462 |
# -buttons=>['OK'],); |
| 463 |
# $dialog -> add("Label", qw/-padx .25c -pady .25c -text/, |
| 464 |
# "The on-line help is broken on MS Windows. Sorry.") |
| 465 |
# -> pack(-side=>'left'); |
| 466 |
# $dialog -> Show; |
| 467 |
# return; |
| 468 |
#}; |
| 469 |
$top->Pod(-file=>$pod_name);}, ); |
| 470 |
## my $file = $Xray::Atoms::atoms_dir; |
| 471 |
## $file = File::Spec->catfile($file, |
| 472 |
## 'tkatoms_use.pod'); |
| 473 |
## $top->Pod(-file=>$file);}, ); |
| 474 |
push @::all_menus, $this; |
| 475 |
$this = $menu |
| 476 |
-> command(-label=>$$labels{'about_atoms'}, @menu_args, |
| 477 |
-command=>[\&tkatoms_text_dialog, |
| 478 |
\$top, &about_tkatoms, 'left']); |
| 479 |
push @::all_menus, $this; |
| 480 |
}; |
| 481 |
|
| 482 |
use vars qw/@clear_menubutton/; |
| 483 |
@clear_menubutton = (-text=>$$labels{clear_menu}, @menu_args,); |
| 484 |
|
| 485 |
use vars qw/@data_menubutton/; |
| 486 |
@data_menubutton = (-text=>$$labels{data_menu}, @menu_args,); |
| 487 |
|
| 488 |
|
| 489 |
my @balloon_args = (-background=>$colors{balloon}, |
| 490 |
-foreground=>$colors{foreground}, |
| 491 |
-font=>$fonts{balloon}, |
| 492 |
-borderwidth=>0,); |
| 493 |
use vars qw/$balloon/; |
| 494 |
$balloon = $top -> Balloon(@balloon_args); |
| 495 |
&configure_balloons; |
| 496 |
|
| 497 |
my $pod; |
| 498 |
|
| 499 |
my @palette = (background =>$colors{background}, |
| 500 |
activeBackground =>$colors{entry}, |
| 501 |
highlightBackground=>$colors{background}, |
| 502 |
selectForeground =>$colors{foreground}, |
| 503 |
foreground =>$colors{foreground}, |
| 504 |
highlightForeground=>$colors{foreground}, |
| 505 |
activeForeground =>$colors{entry}, |
| 506 |
selectColor =>$colors{entry}, |
| 507 |
activeForeground =>$colors{foreground}, |
| 508 |
selectBackground =>$colors{background}, |
| 509 |
highlightColor =>$colors{button}, |
| 510 |
#disabledForeground =>$colors{disabledforeground}, |
| 511 |
insertBackground =>$colors{entry}, |
| 512 |
troughColor =>$colors{trough},); |
| 513 |
## -------------------------------------------------------------------- |
| 514 |
|
| 515 |
## globals used in the display frame |
| 516 |
my ($dump_frame, $dump_frame_text, $dump_frame_buttons, @dump_frames, |
| 517 |
$dump_frame_buttons_run, $dump_frame_buttons_save); |
| 518 |
my $dump_count = 1; |
| 519 |
|
| 520 |
## -------------------------------------------------------------------- |
| 521 |
use vars qw(@all_labels @all_entries @all_buttons @all_radio |
| 522 |
@all_headers @all_menus @all_canvas @all_progress |
| 523 |
@all_labframes @all_scales @all_check @all_sliders |
| 524 |
@all_separators); |
| 525 |
## -------------------------------------------------------------------- |
| 526 |
|
| 527 |
## -------------------------------------------------------------------- |
| 528 |
## crystallography variables |
| 529 |
use vars qw/$cell @sites $keywords @cluster @neutral/; |
| 530 |
$cell = Xray::Xtal::Cell -> new(); |
| 531 |
@sites = (); |
| 532 |
$keywords = Xray::Atoms -> new(); |
| 533 |
@cluster = (); # spherical cluster |
| 534 |
@neutral = (); # charge neutral rhomboidal cluster |
| 535 |
## -------------------------------------------------------------------- |
| 536 |
|
| 537 |
## -------------------------------------------------------------------- |
| 538 |
## now set the rest of the $top properties |
| 539 |
$top -> title($$labels{tkatoms_title}); |
| 540 |
$top -> iconname($$labels{tkatoms_title}); |
| 541 |
$top -> iconbitmap('@'.File::Spec->catfile($Xray::Atoms::lib_dir, "tkatoms3.xbm")) |
| 542 |
unless $is_windows; |
| 543 |
|
| 544 |
$top -> setPalette(@palette); |
| 545 |
$top -> bind('<Control-q>' => \&quit_tkatoms); # sub{exit} |
| 546 |
$top -> bind('<Control-l>' => \&load_input); # what about Molecule? |
| 547 |
$top -> bind('<Control-o>' => \&load_input); # what about Molecule? |
| 548 |
$top -> bind('<Control-s>' => \&save_input); |
| 549 |
$top -> bind('<Control-d>' => sub{&display_in_frame($top, '', 0)}); |
| 550 |
##$top -> bind('<Control-t>' => sub{require Xray::Tk::Sites; |
| 551 |
## &Xray::Tk::Sites::display_sites($top)}); |
| 552 |
## my $icon = File::Spec->catfile($xtal_dir, 'tkatoms.xbm'); |
| 553 |
## $top -> iconbitmap('@'.$icon); |
| 554 |
## -------------------------------------------------------------------- |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
### > crystallography panel |
| 559 |
|
| 560 |
###################################################################### |
| 561 |
######### ################### |
| 562 |
######### Panel containing crystallography data ################### |
| 563 |
######### ################### |
| 564 |
###################################################################### |
| 565 |
|
| 566 |
my $lower_panel = $top -> Frame(-relief=>'ridge', -borderwidth=>4) |
| 567 |
-> pack(-side=>'bottom', -fill=>'both', -expand=>'y'); |
| 568 |
|
| 569 |
my $upper_frame = $lower_panel -> Frame() -> pack(-side=>'top', -expand=>'y'); |
| 570 |
my $image_frame = $upper_frame -> Frame() -> pack(-side=>'left'); |
| 571 |
|
| 572 |
## ------------------------------------------------------------ |
| 573 |
## ball and stick image |
| 574 |
use vars qw($data_dir); |
| 575 |
#my $ballnstick_xpm = ''; |
| 576 |
#while (<DATA>) { $ballnstick_xpm .= $_; }; |
| 577 |
#my $ballnstick_image = $image_frame -> Pixmap('ballnstick', |
| 578 |
# -data=>$ballnstick_xpm); |
| 579 |
|
| 580 |
my $ballnstick_file = (($^O eq 'MSWin32') or ($^O eq 'cygwin')) ? |
| 581 |
File::Spec->catfile($ENV{IFEFFIT_DIR}, "share", "perl", "Xray", "tkatoms.gif"): |
| 582 |
File::Spec->catfile($xtal_dir, "tkatoms.gif"); |
| 583 |
my $ballnstick = $image_frame -> Photo(-file => $ballnstick_file,); |
| 584 |
$image_frame -> Label(-image => $ballnstick) -> pack(-padx=>4); |
| 585 |
## ------------------------------------------------------------ |
| 586 |
|
| 587 |
use vars qw/%atoms_values/; |
| 588 |
%atoms_values = ('edge' => '', |
| 589 |
'titles' => '', |
| 590 |
); |
| 591 |
|
| 592 |
|
| 593 |
## ------------------------------------------------------------ |
| 594 |
## area with titles, space group and lattice parameters |
| 595 |
my $rest_frame = $upper_frame -> Frame() -> pack(-side=>'left'); |
| 596 |
|
| 597 |
## titles |
| 598 |
my $titles_frame = $rest_frame -> Frame() -> pack(qw/-padx 4/); |
| 599 |
my $titles_label = $titles_frame |
| 600 |
-> Label(-text=>$$labels{title}, @label_args) -> pack(-side=>'left'); |
| 601 |
$balloon->attach($titles_label, -msg=>$$help{'titles'},); |
| 602 |
manage($titles_label, "label"); |
| 603 |
my $atoms_titles = $titles_frame |
| 604 |
-> Scrolled(qw/Text -relief sunken -borderwidth 2 -width 50 |
| 605 |
-height 4 -scrollbars e -wrap none/, |
| 606 |
@entry_args) |
| 607 |
-> pack(-side=>'left', -pady=>2); |
| 608 |
$atoms_titles->Subwidget("yscrollbar")->configure(-background=>$colors{background}); |
| 609 |
manage($atoms_titles, "entry"); |
| 610 |
$atoms_widgets{'title'} = $atoms_titles; |
| 611 |
|
| 612 |
#print $/, join("\n", $atoms_titles -> children()), $/; |
| 613 |
|
| 614 |
##print $/, ($atoms_titles -> children())[1] -> cget('-background'), $/; |
| 615 |
($atoms_titles -> children())[1] -> configure(-background=>$colors{background}); |
| 616 |
manage(($atoms_titles -> children())[1], "slider"); |
| 617 |
##print $/, ($atoms_titles -> children())[1] -> cget('-background'), $/; |
| 618 |
|
| 619 |
## use Tk::Pretty; |
| 620 |
## my $str = Pretty (($atoms_titles -> children())[1]->configure()); |
| 621 |
## $str =~ s/\],\[/]\n[/g; |
| 622 |
## print $/, $str, $/; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
## space group and lattice constants |
| 627 |
my $lattice_frame = $rest_frame -> Frame(-relief=>'flat',) -> pack(); |
| 628 |
|
| 629 |
|
| 630 |
## space group symbol |
| 631 |
my $space_label = $lattice_frame -> Label(-text=>$$labels{space}, |
| 632 |
-width=>12, -height=>1, @label_args,) |
| 633 |
-> grid(-column=>0, -row=>0, -columnspan=>3, -padx=>2); |
| 634 |
$balloon->attach($space_label, -msg=>$$help{space},); |
| 635 |
manage($space_label, "label"); |
| 636 |
use vars qw/$space_field/; |
| 637 |
$space_field = $lattice_frame -> Entry(@lattice_entry_args, |
| 638 |
-width=>10,) |
| 639 |
-> grid(-column=>3, -row=>0, -columnspan=>2, -sticky=>'w', -padx=>2); |
| 640 |
$lattice{'space'} = $space_field; |
| 641 |
manage($space_field, "entry"); |
| 642 |
my $space_browser; |
| 643 |
my $space_button = $lattice_frame |
| 644 |
-> Button(-text=>$$labels{space_browse}, |
| 645 |
@button_args, |
| 646 |
-command=>sub{ if (Exists($space_browser)) { |
| 647 |
$space_browser -> raise; |
| 648 |
} else { |
| 649 |
&set_sgb_args; |
| 650 |
$space_browser = $top |
| 651 |
-> SGB(-SpaceWidget=>\$space_field); |
| 652 |
$space_browser->configure(@sgb_args, %$sgb,); |
| 653 |
$space_browser->Show; |
| 654 |
}; |
| 655 |
} ) |
| 656 |
-> grid(-column=>4, -row=>0, -padx=>2, -columnspan=>2); |
| 657 |
$balloon->attach($space_button, -msg=>$$help{space_browse},); |
| 658 |
manage($space_button, "button"); |
| 659 |
|
| 660 |
## --------------------------- edge |
| 661 |
my $edge_label = $lattice_frame -> |
| 662 |
Label(-text=>$$labels{'edge'}, @label_args, ) |
| 663 |
-> grid(-column=>6, -row=>0, -padx=>2); |
| 664 |
$balloon->attach($edge_label, -msg=>$$help{'edge'},); |
| 665 |
manage($edge_label, "label"); |
| 666 |
my $edge_button = $lattice_frame |
| 667 |
-> Optionmenu(-textvariable => \$atoms_values{'edge'}, |
| 668 |
-background => $colors{entry}, |
| 669 |
-activeforeground => $colors{label}, |
| 670 |
-activebackground => $colors{entry}, |
| 671 |
-width=>3, -font=>$fonts{'label'}, -relief=>'groove') |
| 672 |
-> grid(-column=>7, -row=>0, -padx=>2); |
| 673 |
manage($edge_button, "menu"); |
| 674 |
foreach my $e (qw/K L3 L2 L1 none/) { |
| 675 |
my $this = $edge_button -> command(-label => $e, @menu_args, |
| 676 |
-command=>sub{$atoms_values{'edge'}=$e;}); |
| 677 |
manage($this, "menu"); |
| 678 |
}; |
| 679 |
## for now only get cascading menus with pTk 800+ |
| 680 |
if ($Tk::VERSION > 800) { |
| 681 |
my $mcas = $edge_button -> cascade(-label=>'M', -tearoff=>0, |
| 682 |
-foreground=>$colors{'label'}, |
| 683 |
); |
| 684 |
manage($mcas, "menu"); |
| 685 |
foreach my $e (qw/M1 M2 M3 M4 M5/) { |
| 686 |
my $this = $mcas -> command(-label => $e, @menu_args, |
| 687 |
-command=>sub{$atoms_values{'edge'}=$e;}); |
| 688 |
manage($this, "menu"); |
| 689 |
}; |
| 690 |
my $ncas = $edge_button -> cascade(-label=>'N', -tearoff=>0, |
| 691 |
-foreground=>$colors{'label'} |
| 692 |
); |
| 693 |
manage($ncas, "menu"); |
| 694 |
foreach my $e (qw/N1 N2 N3 N4 N5 N6 N7/) { |
| 695 |
my $this = $ncas -> command(-label => $e, @menu_args, |
| 696 |
-command=>sub{$atoms_values{'edge'}=$e;}); |
| 697 |
manage($this, "menu"); |
| 698 |
}; |
| 699 |
my $ocas = $edge_button -> cascade(-label=>'O', -tearoff=>0, |
| 700 |
-foreground=>$colors{'label'}, |
| 701 |
); |
| 702 |
manage($ocas, "menu"); |
| 703 |
foreach my $e (qw/O1 O2 O3 O4 O5 O6 O7/) { |
| 704 |
my $this = $ocas -> command(-label => $e, @menu_args, |
| 705 |
-command=>sub{$atoms_values{'edge'}=$e;}); |
| 706 |
manage($this, "menu"); |
| 707 |
}; |
| 708 |
my $pcas = $edge_button -> cascade(-label=>'P', -tearoff=>0, |
| 709 |
-foreground=>$colors{'label'}, |
| 710 |
); |
| 711 |
manage($pcas, "menu"); |
| 712 |
foreach my $e (qw/P1 P2 P3/) { |
| 713 |
my $this = $pcas -> command(-label => $e, @menu_args, |
| 714 |
-command=>sub{$atoms_values{'edge'}=$e;}); |
| 715 |
manage($this, "menu"); |
| 716 |
}; |
| 717 |
}; |
| 718 |
$atoms_widgets{'edge'} = $edge_button; |
| 719 |
|
| 720 |
|
| 721 |
## lattice constant entry fields |
| 722 |
my $r_lcf = \$lattice_frame; |
| 723 |
|
| 724 |
$lattice{a} = &lattice_constant_widget($r_lcf, "a", 1, 1); |
| 725 |
$lattice{b} = &lattice_constant_widget($r_lcf, "b", 2, 1); |
| 726 |
$lattice{c} = &lattice_constant_widget($r_lcf, "c", 3, 1); |
| 727 |
|
| 728 |
$lattice{alpha} = &lattice_constant_widget($r_lcf, "alpha", 1, 2); |
| 729 |
$lattice{beta} = &lattice_constant_widget($r_lcf, "beta" , 2, 2); |
| 730 |
$lattice{gamma} = &lattice_constant_widget($r_lcf, "gamma", 3, 2); |
| 731 |
|
| 732 |
sub lattice_constant_widget { |
| 733 |
my($parent, $which, $col, $row) = @_; |
| 734 |
my $label = $$parent -> Label(-text=>$$labels{$which}, @lattice_label_args) |
| 735 |
-> grid(-column=>2*$col, -row=>$row, -padx=>2); |
| 736 |
manage($label, "label"); |
| 737 |
my $field = $$parent -> Entry(@lattice_entry_args) |
| 738 |
-> grid(-column=>2*$col+1, -row=>$row, -padx=>2, -sticky=>'w'); |
| 739 |
$balloon->attach($label, -msg=>$$help{$which},); |
| 740 |
manage($field, "entry"); |
| 741 |
return $field; |
| 742 |
}; |
| 743 |
## ---------------------------------------------------------------------- |
| 744 |
|
| 745 |
|
| 746 |
## ---------------------------------------------------------------------- |
| 747 |
## ----- Table of sites ----------------------------------------- |
| 748 |
use vars qw/@site_entries $core_index/; |
| 749 |
@site_entries = (); |
| 750 |
$core_index = 0; # pointer to the currently selected central site |
| 751 |
my $sites_frame = $lower_panel -> Frame(-borderwidth=>2, |
| 752 |
-relief=>'ridge', ) |
| 753 |
-> pack(-padx=>4, -pady=>2); |
| 754 |
|
| 755 |
my $sites_title_frame = $sites_frame -> Frame() ->pack(); |
| 756 |
|
| 757 |
my $sites_label = $sites_title_frame -> Label(-text=>$$labels{"unique"}, |
| 758 |
@header_args, |
| 759 |
-width=>length($$labels{"unique"})) |
| 760 |
-> pack(-side=>'left', -anchor=>'e', -expand=>1); |
| 761 |
$balloon -> attach($sites_label, -msg=>$$help{'unique'}); |
| 762 |
manage($sites_label, "header"); |
| 763 |
|
| 764 |
my $nsites_label = $sites_title_frame |
| 765 |
-> Label(-text=>$$labels{"nsites"}, |
| 766 |
@sites_label_args) |
| 767 |
-> pack(-side=>'left'); |
| 768 |
manage($nsites_label, "label"); |
| 769 |
my $nsites_field = $sites_title_frame |
| 770 |
-> Label(@sites_label_args, -width=>3, |
| 771 |
-textvariable=>\$pnsites,) |
| 772 |
-> pack(-side=>'left'); |
| 773 |
manage($nsites_field, "label"); |
| 774 |
my $add_site_button = $sites_title_frame |
| 775 |
-> Button(-text => $$labels{"add"}, |
| 776 |
-anchor => 'se', @button_args, |
| 777 |
-command => $function_refs{"add"},) |
| 778 |
-> pack(-side=>'right', -padx=>5); |
| 779 |
$balloon->attach($add_site_button, |
| 780 |
-msg=>$$help{'add'},); |
| 781 |
manage($add_site_button, "button"); |
| 782 |
|
| 783 |
$sites_list = $sites_frame |
| 784 |
-> Table(-fixedrows => 1, |
| 785 |
-fixedcolumns => 1, |
| 786 |
-rows => $initial_sites, |
| 787 |
-columns => 8, |
| 788 |
-scrollbars => 'sw', |
| 789 |
-borderwidth => 0, |
| 790 |
-background => $colors{background} |
| 791 |
) |
| 792 |
-> pack(-anchor=>'center', -fill=>'both', -padx=>4); |
| 793 |
#$sites_list->Subwidget("xscrollbar")->configure(-background=>$colors{background}); |
| 794 |
#$sites_list->Subwidget("yscrollbar")->configure(-background=>$colors{background}); |
| 795 |
&site_labels($sites_list); |
| 796 |
foreach my $i (0..3) { |
| 797 |
$unique_sites[$i] = &site_widget($sites_list, $i); |
| 798 |
}; |
| 799 |
|
| 800 |
|
| 801 |
### > program control panels |
| 802 |
|
| 803 |
###################################################################### |
| 804 |
######### ################### |
| 805 |
######### Control panel for the various programs ################### |
| 806 |
######### ################### |
| 807 |
###################################################################### |
| 808 |
|
| 809 |
|
| 810 |
use Tk::NoteBook; |
| 811 |
|
| 812 |
## make the pages of the notebook, one for each program |
| 813 |
my ($notebook, $noteframe); |
| 814 |
if ($meta{one_frame}) { # both panels in one frame |
| 815 |
$notebook = $top -> NoteBook(-backpagecolor=>$colors{background}, |
| 816 |
-inactivebackground=>$colors{background},); |
| 817 |
} else { # split frame in half (good for low-res) |
| 818 |
$noteframe = $top -> Toplevel(-class=>'horae'); |
| 819 |
$noteframe -> iconbitmap('@'.File::Spec->catfile($Xray::Atoms::lib_dir, "tkatoms3.xbm")) |
| 820 |
unless $is_windows; |
| 821 |
$notebook = $noteframe -> NoteBook(-backpagecolor=>$colors{background}, |
| 822 |
-inactivebackground=>$colors{background},); |
| 823 |
$noteframe -> bind('<Control-q>' => \&quit_tkatoms); #sub{exit}); |
| 824 |
$noteframe -> bind('<Control-l>' => \&load_input); # what about Molecule? |
| 825 |
$noteframe -> bind('<Control-s>' => \&save_input); |
| 826 |
$noteframe -> bind('<Control-d>' => sub{&display_in_frame($top, '', 0)}); |
| 827 |
$noteframe -> title($$labels{tkatoms_title}); |
| 828 |
## $noteframe -> iconname($$labels{tkatoms_title}); |
| 829 |
## $noteframe -> iconbitmap('@'.$icon); |
| 830 |
}; |
| 831 |
## my %fr = (); |
| 832 |
require Xray::Tk::Atoms; |
| 833 |
($ifeffit_exists) and require Xray::Tk::Plotter; |
| 834 |
use vars qw/%pages/; ## 'Molecule', |
| 835 |
foreach my $f0 ('Atoms', 'Absorption', 'Powder', 'DAFS', 'Plotter') { |
| 836 |
next if (($f0 eq 'Plotter') and (not $ifeffit_exists)); |
| 837 |
$pages{$f0} = $notebook -> add(lc($f0), -label=>$f0, -anchor=>'center'); |
| 838 |
if ($f0 eq 'Atoms') { |
| 839 |
&Xray::Tk::Atoms::atoms($pages{$f0}); |
| 840 |
next; |
| 841 |
#} elsif ($f0 eq 'Molecule') { |
| 842 |
# $notebook -> |
| 843 |
# pageconfigure(lc($f0), -createcmd=>sub{require Xray::Tk::Molecule; |
| 844 |
# &Xray::Tk::Molecule::molecule}); |
| 845 |
# next; |
| 846 |
} elsif ($f0 eq 'Absorption') { |
| 847 |
$notebook -> |
| 848 |
pageconfigure(lc($f0), -createcmd=>sub{require Xray::Tk::Absorption; |
| 849 |
&Xray::Tk::Absorption::absorption}); |
| 850 |
next; |
| 851 |
} elsif ($f0 eq 'DAFS') { |
| 852 |
$notebook -> |
| 853 |
pageconfigure(lc($f0), -createcmd=>sub{require Xray::Tk::Dafs; |
| 854 |
&Xray::Tk::Dafs::dafs}); |
| 855 |
next; |
| 856 |
} elsif ($f0 eq 'Powder') { |
| 857 |
$notebook -> |
| 858 |
pageconfigure(lc($f0), -createcmd=>sub{require Xray::Tk::Powder; |
| 859 |
&Xray::Tk::Powder::powder}); |
| 860 |
next; |
| 861 |
} elsif ($f0 eq 'Plotter') { |
| 862 |
($ifeffit_exists) && eval '&Xray::Tk::Plotter::plotter($pages{$f0})'; |
| 863 |
next; |
| 864 |
}; |
| 865 |
}; |
| 866 |
$notebook->pack(-expand => 'y', -fill => 'both', -side => 'bottom'); |
| 867 |
|
| 868 |
#print $INC{'Xray/Tk/Absorption.pm'}, $/; |
| 869 |
|
| 870 |
## --------- About to begin the main loop ----------------------------- |
| 871 |
|
| 872 |
my $file; |
| 873 |
if (@ARGV) { |
| 874 |
INPUT:{ |
| 875 |
$file = $ARGV[0], last INPUT if (-e $ARGV[0]); |
| 876 |
$file = $ARGV[0] . ".inp", last INPUT if (-e "$ARGV[0].inp"); |
| 877 |
$file = $ARGV[0] . "inp", last INPUT if (-e "$ARGV[0]inp"); |
| 878 |
$file = 0; |
| 879 |
}; |
| 880 |
}; |
| 881 |
($file) and load_input($file); |
| 882 |
|
| 883 |
## print join($/,@all_labels, @all_entries, @all_buttons, @all_radio, |
| 884 |
## @all_headers, @all_menus),$/; |
| 885 |
## exit; |
| 886 |
|
| 887 |
###################################################################### |
| 888 |
######### ########################## |
| 889 |
MainLoop(); ########################## |
| 890 |
######### ########################## |
| 891 |
###################################################################### |
| 892 |
|
| 893 |
|
| 894 |
###################################################################### |
| 895 |
######### ################################ |
| 896 |
######### Miscellaneous subroutines ################################ |
| 897 |
######### ################################ |
| 898 |
###################################################################### |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
## ------------------------------------------------------------ ## |
| 903 |
## loading and saving input files ## |
| 904 |
## ------------------------------------------------------------ ## |
| 905 |
|
| 906 |
sub load_input { |
| 907 |
my $inputfile; |
| 908 |
#local $Tk::FBox::a; |
| 909 |
#local $Tk::FBox::b; |
| 910 |
unless (($_[0] and -e $_[0]) or ($_[0] and $_[0] =~ /^http:/)) { |
| 911 |
my $path = $meta{default_filepath} || cwd(); |
| 912 |
my $types = [['input files', '.inp'], |
| 913 |
['All Files', '*'],]; |
| 914 |
$inputfile = $top -> getOpenFile(-defaultextension=>'inp', |
| 915 |
-filetypes=>$types, |
| 916 |
-initialdir=>$path, |
| 917 |
#($is_windows) ? () : |
| 918 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}), |
| 919 |
-title => $$labels{'file_dialog'}); |
| 920 |
return 0 unless $inputfile; |
| 921 |
} else { |
| 922 |
$inputfile = $_[0]; |
| 923 |
}; |
| 924 |
($inputfile =~ /^http:/) or $meta{default_filepath} = dirname($inputfile); |
| 925 |
&Xray::Tk::Atoms::clear_atoms(); |
| 926 |
&clear_lattice(); |
| 927 |
$keywords -> make(quiet=>1, die=>1); |
| 928 |
$keywords -> parse_input($inputfile, 1); |
| 929 |
foreach my $key (keys %atoms_widgets) { |
| 930 |
next if ($key =~ /_button$/); |
| 931 |
KEYWORDS: { |
| 932 |
($key eq 'title') && do { |
| 933 |
$atoms_widgets{'title'} -> delete(qw/1.0 end/); |
| 934 |
foreach my $t (@{$keywords->{'title'}}) { |
| 935 |
$atoms_widgets{'title'} -> insert('end', $t.$/); |
| 936 |
}; |
| 937 |
last KEYWORDS; |
| 938 |
}; |
| 939 |
($key eq 'shift') && do { |
| 940 |
foreach my $i (0..2) { |
| 941 |
$atoms_widgets{'shift'}[$i] -> delete(qw/0 end/); |
| 942 |
$atoms_widgets{'shift'}[$i] -> insert(0, $keywords->{'shift'}[$i]); |
| 943 |
}; |
| 944 |
last KEYWORDS; |
| 945 |
}; |
| 946 |
($key eq 'edge') && do { |
| 947 |
$atoms_values{'edge'} = $keywords->{'edge'}; |
| 948 |
last KEYWORDS; |
| 949 |
}; |
| 950 |
($key =~ /argon|krypton|nitrogen/) && do { |
| 951 |
$atoms_widgets{$key} -> set($keywords->{$key}); |
| 952 |
last KEYWORDS; |
| 953 |
}; |
| 954 |
do { |
| 955 |
$atoms_widgets{$key} -> delete(qw/0 end/); |
| 956 |
$keywords->{$key} and |
| 957 |
$atoms_widgets{$key} -> insert(0, $keywords->{$key}); |
| 958 |
last KEYWORDS; |
| 959 |
}; |
| 960 |
}; |
| 961 |
}; |
| 962 |
foreach my $key (keys %lattice) { |
| 963 |
LATTICE: { |
| 964 |
($key eq 'space') && do { |
| 965 |
$lattice{$key} -> delete(qw/0 end/); |
| 966 |
$lattice{$key} -> insert(0, $keywords->{$key}); |
| 967 |
}; |
| 968 |
($key =~ /^(a|b|c)$/) && do { |
| 969 |
if (abs($keywords->{$key}) > EPSILON) { |
| 970 |
$lattice{$key} -> delete(qw/0 end/); |
| 971 |
$lattice{$key} -> insert(0, $keywords->{$key}); |
| 972 |
}; |
| 973 |
last LATTICE; |
| 974 |
}; |
| 975 |
($key =~ /^(alpha|beta|gamma)$/) && do { |
| 976 |
last LATTICE if (abs($keywords->{$key}-90) < EPSILON); |
| 977 |
last LATTICE if (abs($keywords->{$key}) < EPSILON); |
| 978 |
$lattice{$key} -> delete(qw/0 end/); |
| 979 |
$lattice{$key} -> insert(0, $keywords->{$key}); |
| 980 |
last LATTICE; |
| 981 |
}; |
| 982 |
}; |
| 983 |
}; |
| 984 |
my $count = 1; |
| 985 |
$site_entries[0]{'core'} -> select; |
| 986 |
foreach my $s (@{$keywords->{'sites'}}) { |
| 987 |
if ($count == 1) { |
| 988 |
($keywords->{'core'}) or $keywords->{'core'} = $$s[0] || $$s[4]; |
| 989 |
}; |
| 990 |
($count > $pnsites) && &add_one_site; |
| 991 |
$site_entries[$count-1]{'elem'} -> insert(0,$$s[0]); |
| 992 |
$site_entries[$count-1]{'x'} -> insert(0,$$s[1]); |
| 993 |
$site_entries[$count-1]{'y'} -> insert(0,$$s[2]); |
| 994 |
$site_entries[$count-1]{'z'} -> insert(0,$$s[3]); |
| 995 |
($$s[4]) && |
| 996 |
$site_entries[$count-1]{'tag'} -> insert(0,$$s[4]); |
| 997 |
($$s[5]) && |
| 998 |
$site_entries[$count-1]{'occ'} -> set($$s[5]); |
| 999 |
if ( (lc($keywords->{"core"}) eq lc($$s[4])) or |
| 1000 |
(lc($keywords->{"core"}) eq lc($$s[0])) ) { |
| 1001 |
$site_entries[$count-1]{'core'} -> select; |
| 1002 |
}; |
| 1003 |
++$count; |
| 1004 |
}; |
| 1005 |
$_[1] or register_recent($inputfile); |
| 1006 |
}; |
| 1007 |
|
| 1008 |
|
| 1009 |
sub register_recent { |
| 1010 |
my $file = $_[0]; |
| 1011 |
my $name = basename($file); |
| 1012 |
## put this one on the list |
| 1013 |
unshift @recent_files, $file; |
| 1014 |
($#recent_files > 8) and pop @recent_files; |
| 1015 |
$recent_menu = $top -> Menu(@menu_args, -tearoff=>0, |
| 1016 |
-menuitems=>\@recent_files); |
| 1017 |
## update the list in each of the tabs |
| 1018 |
foreach my $r (@recent_registry) { |
| 1019 |
$r -> command(-label=>$file, -command=>sub{&load_input($file, 1)}); |
| 1020 |
#$r -> delete(0, 'end'); |
| 1021 |
#foreach my $f (@recent_files) { |
| 1022 |
# $r -> command(-label=>$f, -command=>sub{print $f,$/}); |
| 1023 |
#}; |
| 1024 |
}; |
| 1025 |
#print @recent_files, $/; |
| 1026 |
#print join($/, @recent_registry), $/; |
| 1027 |
}; |
| 1028 |
|
| 1029 |
sub load_adb { |
| 1030 |
my $adb_box = $top -> Toplevel(-class=>'horae'); |
| 1031 |
$adb_box -> iconbitmap('@'.File::Spec->catfile($Xray::Atoms::lib_dir, "tkatoms3.xbm")) |
| 1032 |
unless $is_windows; |
| 1033 |
$adb_box -> title('ADB'); |
| 1034 |
$adb_box -> iconname('ADB'); |
| 1035 |
my $frame = $adb_box -> Frame() -> pack(-expand=>1); |
| 1036 |
my $label = $frame -> Label(-text=>$$labels{adb_header}, |
| 1037 |
@::header_args) |
| 1038 |
-> pack(); |
| 1039 |
&::manage($label, "header"); |
| 1040 |
$frame = $adb_box -> Frame(-borderwidth=>4, -relief=>'ridge') |
| 1041 |
-> pack(); |
| 1042 |
my $list = $frame |
| 1043 |
-> Scrolled('Text', qw/-scrollbars e -height 20 -width 20/) |
| 1044 |
-> pack(); |
| 1045 |
$list->Subwidget("yscrollbar")->configure(-background=>$colors{background}); |
| 1046 |
my @inps; |
| 1047 |
fetch_adb_list(\@inps); |
| 1048 |
foreach (@inps) { |
| 1049 |
my $b = $list -> Button(-text=>$_, -width=>16, -relief=>'groove', |
| 1050 |
@label_args, |
| 1051 |
-command=>[\&fetch_adb_file, $_, $adb_box]); |
| 1052 |
$list -> windowCreate('end', -window=>$b); |
| 1053 |
manage($b, "label"); |
| 1054 |
}; |
| 1055 |
$frame = $adb_box -> Frame() -> pack(-expand=>1); |
| 1056 |
my $button => $frame -> Button(-text=>$$labels{'dismiss'}, |
| 1057 |
@button_args, |
| 1058 |
-command=>sub{$adb_box -> destroy}) |
| 1059 |
-> pack(); |
| 1060 |
manage($button, "button"); |
| 1061 |
}; |
| 1062 |
|
| 1063 |
sub fetch_adb_file { |
| 1064 |
my ($name, $parent) = @_; |
| 1065 |
load_input($meta{ADB_location}.$name); |
| 1066 |
#$parent -> destroy; |
| 1067 |
}; |
| 1068 |
|
| 1069 |
sub fetch_adb_list { |
| 1070 |
my $r_list = $_[0]; |
| 1071 |
my %found = (); |
| 1072 |
my $list = LWP::Simple::get($meta{ADB_location}); |
| 1073 |
while ($list =~ /([A-Za-z0-9_-]+\.inp\b)/g) { |
| 1074 |
next if ($1 eq 'feff.inp'); |
| 1075 |
next if $found{$1} ++; |
| 1076 |
push @$r_list, $1; |
| 1077 |
}; |
| 1078 |
return $r_list; |
| 1079 |
}; |
| 1080 |
|
| 1081 |
|
| 1082 |
sub download_adb { |
| 1083 |
require Tk::FileSelect; |
| 1084 |
my $path = $meta{default_filepath} || cwd(); |
| 1085 |
my $FSel = $top->FileSelect(-title => $$labels{adb_dldir}, |
| 1086 |
-create => 1, |
| 1087 |
-directory => $path, |
| 1088 |
-SelDir => 1,); |
| 1089 |
##%$file_dialog,); |
| 1090 |
my $dir = $FSel->Show(-Horiz => 1); |
| 1091 |
(-d $dir) or do { |
| 1092 |
require File::Path; |
| 1093 |
File::Path::mkpath($dir, 0, 0755); |
| 1094 |
}; |
| 1095 |
my @inps; |
| 1096 |
fetch_adb_list(\@inps); |
| 1097 |
my $box = $top -> Toplevel(-class=>'horae'); |
| 1098 |
my $frame = $box -> Frame() -> pack(-expand=>1); |
| 1099 |
my $num = $#inps + 1; |
| 1100 |
my $label = $frame -> Label(-text=>$$labels{adb_dlnum} . " $num", |
| 1101 |
@::header_args) |
| 1102 |
-> pack(); |
| 1103 |
&::manage($label, "header"); |
| 1104 |
$frame = $box -> Frame() -> pack(-expand=>1); |
| 1105 |
my $text = $frame -> Label(-relief=>'flat', |
| 1106 |
-text=>$$labels{adb_dldirname}." \n$dir", @label_args) |
| 1107 |
-> pack(); |
| 1108 |
&::manage($text, "label"); |
| 1109 |
$text = $frame -> Text(-relief=>'flat', -width=>40, -height=>1) |
| 1110 |
-> pack(); |
| 1111 |
&::manage($text, "entry"); |
| 1112 |
my $quit = 0; |
| 1113 |
my $button => $box -> Button(-text=>$$labels{'quit'}, |
| 1114 |
@button_args, |
| 1115 |
-command=>sub{$quit = 1;}) |
| 1116 |
-> pack(); |
| 1117 |
manage($button, "button"); |
| 1118 |
$top->update; |
| 1119 |
my $i = 0; |
| 1120 |
foreach (@inps) { |
| 1121 |
last if ($quit); |
| 1122 |
++$i; |
| 1123 |
$text -> delete(qw/1.0 end/); |
| 1124 |
$text -> insert('1.0', $$labels{adb_dling}." $i: $_"); |
| 1125 |
$top -> update; |
| 1126 |
open DL, '>'.$dir.'/'.$_; |
| 1127 |
my $file = LWP::Simple::get($meta{ADB_location}.$_); |
| 1128 |
print DL $file; |
| 1129 |
close DL; |
| 1130 |
}; |
| 1131 |
$box -> destroy; |
| 1132 |
}; |
| 1133 |
|
| 1134 |
sub save_input { |
| 1135 |
$cell -> make( Occupancy=>0 ); |
| 1136 |
&set_core($core_index); |
| 1137 |
&validate_lattice(0); |
| 1138 |
&Xray::Tk::Atoms::atoms_validate(0); |
| 1139 |
$keywords -> verify_keywords($cell, \@sites, 1); |
| 1140 |
my $contents = ""; |
| 1141 |
$keywords -> make('identity'=>"TkAtoms $v"); |
| 1142 |
my ($ofname, $is_feff) |
| 1143 |
= parse_atp('atoms', $cell, $keywords, \@cluster, \@neutral, \$contents); |
| 1144 |
my $path = $meta{default_filepath} || cwd(); |
| 1145 |
my $types = [['input files', '.inp' ], |
| 1146 |
['All Files', '*', ],]; |
| 1147 |
my $inputfile = $top -> getSaveFile(-defaultextension=>'inp', |
| 1148 |
-filetypes=>$types, |
| 1149 |
#(not $is_windows) ? |
| 1150 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 1151 |
-initialdir=>$path, |
| 1152 |
-initialfile=>$ofname, |
| 1153 |
-title => $$labels{'save_dialog'}); |
| 1154 |
return 0 unless $inputfile; |
| 1155 |
$meta{default_filepath} = dirname($inputfile); |
| 1156 |
open (INP, ">".$inputfile) or |
| 1157 |
die $$Xray::Atoms::messages{cannot_write} . $inputfile . $/; |
| 1158 |
print INP $contents; |
| 1159 |
close INP; |
| 1160 |
}; |
| 1161 |
|
| 1162 |
|
| 1163 |
sub quit_tkatoms { |
| 1164 |
## only want to offer the possibility of saving if it need be done. |
| 1165 |
## also want to suppress warning messages. |
| 1166 |
($meta{never_ask_to_save}) and exit; |
| 1167 |
$meta{no_crystal_warnings} = 1; |
| 1168 |
@sites = (); |
| 1169 |
my $cancel = 0; |
| 1170 |
my $axis = ($lattice{a}->get or $lattice{b}->get or $lattice{c}->get); |
| 1171 |
if (($lattice{space}->get) and ($axis)) { # space group defined? |
| 1172 |
&validate_lattice(0); |
| 1173 |
(@sites) and do { # any sites defined? |
| 1174 |
my $dialog = $top -> |
| 1175 |
DialogBox(-title=>$$labels{'save_data'}, |
| 1176 |
-buttons=>[$$labels{'yes'}, $$labels{'no'},$$labels{'cancel'}]); |
| 1177 |
$dialog -> add("Label", qw/-padx .25c -pady .25c -text/, |
| 1178 |
$$labels{'save_data_message'}) |
| 1179 |
-> pack(-side=>'left'); |
| 1180 |
my $button = $dialog -> Show; |
| 1181 |
($button eq $$labels{'yes'}) and &save_input; |
| 1182 |
($button eq $$labels{'cancel'}) and $cancel = 1; |
| 1183 |
}; |
| 1184 |
}; |
| 1185 |
($cancel) or exit; |
| 1186 |
}; |
| 1187 |
|
| 1188 |
|
| 1189 |
### >> site widget subroutines |
| 1190 |
|
| 1191 |
## ------------------------------------------------------------ ## |
| 1192 |
## subroutines for the site widgets ## |
| 1193 |
## ------------------------------------------------------------ ## |
| 1194 |
|
| 1195 |
|
| 1196 |
## This subroutine returns the frame containing the widgets used to |
| 1197 |
## define a site. It also filled the LoH @site_entries with the |
| 1198 |
## widgets containing the element, coordinates, and tag of the site. |
| 1199 |
## The list part is an index indicating the site, the hash part is |
| 1200 |
## words like 'elem', 'x', and so on. |
| 1201 |
my @valance_values; |
| 1202 |
sub site_widget { |
| 1203 |
my ($parent, $which) = @_; |
| 1204 |
my $site_label = $parent -> Label(-text => $which+1, @header_args, |
| 1205 |
-font => $fonts{entry}, |
| 1206 |
-width => 2,); |
| 1207 |
$parent -> put($which+1, 0, $site_label); |
| 1208 |
manage($site_label, "header"); |
| 1209 |
$site_entries[$which]{'core'} = $parent |
| 1210 |
-> Radiobutton(-value => $which, |
| 1211 |
-selectcolor => $colors{radio}, |
| 1212 |
-variable => \$core_index, |
| 1213 |
-command => [\&set_core, $which], |
| 1214 |
); |
| 1215 |
$parent -> put($which+1, 1, $site_entries[$which]{'core'}); |
| 1216 |
$balloon->attach($site_entries[$which]{'core'}, -msg=>$$help{'core'},); |
| 1217 |
manage($site_entries[$which]{'core'}, "radio"); |
| 1218 |
my %width = ('elem'=>5, 'x'=>9, 'y'=>9, 'z'=>9, 'tag'=>10); |
| 1219 |
my $count = 1; |
| 1220 |
foreach my $coord ('elem', 'x', 'y', 'z', 'tag') { |
| 1221 |
$site_entries[$which]{$coord} = $parent |
| 1222 |
-> Entry(-width=>$width{$coord}, @entry_args,); |
| 1223 |
$parent -> put($which+1, ++$count, $site_entries[$which]{$coord}); |
| 1224 |
manage($site_entries[$which]{$coord}, "entry"); |
| 1225 |
if ($coord =~ /^(x|y|z)$/) { |
| 1226 |
$site_entries[$which]{$coord} -> insert(0,"0"); |
| 1227 |
}; |
| 1228 |
$site_entries[$which]{$coord} -> |
| 1229 |
bind("<$meta{unused_modifier}-Key-Right>", |
| 1230 |
[\&site_navigate, \$sites_list, \@site_entries, |
| 1231 |
$which, $coord, 0, 0]); |
| 1232 |
$site_entries[$which]{$coord} -> |
| 1233 |
bind("<$meta{unused_modifier}-Key-Left>", |
| 1234 |
[\&site_navigate, \$sites_list, \@site_entries, |
| 1235 |
$which, $coord, 1, 0]); |
| 1236 |
$site_entries[$which]{$coord} -> |
| 1237 |
bind("<$meta{unused_modifier}-Key-Up>", |
| 1238 |
[\&site_navigate, \$sites_list, \@site_entries, |
| 1239 |
$which, $coord, 0, 1]); |
| 1240 |
$site_entries[$which]{$coord} -> |
| 1241 |
bind("<$meta{unused_modifier}-Key-Down>", |
| 1242 |
[\&site_navigate, \$sites_list, \@site_entries, |
| 1243 |
$which, $coord, 1, 1]); |
| 1244 |
}; |
| 1245 |
$occupancy[$which] = 1.00; |
| 1246 |
$site_entries[$which]{'occ'} = $parent |
| 1247 |
-> Scale(-from => 0, |
| 1248 |
-to => 1, |
| 1249 |
-orient => 'horizontal', |
| 1250 |
-resolution => 0.01, |
| 1251 |
'-length' => 50, |
| 1252 |
-sliderlength => 15, |
| 1253 |
-showvalue => 0, |
| 1254 |
-variable => \$occupancy[$which], |
| 1255 |
-foreground => $colors{label},); |
| 1256 |
$parent -> put($which+1, ++$count, $site_entries[$which]{'occ'}); |
| 1257 |
## this Scale one needs to go into some list |
| 1258 |
$site_entries[$which]{'occ_label'} = $parent |
| 1259 |
-> Label(-width=>4, -textvariable=>\$occupancy[$which], |
| 1260 |
-font=>$fonts{label}, -foreground=>$colors{label},); |
| 1261 |
$parent -> put($which+1, ++$count, $site_entries[$which]{'occ_label'}); |
| 1262 |
manage($site_entries[$which]{'occ_label'}, "label"); |
| 1263 |
foreach my $b ('clear_site') { # ('clear_site', 'remove') { |
| 1264 |
my $button = $parent -> Button(-text=>$$labels{$b}, @button_args, |
| 1265 |
-command=>[$function_refs{$b}, $which]); |
| 1266 |
$parent -> put($which+1, ++$count, $button); |
| 1267 |
$balloon->attach($button, -msg=>$$help{$b},); |
| 1268 |
manage($button, "button"); |
| 1269 |
}; |
| 1270 |
|
| 1271 |
# valance |
| 1272 |
my $up_bitmap = "#define up_width 14 |
| 1273 |
#define up_height 13 |
| 1274 |
static unsigned char up_bits[] = { |
| 1275 |
0xc0, 0x00, 0xc0, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xf0, 0x03, 0xf0, 0x03, |
| 1276 |
0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, 0xfe, 0x1f, 0xfe, 0x1f, |
| 1277 |
0x00, 0x00};"; |
| 1278 |
my $up_img = $parent -> Bitmap('up', -data=>$up_bitmap, |
| 1279 |
-foreground=>$colors{entry}); |
| 1280 |
my $dn_bitmap = "#define dn_width 14 |
| 1281 |
#define dn_height 13 |
| 1282 |
static unsigned char dn_bits[] = { |
| 1283 |
0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, |
| 1284 |
0xf0, 0x03, 0xf0, 0x03, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00, 0xc0, 0x00, |
| 1285 |
0x00, 0x00};"; |
| 1286 |
my $dn_img = $parent -> Bitmap('dn', -data=>$dn_bitmap, |
| 1287 |
-foreground=>$colors{entry}); |
| 1288 |
##my $up_img = File::Spec->catfile($xtal_dir, 'up.xbm'); |
| 1289 |
##my $dn_img = File::Spec->catfile($xtal_dir, 'dn.xbm'); |
| 1290 |
my $valance_frame = $parent -> Frame(-borderwidth=>2, -relief=>'sunken'); |
| 1291 |
my $up = $valance_frame -> Button(#-text=>"^", |
| 1292 |
@button_args, |
| 1293 |
-command=>sub{++$valance_values[$which]}, |
| 1294 |
-image => $up_img, |
| 1295 |
) |
| 1296 |
-> pack(-side=>'left'); |
| 1297 |
$site_entries[$which]{'Val'} = $valance_frame |
| 1298 |
-> Entry(-width=>2, @::entry_args, -textvariable=>\$valance_values[$which]) |
| 1299 |
-> pack(-side=>'left'); |
| 1300 |
my $dn = $valance_frame -> Button(#-text=>"v", |
| 1301 |
@button_args, |
| 1302 |
-command=>sub{--$valance_values[$which]}, |
| 1303 |
-image => $dn_img, |
| 1304 |
) |
| 1305 |
-> pack(-side=>'left'); |
| 1306 |
$parent -> put($which+1, ++$count, $valance_frame); |
| 1307 |
$balloon -> attach($up, -msg=>$$::help{valance_up}); |
| 1308 |
$balloon -> attach($dn, -msg=>$$::help{valance_dn}); |
| 1309 |
manage($up, "button"); |
| 1310 |
manage($dn, "button"); |
| 1311 |
manage($site_entries[$which]{'Val'}, "entry"); |
| 1312 |
|
| 1313 |
# thermal factors |
| 1314 |
$site_entries[$which]{B} = $parent |
| 1315 |
-> Entry(-width=>8, @::entry_args,); |
| 1316 |
$parent -> put($which+1, ++$count, $site_entries[$which]{B}); |
| 1317 |
manage($site_entries[$which]{B}, "entry"); |
| 1318 |
#foreach my $l ('Bx', 'By', 'Bz') { |
| 1319 |
# $site_entries[$which]{$l} = $parent |
| 1320 |
# -> Entry(-width=>8, @::entry_args,); |
| 1321 |
# $parent -> put($which+1, ++$count, $site_entries[$which]{$l}); |
| 1322 |
# manage($site_entries[$which]{$l}, "entry"); |
| 1323 |
#}; |
| 1324 |
|
| 1325 |
# color column |
| 1326 |
my $fr = $parent -> Frame(-borderwidth=>2, -relief=>'sunken'); |
| 1327 |
my $site = Xray::Xtal::Site -> new(); |
| 1328 |
my $this_color = $site->default_color($which); |
| 1329 |
$site_entries[$which]{color} = |
| 1330 |
$fr -> Label(-text=>' ', |
| 1331 |
-background=>$this_color, |
| 1332 |
-borderwidth=>1, -relief=>'raised') |
| 1333 |
-> pack(-side=>'left', -padx=>2); |
| 1334 |
undef $site; |
| 1335 |
my $button = $fr -> |
| 1336 |
Button(-text=>$$::config{'set'}, |
| 1337 |
@::button_args, |
| 1338 |
-command=>sub{1; |
| 1339 |
#$current = ($ce->children())[11] -> get(); |
| 1340 |
#$values{$name} = $current; |
| 1341 |
#$color_button{$name} -> configure(-background=>$current); |
| 1342 |
}) |
| 1343 |
-> pack(-side=>'left'); |
| 1344 |
manage($button, "button"); |
| 1345 |
(exists $$help{set_site_color}) and |
| 1346 |
$::balloon->attach($button, -msg=>$$help{set_site_color},); |
| 1347 |
$parent -> put($which+1, ++$count, $fr); #$site_entries[$which]{$l}); |
| 1348 |
|
| 1349 |
#file column |
| 1350 |
$fr = $parent -> Frame(-borderwidth=>2, -relief=>'sunken'); |
| 1351 |
my $this_file = ""; |
| 1352 |
$site_entries[$which]{file} = |
| 1353 |
$fr -> Entry(-width=>10, @::entry_args, -textvariable=>$this_file) |
| 1354 |
-> pack(-side=>'left'); |
| 1355 |
manage($site_entries[$which]{file}, "entry"); |
| 1356 |
my $current = cwd(); |
| 1357 |
my $home; |
| 1358 |
eval '$home = $ENV{"HOME"} || $ENV{"LOGDIR"} || (getpwuid($<))[7];' |
| 1359 |
or $home = ""; |
| 1360 |
$button = $fr -> |
| 1361 |
Button(-text=>$$config{'browse'}, |
| 1362 |
@::button_args, |
| 1363 |
-command=>sub{ |
| 1364 |
#local $Tk::FBox::a; |
| 1365 |
#local $Tk::FBox::b; |
| 1366 |
my $path = $meta{default_filepath} || cwd(); |
| 1367 |
my $types = [['data files', '.dat' ], |
| 1368 |
['All Files', '*', ],]; |
| 1369 |
$this_file = $top -> getOpenFile(-filetypes=>$types, |
| 1370 |
-initialdir=>$path, |
| 1371 |
#(not $is_windows) ? |
| 1372 |
#(-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 1373 |
-title => "TkAtoms: " . |
| 1374 |
$$labels{'site_aux_file'}); |
| 1375 |
$site_entries[$which]{file} -> delete(0,'end'); |
| 1376 |
$site_entries[$which]{file} -> insert(0,$this_file); |
| 1377 |
$site_entries[$which]{file} -> xview(moveto=>1); |
| 1378 |
($this_file) and $meta{default_filepath} = dirname($this_file); |
| 1379 |
return 0; |
| 1380 |
}) |
| 1381 |
-> pack(-side=>'left'); |
| 1382 |
manage($button, "button"); |
| 1383 |
(exists $$config{browse_help}) and |
| 1384 |
$::balloon->attach($button, -msg=>$$config{browse_help},); |
| 1385 |
$parent -> put($which+1, ++$count, $fr); |
| 1386 |
}; |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
## general scheme for moving around a table of the sort use in TkAtoms |
| 1391 |
## for sites, typically boud to <mod-arrow> where "mod" is defined in |
| 1392 |
## rcfile. |
| 1393 |
sub site_navigate { |
| 1394 |
shift @_; |
| 1395 |
my ($widget, $r_list, $which, $coord, $direction, $dimension) = @_; |
| 1396 |
if ($dimension) { |
| 1397 |
my %col = ('elem'=>0, 'x'=>1, 'y'=>2, 'z'=>3, 'tag'=>4); |
| 1398 |
my $row = ($direction) ? $which+1 : $which-1; |
| 1399 |
my $inc = ($direction) ? 1 : -1; |
| 1400 |
($row < 0) and $row = $#{$r_list}; # wrap |
| 1401 |
($row > $#{$r_list}) and $row = 0; |
| 1402 |
$$widget -> yview('moveto',($row/($#{$r_list})),'pages'); |
| 1403 |
$$r_list[$row]{$coord} -> focus(); |
| 1404 |
$$r_list[$row]{$coord} -> selectionRange(0, 'end'); |
| 1405 |
} else { |
| 1406 |
my %forward = |
| 1407 |
('elem'=>'x', 'x'=>'y', 'y'=>'z', 'z'=>'tag', 'tag'=>'elem'); |
| 1408 |
my %backward = |
| 1409 |
('elem'=>'tag', 'x'=>'elem', 'y'=>'x', 'z'=>'y', 'tag'=>'z'); |
| 1410 |
my $point = ($direction) ? $backward{$coord} : $forward{$coord}; |
| 1411 |
$$r_list[$which]{$point} -> focus(); |
| 1412 |
$$r_list[$which]{$point} -> selectionRange(0, 'end'); |
| 1413 |
return; |
| 1414 |
}; |
| 1415 |
}; |
| 1416 |
|
| 1417 |
sub set_core { |
| 1418 |
my $which = $_[0]; |
| 1419 |
my $tag = $site_entries[$which]{'tag'} -> get(); |
| 1420 |
($tag =~ /^\s*$/ ) and $tag = $site_entries[$which]{'elem'} -> get(); |
| 1421 |
$keywords -> make('core'=> $tag); |
| 1422 |
$core_index = $which; |
| 1423 |
}; |
| 1424 |
|
| 1425 |
## This subroutine writes out the column labels at the top of the |
| 1426 |
## sites list. |
| 1427 |
sub site_labels { |
| 1428 |
my $parent = $_[0]; |
| 1429 |
#my $frame = $$parent -> Frame() -> pack(); |
| 1430 |
my @site_label_args = (-foreground=>$colors{"label"}, |
| 1431 |
-font=>$fonts{'entry'},); |
| 1432 |
my $count = 0; |
| 1433 |
my $site_label = $parent -> Label(-width=>2,); |
| 1434 |
$parent -> put(0, $count++, $site_label); |
| 1435 |
manage($site_label, "label"); |
| 1436 |
my %width = ('core'=> 4, 'elem'=>5, |
| 1437 |
'x'=>8, 'y'=>8, 'z'=>8, 'tag'=>10, 'occ'=>8, |
| 1438 |
'valence'=>8, 'file'=>12, 'b'=>8, 'bx'=>8, 'by'=>8, |
| 1439 |
'bz'=>8, 'color'=>8); |
| 1440 |
foreach my $coord ('core', 'elem', 'x', 'y', 'z', 'tag', 'occ', ' ', ' ', |
| 1441 |
'valence', 'B', 'color', 'file') { # 'Bx', 'By', 'Bz' |
| 1442 |
my $field = $parent |
| 1443 |
-> Label(-text=>$$labels{$coord}, -width=>$width{$coord}||2, |
| 1444 |
@site_label_args); |
| 1445 |
$parent -> put(0, $count++, $field); |
| 1446 |
$balloon->attach($field, -msg=>$$help{$coord},); |
| 1447 |
manage($field, "label"); |
| 1448 |
}; |
| 1449 |
}; |
| 1450 |
|
| 1451 |
sub add_one_site { |
| 1452 |
++$nsites; ++$pnsites; |
| 1453 |
$unique_sites[$nsites] = &site_widget($sites_list, $nsites); |
| 1454 |
#$sites_list -> put($nsites+1, 0, $unique_sites[$nsites]); |
| 1455 |
}; |
| 1456 |
|
| 1457 |
sub clear_site { |
| 1458 |
my $site = $_[0]; |
| 1459 |
(defined $sites[$site]) and $sites[$site] -> clear; |
| 1460 |
##foreach my $key (keys %{$site_entries[$site]}) { |
| 1461 |
foreach my $key (qw/elem x y z tag Val B file/) { # reset color too! |
| 1462 |
# Bx By Bz |
| 1463 |
$site_entries[$site]{$key} -> delete(qw/0 end/); |
| 1464 |
if ($key =~ /^(x|y|z)$/) { |
| 1465 |
$site_entries[$site]{$key} -> insert(0,0); |
| 1466 |
}; |
| 1467 |
$site_entries[$site]{'occ'} -> set(1); |
| 1468 |
}; |
| 1469 |
}; |
| 1470 |
|
| 1471 |
sub remove_site {print "remove site$/"}; |
| 1472 |
|
| 1473 |
|
| 1474 |
### >> lattice data subroutines |
| 1475 |
|
| 1476 |
## ------------------------------------------------------------ ## |
| 1477 |
## subroutines for lattice data ## |
| 1478 |
## ------------------------------------------------------------ ## |
| 1479 |
|
| 1480 |
|
| 1481 |
## check the lattice and fill up the Cell and Site data structures. |
| 1482 |
## If the argument is true, then display an info dialog if the cell is |
| 1483 |
## ok. Display warning or error dialogs as problems are found. |
| 1484 |
sub validate_lattice { |
| 1485 |
my $display_ok = $_[0]; |
| 1486 |
## read space group, lattice constants and angles |
| 1487 |
my $sg = $lattice{space} ->get; |
| 1488 |
my $a = &number($lattice{a} ->get, 1); |
| 1489 |
my $b = &number($lattice{b} ->get, 1); |
| 1490 |
my $c = &number($lattice{c} ->get, 1); |
| 1491 |
my $al = &number($lattice{alpha} ->get, 1); |
| 1492 |
my $be = &number($lattice{beta} ->get, 1); |
| 1493 |
my $ga = &number($lattice{gamma} ->get, 1); |
| 1494 |
if ($sg =~ /^\s*$/) { |
| 1495 |
return &tkatoms_dialog(\$top, 'no_space_group', 'warning'); |
| 1496 |
}; |
| 1497 |
## make a cell |
| 1498 |
$cell -> make( Space_group=>$sg ); |
| 1499 |
my ($rg) = $cell -> attributes("Space_group"); |
| 1500 |
unless ($rg) { |
| 1501 |
return &tkatoms_dialog(\$top, 'not_a_group', 'warning'); |
| 1502 |
}; |
| 1503 |
$cell -> make( A=>$a, B=>$b, C=>$c, Alpha=>$al, Beta=>$be, Gamma=>$ga ); |
| 1504 |
($a, $b, $c, $al, $be, $ga) = |
| 1505 |
$cell -> attributes("A", "B", "C", "Alpha", "Beta", "Gamma"); |
| 1506 |
## update cell fields |
| 1507 |
$lattice{a} -> delete(qw/0 end/); $lattice{a} -> insert(0, $a); |
| 1508 |
$lattice{b} -> delete(qw/0 end/); $lattice{b} -> insert(0, $b); |
| 1509 |
$lattice{c} -> delete(qw/0 end/); $lattice{c} -> insert(0, $c); |
| 1510 |
$lattice{alpha} -> delete(qw/0 end/); $lattice{alpha} -> insert(0, $al); |
| 1511 |
$lattice{beta} -> delete(qw/0 end/); $lattice{beta} -> insert(0, $be); |
| 1512 |
$lattice{gamma} -> delete(qw/0 end/); $lattice{gamma} -> insert(0, $ga); |
| 1513 |
## read unique site widgets and make list of site objects |
| 1514 |
my ($i, $is)=(0,0); |
| 1515 |
@sites = (); # refresh sites array |
| 1516 |
$keywords -> {'sites'} = (); |
| 1517 |
foreach my $s (@site_entries) { |
| 1518 |
++$is; |
| 1519 |
my ($e, $x, $y, $z, $t, $o) = |
| 1520 |
($$s{elem}->get, |
| 1521 |
&number($$s{'x'}->get, 1), |
| 1522 |
&number($$s{'y'}->get, 1), |
| 1523 |
&number($$s{'z'}->get, 1), |
| 1524 |
$$s{tag}->get, |
| 1525 |
&number($$s{occ}->get, 1) ); |
| 1526 |
my $ee = Chemistry::Elements::get_symbol($e); |
| 1527 |
if ($e and not defined($ee)) { |
| 1528 |
$top -> messageBox(-icon => 'error', |
| 1529 |
-message => join("", '"', $e, '" ', |
| 1530 |
$$messages{not_an_element}, " ", |
| 1531 |
$$messages{at_site}, |
| 1532 |
" ", $is, $/), |
| 1533 |
-title => 'Atoms: Error', |
| 1534 |
-type => 'OK'); |
| 1535 |
return; |
| 1536 |
}; |
| 1537 |
my ($val, $b, $color, $file) = ## $bx, $by, $bz, |
| 1538 |
(&number($$s{Val}->get, 1), ## should have some more error checking here |
| 1539 |
&number($$s{B} ->get, 1), |
| 1540 |
## &number($$s{Bx}->get, 1), |
| 1541 |
## &number($$s{By}->get, 1), |
| 1542 |
## &number($$s{Bz}->get, 1), |
| 1543 |
$$s{color}->cget('-background'), |
| 1544 |
$$s{file}->get); |
| 1545 |
next unless defined $e; |
| 1546 |
next if ($e =~ /^\s*$/); |
| 1547 |
$sites[$i] = Xray::Xtal::Site -> new($i); |
| 1548 |
$keywords -> make("sites"=> $e, $x, $y, $z, $t, $o); |
| 1549 |
#print join(" ", $e, $x, $y, $z, $t, $o, $/); |
| 1550 |
$sites[$i] -> make(Element=>$e, |
| 1551 |
X=>$x+$ {$keywords->{"shift"}}[0], |
| 1552 |
Y=>$y+$ {$keywords->{"shift"}}[1], |
| 1553 |
Z=>$z+$ {$keywords->{"shift"}}[2], |
| 1554 |
Occupancy=>$o, |
| 1555 |
Valence=>$val, |
| 1556 |
B=>$b, |
| 1557 |
## Bx=>$bx, By=>$by, Bz=>$bz, |
| 1558 |
Color=>$color, File=>$file ); |
| 1559 |
($t !~ /^\s*$/) && ( $sites[$i] -> make(Tag=>$t) ); |
| 1560 |
++$i; |
| 1561 |
}; |
| 1562 |
$cell -> populate(\@sites); |
| 1563 |
$cell -> verify_cell(); |
| 1564 |
my $message = $cell -> warn_shift(); |
| 1565 |
(($message) and (not $meta{no_crystal_warnings})) and |
| 1566 |
&tkatoms_text_dialog(\$top, $message); |
| 1567 |
$message = $cell -> cell_check(); |
| 1568 |
(($message) and (not $meta{no_crystal_warnings})) and |
| 1569 |
&tkatoms_text_dialog(\$top, $message); |
| 1570 |
($display_ok) and &tkatoms_dialog(\$top, 'cell_ok', 'info'); |
| 1571 |
return 0; |
| 1572 |
}; |
| 1573 |
|
| 1574 |
sub clear_lattice { |
| 1575 |
$core_index = 0; |
| 1576 |
$keywords = Xray::Atoms -> new(); |
| 1577 |
$keywords->make('edge' => ''); |
| 1578 |
$atoms_values{'edge'} = ''; |
| 1579 |
$atoms_titles -> delete(qw/1.0 end/); |
| 1580 |
$cell -> Xray::Xtal::Cell::clear(); |
| 1581 |
foreach my $x ("space", "a", "b", "c", "alpha", "beta", "gamma") { |
| 1582 |
$lattice{$x} -> delete(qw/0 end/); |
| 1583 |
}; |
| 1584 |
foreach my $i (0..$#site_entries) { |
| 1585 |
&clear_site($i); |
| 1586 |
}; |
| 1587 |
undef @sites; |
| 1588 |
@sites = (); |
| 1589 |
$nsites = 3; |
| 1590 |
$pnsites = $nsites+1; |
| 1591 |
## it would be nice to remove these lines from the Table, but the |
| 1592 |
## following causes noisy badness |
| 1593 |
##foreach my $i ($pnsites..$#unique_sites) { |
| 1594 |
## $unique_sites[$i] -> destroy(); |
| 1595 |
##}; |
| 1596 |
}; |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
### >> user communication |
| 1602 |
|
| 1603 |
## ------------------------------------------------------------ ## |
| 1604 |
## subroutines for communication with user ## |
| 1605 |
## ------------------------------------------------------------ ## |
| 1606 |
|
| 1607 |
## how do these dialogs need to interact with @all_ lists |
| 1608 |
|
| 1609 |
## This is a generic "communicate with the user" dialog box |
| 1610 |
## it displayes a message and has an OK button to continue |
| 1611 |
## $parent is the parent widget |
| 1612 |
## $which is the help message key from tkatomsrc.?? |
| 1613 |
## $level is 'info', 'warning', or 'error' |
| 1614 |
sub tkatoms_dialog { |
| 1615 |
my ($parent, $which, $level) = @_; |
| 1616 |
my $dlevel = $level . '_title'; |
| 1617 |
my $dialog = $$parent -> DialogBox(-title=>$$dialogs{$dlevel}, |
| 1618 |
-buttons=>[$$labels{ok}],); |
| 1619 |
$dialog -> add("Label", -bitmap=>$level, -width=>'1c', |
| 1620 |
-foreground=>$colors{"label"}, |
| 1621 |
) |
| 1622 |
-> pack(-side=>'left'); |
| 1623 |
$dialog -> add("Label", -text=>$$dialogs{$which}, |
| 1624 |
qw/-padx .25c -pady .25c/, |
| 1625 |
-foreground=>$colors{"label"}, |
| 1626 |
-font=>$fonts{'label'}, |
| 1627 |
) |
| 1628 |
-> pack(-side=>'left'); |
| 1629 |
#return $dialog; |
| 1630 |
my $ok = $dialog -> Show; |
| 1631 |
$top->update; |
| 1632 |
return $ok; |
| 1633 |
}; |
| 1634 |
sub tkatoms_text_dialog { |
| 1635 |
my ($parent, $text, $justification) = @_; |
| 1636 |
$justification ||= "center"; |
| 1637 |
my $dialog = $$parent -> DialogBox(-title=>$$dialogs{info_title}, |
| 1638 |
-buttons=>[$$labels{ok}],); |
| 1639 |
$dialog -> add("Label", -text=>$text, |
| 1640 |
qw/-padx .25c -pady .25c/, |
| 1641 |
-foreground=>$colors{"label"}, |
| 1642 |
-font=>$fonts{label}, |
| 1643 |
-justify=>$justification, |
| 1644 |
) |
| 1645 |
-> pack(-side=>'left'); |
| 1646 |
my $ok = $dialog -> Show; |
| 1647 |
$top->update; |
| 1648 |
return $ok; |
| 1649 |
}; |
| 1650 |
|
| 1651 |
|
| 1652 |
## frame for displaying data or output files |
| 1653 |
sub display_in_frame { |
| 1654 |
my ($parent, $which, $atp, $ofname, $feff) = @_; |
| 1655 |
if (not Exists $dump_frame) { |
| 1656 |
$dump_frame = $parent->Toplevel(-class=>'horae'); |
| 1657 |
$dump_frame -> bind('<Control-q>' => sub{$dump_frame->destroy}); |
| 1658 |
$dump_frame -> bind('<Control-d>' => sub{$dump_frame->destroy}); |
| 1659 |
$dump_frame -> title("TkAtoms ".$$labels{'display'}." $dump_count"); |
| 1660 |
$dump_frame -> iconname("TkAtoms ".$$labels{'display'}." $dump_count"); |
| 1661 |
$dump_frame -> iconbitmap('@'.File::Spec->catfile($Xray::Atoms::lib_dir, "tkatoms3.xbm")) |
| 1662 |
unless $is_windows; |
| 1663 |
$dump_frame_buttons = $dump_frame->Frame; |
| 1664 |
$dump_frame_buttons->pack(qw/-side bottom -expand 1 -fill x/); |
| 1665 |
my $dump_frame_buttons_dismiss = $dump_frame_buttons |
| 1666 |
-> Button( |
| 1667 |
-text => $$labels{'dismiss'}, @button_args, |
| 1668 |
-command => [$dump_frame => 'withdraw'], |
| 1669 |
); |
| 1670 |
manage($dump_frame_buttons_dismiss, "button"); |
| 1671 |
$balloon -> attach($dump_frame_buttons_dismiss, -msg=>$$help{dump_dismiss},); |
| 1672 |
$dump_frame_buttons_dismiss->pack(qw/-side left -expand 1/); |
| 1673 |
$dump_frame_buttons_save = $dump_frame_buttons |
| 1674 |
-> Button( |
| 1675 |
-text => $$labels{'save'}, @button_args, |
| 1676 |
-command => [\&save_file, \$dump_frame_text, $atp, $ofname], |
| 1677 |
-state => 'disabled', |
| 1678 |
); |
| 1679 |
manage($dump_frame_buttons_save, "button"); |
| 1680 |
$balloon -> attach($dump_frame_buttons_save, -msg=>$$help{dump_save},); |
| 1681 |
$dump_frame_buttons_save->pack(qw/-side left -expand 1/); |
| 1682 |
|
| 1683 |
my $dump_frame_buttons_preserve = $dump_frame_buttons |
| 1684 |
-> Button(-text => $$labels{'preserve'}, @button_args, ); |
| 1685 |
$dump_frame_buttons_preserve -> |
| 1686 |
configure(-command => sub{push @dump_frames, $dump_frame; |
| 1687 |
undef($dump_frame); |
| 1688 |
++$dump_count; |
| 1689 |
$dump_frame_buttons_preserve-> |
| 1690 |
configure(-state=>'disabled'); |
| 1691 |
$balloon -> detach($dump_frame_buttons_preserve); |
| 1692 |
}); |
| 1693 |
|
| 1694 |
manage($dump_frame_buttons_preserve, "button"); |
| 1695 |
$balloon -> attach($dump_frame_buttons_preserve, -msg=>$$help{dump_preserve}); |
| 1696 |
$dump_frame_buttons_preserve->pack(qw/-side left -expand 1/); |
| 1697 |
|
| 1698 |
$dump_frame_buttons_run = $dump_frame_buttons |
| 1699 |
-> Button(-text => $$labels{run_feff}, @button_args, |
| 1700 |
-command => [\&tkatoms_text_dialog, \$top, |
| 1701 |
$$labels{no_feff_yet}], |
| 1702 |
-state => 'disabled', |
| 1703 |
); |
| 1704 |
$dump_frame_buttons_run->pack(qw/-side left -expand 1/); |
| 1705 |
manage($dump_frame_buttons_run, "button"); |
| 1706 |
$balloon -> attach($dump_frame_buttons_run, -msg=>$$help{dump_run},); |
| 1707 |
$dump_frame_text = $dump_frame |
| 1708 |
-> Scrolled('Text', qw/-scrollbars se -height 40 -wrap none/); |
| 1709 |
$dump_frame_text->pack(qw/-side left -expand 1 -fill both/); |
| 1710 |
$dump_frame_text->Subwidget("xscrollbar")->configure(-background=>$colors{background}); |
| 1711 |
$dump_frame_text->Subwidget("yscrollbar")->configure(-background=>$colors{background}); |
| 1712 |
#($dump_frame_text -> children())[1]->configure(-background=>$colors{background}); |
| 1713 |
manage(($dump_frame_text -> children())[1], "slider"); |
| 1714 |
} else { |
| 1715 |
$dump_frame->deiconify; |
| 1716 |
$dump_frame->raise; |
| 1717 |
$dump_frame_buttons_save -> configure(-state=>'disabled'); |
| 1718 |
$dump_frame_buttons_run -> configure(-state=>'disabled'); |
| 1719 |
}; |
| 1720 |
$dump_frame_text->configure(qw/-state normal/); |
| 1721 |
$dump_frame_text->delete(qw/1.0 end/); |
| 1722 |
WHICH: { |
| 1723 |
($which eq '') && do { |
| 1724 |
use Data::Dumper; |
| 1725 |
$Data::Dumper::Purity = 1; |
| 1726 |
$dump_frame_text-> |
| 1727 |
insert('1.0', Data::Dumper->Dump([$Xray::Atoms::VERSION], |
| 1728 |
[qw(version)])); |
| 1729 |
$dump_frame_text-> |
| 1730 |
insert('end', Data::Dumper->Dump([$cell], [qw(cell)])); |
| 1731 |
$dump_frame_text-> |
| 1732 |
insert('end', Data::Dumper->Dump([\@sites], [qw(*sites)])); |
| 1733 |
$dump_frame_text-> |
| 1734 |
insert('end', Data::Dumper->Dump([$keywords], [qw(*keywords)])); |
| 1735 |
$dump_frame_text-> |
| 1736 |
insert('end', Data::Dumper->Dump([\%meta], |
| 1737 |
[qw(*meta)])); |
| 1738 |
$dump_frame_text-> |
| 1739 |
insert('end', Data::Dumper->Dump([$core_index], [qw(core_index)])); |
| 1740 |
#$dump_frame_text-> |
| 1741 |
#insert('end', Data::Dumper->Dump([$Xray::Tk::Atoms::selected_atp], |
| 1742 |
# [qw(selected_atp)])); |
| 1743 |
$dump_frame_buttons_save -> |
| 1744 |
configure(-state=>'normal', |
| 1745 |
-command => [\&save_file, \$dump_frame_text, "", ""] |
| 1746 |
); |
| 1747 |
last WHICH; |
| 1748 |
}; |
| 1749 |
do { |
| 1750 |
$dump_frame_text -> insert('end', $$which); |
| 1751 |
$dump_frame_buttons_save -> |
| 1752 |
configure(-state=>'normal', |
| 1753 |
-command => [\&save_file, \$dump_frame_text, $atp, $ofname] |
| 1754 |
); |
| 1755 |
if ($feff) {$dump_frame_buttons_run -> configure(-state=>'normal');}; |
| 1756 |
last WHICH; |
| 1757 |
}; |
| 1758 |
}; |
| 1759 |
$dump_frame_text->markSet(qw/insert 1.0/); |
| 1760 |
($which eq '') && ($dump_frame_text->configure(qw/-state disabled/)); |
| 1761 |
$top->update; |
| 1762 |
}; # end display_in_frame |
| 1763 |
|
| 1764 |
|
| 1765 |
sub save_file { |
| 1766 |
my $r_text_widget = $_[0]; |
| 1767 |
my $atp = $_[1]; |
| 1768 |
my $ofname = $_[2]; |
| 1769 |
my $path = $meta{default_filepath} || cwd(); |
| 1770 |
my $types = [['All Files', '*', ],]; |
| 1771 |
my $fname = $top -> getSaveFile(-defaultextension=>'inp', |
| 1772 |
-filetypes=>$types, |
| 1773 |
#(not $is_windows) ? |
| 1774 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 1775 |
-initialdir=>$path, |
| 1776 |
-initialfile=>$ofname, |
| 1777 |
-title => $$labels{'save_dialog'}); |
| 1778 |
return 0 unless $fname; |
| 1779 |
$meta{default_filepath} = dirname($fname); |
| 1780 |
open OUT, ">".$fname or die $!; |
| 1781 |
print OUT $$r_text_widget->get(qw/1.0 end/); |
| 1782 |
close OUT; |
| 1783 |
}; |
| 1784 |
|
| 1785 |
|
| 1786 |
sub set_gas { |
| 1787 |
$keywords->make($_[0]=>$atoms_widgets{$_[0]}->get); |
| 1788 |
}; |
| 1789 |
|
| 1790 |
|
| 1791 |
sub configure_balloons { |
| 1792 |
if ($meta{display_balloons}) { |
| 1793 |
$balloon -> configure(-state=>'balloon', -initwait=>500); |
| 1794 |
} else { |
| 1795 |
$balloon -> configure(-state=>'none'); |
| 1796 |
}; |
| 1797 |
}; |
| 1798 |
|
| 1799 |
sub set_variables { |
| 1800 |
my $r_hash = $_[0]; |
| 1801 |
foreach my $vvv (qw(always_write_feff atoms_language write_to_pwd |
| 1802 |
prefer_feff_eight absorption_tables dafs_default |
| 1803 |
plotting_hook default_filepath unused_modifier |
| 1804 |
display_balloons no_crystal_warnings one_frame |
| 1805 |
ADB_location)) { |
| 1806 |
eval "\$meta{$vvv} = \$\$r_hash{$vvv};"; |
| 1807 |
}; |
| 1808 |
&configure_balloons; |
| 1809 |
#print STDOUT join($/, $always_write_feff, $atoms_language, |
| 1810 |
#$write_to_pwd, $prefer_feff_eight, |
| 1811 |
#$absorption_tables, $dafs_default, |
| 1812 |
#$plotting_hook, $default_filepath, |
| 1813 |
#$unused_modifier, $/); |
| 1814 |
}; |
| 1815 |
|
| 1816 |
|
| 1817 |
sub read_rc { |
| 1818 |
open RC, $_[0] or die "could not open $_[0] as a configuration file\n"; |
| 1819 |
my $mode = ""; |
| 1820 |
while (<RC>) { |
| 1821 |
next if (/^\s*$/); |
| 1822 |
next if (/^\s*\#/); |
| 1823 |
#warn ("old style rc file, line $.!\n"), next if (/^\s*\$/); |
| 1824 |
if (/\[(\w+)\]/) { |
| 1825 |
$mode = lc($1); |
| 1826 |
next; |
| 1827 |
}; |
| 1828 |
chomp; |
| 1829 |
s/^\s+//; |
| 1830 |
unless ($_ =~ /\$c_/) {s/\s*\#.*$//;}; |
| 1831 |
my @line = split(/[ \t]*[ \t=][ \t]*/, $_); |
| 1832 |
(defined $line[1]) and |
| 1833 |
(($line[1] eq "''") or ($line[1] eq '""')) |
| 1834 |
and $line[1] = ''; |
| 1835 |
MODE: { |
| 1836 |
($line[0] =~ /^\s*\$([a-zA-Z_]+)/) and do { |
| 1837 |
my $var = $1; |
| 1838 |
$line[1] =~ s/[;\'\"]//g; |
| 1839 |
if ($var =~ /^c_/) { # colors |
| 1840 |
my $v = substr($var, 2); |
| 1841 |
$colors{$v} = $line[1]; |
| 1842 |
if (($colors{$v} =~ /^[0-9a-fA-F]{6}$/) or |
| 1843 |
($colors{$v} =~ /^[0-9a-fA-F]{12}$/)) { |
| 1844 |
$colors{$v} = '#'.$line[1]; |
| 1845 |
}; |
| 1846 |
#print $var, " ", $colors{$v}, $/; |
| 1847 |
} elsif ($var =~ /^f_/) { # fonts |
| 1848 |
my $v = substr($var, 2); |
| 1849 |
$fonts{$v} = join(" ", @line[1..$#line]); |
| 1850 |
$fonts{$v} =~ s/[;\'\"]//g; |
| 1851 |
#print $var, " ", $fonts{$v}, $/; |
| 1852 |
} else { # meta |
| 1853 |
$meta{$var} = $line[1]; |
| 1854 |
#print $var, " ", $meta{$var}, $/; |
| 1855 |
}; |
| 1856 |
last MODE; |
| 1857 |
}; |
| 1858 |
($mode eq 'meta') and do { |
| 1859 |
$meta{$line[0]} = $line[1]; |
| 1860 |
last MODE; |
| 1861 |
}; |
| 1862 |
($mode eq 'colors') and do { |
| 1863 |
$colors{$line[0]} = $line[1]; |
| 1864 |
(($colors{$line[0]} =~ /[0-9a-fA-F]{6}/) or |
| 1865 |
($colors{$line[0]} =~ /[0-9a-fA-F]{12}/)) and |
| 1866 |
$colors{$line[0]} = '#'.$line[1]; |
| 1867 |
last MODE; |
| 1868 |
}; |
| 1869 |
($mode eq 'fonts') and do { |
| 1870 |
$fonts{$line[0]} = join(" ", @line[1..$#line]); |
| 1871 |
last MODE; |
| 1872 |
}; |
| 1873 |
}; |
| 1874 |
}; |
| 1875 |
}; |
| 1876 |
|
| 1877 |
## As widgets are created, push them onto lists for use with the color |
| 1878 |
## and font configurator. |
| 1879 |
sub manage { |
| 1880 |
my ($widget, $type) = @_; |
| 1881 |
SWITCH: { |
| 1882 |
($type eq 'label') and do { |
| 1883 |
push @all_labels, $widget; |
| 1884 |
last SWITCH; |
| 1885 |
}; |
| 1886 |
($type eq 'entry') and do { |
| 1887 |
push @all_entries, $widget; |
| 1888 |
last SWITCH; |
| 1889 |
}; |
| 1890 |
($type eq 'button') and do { |
| 1891 |
push @all_buttons, $widget; |
| 1892 |
last SWITCH; |
| 1893 |
}; |
| 1894 |
($type eq 'radio') and do { |
| 1895 |
push @all_radio, $widget; |
| 1896 |
last SWITCH; |
| 1897 |
}; |
| 1898 |
($type eq 'header') and do { |
| 1899 |
push @all_headers, $widget; |
| 1900 |
last SWITCH; |
| 1901 |
}; |
| 1902 |
($type eq 'menu') and do { |
| 1903 |
push @all_menus, $widget; |
| 1904 |
last SWITCH; |
| 1905 |
}; |
| 1906 |
($type eq 'canvas') and do { |
| 1907 |
push @all_canvas, $widget; |
| 1908 |
last SWITCH; |
| 1909 |
}; |
| 1910 |
($type eq 'progress') and do { |
| 1911 |
push @all_progress, $widget; |
| 1912 |
last SWITCH; |
| 1913 |
}; |
| 1914 |
($type eq 'labframe') and do { |
| 1915 |
push @all_labframes, $widget; |
| 1916 |
last SWITCH; |
| 1917 |
}; |
| 1918 |
($type eq 'scale') and do { |
| 1919 |
push @all_scales, $widget; |
| 1920 |
last SWITCH; |
| 1921 |
}; |
| 1922 |
($type eq 'check') and do { |
| 1923 |
push @all_check, $widget; |
| 1924 |
last SWITCH; |
| 1925 |
}; |
| 1926 |
($type eq 'slider') and do { |
| 1927 |
push @all_sliders, $widget; |
| 1928 |
last SWITCH; |
| 1929 |
}; |
| 1930 |
($type eq 'separator') and do { |
| 1931 |
push @all_separators, $widget; |
| 1932 |
last SWITCH; |
| 1933 |
}; |
| 1934 |
warn "unknown widget type: $type\n"; |
| 1935 |
}; |
| 1936 |
}; |
| 1937 |
|
| 1938 |
1; |