Debian Codegraph @

artemis_parts/head.pl

raw
1 ## -*- cperl -*-
2 ## This file is part of Artemis, copyright (c) 2002-2010 Bruce Ravel
3 ##
4
5 BEGIN {
6 ## ## make sure the pgplot environment is sane...
7 ## ## these defaults assume that the pgplot rpm was installed
8 ## $ENV{PGPLOT_DIR} ||= '/usr/local/share/pgplot';
9 ## $ENV{PGPLOT_DEV} ||= '/XSERVE';
10
11 use Tk;
12 die "Artemis requires Tk version 800.022 or later\n" if ($Tk::VERSION < 800.022);
13 #require Ifeffit;
14 #die "Artemis requires Ifeffit.pm version 1.2 or later\n" if ($Ifeffit::VERSION < 1.2);
15 #import Ifeffit qw/ifeffit/;
16 use Ifeffit qw(ifeffit get_array put_array);
17 ifeffit("\&screen_echo = 0\n");
18 };
19
20 use strict;
21 ## use diagnostics;
22
23 ## The next line is not necessary when artemis is run as an
24 ## interpretted script but PAR needs some help knowing which Tk
25 ## modules to load.
26 use Tk::widgets qw(Wm Derived Frame NoteBook Tree Bitmap Button Optionmenu Dialog
27 DialogBox TextUndo TextUndoQuiet ROText
28 Checkbutton Entry Label Radiobutton Scrollbar Canvas HList
29 Pixmap ItemStyle Splashscreen Photo waitVariableX
30 PathparamEntry Pane NumEntry NumEntryPlain FireButton
31 LabFrame Pod Pod/Text Pod/Search Pod/Tree More Listbox
32 FileSelect Menu BrowseEntry);
33 ### wtf?!?! PerlApp needs this line:
34 use Tk::DirTree;
35 use Tk::Pod;
36 use Tk::TextUndo;
37 use Tk::TextUndoQuiet;
38 ##use Tk::bindDump;
39 use Ifeffit::Path;
40 use Ifeffit::Parameter;
41 use Ifeffit::ArtemisLog;
42 use Ifeffit::Files;
43 use Ifeffit::ParseFeff;
44 ##my $absorption_exists = (eval "require Xray::Absorption");
45 use Xray::Absorption;
46 use Cwd;
47 use File::Basename;
48 use File::Copy;
49 use File::Path;
50 use File::Compare;
51 use Chemistry::Elements qw(get_symbol get_name get_Z);
52 use Compress::Zlib;
53 use Math::Round qw(round);
54 use Text::Wrap;
55 $Text::Wrap::columns = 65;
56 use Text::ParseWords;
57 use Digest::MD5 qw(md5_hex);
58 use Data::Dumper;
59 use Safe;
60 use Fcntl;
61 use Config::IniFiles;
62 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
63 use Xray::Xtal;
64 $Xray::Xtal::run_level = 3;
65 use Xray::Atoms qw(build_cluster rcfile_name);
66 use Xray::ATP; # qw(parse_atp);
67 use Xray::Tk::SGB;
68 my $STAR_Parser_exists = (eval "require STAR::Parser");
69 if ($STAR_Parser_exists) {
70 import STAR::Parser;
71 };
72 use constant PI => 3.14159265358979323844;
73 use constant THIRD => 1/3;
74 use constant TWOTH => 2/3;
75 use constant EPSILON => 0.00001;
76 use constant DELTA => 0.001;
77
78
79 my $VERSION = "0.8.014";
80 my $is_windows = (($^O eq 'MSWin32') or ($^O eq 'cygwin'));
81 my $mouse_over_cursor = 'mouse';
82
83 my $vstr = Ifeffit::Tools->vstr;
84 if ($vstr < 1.02005) {
85 my $mw = MainWindow->new();
86 $mw -> withdraw();
87 my $message = "This version of Artemis requires Ifeffit 1.2.5 or later.
88
89 You can get the latest Ifeffit from http://cars.uchicago.edu/ifeffit.
90
91 If you have recently upgraded Ifeffit, you should also rebuild Athena and Artemis.
92 ";
93 my $dialog =
94 $mw -> Dialog(-bitmap => 'error',
95 -text => $message,
96 -title => 'Artemis: Exiting...',
97 -buttons => [qw/OK/],
98 -default_button => 'OK',
99 -font => ($is_windows) ? "Helvetica 8 normal" : "Helvetica 12 normal",
100 -popover => 'cursor');
101 my $response = $dialog->Show();
102 exit;
103 };
104
105
106 unless (($VERSION eq $Ifeffit::Path::VERSION) and
107 ($VERSION eq $Ifeffit::Parameter::VERSION) and
108 ($VERSION eq $Ifeffit::ArtemisLog::VERSION)) {
109 my $mw = MainWindow->new();
110 $mw -> withdraw();
111 my $message = "Artemis appears to be installed incorrectly.
112
113 The main program and one or more of the Ifeffit/Path.pm,
114 Ifeffit/Parameter.pm, and Ifeffit/ArtemisLog.pm
115 modules have different version numbers.
116
117 main program: $0
118 Path.pm: $INC{'Ifeffit/Path.pm'}
119 Parameter.pm: $INC{'Ifeffit/Parameter.pm'}
120 ArtemisLog.pm: $INC{'Ifeffit/ArtemisLog.pm'}
121 ";
122 my $dialog =
123 $mw -> Dialog(-bitmap => 'error',
124 -text => $message,
125 -title => 'Artemis: Exiting...',
126 -buttons => [qw/OK/],
127 -default_button => 'OK',
128 -font => ($is_windows) ? "Helvetica 8 normal" : "Helvetica 12 normal",
129 -popover => 'cursor');
130 my $response = $dialog->Show();
131 exit;
132 };
133 my $About = "Artemis $VERSION (c) 2002-2008 Bruce Ravel <bravel\@anl.gov> -- NO WARRANTY -- see license for details";
134 my $About_Ifeffit = "Using Ifeffit ".Ifeffit::get_string("\$&build");
135 $About_Ifeffit =~ s{\s+}{ }g;
136 ## family????
137 my $setup = Ifeffit::Path -> new(type=>'data');
138
139 ## ============================================================================
140 ## ============================================================================
141 ## Define are some global variables
142 use vars qw(%notecard %notes %labels %props);
143 my $is_osx = ($^O eq 'darwin');
144 my ($n_gsd, $n_feff, $n_data) = (0, 0, 0);
145 ## my (@gsd_choice, @gsd_name, @gsd_name_widget, @gsd_mathexp,
146 ## @gsd_button, @gsd_updated);
147 my @gds_regex = ();
148 my @gds = ();
149 my @bad_params = ();
150 my %gds_styles = ();
151 my %gds_selected = (which=>0, name=>"", mathexp=>"", type=>"", showing=>"edit");
152 my %intrp_styles = ();
153 my @atoms = ();
154 my %atoms_styles = ();
155 my $current_data_dir = '';
156 my $current = '';
157 my $current_file = '';
158 my $project_name = '';
159 my $project_folder = '';
160 my $project_saved = 1;
161 my $autosave_filename = "";
162 my $parameters_changed = 0;
163 my @athena_fh = ();
164 my ($sgb, $fefftabs, %feffcard);
165 my @done = (" done!", 1);
166 ##my @echo_history = ();
167 my @rename_buffer;
168 my $generic_name = "artemis.stuff";
169 my $last_plot = '';
170 my %fit = (index=>1, count=>0, count_full=>0, new=>1, label=>"", comment=>"", fom=>0);
171
172 ## (stack, start, offset, invert, indicator, indicators...)
173 my @extra = (0,0,0,0,0, "");
174
175 my (%paths, %widgets, %grab, $list, %atoms_params, %log_params, %ath_params); #, %apa_params);
176
177 ## this regex matches the Ifeffit::Path object types that are not plotted
178 my $no_plot_regex = '(feff\d+|gsd|journal)';
179 ## all the functions in ifeffit
180 ## (insert (make-regexp '("abs" "min" "max" "sign" "sqrt" "exp" "log"
181 ## "ln" "log10" "sin" "cos" "tan" "asin" "acos"
182 ## "atan" "sinh" "tanh" "coth" "gamma" "loggamma"
183 ## "erf" "erfc" "gauss" "loren" "pvoight" "debye"
184 ## "eins" "npts" "ceil" "floor" "vsum" "vprod"
185 ## "indarr" "ones" "zeros" "range" "deriv" "penalty"
186 ## "smooth" "interp" "qinterp" "splint" "eins" "debye")))
187 my $function_regex = "a(bs|cos|sin|tan)|c(eil|o(s|th))|" .
188 "de(bye|riv)|e(ins|rfc?|xp)|floor|ga(mma|uss)|" .
189 "in(darr|terp)|l(n|o(g(|10|gamma)|ren))|m(ax|in)|" .
190 "npts|ones|p(enalty|voight)|qinterp|r(ange|ebin)|" .
191 "s(i(gn|nh?)|mooth|plint|qrt)|" .
192 "tanh?|v(prod|sum)|zeros";
193
194
195 my %limits = ( # Ifeffit's limits on things
196 paths_per_set => Ifeffit::get_scalar('&max_paths') || 100,
197 total_paths => Ifeffit::get_scalar('&max_paths') || 100,
198 variables => Ifeffit::get_scalar('&max_varys') || 128,
199 spline_knots => 32,
200 data_sets => Ifeffit::get_scalar('&max_data_sets') || 16,
201 output_columns => Ifeffit::get_scalar('&max_output_cols') || 16,
202 );
203 --$limits{output_columns}; ## one less than its actual value since
204 ## the first column will always be the abscissa
205
206 my $dmode = 5;
207 ## ==== DEBUG =====
208 ## $dmode += 16;
209 ## ==== DEBUG =====
210 my $debug_menu = 0;
211 my $debug_file_path = 0;
212
213 use vars qw($top);
214 $top = MainWindow->new(-class=>'horae');
215 $top -> withdraw;
216 $top -> optionAdd('*font', 'Helvetica 14 bold');
217 $top -> optionAdd('*font', 'Helvetica 9 bold');
218 my $splash_background = 'antiquewhite3';
219 my $splash = $top->Splashscreen();
220 my $splash_image = $top -> Photo(-file => $setup -> find('artemis', 'logo'));
221 $splash -> Label(-image=>$splash_image, -background => $splash_background)
222 -> pack(qw/-fill both -expand 1 -padx 0 -pady 0 -side left/);
223 my $splash_frame = $splash -> Frame(-background => $splash_background,)
224 -> pack(qw/-fill both -expand 1 -padx 0 -pady 0 -side right/);
225 $splash_frame -> Label(-text => "Artemis\nversion $VERSION",
226 -background => $splash_background,
227 -width => 22,
228 -font => 'Helvetica 14 bold',)
229 -> pack(qw/-fill both -expand 1/);
230 my $splash_status = $splash_frame -> Label(-text => q{},
231 -background => $splash_background,
232 -font => 'Helvetica 9 bold',
233 -justify => 'left',
234 -borderwidth=> 2,
235 -relief => 'ridge')
236 -> pack(-anchor=>'w', -fill=>'x');
237 $splash -> Splash;
238 $top -> update;
239
240
241
242 ## ---------------------------------------------------------------------
243 ## add document location to the Pod path
244 Tk::Pod->Dir($setup -> find('artemis', 'doc'));
245
246 ## ============================================================================
247 ## ============================================================================
248 ## read configuration files:
249 splash_message("Importing configuration files");
250
251 ## check to see if config and mru files from 0.6.001 or earlier are
252 ## around and convert to new location.
253 &convert_config_files;
254
255 my (%plot_features, $screen, @clist, %header, @op_text);
256 my $dummy_rcfile = $setup -> find('artemis', 'rc_dummy');
257 open I, ">".$dummy_rcfile; print I "[meta]\ndummy_parameter=1\n"; close I;
258 my $system_rcfile = $setup -> find('artemis', 'rc_sys');
259 my $personal_rcfile = $setup -> find('artemis', 'rc_personal');
260 my $personal_version = $setup -> find('artemis', 'version_marker');
261
262 ## config values hardwired in the code
263 my %default_config;
264 tie %default_config, 'Config::IniFiles', ();
265 ($screen, @clist) = &default_rc(\%default_config); # set defaults
266 my $default_config_ref = tied %default_config;
267 $default_config_ref -> SetFileName($dummy_rcfile);
268
269 ## system-wide rc file (but check to see that it exists...
270 my %system_config;
271 tie %system_config, 'Config::IniFiles', (-file=>$system_rcfile, -import=>$default_config_ref)
272 if -e $system_rcfile;;
273
274 ## if the user does not have a personal rc file, create one
275 if ((! -e $personal_rcfile) or (-z $personal_rcfile)) {
276 open I, ">".$personal_rcfile;
277 print I "[meta]\ndummy_parameter=1\n";
278 close I;
279 }
280 ## if the user does not have a personal rc file, create one
281 if (! -e $personal_version) {
282 open V, ">".$personal_version;
283 print V "";
284 close V;
285 open I, ">".$personal_rcfile;
286 print I "[general]\ndummy_parameter=1\n";
287 close I;
288 };
289 my %config;
290 if (-e $system_rcfile) { # import system-wide file if it exists
291 my $system_config_ref = tied %system_config;
292 $system_config_ref -> WriteConfig($dummy_rcfile);
293 tie %config, 'Config::IniFiles', (-file=>$personal_rcfile, -import=>$system_config_ref );
294 unless (tied %config) { # crude hack to deal with improper rcfile
295 open I, ">".$personal_rcfile;
296 print I "[meta]\ndummy_parameter=1\n";
297 close I;
298 tie %config, 'Config::IniFiles', (-file=>$personal_rcfile, -import=>$system_config_ref );
299 };
300 } else { # else import the default
301 tie %config, 'Config::IniFiles', (-file=>$personal_rcfile, -import=>$default_config_ref);
302 unless (tied %config) {
303 open I, ">".$personal_rcfile;
304 print I "[meta]\ndummy_parameter=1\n";
305 close I;
306 tie %config, 'Config::IniFiles', (-file=>$personal_rcfile, -import=>$default_config_ref );
307 };
308 };
309 delete $config{general}{dummy_parameter};
310 my $config_ref = tied %config;
311 $config_ref -> WriteConfig($personal_rcfile);
312 unlink $dummy_rcfile;
313
314
315 foreach my $fonttype (keys %{ $config{fonts} }) {
316 $top -> optionAdd('*font', $config{fonts}{$fonttype});
317 };
318 $top -> optionAdd('*font', $config{fonts}{med});
319
320
321 ## ---------------------------------------------------------------------
322 ## several things that need to be set now that the config file has
323 ## been read
324 if ($is_windows) {
325 ($config{colors}{check} = 'red2') if ($config{colors}{check} eq 'red4');
326 };
327 ## this fixes a scalar name collision in ifeffit introduced along with
328 ## the reading of Athena projects and the performing of splines in
329 ## Artemis.
330 ($config{autoparams}{e0} = 'enot') if ($config{autoparams}{e0} eq 'e0');
331 ($config{autoparams}{e0} = 'delr') if ($config{autoparams}{delr} eq 'dr');
332
333 map { $plot_features{$_} = $config{plot}{$_}} (keys %{$config{plot}});
334 $plot_features{rmax_out} = $config{plot}{rmax_out} || 10;
335 $plot_features{bkg} = 0;
336 $plot_features{res} = 0;
337 Ifeffit::put_scalar('&plot_key_x', $config{plot}{key_x});
338 Ifeffit::put_scalar('&plot_key_y0', $config{plot}{'key_y'});
339 Ifeffit::put_scalar('&plot_key_dy', $config{plot}{key_dy});
340 ## $config{general}{workspace} =~ s/\~/$ENV{HOME}/;
341
342
343 ##$config{general}{query_save} = 0;
344
345 ## choose the absorption tables for Atoms
346 ##($absorption_exists) and eval "Xray::Absorption -> load($config{atoms}{absorption_tables})";
347 Xray::Absorption -> load($config{atoms}{absorption_tables});
348
349 ## default log type
350 my @log_type = set_log_style($config{log}{style});
351
352 splash_message("Making stash directory");
353 ## establish stash directory
354 &Ifeffit::Tools::initialize_horae_space;
355 ## my $stash_dir = $config{general}{workspace} || $Ifeffit::Tools::horae_stash_dir;
356 my $stash_dir = $Ifeffit::Tools::horae_stash_dir;
357
358 my $trapfile = File::Spec->catfile($stash_dir, "ARTEMIS.TRAP");
359 ## ---------------------------------------------------------------------
360
361 ## ============================================================================
362 ## ============================================================================
363 ## open and read most recently used (MRU) file
364 splash_message("Importing recent files list");
365 my $mrufile = $setup -> find('artemis', 'mru');
366 # touch an empty file if needed
367 unless (-e $mrufile) {open M, ">".$mrufile; print M "[mru]\n"; close M};
368 my %mru;
369 tie %mru, 'Config::IniFiles', ( -file => $mrufile );
370 foreach my $i (1 .. $config{general}{mru_limit}) {
371 exists $mru{mru}{$i} or ($mru{mru}{$i} = "");
372 };
373
374 $current_data_dir = $mru{config}{last_working_directory}
375 if ($config{general}{remember_cwd});
376
377 ## ============================================================================
378 splash_message("Setting up context help and hints");
379 ## ============================================================================
380 ## click help text strings
381 my %click_help =
382 (## guess, set, def
383 'Param. name' => "The names of fixed and varied parameters for use in math expressions",
384 'Math expression' => "Math expressions used to evaluate path parameters, establish constraints, and build fitting models",
385 'Grab best fit' => "Click on these buttons to insert the best fit values after a fit is finished",
386 ## operational parameters
387 'Titles' => "User-supplied, editable commentary about these data",
388 'Data file' => "Name of the project data file containing these chi(k) data.",
389 'k-range' => "The range of the fit or the Fourier transform in k space (this should cover the range of reliable data)",
390 'Data controls' => "Variables which control how these data are used in the fit. The include and plot buttons are only relevant to a multiple data set fit.",
391 'Fit k-weights' => "Weighting factor for chi(k) used in the fit for these data. (You may fit using 1 or more k-weightings.)",
392 'Fourier and fit parameters' => "Parameters which determine how the Fourier transforms are made and the range over which the fit is made.",
393 'Other parameters' => "Other parameters controlling details of the fit to these data.",
394 'dk' => "Width of the Fourier transform window sill in k space (this is typicaly a one to a few inverse Angstroms)",
395 'k window' => "Functional form of the Fourier transform window in k space",
396 'R-range' => "The range of the fit or the Fourier transform in R space (this should cover the peaks you wish to include in your fit)",
397 'dr' => "Width of the Fourier transform window sill in R space (typical values are between 0 to 1)",
398 'R window' => "Functional form of the Fourier transform window in R space",
399 'Fitting space' => "Data space in which to perform the minimization (the authors of Ifeffit and Artemis prefer R space)",
400 'Path to use for phase corrections' => "Correct Fourier transforms by the full phase shift of the chosen path",
401 'Phase corrected Fourier transforms' => "Correct Fourier transforms by the phase shift of the central atom",
402 'elem' => 'The element of the absorber, needed for phase correctioned FTs',
403 'edge' => 'The absorbtion edge of these data, needed for phase correctioned FTs',
404 'Epsilon' => "Explicitly specify the measurement uncertainty (in k) (useful for weighting components of a multi-data set fit)",
405 'Minimum reported correlation' => "Smallest value of correlation between variables to report once the fit is finished (0.25 to 0.5 are sensible)",
406 ## Feff calculation
407 'Interpretation of the FEFF calculation' => "A schematic representation of the paths from a FEFF run (try right-clicking in different places in the box)",
408 'Core' => "Use these buttons to select the central atom",
409 'El.' => "Specify the two-letter atomic symbols of each atom in this column (leave the element blank to skip this site)",
410 "X" => "Specify the x-axis coordinate of each atom in this column",
411 "Y" => "Specify the y-axis coordinate of each atom in this column",
412 "Z" => "Specify the z-axis coordinate of each atom in this column",
413 "Tag" => "Specify a site-specific tag for each atom in this column",
414 "Occ." => "Set the occupancy of each site between 0 and 100% (not used in the feff.inp atom list!!)",
415 "Cluster size" => "Enter the radial extent of the cluster of atoms to write to the feff.inp file",
416 "Shift vector" => "Insert the shift vector values here if this is a space group that needs one",
417 "Space group" => "Enter the symbol of your space group (Hermann-Maguin, Schoenflies, and index number are all ok)",
418 "Edge" => "Select the absorption edge to be used in the Feff calculation",
419 "A" => "Enter the a lattice constant of the unit cell",
420 "B" => "Enter the a lattice constant of the unit cell",
421 "C" => "Enter the a lattice constant of the unit cell",
422 "Alpha" => "Enter the alpha angle of the unit cell (alpha is the angle between b and c)",
423 "Beta" => "Enter the beta angle of the unit cell (beta is the angle between a and c)",
424 "Gamma" => "Enter the gamma angle of the unit cell (gamma is the angle between a and b)",
425 ## paths
426 'FEFF calculation' => "The Feff calculation that this path is a part of",
427 'feff:' => "The path and name of the feffNNNN.dat file",
428 'label:' => "User-defined text used to describe this path",
429 'N:' => "The degeneracy of this path (this must be a number and cannot be a variable)",
430 'S02:' => "A math expression describing all amplitude terms other than degeneracy for this path",
431 'E0:' => "A math expression defining the energy shift for this path",
432 'delE0:' => "A math expression defining the energy shift for this path",
433 'delR:' => "A math expression defining the change in path length relative to R_effective for this path",
434 'sigma^2:' => "A math expression defining the relative mean square displacement about R_effective for this path",
435 'Ei:' => "A math expression for the additional broadening this path, in eV",
436 '3rd:' => "A math expression defining the third cumulant for this path",
437 '4th:' => "A math expression defining the fourth cumulant for this path",
438 'dphase:' => "An math expression defining a constant phase offset (useful for DAFS data)",
439 'k_array:' => "An array modifying the k-axis of this path (use with care!)",
440 'phase_array:' => "An array-valued math expression for an additional phase shift (use with care!)",
441 'amp_array:' => "An array-valued math expression for an amplitude correction (use with care!)",
442 ## histogram
443 'Path list entry' => "The text template for the list entries of each bin the histogram",
444 'Position column' => "The text column containing the bin positions.",
445 'Height column' => "The text column containing the bin heights.",
446
447 'null' => "???",
448 );
449 $click_help{'Path to FEFF:'} = $click_help{'Path to FEFF calculation'};
450
451 ## ============================================================================
452 ## ============================================================================
453 ## command completion in the ifeffit buffer
454 use Text::Abbrev;
455 my %abbrevs = abbrev qw(chi_noise color comment cursor def echo erase
456 exit feffit ff2chi fftf fftr findee guess
457 history load macro minimize newplot path pause
458 plot pre_edge print quit read_data rename
459 reset restore save set show spline sync
460 write_data zoom @all @arrays @commands @group
461 @macros @path @scalars @strings @variables );
462
463
464 ## ============================================================================
465 ## ============================================================================
466 ## read hints file and initialize hints
467 my $hint_file = $setup -> find('artemis', 'hints');
468 my @hints = ();
469 my ($hint_n, $hint_x);
470 if (-e $hint_file) {
471 open HINT, $hint_file or die "could not open hint file $hint_file for reading\n";
472 while (<HINT>) {
473 next if (/^\s*($|\#)/);
474 chomp;
475 push @hints, $_;
476 };
477 srand;
478 $hint_x = $#hints;
479 $hint_n = int(rand $hint_x);
480 close HINT;
481 };
482
483
484 ## ============================================================================
485 ## ============================================================================
486 ## begin drawing main window, initialize splash screen, and establish
487 ## key bindings
488 $top -> setPalette(foreground => $config{colors}{foreground},
489 background => $config{colors}{background},
490 activeBackground => $config{colors}{activebackground},
491 disabledForeground => $config{colors}{disabledforeground},
492 disabledBackground => $config{colors}{background},
493 highlightColor => $config{colors}{button},
494 -highlightthickness => 2,
495 -font => $config{fonts}{med},
496 );
497 $top -> protocol(WM_DELETE_WINDOW => \&quit_artemis);
498 $top -> title('Artemis');
499 $top -> iconname('Artemis');
500 #my $iconbitmap = $setup -> find('artemis', 'xbm');
501 #$top -> iconbitmap('@'.$iconbitmap);
502 my $iconimage = $top -> Photo(-file => $setup -> find('artemis', 'xpm'));
503 $top -> iconimage($iconimage);
504
505 splash_message("Setting up key bindings");
506 my $multikey = "";
507 $top -> bind('<Control-a>' => \&select_all);
508 $top -> bind('<Control-d>' => \&keyboard_d);
509 $top -> bind('<Control-e>' => \&keyboard_e);
510 $top -> bind('<Control-g>' => \&keyboard_g);
511 $top -> bind('<Control-h>' => \&show_hint);
512 $top -> bind('<Control-i>' => \&import_atoms);
513 $top -> bind('<Control-j>' => \&keyboard_down);
514 $top -> bind('<Alt-j>' => \&keyboard_alt_j);
515 $top -> bind('<Control-k>' => \&keyboard_up);
516 $top -> bind('<Alt-k>' => \&keyboard_alt_k);
517 $top -> bind('<Control-l>' => sub{$list->focus});
518 $top -> bind('<Control-m>' => sub{pod_display("artemis.pod")});
519 $top -> bind('<Control-n>' => \&rename_this);
520 $top -> bind('<Control-o>' => \&open_file);
521 $top -> bind('<Control-p>' => sub{
522 if ($is_windows) {
523 Error("Print from the plot window instead.");
524 } else {
525 &replot('print')
526 }});
527 $top -> bind('<Control-q>' => \&quit_artemis);
528 $top -> bind('<Control-r>' => sub{&read_feff(0)});
529 $top -> bind('<Control-s>' => sub{&save_project(0,0)});
530 $top -> bind('<Control-t>' =>
531 sub {
532 ($current =~ /feff\d+\.\d+$/) ?
533 $widgets{path_include} -> invoke() :
534 Echo('Control-t toggles a path for including in the fit.');
535 });
536 $top -> bind('<Control-u>' => \&deselect_all);
537 ##$top -> bind('<Control-w>' => sub{generate_script(0)});
538 $top -> bind('<Control-w>' => sub {
539 my $dialog =
540 $top -> Dialog(-bitmap => 'questhead',
541 -text => "Save this project before closing?.",
542 -title => 'Artemis: Question...',
543 -buttons => ['Save', 'Just close it', 'Cancel'],
544 -default_button => 'Save',
545 -font => $config{fonts}{med},
546 -popover => 'cursor');
547 &posted_Dialog;
548 my $response = $dialog->Show();
549 Echo("Not closing project."), return if $response eq 'Cancel';
550 save_project(0,0) if $response eq 'Save';
551 delete_project(0);
552 Echo("Closed project");
553 });
554 $top -> bind('<Control-y>' => \&gds2_keyboard_type);
555 $top -> bind('<Control-period>' => \&cursor);
556 $top -> bind('<Control-semicolon>' => \&keyboard_plot);
557 $top -> bind('<Control-equal>' => \&zoom);
558 $top -> bind('<Control-minus>' => sub{&replot('replot')});
559 $top -> bind('<Shift-Alt-d>' => \&dump_paths);
560
561
562 ## top level widget for displaying verious interactions
563 my $update = $top -> Toplevel(-class=>'horae');
564 $update -> withdraw;
565 $update -> protocol(WM_DELETE_WINDOW => sub{$update->withdraw});
566 #$update -> iconbitmap('@'.$iconbitmap);
567 $update -> iconimage($iconimage);
568 my $notebook = $update -> NoteBook(-backpagecolor=>$config{colors}{background},
569 -inactivebackground=>$config{colors}{inactivebackground},);
570 $top -> bind('<Control-Key-1>' => sub{raise_palette('ifeffit') } );
571 $top -> bind('<Control-Key-2>' => sub{raise_palette('results') } );
572 $top -> bind('<Control-Key-3>' => sub{raise_palette('files') } );
573 $top -> bind('<Control-Key-4>' => sub{raise_palette('messages') } );
574 $top -> bind('<Control-Key-5>' => sub{raise_palette('echo') } );
575 $top -> bind('<Control-Key-6>' => sub{raise_palette('journal') } );
576 $top -> bind('<Control-Key-7>' => sub{raise_palette('properties')} );
577
578 ## $top -> bind('<Control-e>' => sub{print "doing something bad ... \n";
579 ## &foo;
580 ## });
581
582 ## ============================================================================
583 ## ============================================================================
584 ## arrays of commonly used widget arguments
585 my @button_list = (-foreground => $config{colors}{activebackground},
586 -activeforeground => $config{colors}{activebackground},
587 -background => $config{colors}{button},
588 -activebackground => $config{colors}{activebutton},
589 -font => $config{fonts}{bold},);
590 my @button2_list = (-foreground => $config{colors}{button},
591 -activeforeground => $config{colors}{button},
592 -background => $config{colors}{background},
593 -activebackground => $config{colors}{activebackground},
594 -font => $config{fonts}{smbold},);
595 my @button3_list = (-foreground => $config{colors}{button},
596 -activeforeground => $config{colors}{button},
597 -background => $config{colors}{background2},
598 -activebackground => $config{colors}{activebackground2});
599 my @fitbutton_list = (-foreground => $config{colors}{activebackground},
600 -activeforeground => $config{colors}{activebackground},
601 -background => $config{colors}{fitbutton},
602 -activebackground => $config{colors}{activefitbutton},
603 -font => $config{fonts}{bold},);
604 my @menu_args = (-foreground => $config{colors}{foreground},
605 -background => $config{colors}{background},
606 -activeforeground => $config{colors}{activebutton},
607 );
608 #-font => $config{fonts}{small}, );
609 my @menu_header_args = (-foreground =>'grey20',
610 -activeforeground =>'grey20',
611 -font =>$config{fonts}{smbold}, );
612 my @title = (-fill => $config{colors}{activehighlightcolor},
613 -font => $config{fonts}{bignbold});
614 my @title2 = (-foreground => $config{colors}{activehighlightcolor},
615 -font => $config{fonts}{bignbold});
616 my @window_size = (-width => $config{geometry}{main_width}.'c',
617 -height => $config{geometry}{main_height}.'c');
618
619
620 ## ============================================================================
621 ## ============================================================================
622 ## menubar
623 ## my $menubar = $top -> Frame(-relief=>'ridge', -borderwidth=>2)
624 ## -> pack(-side=>"top", -anchor=>'nw', -fill=>'x');
625 splash_message("Creating projectbar and menus");
626 $top -> configure(-menu=> my $menubar = $top->Menu(-relief=>'ridge'));
627
628
629 ## ============================================================================
630 ## ============================================================================
631 ## projectbar
632 my $projectbar = $top -> Frame(-relief=>'flat', -borderwidth=>2);
633 $projectbar -> Label(-text=>'Current project: ', -font=>$config{fonts}{bold},
634 -foreground=>$config{colors}{button})
635 -> pack(-side=>'left', -padx=>4);
636 my $project_label;
637 if ($config{general}{projectbar} eq 'file') {
638 $project_label = $projectbar -> Label(-textvariable => \$project_name,
639 -font => $config{fonts}{med},
640 -relief => 'flat',
641 -anchor => 'e')
642 -> pack(-side=>'left');
643 } elsif ($config{general}{projectbar} eq 'title') {
644 $project_label = $projectbar -> Label(-textvariable => \$props{'Project title'},
645 -font => $config{fonts}{med},
646 -relief => 'flat',
647 -anchor => 'e')
648 -> pack(-side=>'left');
649 };
650 $widgets{project_modified} = $projectbar -> Label(-text=>'',
651 -width=>9,
652 -relief=>'groove',
653 -font=>$config{fonts}{small},)
654 -> pack(-side=>'right', -padx=>2);
655 my @hilite = (-foreground => $config{colors}{highlightcolor},
656 -background => $config{colors}{activebackground},
657 -cursor => $mouse_over_cursor,);
658 my @normal = (-foreground => $config{colors}{foreground},
659 -background => $config{colors}{background});
660 $widgets{project_modified} -> bind("<ButtonPress-1>", sub{&save_project(0,0) unless $project_saved});
661 $widgets{project_modified} -> bind("<ButtonPress-2>", sub{&save_project(0,0) unless $project_saved});
662 $widgets{project_modified} -> bind("<ButtonPress-3>", sub{&save_project(0,0) unless $project_saved});
663 $widgets{project_modified} -> bind("<Any-Enter>", sub{$widgets{project_modified}->configure(@hilite) unless $project_saved});
664 $widgets{project_modified} -> bind("<Any-Leave>", sub{$widgets{project_modified}->configure(@normal)});
665 $projectbar -> pack(-side=>"top", -anchor=>'nw', -fill=>'x')
666 unless ($config{general}{projectbar} eq 'none');
667
668 ## ============================================================================
669 ## ============================================================================
670 ## File menu
671 my $save_index = 10; # data all_paths (+1) selected (+3)
672 my $file_menu = $menubar
673 -> cascade(-label=>'~File', @menu_args,
674 -menuitems=>[[ command => 'Open file', -accelerator => 'Ctrl-o',
675 -command => \&open_file],
676 [ cascade => 'Recent files', -tearoff=>0,
677 -menuitems=>[]],
678 [ cascade => 'Project data', -tearoff=>0,
679 -menuitems => [
680 [ command => 'Import project data', @menu_args,
681 -command => sub{dispatch_read_data(0, "", 1)}],
682 ##-command => sub{dispatch_read_data($paths{$current}->data, "", 1)}],
683 [ command => 'Transfer many data files', @menu_args,
684 -command => \&bulk_data],
685 ]],
686 "-",
687 [ command =>'Convert a feffit input file',
688 -state => ($config{general}{import_feffit}) ? 'normal' : 'disabled',
689 -command=>\&feffit_convert_input],
690 "-",
691 [ command =>'Save project', -accelerator => 'Ctrl-s',
692 -command => [\&save_project, 0, 0]],
693 [ command =>'Save project as ...',
694 -command => [\&save_project, 1, 0]],
695 "-",
696 [ cascade => 'Save data as ...', -tearoff=>0,
697 -state =>'disabled',
698 -menuitems => [[ command=>'chi(k)', @menu_args,
699 -command=>[\&save_data, 'data', 'k']],
700 [ command=>'chi(R)', @menu_args,
701 -command=>[\&save_data, 'data', 'r']],
702 [ command=>'chi(q)', @menu_args,
703 -command=>[\&save_data, 'data', 'q']]]
704 ],
705 [ cascade => 'Save fit as ...', -tearoff=>0,
706 -state =>'disabled',
707 -menuitems => [[ command=>'chi(k)', @menu_args,
708 -command=>[\&save_fit, 'fit', 'k']],
709 [ command=>'chi(R)', @menu_args,
710 -command=>[\&save_fit, 'fit', 'r']],
711 [ command=>'chi(q)', @menu_args,
712 -command=>[\&save_fit, 'fit', 'q']]]
713 ],
714 [ cascade => 'Save background as ...', -tearoff=>0,
715 -state =>'disabled',
716 -menuitems => [[ command=>'chi(k)', @menu_args,
717 -command=>[\&save_fit, 'bkg', 'k']],
718 [ command=>'chi(R)', @menu_args,
719 -command=>[\&save_fit, 'bkg', 'r']],
720 [ command=>'chi(q)', @menu_args,
721 -command=>[\&save_fit, 'bkg', 'q']]]
722 ],
723 [ cascade => 'Save residual as ...', -tearoff=>0,
724 -state =>'disabled',
725 -menuitems => [[ command=>'chi(k)', @menu_args,
726 -command=>[\&save_fit, 'res', 'k']],
727 [ command=>'chi(R)', @menu_args,
728 -command=>[\&save_fit, 'res', 'r']],
729 [ command=>'chi(q)', @menu_args,
730 -command=>[\&save_fit, 'res', 'q']]]
731 ],
732 [ cascade => 'Save ALL paths as ...', -tearoff=>0,
733 -state =>'disabled',
734 -menuitems => [[ command=>'chi(k)', @menu_args,
735 -command=>[\&save_all_paths, 'k']],
736 [ command=>'chi(R)', @menu_args,
737 -command=>[\&save_all_paths, 'R']],
738 [ command=>'chi(q)', @menu_args,
739 -command=>[\&save_all_paths, 'q']]]
740 ],
741 "-",
742 [cascade => "Save selected groups as", -tearoff=>0,
743 -state =>'disabled',
744 -menuitems=>[
745 [ command=>"chi(k)", @menu_args,
746 -command=>[\&save_selected, 'k']],
747 [ command=>"k*chi(k)", @menu_args,
748 -command=>[\&save_selected, 'k1']],
749 [ command=>"k^2*chi(k)", @menu_args,
750 -command=>[\&save_selected, 'k2']],
751 [ command=>"k^3*chi(k)", @menu_args,
752 -command=>[\&save_selected, 'k3']],
753 "-",
754 [ command=>"|chi(R)|", @menu_args,
755 -command=>[\&save_selected, 'rm']],
756 [ command=>"Re[chi(R)]", @menu_args,
757 -command=>[\&save_selected, 'rr']],
758 [ command=>"Im[chi(R)]", @menu_args,
759 -command=>[\&save_selected, 'ri']],
760 "-",
761 [ command=>"|chi(q)|", @menu_args,
762 -command=>[\&save_selected, 'qm']],
763 [ command=>"Re[chi(q)]", @menu_args,
764 -command=>[\&save_selected, 'qr']],
765 [ command=>"Im[chi(q)]", @menu_args,
766 -command=>[\&save_selected, 'qi']],
767 ]],
768 "-",
769 [ command =>'Close project', -accelerator => 'Crtl-w',
770 -command => sub {
771 my $dialog =
772 $top -> Dialog(-bitmap => 'questhead',
773 -text => "Save this project before closing?.",
774 -title => 'Artemis: Question...',
775 -buttons => ['Save', 'Just close it', 'Cancel'],
776 -default_button => 'Save',
777 -font => $config{fonts}{med},
778 -popover => 'cursor');
779 &posted_Dialog;
780 my $response = $dialog->Show();
781 Echo("Not closing project"), return if $response eq 'Cancel';
782 save_project(0,0) if $response eq 'Save';
783 delete_project(0);
784 Echo("Closed project.");
785 }],
786 [ command =>'Quit', -accelerator => 'Ctrl-q',
787 -command=>\&quit_artemis]
788 ]);
789 # -> pack(-side=>'left');
790
791 ## ============================================================================
792 ## ============================================================================
793 ## edit menu
794 my $edit_menu = $menubar
795 -> cascade(-label=>'~Edit', @menu_args,
796 -menuitems=>[
797 [ command => "Write Ifeffit script",
798 -command => [\&generate_script, 0]],
799 "-",
800 [ command => "Display Ifeffit buffer", -accelerator => 'Ctrl-1',
801 -command => sub{raise_palette('ifeffit');}],
802 [ command => "Display fit results", -accelerator => 'Ctrl-2',
803 -command => sub{raise_palette('results');}],
804 [ command => "View files", -accelerator => 'Ctrl-3',
805 -command => sub{raise_palette('files');}],
806 [ command => "View messages", -accelerator => 'Ctrl-4',
807 -command => sub{raise_palette('messages');}],
808 [ command => "Display echo buffer", -accelerator => 'Ctrl-5',
809 -command => sub{raise_palette('echo');}],
810 [ command => "Write in journal", -accelerator => 'Ctrl-6',
811 -command => sub{raise_palette('journal');}],
812 [ command => "Edit project properties", -accelerator => 'Ctrl-7',
813 -command => sub{raise_palette('properties');}],
814 "-",
815 [ command => "Compact project",
816 -command => \&compactify_project],
817 "-",
818 [ command => 'Edit preferences',
819 -command => \&prefs],
820 ]);
821 # -> pack(-side=>'left');
822
823
824 ## ============================================================================
825 ## ============================================================================
826 ## show menu
827 ## my $show_menu = $menubar -> cascade(-label=>'Show', @menu_args,);
828 ## # -> pack(-side=>'left');
829 ## $show_menu -> AddItems([ command=>"Show groups",
830 ## -command=>[\&show_things, 'groups']],
831 ## #[ command=>"Show paths",
832 ## # -command=>[\&show_things, 'paths']],
833 ## [ command=>'Show this path', -state=>'disabled',
834 ## -command=>\&show_path],
835 ## [ command=>"Show variables",
836 ## -command=>[\&show_things, 'variables']],
837 ## [ command=>"Show def variables",
838 ## -command=>[\&show_defs]],
839 ## [ command=>"Show scalars",
840 ## -command=>[\&show_things, 'scalars']],
841 ## [ command=>"Show arrays",
842 ## -command=>[\&show_things, 'arrays']],
843 ## [ command=>"Show strings",
844 ## -command=>[\&show_things, 'strings']],
845 ## #[ command=>"Show all",
846 ## # -command=>[\&show_things, 'all']],
847 ## "-",
848 ## [ command=>"Show project folder",
849 ## -command=>sub{Echo("Project folder: $project_folder")}],
850 ## );
851 ##
852
853
854
855 ## ## vertical separator
856 ## $menubar -> Frame(-width=>2, -borderwidth=>2, -relief=>'sunken') ->
857 ## pack(-side=>'left', -fill=>'y', -pady=>2);
858
859 $menubar -> separator;
860
861
862 ## ============================================================================
863 ## ============================================================================
864 ## gsd menu
865 my $gsd_menu = $menubar
866 -> cascade(-label=>'~GDS', @menu_args,
867 -menuitems=>[[ command => 'Grab all best fit values',
868 -command => \&grab_all_best_fits],
869 [ command => 'Annotate selected parameter',
870 -command => \&gds2_annotation],
871 [ command => 'Locate parameter',
872 -command => \&gds2_locate],
873 [ command => 'Show all parameters',
874 -command => \&gds2_show],
875 [ command => 'Reset all variables',
876 -command => \&reset_all_variables],
877 [ command => 'Convert all guesses to sets',
878 -command => \&gds2_guess_to_set],
879 [ command => 'Discard all variables',
880 -command => \&clear_all_variables],
881 "-",
882 [ command => 'Highlight parameters matching ...',
883 -command => \&gds2_highlight],
884 [ command => 'Clear parameter highlights',
885 -command => \&gds2_clear_highlights],
886 "-",
887 [ command => 'Import variables from text file',
888 -command => \&gds2_import_text],
889 [ command => 'Export variables to text file',
890 -command => \&gds2_export_text],
891 "-",
892 [ command => 'How many independent points?',
893 -command => \&nidp],
894 [ cascade => 'Quick help',
895 -tearoff => 0,
896 -menuitems => [
897 [ command => 'guess',
898 -command => [\&Echo, "Guesses are varied to best fit the data; math expressions are written in terms of them"]],
899 [ command => 'def',
900 -command => [\&Echo, "A def parameter's math expression is stored and updated througout a fit"]],
901 [ command => 'set',
902 -command => [\&Echo, "A set parameter is a math expression which is evaluated at the time of definition"]],
903 [ command => 'skip',
904 -command => [\&Echo, "A skip parameter is ignored by Artemis but retained in the project"]],
905 [ command => 'restrain',
906 -command => [\&Echo, "A restrain parameter is a math expression which is evaluated and added to chi-square during the fit"]],
907 [ command => 'after',
908 -command => [\&Echo, "An after parameter is a math expression which is evaluated after the fit and written to the log"]],
909 ]],
910 ]);
911 # -> pack(-side=>'left');
912
913 ## ============================================================================
914 ## ============================================================================
915 ## data menu
916 my $data_menu = $menubar
917 -> cascade(-label=>'~Data', @menu_args,
918 -menuitems=>[[ command => 'Fit',
919 -command => [\&generate_script, 1]],
920 ##[ cascade => "Sum of paths (this data set) ...", -tearoff=>0,
921 ## -menuitems=>[[ command => 'All inlcuded paths', @menu_args,
922 ## -command => [\&generate_script, 2]],
923 ## [ command => 'Selected & included paths', @menu_args,
924 ## -command => [\&generate_script, 2, 'selected, included']],
925 ## [ command => 'All selected paths', @menu_args,
926 ## -command => [\&generate_script, 2, 'all selected']],
927 ## ]],
928 ##[ command => 'Automated first shell fit',
929 ## -state => 'disabled',
930 ## -command => [\&firstshell, 1]],
931 [ command => 'Save background subtracted as chi(k)',
932 -command => \&save_bkgsub_data,
933 -state => 'disabled',],
934 [ command => 'Make difference spectra using selected paths',
935 -command => \&make_difference_spectrum],
936 "-",
937 [ cascade => 'Clone a FEFF calculation ...',
938 -tearoff => 0,
939 -menuitems =>[
940 [ command => 'link',
941 -command => [\&clone_feff, 'link']],
942 [ command => 'copy',
943 -command => [\&clone_feff, 'copy']],
944 ]],
945 #[ command => 'Change this data file',
946 # -command => \&renew_data], #dispatch_read_data],
947 [ command => 'Rename these data', -accelerator=>'Ctrl-n',
948 -command => \&rename_data],
949 [ command => 'View this data file',
950 -command => [\&display_file, 'data', 'this']],
951 [ command => 'Restore default parameter values',
952 -command => [\&restore_default, 'all']],
953 "-",
954 [ command => 'Discard this data set',
955 -command => \&delete_data],
956 "-",
957 [ command => 'What is epsilon_k?',
958 -command => \&fetch_epsilon_k],
959 [ command => 'How many independent points?',
960 -command => \&nidp],
961 ]);
962 # -> pack(-side=>'left');
963
964 my $sum_menu = $menubar
965 -> cascade(-label=>'Sum', @menu_args, -underline=>1,
966 -menuitems=>[[ command => 'All included paths for this data set', @menu_args,
967 -command => [\&generate_script, 2]],
968 [ command => 'Selected & included paths for this data set', @menu_args,
969 -command => [\&generate_script, 2, 'selected, included']],
970 [ command => 'All selected paths for this data set', @menu_args,
971 -command => [\&generate_script, 2, 'all selected']],
972 ]);
973
974 my $fit_menu = $menubar
975 -> cascade(-label=>'Fits', @menu_args, -underline=>1,
976 -menuitems=>[[ command => "Restore this fit model",
977 -command => \&logview_restore_model,
978 -state => 'disabled'],
979 "-",
980 [ cascade => 'Save data + this fit, residual (bkg) as ...',
981 -tearoff => 0,
982 -menuitems =>[
983 [ command =>'chi(k)', @menu_args,
984 -command =>[\&save_full_data, 'k']],
985 "-",
986 [ command =>'|chi(R)|', @menu_args,
987 -command =>[\&save_full_data, 'r_mag']],
988 [ command =>'Re[chi(R)]', @menu_args,
989 -command =>[\&save_full_data, 'r_re']],
990 [ command =>'Im[chi(R)]', @menu_args,
991 -command =>[\&save_full_data, 'r_im']],
992 "-",
993 [ command =>'|chi(q)|', @menu_args,
994 -command =>[\&save_full_data, 'q_mag']],
995 [ command =>'Re[chi(q)]', @menu_args,
996 -command =>[\&save_full_data, 'q_re']],
997 [ command =>'Im[chi(q)]', @menu_args,
998 -command =>[\&save_full_data, 'q_im']],
999 ],
1000 ],
1001 [ command => 'Rename this fit',
1002 -accelerator=>'Ctrl-n',
1003 -command =>\&rename_fit ],
1004 [ cascade => 'This fit\'s comment ...',
1005 -tearoff => 0,
1006 -menuitems => [
1007 [ command => "Show",
1008 -command =>\&logview_show_comment ],
1009 [ command => "Change",
1010 -command =>\&logview_change_comment ],
1011 ],
1012 ],
1013 [ cascade => 'This fit\'s figure of merit ...',
1014 -tearoff => 0,
1015 -menuitems => [
1016 [ command => "Show",
1017 -command =>\&logview_show_fom ],
1018 [ command => "Change",
1019 -command =>\&logview_change_fom ],
1020 ],
1021 ],
1022 [ command => "Show warnings from this fit",
1023 -command => \&display_warnings,
1024 ],
1025 [ cascade => "Plot running R-factor ...", -tearoff=>0,
1026 -state => 'disabled',
1027 -menuitems => [[ command=>"computed in k", @menu_args,
1028 -command=>[\&running_r_factor, 'k']],
1029 [ command=>"computed in R", @menu_args,
1030 -command=>[\&running_r_factor, 'r']],
1031 [ command=>"computed in q", @menu_args,
1032 -command=>[\&running_r_factor, 'q']]]],
1033 #"-",
1034 #[ command => "Hide this fit",
1035 # -command => \&hide_fit],
1036 #[ command => "Hide selected fits",
1037 # -command => \&hide_selected_fits],
1038 #[ command => "Show all fits",
1039 # -command => \&show_fits],
1040 "-",
1041 [ command => "Discard this fit",
1042 -command => \&discard_fit],
1043 [ command => "Discard selected fits",
1044 -command => \&discard_selected_fits],
1045 [ command => "Discard all fits",
1046 -command => \&discard_all_fits],
1047 "-",
1048 [ checkbutton => "Make new entry for each fit",
1049 -selectcolor => $config{colors}{check},
1050 -variable => \$fit{new},
1051 -onvalue => 1,
1052 -offvalue => 0,],
1053 [ checkbutton => "Show fit information dialog",
1054 -selectcolor => $config{colors}{check},
1055 -variable => \$config{general}{fit_query},
1056 -onvalue => 1,
1057 -offvalue => 0,],
1058 ]);
1059
1060 ## ============================================================================
1061 ## ============================================================================
1062 ## FEFF Menu
1063 my $feff_menu = $menubar
1064 -> cascade(-label=>'~Theory', @menu_args,
1065 -menuitems=>[[ command => "New Atoms page",
1066 -command => \&new_atoms],
1067 [ command => "New Feff input template",
1068 -command => \&feff_template],
1069 [ command => "Quick first shell theory",
1070 -command => [\&firstshell, 0]],
1071 "-",
1072 [ command => "Add a feff path",
1073 -command => [\&read_feff, '^^']], #\&add_a_path],
1074 [ command => 'Rename this FEFF calculation',
1075 -accelerator=>'Ctrl-n',
1076 -command => \&rename_feff],
1077 [ cascade => "View ...", -tearoff=>0,
1078 -menuitems=>[[ command => "log of Feff run", @menu_args,
1079 -command => [\&display_file, 'feff', 'feff.run']],
1080 [ command => "misc.dat", @menu_args,
1081 -command => [\&display_file, 'feff', 'misc.dat']],
1082 [ command => "files.dat", @menu_args,
1083 -command => [\&display_file, 'feff', 'files.dat']],
1084 [ command => "paths.dat", @menu_args,
1085 -command => [\&display_file, 'feff', 'paths.dat']],
1086 ]],
1087 [ cascade => 'Set path degeneracies ...', -tearoff=>0,
1088 -menuitems => [
1089 [ command => 'to 1', @menu_args,
1090 -command => [\&set_degeneracy, 1]],
1091 [ command => 'to FEFF', @menu_args,
1092 -command => [\&set_degeneracy, 'feff']],
1093 ]],
1094 "-",
1095 [ command => "Atoms", @menu_header_args],
1096 [ command => " Space group browser",
1097 -command => \&post_sgb ],
1098 [ cascade => ' Write special output', -tearoff=>0,],
1099 [ command => " Clear Atoms page",
1100 -command => \&clear_atoms ],
1101 "-",
1102 [ command => 'Discard this FEFF calculation',
1103 -command => [\&delete_feff,0,0],
1104 -state => 'disabled'],
1105 "-",
1106 [ command => 'Identify this FEFF calculation',
1107 -command => \&identify_feff, -state=>'disabled'],
1108 ]);
1109 # -> pack(-side=>'left');
1110 &set_atp_menu;
1111
1112
1113
1114 ## ============================================================================
1115 ## ============================================================================
1116 ## Paths menu
1117 my @paths_menuitems = ([ command => 'View this feffNNNN.dat file', -state=>'disabled',
1118 -command => [\&display_file, 'path', 'this']],
1119 [ command => 'Show this path', -state=>'disabled',
1120 -command => \&show_path],
1121 [ cascade => "Save this path as ...", -tearoff=>0,
1122 -state=>'disabled',
1123 -menuitems=>[[ command=>"chi(k)", @menu_args,
1124 -command=>[\&save_data, 'path', 'k']],
1125 [ command=>"chi(R)", @menu_args,
1126 -command=>[\&save_data, 'path', 'r']],
1127 [ command=>"chi(q)", @menu_args,
1128 -command=>[\&save_data, 'path', 'q']]]],
1129 "-",
1130 );
1131
1132 my @add_cascade = ();
1133 my @clear_cascade = ();
1134 foreach (qw(label S02 E0 delR sigma^2 Ei 3rd 4th dphase k_array phase_array amp_array)) {
1135 push @add_cascade, [ command=>$_, @menu_args,
1136 -command=>[\&add_mathexp, $_]];
1137 push @clear_cascade, [ command=>$_, @menu_args,
1138 -command=>[\&add_to_paths, $_, '^^clear^^', 'this']];
1139 };
1140 push @paths_menuitems, [ cascade => "Add math expression to each path",
1141 -tearoff=>0, -menuitems=>\@add_cascade];
1142 push @paths_menuitems, [ cascade => "Clear math expression for each path",
1143 -tearoff=>0, -menuitems=>\@clear_cascade];
1144 push @paths_menuitems, [ cascade => "Include paths for fitting", -tearoff=>0,
1145 -menuitems=>
1146 [[ command=>"For THIS feff calculation ...", @menu_header_args],
1147 [ command=>" include all paths", @menu_args,
1148 -command=>[\&select_paths, 'all,this']],
1149 [ command=>" exclude all paths after current", @menu_args,
1150 -command=>[\&select_paths, 'current']],
1151 [ command=>" include only paths with N or fewer legs", @menu_args,
1152 -command=>[\&select_paths, 'nlegs']],
1153 [ command=>" include only paths shorter than R", @menu_args,
1154 -command=>[\&select_paths, 'r'],],
1155 [ command=>" include only paths with amplitude larger than A", @menu_args,
1156 -command=>[\&select_paths, 'amp'],],
1157 [ command=>" exclude all paths", @menu_args,
1158 -command=>[\&select_paths, 'none,this']],
1159 [ command=>" invert the included paths", @menu_args,
1160 -command=>[\&select_paths, 'invert,this']],
1161 "-",
1162 [ command=>"For EACH feff calculation ...", @menu_header_args, ],
1163 [ command=>" include all paths", @menu_args,
1164 -command=>[\&select_paths, 'all,each']],
1165 [ command=>" exclude all paths", @menu_args,
1166 -command=>[\&select_paths, 'none,each']],
1167 [ command=>" invert the included paths", @menu_args,
1168 -command=>[\&select_paths, 'invert']],
1169 "-",
1170 [ command=>"Include selected paths", @menu_args,
1171 -command=>[\&select_paths, 'selon']],
1172 [ command=>"Exclude selected paths", @menu_args,
1173 -command=>[\&select_paths, 'seloff']],
1174 ]];
1175 push @paths_menuitems, [ cascade => "Discard paths", -tearoff=>0,
1176 -menuitems=>
1177 [[ command=>"Discard this path", @menu_args,
1178 -command=>[\&delete_path, 'this']],
1179 "-",
1180 [ command=>"For THIS feff calculation ...", @menu_header_args,],
1181 [ command=>" discard all paths", @menu_args,
1182 -command=>[\&delete_path, 'all']],
1183 [ command=>" discard all paths after current", @menu_args,
1184 -command=>[\&delete_path, 'current']],
1185 [ command=>" discard all paths with more than N legs", @menu_args,
1186 -command=>[\&delete_path, 'nlegs']],
1187 [ command=>" discard all paths longer than R", @menu_args,
1188 -command=>[\&delete_path, 'r']],
1189 [ command=>" discard all paths with amplitude smaller than A", @menu_args,
1190 -command=>[\&delete_path, 'amp']],
1191 "-",
1192 [ command=>"Discard selected paths", @menu_args,
1193 -command=>[\&delete_path, 'sel']],
1194 ]];
1195 push @paths_menuitems, "-",
1196 [ command=>"Clone this feff path", -state => 'disabled',
1197 -command=>\&clone_this_path],
1198 [ command=>"Rename this path", -state => 'disabled',
1199 -accelerator=>'Ctrl-n',
1200 -command=>\&rename_this],
1201 [ cascade=>"Export these paths parameters ...",
1202 -menuitems=>[[ command => "to every path in THIS feff calculation",
1203 -command => [\&copy_pps, 'this']],
1204 [ command => "to every path in EACH feff with THIS data set",
1205 -command => [\&copy_pps, 'data']],
1206 [ command => "to every path in EACH feff calculation",
1207 -command => [\&copy_pps, 'each']],
1208 [ command => "to SELECTED paths",
1209 -command => [\&copy_pps, 'sel']]
1210 ]
1211 ],
1212 [ command=>"Add a feff path",
1213 -command=>[\&read_feff, '^^']],
1214 "-",
1215 [ checkbutton=>"Extended path parameters",
1216 -selectcolor=>$config{colors}{check},
1217 -variable=>\$config{paths}{extpp},
1218 -command=>\&manage_extended_params];
1219
1220 my $paths_menu = $menubar
1221 -> cascade(-label=>'~Paths', @menu_args,
1222 -menuitems=>\@paths_menuitems);
1223 # -> pack(-side=>'left');
1224
1225
1226
1227
1228
1229 ## vertical separator
1230 #$menubar -> Frame(-width=>2, -borderwidth=>2, -relief=>'sunken') ->
1231 # pack(-side=>'left', -fill=>'y', -pady=>2);
1232
1233 ## ============================================================================
1234 ## ============================================================================
1235 ## plot menu
1236 my @plot_menuitems = (['cascade'=>'Plot in ...', -tearoff=>0,
1237 -menuitems=>[['command'=>'k-space', @menu_args,
1238 -command =>[\&plot, 'k', 0]],
1239 ['command'=>'R-space', @menu_args,
1240 -command =>[\&plot, 'r', 0]],
1241 ['command'=>'q-space', @menu_args,
1242 -command =>[\&plot, 'q', 0]]]],
1243 ['command'=>'Select all for plotting', -accelerator => 'Ctrl-a',
1244 -command =>\&select_all],
1245 ['command'=>'Deselect all for plotting', -accelerator => 'Ctrl-u',
1246 -command =>\&deselect_all],
1247 "-",
1248 ['command'=>'Zoom', -accelerator => 'Ctrl-=',
1249 -command =>\&zoom], # no trailing newline!!
1250 ['command'=>'Unzoom', -accelerator => 'Crtl--',
1251 -command=>[\&replot, 'replot']],
1252 ['command'=>'Cursor', -accelerator => 'Ctrl-.',
1253 -command =>\&cursor], # no trailing newline!!
1254 '-');
1255
1256
1257
1258
1259 my %image_formats = (gif => "GIF (landscape)",
1260 vgif => "GIF (portrait)",
1261 png => "PNG (landscape)",
1262 vpng => "PNG (portrait)",
1263 tpng => "PNG (black background)",
1264 ps => "B/W Postscript (landscape)",
1265 cps => "Color Postscipt (landscape)",
1266 vps => "B/W Postscript (portrait)",
1267 vcps => "Color Postscipt (portrait)",);
1268 my @format_list;
1269 foreach my $f ( split(" ", Ifeffit::get_string('plot_devices')) ) {
1270 my $format = substr($f,1); # strip the leading slash
1271 next if ($format =~ /null/);
1272 next if ($format =~ /^x/);
1273 next if ($format =~ /^c?gw/);
1274 $image_formats{$format} ||= $format;
1275 push @format_list, ['command' =>$image_formats{$format}, -command =>[\&replot, $f]];
1276 };
1277 push @plot_menuitems, [cascade=>"Save image as ...", -tearoff=>0,
1278 -menuitems=>\@format_list];
1279
1280
1281 push @plot_menuitems, "-",
1282 ['command'=>'Print last plot',
1283 -accelerator => 'Ctrl-p',
1284 -command=>[\&replot, 'print'],
1285 -state=>($is_windows)?'disabled':'normal'];
1286
1287
1288 my $plot_menu = $menubar -> cascade(-label=>'Plot', @menu_args, -underline=>2,
1289 -menuitems=>\@plot_menuitems);
1290 # -> pack(-side=>'left');
1291 (@format_list) or $plot_menu -> menu -> entryconfigure(9, -state=>'disabled');
1292
1293
1294 $menubar -> separator;
1295
1296 ## ============================================================================
1297 ## ============================================================================
1298 ## settings menu
1299 ## my $settings_menu =
1300 ## $menubar -> cascade(-label=>"Settings", @menu_args, -underline=>0,
1301 ## -menuitems => [[ command => 'Swap panels', -accelerator => 'Ctrl-/',
1302 ## -state=>'disabled',
1303 ## -command => \&swap_panels],
1304 ## "-",
1305 ## [ command => 'Edit preferences',
1306 ## -command => \&prefs],
1307 ## ]);
1308
1309
1310 ## ============================================================================
1311 ## ============================================================================
1312 ## help menu
1313 $menubar -> cascade(-label=>"~Help", @menu_args,
1314 -menuitems=>[['command'=> 'Document', -accelerator=>'Ctrl-m',
1315 -command =>sub{pod_display("artemis.pod")}],
1316 ['command'=>'Dump paths',
1317 -command=>\&dump_paths],
1318 ['command'=>'Show a hint', -accelerator => 'Ctrl-h',
1319 -command =>\&show_hint],
1320 ['command'=>'About Ifeffit',
1321 -command =>sub{Echo($About_Ifeffit)}],
1322 ['command'=>'About Artemis',
1323 -command =>sub{Echo($About)}]
1324 ]
1325 );
1326
1327
1328
1329 ## ============================================================================
1330 ## ============================================================================
1331 ## set up the echo area
1332 splash_message("Creating echo area");
1333 my $ebar = $top -> Frame(-relief=>'flat', -borderwidth=>3)
1334 -> pack(-side=>"bottom", -fill=>'x');
1335 my $echo = $ebar -> Label(qw/-relief flat -justify left -anchor w/,
1336 -font => $config{fonts}{small},
1337 -foreground => $config{colors}{button},
1338 #-background => 'green',
1339 -text=> "Using Ifeffit ".Ifeffit::get_string("\$&build"))
1340 -> pack(-side=>'left', -fill=>'x');
1341 $echo -> bind('<KeyPress>' => sub{$multikey = $Tk::event->K; });
1342
1343
1344
1345
1346 splash_message("Creating layout");
1347 ## ============================================================================
1348 ## ============================================================================
1349 ## main panel (fat) (operational/path parameters)
1350 my $fat = $top -> Frame(-relief=>'sunken', -borderwidth=>2,)# @window_size)
1351 -> pack(-fill=>'both', -expand=>1);
1352
1353 ## ============================================================================
1354 ## ============================================================================
1355 ## skinny panel with path list
1356 my $skinny = $top -> Frame(-relief=>'sunken', -borderwidth=>2);
1357
1358 ## ============================================================================
1359 ## ============================================================================
1360 ## plot controls panel
1361 my $skinny2 = $top -> Frame(-relief=>'sunken', -borderwidth=>2);
1362
1363 &layout; # layout panels in user-selected order
1364
1365 ## fit and ff2chi buttons
1366 my $fitbar = $skinny2 -> Frame(-relief=>'ridge', -borderwidth=>2)
1367 -> pack(-anchor=>'nw', -fill=>'x');
1368 my $fit_button = $fitbar -> Button(-width=>1, @fitbutton_list,)
1369 -> pack(-side=>'left', -expand=>1, -fill=>'x');
1370 &set_fit_button('disable');
1371 ## my $ff2chi_button = $fitbar -> Button(-text=>'ff2chi', -width=>1, @fitbutton_list,
1372 ## -command=>[\&generate_script, 2])
1373 ## -> pack(-side=>'left', -expand=>1, -fill=>'x');
1374
1375 my $lab = $skinny -> Label(-text => 'Data & Paths',
1376 -font => $config{fonts}{smbold},
1377 -foreground => $config{colors}{activehighlightcolor},
1378 -justify => 'center',
1379 -relief => 'raised')
1380 -> pack(-fill => 'x', -anchor=>'n');
1381
1382 $list = $skinny -> Scrolled('Tree',
1383 -separator => '.',
1384 -selectmode => 'extended',
1385 #-width => 30,
1386 -height => 1,
1387 -indent => 20,
1388 -scrollbars => 'se',
1389 -itemtype => 'imagetext',
1390 -font => $config{fonts}{med},
1391 -selectbackground => $config{colors}{current},
1392 -browsecmd => [\&display_properties, Ev('b')],
1393 -indicatorcmd => \&hide_branch,
1394 )
1395 -> pack(qw/-expand 1 -fill both -anchor n -side top/);
1396 BindMouseWheel($list);
1397 $list->bind('<ButtonPress-2>',\&anchor_display);
1398 $list->bind('<ButtonPress-3>', [\&list_mouse_menu, Ev('X'), Ev('Y')]);
1399 $list->bind('<Control-ButtonPress-3>', [\&list_mouse_menu, Ev('X'), Ev('Y')]);
1400
1401
1402 $skinny2 -> Label(-text=>'Plot selected groups in',
1403 -font=>$config{fonts}{smbold},
1404 -foreground=>$config{colors}{foreground},
1405 -justify=>'center', -relief=>'raised')
1406 ->pack(-fill => 'x', -side => 'top');
1407 my $plotbar = $skinny2 -> Frame(-relief=>'ridge', -borderwidth=>2)
1408 -> pack(-anchor=>'nw', -fill=>'x');
1409 my $plotq_button = $plotbar -> Button(-text=>'q', @button_list,
1410 -command=>[\&plot, 'q', 0])
1411 -> pack(-side=>'right', -expand=>1, -fill=>'x');
1412 my $plotr_button = $plotbar -> Button(-text=>'R', @button_list,
1413 -command=>[\&plot, 'r', 0])
1414 -> pack(-side=>'right', -expand=>1, -fill=>'x');
1415 my $plotk_button = $plotbar -> Button(-text=>'k', @button_list,
1416 -command=>[\&plot, 'k', 0])
1417 -> pack(-side=>'right', -expand=>1, -fill=>'x');
1418
1419
1420
1421
1422
1423
1424 ## ============================================================================
1425 ## ============================================================================
1426 ## Setup the toplevel window for various textual interactions,
1427 ## including the ifeffit buffer and the raw text edit
1428 splash_message("Creating palettes");
1429 $update -> title("Artemis palettes");
1430 $update -> bind('<Control-q>' => sub{$update->withdraw});
1431 foreach my $n (qw(ifeffit results files messages echo journal properties)) {
1432 $notecard{$n} = $notebook -> add($n, -label=>ucfirst($n), -anchor=>'center', -underline=>0);
1433 my $topbar = $notecard{$n} -> Frame(-relief=>'flat', -borderwidth=>2)
1434 -> pack(-expand=>0, -fill=>'x');
1435 $topbar -> Button(-text=>'Dismiss', -command=>sub{$update->withdraw}, @button2_list)
1436 -> pack(-side=>'right');
1437 $labels{$n} = $topbar -> Label(-foreground=>$config{colors}{activehighlightcolor},
1438 -font=>$config{fonts}{large})
1439 -> pack(-side=>'left', -fill=>'x');
1440 my $h;
1441 SWITCH: {
1442 $h = 13, last SWITCH if ($n eq 'ifeffit');
1443 $h = 15, last SWITCH if ($n eq 'results');
1444 $h = 13, last SWITCH if ($n eq 'files');
1445 $h = 15, last SWITCH if ($n eq 'messages');
1446 $h = 15, last SWITCH if ($n eq 'echo');
1447 $h = 15, last SWITCH if ($n eq 'journal');
1448 $h = 13;
1449 };
1450 if ($n eq 'properties') {
1451 my $frame = $notecard{$n} -> Scrolled("Pane",
1452 -relief=>'flat',
1453 -borderwidth=>2,
1454 -scrollbars=>"oe",
1455 )
1456 -> pack(-expand=>1, -fill=>'both', -side=>'top');
1457 $frame -> Subwidget("yscrollbar")
1458 -> configure(-background=>$config{colors}{background},
1459 ($is_windows) ? () : (-width=>8));
1460 my $r = 0;
1461 foreach ('Project title', 'Comment', 'Prepared by', 'Contact') {
1462 my $subfr = $frame -> Frame(-relief=>'groove',
1463 -borderwidth=>2,)
1464 -> pack(-fill=>'x', -expand=>1, -side=>'top');
1465 $subfr -> Label(-text => "$_:",
1466 -width => 20,
1467 -anchor => 'e',
1468 -foreground => $config{colors}{activehighlightcolor})
1469 -> pack(-side=>'left', -anchor=>'e', -padx=>4);
1470 $subfr -> Entry(-width => 0,
1471 -textvariable => \$props{$_},
1472 )
1473 -> pack(-side=>'right', -anchor=>'w', -fill=>'x', -expand=>1);
1474 };
1475 $props{'Project title'} = "<insert a title for your project here>";
1476 $props{'Comment'} = q{};
1477 $props{'Prepared by'} = "<insert your name and/or the name of your computer here>";
1478 $props{'Information content'} = q{};
1479 $props{'Project location'} = q{};
1480 #$props{'Prepared by'} = ($is_windows) ? "<insert your name and/or the name of your computer here>" :
1481 # join("\@", $ENV{USER}||"you", $ENV{HOST}||"your.computer");
1482 $props{Contact} = "<insert your email address and/or phone number here>";
1483 foreach ('Started', 'Last fit', 'Environment', 'Project location', 'Information content') {
1484 my $subfr = $frame -> Frame(-relief=>'groove',
1485 -borderwidth=>2,)
1486 -> pack(-fill=>'x', -expand=>1, -side=>'top');
1487 $subfr -> Label(-text => "$_:",
1488 -width => 20,
1489 -anchor => 'e',
1490 -foreground => $config{colors}{activehighlightcolor})
1491 -> pack(-side=>'left', -anchor=>'e', -padx=>4);
1492 $subfr -> Entry(-width => 0,
1493 -textvariable => \$props{$_},
1494 -state => 'disabled',
1495 -foreground => $config{colors}{foreground},
1496 (($Tk::VERSION > 804) ? (-disabledforeground => $config{colors}{foreground},) : ()),
1497 -relief => 'flat',
1498 )
1499 #-font=>(($_ eq 'Environment') or ($_ eq 'Information content'))
1500 #? $config{fonts}{small} : $config{fonts}{med})
1501 -> pack(-side=>'right', -anchor=>'w', -fill=>'x');
1502 };
1503 } else {
1504 my $which = ($n eq 'journal') ? 'Text' : 'ROText';
1505 $notes{$n} = $notecard{$n} -> Scrolled($which,
1506 -relief => 'sunken',
1507 -borderwidth => 2,
1508 -wrap => 'none',
1509 -scrollbars => 'se',
1510 -width => 7,
1511 -height => $h,
1512 -font => $config{fonts}{fixed} )
1513 -> pack(qw/-expand 1 -fill both -side top/);
1514 $notebook -> pageconfigure($n, -raisecmd=>sub{$notes{$n}->focus});
1515 BindMouseWheel($notes{$n});
1516 $notes{$n} -> Subwidget("yscrollbar")
1517 -> configure(-background=>$config{colors}{background},
1518 ($is_windows) ? () : (-width=>8));
1519 $notes{$n} -> Subwidget("xscrollbar")
1520 -> configure(-background=>$config{colors}{background},
1521 ($is_windows) ? () : (-width=>8));
1522 &disable_mouse3($notes{$n}->Subwidget(lc($which)));
1523 $notes{$n} -> bind("<Control-a>" => sub{$notes{$n}->selectAll;
1524 $notes{$n}->break;});
1525 };
1526 SWITCH: {
1527 ($n =~ /results/) and do {
1528 $widgets{results_save} =
1529 $topbar -> Button(-text=>'Save', @button2_list, -state=>'disabled',
1530 -command=>sub{
1531 my $fname = 'artemis.log';
1532 if ($project_name) {
1533 ($fname = basename($project_name)) =~ s/apj$/log/;
1534 ($fname .= ".log") unless ($fname =~ /.log$/);
1535 };
1536 &save_from_palette('results', $fname,
1537 'Artemis: Saving results to a log file',
1538 ['Artemis results', '.log'],
1539 "", "")})
1540 -> pack(-side=>'right');
1541 $widgets{results_choose} =
1542 $topbar -> Optionmenu(-options=>[["Raw log file" => 'raw'],
1543 ["Quick view" => 'quick'],
1544 ["Column view" => 'column'],
1545 ["Operational view" => 'operational'],
1546 ],
1547 -variable=>\$log_type[1],
1548 -textvariable=>\$log_type[0],
1549 -command=>sub{log_file_display()},
1550 -state=>'disabled')
1551 -> pack(-side=>'right');
1552 last SWITCH;
1553 };
1554 ($n =~ /ifeffit/) and do {
1555 $widgets{ifeffit_save} =
1556 $topbar -> Button(-text=>'Save buffer to file', @button2_list,
1557 -command=>sub{&save_from_palette('ifeffit', 'ifeffit.buffer',
1558 'Artemis: Saving ifeffit buffer to a file',
1559 ['Ifeffit buffer', '.buffer'],
1560 "# Artemis version $Ifeffit::Path::VERSION\n" .
1561 $paths{data0}->project_header($project_folder),
1562 "")})
1563 -> pack(-side=>'right');
1564 last SWITCH;
1565 };
1566 ($n =~ /files/) and do {
1567 $widgets{files_browse} =
1568 $topbar -> Button(-text=>'Browse', @button2_list,
1569 -command=>sub{
1570 my $path = $current_data_dir || cwd;
1571 my $types = [['Text files', '*.txt'], ['All files', '*'],];
1572 my $file = $top -> getOpenFile(-filetypes=>$types,
1573 ##(not $is_windows) ?
1574 ## (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () ,
1575 -initialdir=>$path,
1576 -title => "Artemis: View a file");
1577 return unless ($file);
1578 my ($name, $pth, $suffix) = fileparse($file);
1579 $current_data_dir = $pth;
1580 &display_file('file', $file);
1581 })
1582 -> pack(-side=>'right');
1583 last SWITCH;
1584 };
1585 ($n =~ /messages/) and do {
1586 $widgets{ifeffit_save} =
1587 $topbar -> Button(-text=>'Save buffer to file', @button2_list,
1588 -command=>sub{&save_from_palette('messages', 'artemis.msg',
1589 'Artemis: Saving Artemis\' message to a file',
1590 ['Artemis message', '.msg'],
1591 "# Artemis version $Ifeffit::Path::VERSION\n" .
1592 $paths{data0}->project_header($project_folder),
1593 "")})
1594 -> pack(-side=>'right');
1595 last SWITCH;
1596 };
1597 };
1598 };
1599 $notebook->pack(-expand=>1, -fill => 'both', -side=>'left');
1600 $labels{ifeffit} -> configure(-text=>"Ifeffit interaction buffer");
1601 $notes{ifeffit} -> tagConfigure ('command', -foreground=>$config{colors}{foreground},
1602 -lmargin1=>4, -lmargin2=>4);
1603 $notes{ifeffit} -> tagConfigure ('response', -foreground=>$config{colors}{highlightcolor},
1604 -lmargin1=>20, -lmargin2=>20);
1605 $notes{ifeffit} -> tagConfigure ('comment', -foreground=>$config{colors}{button},
1606 -lmargin1=>4, -lmargin2=>4);
1607 $labels{files} -> configure(-text=>"View files");
1608 $labels{messages}-> configure(-text=>"Messages from Artemis");
1609 $notes{messages} -> tagConfigure('absorber', -foreground=>$config{colors}{button});
1610 $notes{messages} -> tagConfigure('angles', -font=>$config{fonts}{fixedit}, -foreground=>$config{colors}{disabledforeground});
1611 $notes{messages} -> tagConfigure('bold', -font=>$config{fonts}{fixedbold}, -underline=>1);
1612 $notes{messages} -> tagConfigure('warning', -font=>$config{fonts}{fixedbold}, -foreground=>'red3', -background=>'white');
1613 $notes{messages} -> tagConfigure('guess2', -spacing1=>2, -background=>$config{colors}{background2});
1614 $notes{messages} -> tagConfigure('guess', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{guess_color}, -background=>$config{colors}{background2});
1615 $notes{messages} -> tagConfigure('def', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{def_color});
1616 $notes{messages} -> tagConfigure('set', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{set_color});
1617 $notes{messages} -> tagConfigure('skip', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{skip_color});
1618 $notes{messages} -> tagConfigure('after', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{after_color});
1619 $notes{messages} -> tagConfigure('restrain', -font=>$config{fonts}{fixedbold}, -spacing1=>1, -spacing3=>1, -foreground=>$config{gds}{restrain_color});
1620 $labels{echo} -> configure(-text=>"Record of all text written to the echo area");
1621 $labels{results} -> configure(-text=>"Results from the last fit");
1622 $notes{results} -> tagConfigure('pathid', -font=>$config{fonts}{fixedit}, -underline=>1);
1623 $notes{results} -> tagConfigure('warning', -font=>$config{fonts}{fixedbold}, -foreground=>'red3', -background=>'white');
1624 $labels{journal} -> configure(-text=>"Keep a journal of your analysis project");
1625 $notes{journal} -> configure(-wrap=>"word");
1626 $notes{journal} -> bind('<Control-s>' => sub{&save_project(0,0)});
1627 $labels{properties} -> configure(-text=>"Properties of this project");
1628
1629 ## set up the button bar in the files notecard
1630 my $filesbbar = $notecard{files} -> Frame(qw/-relief flat -borderwidth 2/)
1631 -> pack(qw/-expand 0 -fill x/);
1632 $filesbbar -> Label(-textvariable=>\$current_file,
1633 -foreground=>$config{colors}{foreground},
1634 -relief=>'groove')
1635 -> pack(qw/-expand 1 -fill x -side left/);
1636 $filesbbar -> Button(-text=>'Save', @button2_list,
1637 -command=>sub{&save_from_palette('files', $generic_name,
1638 'Artemis: Saving to a file',
1639 "",
1640 "", "")})
1641 -> pack(qw/-expand 1 -fill x -side left/);
1642 $filesbbar -> Button(-text=>'Clear', @button2_list,
1643 -command=>sub{$notes{files}->delete(qw/1.0 end/);
1644 $current_file = ''; })
1645 -> pack(qw/-expand 1 -fill x -side left/);
1646
1647
1648 ## set up the command line in the ifeffit interaction buffer
1649 my $cmdline = $notecard{ifeffit} -> Frame(qw/-relief flat -borderwidth 2/)
1650 -> pack(qw/-expand 0 -fill x/);
1651 $cmdline -> Label(-text => 'Ifeffit> ',
1652 -foreground => $config{colors}{activehighlightcolor},
1653 -font => $config{fonts}{fixed},)
1654 -> pack(-side=>'left');
1655 my $cmdbox = $cmdline -> Entry(-width => 75,
1656 -relief => 'sunken',
1657 -borderwidth => 2)
1658 -> pack(-side=>'bottom', -expand=>1, -fill=>'x');
1659 my @cmd_buffer = ("");
1660 my $cmd_pointer = $#cmd_buffer;
1661 $cmdbox->bind("<KeyPress-Return>",
1662 sub{ $paths{data0}->dispose($cmdbox->get()."\n", $dmode);
1663 $cmd_buffer[$#cmd_buffer] = $cmdbox->get();
1664 push @cmd_buffer, "";
1665 $cmd_pointer = $#cmd_buffer;
1666 $cmdbox->delete(0,'end'); });
1667 $cmdbox->bind("<KeyPress-Up>",
1668 sub{ --$cmd_pointer; ($cmd_pointer<0) and ($cmd_pointer=0);
1669 $cmdbox->delete(0,'end');
1670 $cmdbox->insert(0, $cmd_buffer[$cmd_pointer]); });
1671 $cmdbox->bind("<KeyPress-Down>",
1672 sub{ ++$cmd_pointer; ($cmd_pointer>$#cmd_buffer) and ($cmd_pointer= $#cmd_buffer);
1673 $cmdbox->delete(0,'end');
1674 $cmdbox->insert(0, $cmd_buffer[$cmd_pointer]); });
1675 $cmdbox->bind("<KeyPress-Tab>", # command completion
1676 sub{ my $str = $cmdbox -> get;
1677 my $i = $cmdbox -> index('insert');
1678 $str = substr($str, 0, $i);
1679 $str = reverse $str;
1680 $i = index($str, " ");
1681 ($i != -1) and ($str = substr($str, 0, $i));
1682 $str = reverse $str;
1683 my $rep = $abbrevs{$str} || "";
1684 ($rep) and ($rep = substr($rep, length($str)));
1685 $cmdbox->insert('insert', $rep);
1686 $cmdbox->break; # halt further searching of
1687 # bindtags list to avoid loosing
1688 # focus on this widget see Mastering
1689 # Perl/Tk, ch. 15, p. 374
1690 });
1691 ## reserved word/group name completion
1692
1693
1694 ## define various types of text for the paths list
1695 my %list_styles = (
1696 enabled => $list->ItemStyle ('imagetext',
1697 -foreground => 'black',
1698 -selectforeground => 'black',
1699 -font => $config{fonts}{smbold},
1700 -selectbackground => $config{colors}{current},),
1701 enabled_ss => $list->ItemStyle ('imagetext',
1702 -foreground => 'black',
1703 -background => $config{intrp}{ss},
1704 -selectforeground => 'black',
1705 -font => $config{fonts}{smbold},
1706 -selectbackground => $config{colors}{current},),
1707 enabled_col => $list->ItemStyle ('imagetext',
1708 -foreground => 'black',
1709 -background => $config{intrp}{focus},
1710 -selectforeground => 'black',
1711 -font => $config{fonts}{smbold},
1712 -selectbackground => $config{colors}{current},),
1713 hidden => $list->ItemStyle ('imagetext',
1714 -foreground => $config{colors}{hidden},
1715 -selectforeground => $config{colors}{hidden},
1716 -font => $config{fonts}{smbold},
1717 -selectbackground => $config{colors}{current},),
1718 noplot => $list->ItemStyle ('imagetext',
1719 -foreground => 'black',
1720 -selectforeground => 'black',
1721 -font => $config{fonts}{noplot},
1722 -selectbackground => 'yellow'),
1723 disabled => $list->ItemStyle ('imagetext',
1724 -foreground => $config{colors}{exclude},
1725 -activeforeground => $config{colors}{exclude},
1726 -selectforeground => $config{colors}{exclude},
1727 -font => $config{fonts}{smbold},
1728 -selectbackground => $config{colors}{activebackground},),
1729 disabled_ss => $list->ItemStyle ('imagetext',
1730 -foreground => $config{colors}{exclude},
1731 -background => $config{intrp}{ss},
1732 -activeforeground => $config{colors}{exclude},
1733 -selectforeground => $config{colors}{exclude},
1734 -font => $config{fonts}{smbold},
1735 -selectbackground => $config{colors}{activebackground},),
1736 disabled_col => $list->ItemStyle ('imagetext',
1737 -foreground => $config{colors}{exclude},
1738 -background => $config{intrp}{focus},
1739 -activeforeground => $config{colors}{exclude},
1740 -selectforeground => $config{colors}{exclude},
1741 -font => $config{fonts}{smbold},
1742 -selectbackground => $config{colors}{activebackground},),
1743 noplotdis => $list->ItemStyle ('imagetext',
1744 -foreground => $config{colors}{exclude},
1745 -activeforeground => $config{colors}{exclude},
1746 -selectforeground => $config{colors}{exclude},
1747 -font => $config{fonts}{noplot},
1748 -selectbackground => 'yellow'),
1749 );
1750
1751 $list -> add('gsd', -text=>'Guess, Def, Set ', -style=>$list_styles{noplot});
1752 $list -> setmode('gsd', 'none');
1753 $list -> add('data0', -text=>'Data', -style=>$list_styles{enabled});
1754 $list -> setmode('data0', 'none');
1755 $list -> autosetmode();
1756
1757 $list -> add("data0.0", -text=>'Fit', -style=>$list_styles{enabled},);
1758 $list -> setmode('data0.0', 'close');
1759 ## $list -> add("data0.1", -text=>'Residual', -style=>$list_styles{enabled},);
1760 ## $list -> setmode('data0.1', 'none');
1761 ## $list -> add("data0.2", -text=>'Background', -style=>$list_styles{enabled},);
1762 ## $list -> setmode('data0.2', 'none');
1763 $list -> hide('entry', "data0.0");
1764 ## $list -> hide('entry', "data0.1");
1765 ## $list -> hide('entry', "data0.2");
1766
1767 $list->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background});
1768 $list->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background});
1769
1770
1771 my %temp = ();
1772 &set_temp;
1773 sub set_temp {
1774 $temp{op_kwindow} = $config{data}{kwindow};
1775 $temp{op_rwindow} = $config{data}{rwindow};
1776 $temp{op_fitspace} = 'R';
1777 $temp{op_include} = 0;
1778 $temp{op_plot} = 0;
1779 $temp{op_do_bkg} = 'no';
1780 $temp{op_pcplot} = 'No';
1781 $temp{op_pcpath} = 'None';
1782 $temp{op_pcpath_label} = 'None';
1783 $temp{op_k1} = 0;
1784 $temp{op_k2} = 0;
1785 $temp{op_k3} = 0;
1786 $temp{op_karb_use} = 0;
1787 $temp{bkg_fixstep} = 0;
1788 $temp{bkg_flatten} = 0;
1789 $temp{bkg_clamp2} = 'None';
1790 };
1791
1792 ## ============================================================================
1793 ## ============================================================================
1794
1795
1796 ## set up error handlers
1797 #$SIG{__DIE__} = sub{$setup->trap('Artemis',$VERSION, 'die', $trapfile, \&Error, $project_folder)};
1798 #$SIG{__WARN__} = sub{$setup->trap("Artemis", $VERSION, "warn", $trapfile, \&Error, $project_folder)};
1799 $SIG{__DIE__} = sub{Carp::cluck(@_); print STDERR $/; Error("Artemis trapped one or more warnings! Warning message dumped to screen.")};
1800 $SIG{__WARN__} = sub{Carp::cluck(@_); print STDERR $/; Error("Artemis trapped one or more errors! Error message dumped to screen.")};
1801
1802 splash_message("Setting up initial data objects");
1803 $setup -> SetDefault(fit_space => $config{data}{fit_space},
1804 do_bkg => ($config{data}{fit_bkg}) ? 'yes' : 'no',
1805 kmin => $config{data}{kmin},
1806 kmax => $config{data}{kmax} || 15,
1807 dk => $config{data}{dk},
1808 k1 => ($config{data}{kweight} == 1),
1809 k2 => ($config{data}{kweight} == 2),
1810 k3 => ($config{data}{kweight} == 3),
1811 rmin => $config{data}{rmin},
1812 rmax => $config{data}{rmax},
1813 dr => $config{data}{dr},
1814 kwindow => $config{data}{kwindow},
1815 rwindow => $config{data}{rwindow},
1816 cormin => $config{data}{cormin},
1817 nindicators => $config{plot}{nindicators},
1818 indicatorcolor => $config{plot}{indicatorcolor},
1819 indicatorline => $config{plot}{indicatorline},
1820 );
1821 $paths{data0} = Ifeffit::Path -> new(id => 'data0',
1822 group => 'data0',
1823 type => 'data',
1824 sameas => 0,
1825 file => "",
1826 include => 1,
1827 family => \%paths);
1828 $paths{"data0.0"} = Ifeffit::Path -> new(id => "data0.0",
1829 type => 'fit',
1830 group => 'data0_fit',
1831 sameas => 'data0',
1832 lab => 'Fit',
1833 parent => 0,
1834 family => \%paths);
1835 ## $paths{"data0.2"} = Ifeffit::Path -> new(id=>"data0.2", type=>'bkg',
1836 ## group=>'data0_bkg',
1837 ## sameas=>'data0', lab=>'Background',
1838 ## family=>\%paths);
1839 ## $paths{"data0.1"} = Ifeffit::Path -> new(id=>"data0.1", type=>'res',
1840 ## group=>'data0_res',
1841 ## sameas=>'data0', lab=>'Residual',
1842 ## family=>\%paths);
1843 $paths{gsd} = Ifeffit::Path -> new(id=>'gsd', type=>'gsd', family=>\%paths);
1844 $props{Environment} = (split(/\n/, $paths{data0} -> project_header))[1];
1845 $props{Environment} =~ s/\# /Artemis $VERSION /;
1846 $props{Started} = $paths{data0} -> date_of_file;
1847
1848
1849 splash_message("Populating main window");
1850 my $current_canvas = 'op';
1851 my $opparams = make_opparams($fat);
1852 my $gsd = make_gds2($fat);
1853 my $feff = make_feff($fat);
1854 my $path = make_path($fat);
1855 my $logviewer = logviewer($fat);
1856 map {($_ =~ /^op/) and $widgets{$_}->configure(-state=>'disabled')} (keys %widgets);
1857 map {$grab{$_}->configure(-state=>'disabled')} (keys %grab);
1858
1859 $opparams -> pack();
1860 # select and anchor the first data file and give the list initial focus
1861 $list->Subwidget("tree")->anchorSet('data0');
1862 $list->Subwidget("tree")->selectionSet('data0');
1863 $list->Subwidget("tree")->focus();
1864 $current = 'data0';
1865
1866 ## ============================================================================
1867 ## ============================================================================
1868 splash_message("Setting up plotting options");
1869 $skinny2 -> Label(-text=>'Plotting options',
1870 -font=>$config{fonts}{smbold},
1871 -foreground=>$config{colors}{foreground},
1872 -justify=>'center', -relief=>'raised')
1873 ->pack(-fill => 'x', -side => 'top');
1874 my $kweights = $skinny2 -> Frame(-borderwidth=>2, -relief=>'ridge');
1875 $kweights -> Radiobutton(-text => '0',
1876 -selectcolor => $config{colors}{check},
1877 -font => $config{fonts}{med},
1878 -foreground => $config{colors}{activehighlightcolor},
1879 -activeforeground => $config{colors}{activehighlightcolor},
1880 -value => '0',
1881 -variable => \$plot_features{kweight},
1882 -command => sub{&plot($last_plot, 0)})
1883 -> pack(-side=>'left');
1884 $kweights -> Radiobutton(-text => '1',
1885 -selectcolor => $config{colors}{check},
1886 -font => $config{fonts}{med},
1887 -foreground => $config{colors}{activehighlightcolor},
1888 -activeforeground => $config{colors}{activehighlightcolor},
1889 -value => '1',
1890 -variable => \$plot_features{kweight},
1891 -command => sub{&plot($last_plot, 0)})
1892 -> pack(-side=>'left');
1893 $kweights -> Radiobutton(-text => '2',
1894 -selectcolor => $config{colors}{check},
1895 -font => $config{fonts}{med},
1896 -foreground => $config{colors}{activehighlightcolor},
1897 -activeforeground => $config{colors}{activehighlightcolor},
1898 -value => '2',
1899 -variable => \$plot_features{kweight},
1900 -command => sub{&plot($last_plot, 0)})
1901 -> pack(-side=>'left');
1902 $kweights -> Radiobutton(-text => '3',
1903 -selectcolor => $config{colors}{check},
1904 -font => $config{fonts}{med},
1905 -foreground => $config{colors}{activehighlightcolor},
1906 -activeforeground => $config{colors}{activehighlightcolor},
1907 -value => '3',
1908 -variable => \$plot_features{kweight},
1909 -command => sub{&plot($last_plot, 0)})
1910 -> pack(-side=>'left');
1911 $kweights -> Radiobutton(-text => 'kw',
1912 -selectcolor => $config{colors}{check},
1913 -font => $config{fonts}{med},
1914 -foreground => $config{colors}{activehighlightcolor},
1915 -activeforeground => $config{colors}{activehighlightcolor},
1916 -value => 'kw',
1917 -variable => \$plot_features{kweight},
1918 -command => sub{&plot($last_plot, 0)})
1919 -> pack(-side=>'left');
1920
1921 $kweights -> pack(-fill => 'x');
1922
1923 $widgets{plot_extra_frame} = $skinny2 -> Frame(-borderwidth=>0, -relief=>'flat');
1924 $widgets{plot_extra} = $widgets{plot_extra_frame} -> NoteBook(-backpagecolor=>$config{colors}{background},
1925 -inactivebackground=>$config{colors}{inactivebackground},
1926 -font=>$config{fonts}{med}
1927 )
1928 -> pack(-fill=>'both', -side=>'top', -expand=>1, -padx=>2, -pady=>2);
1929 $widgets{plot_Main} = $widgets{plot_extra} -> add('main', -label=>'Main', -anchor=>'center');
1930 $widgets{plot_Ind} = $widgets{plot_extra} -> add('indicators', -label=>'Indic', -anchor=>'center');
1931 &setup_indicators;
1932 $widgets{plot_Sta} = $widgets{plot_extra} -> add('traces', -label=>'Traces', -anchor=>'center');
1933 &setup_stack;
1934 ## $widgets{plot_Inv} = $widgets{plot_extra} -> add('invert', -label=>'Inv', -anchor=>'center');
1935 ## &setup_invert;
1936 ## $widgets{plot_extra_frame} -> Button(-text=>'Hide extra features',
1937 ## @button2_list,
1938 ## -command=>\&remove_extra_plot)
1939 ## -> pack(-fill=>'x', -side=>'bottom', -padx=>2);
1940
1941 &set_plotoptions($widgets{plot_Main});
1942 $widgets{plot_extra} -> raise('main');
1943
1944
1945 $widgets{help_plot} =
1946 $skinny2 -> Button(-text=>'Document: Plotting', @button2_list,
1947 -command=>sub{pod_display("artemis_plot.pod")} )
1948 -> pack(-side=>'bottom', -fill=>'x', -padx=>2, -pady=>2);
1949
1950 $widgets{plot_extra_frame} -> pack(-fill => 'both', -side => 'top', -expand=>1);
1951
1952
1953
1954 ##my $plotsel = $skinny -> NoteBook();
1955 my %plotcard;
1956 ## foreach (qw/k r q/) {
1957 ## my $lab;
1958 ## ($_ eq 'k') and ($lab = " k ");
1959 ## ($_ eq 'r') and ($lab = " R ");
1960 ## ($_ eq 'q') and ($lab = " q ");
1961 ## $plotcard{$_} = $plotsel -> add($_, -label=>$lab, -anchor=>'center');
1962 ## };
1963 ## $plotcard{Help} = $plotsel -> add('Help', -label=>'Help', -anchor=>'center');
1964 #&set_plotcards;
1965 ##$plotsel-> pack(-fill => 'x', -side => 'bottom');
1966 ##$plotsel -> raise('r');
1967 #$fr -> pack(-side=>'bottom', -fill=>'x', -anchor=>'s');
1968 #$list -> createWindow('0.1c', '18c', -anchor=>'sw', -width=>'5.3c', -window => $fr);
1969
1970 $list->Subwidget("tree")->anchorSet('gsd');
1971 &display_properties;
1972 $top -> update;
1973
1974
1975
1976
1977
1978 ## ============================================================================
1979 ## ============================================================================
1980 ## remove splashscreen and display program
1981 splash_message("Initializing Ifeffit");
1982 $list->Subwidget("tree")->anchorSet('data0');
1983 &display_properties;
1984
1985 my $macros_string = write_macros();
1986 $paths{data0} -> dispose($macros_string, $dmode);
1987 ## set the charsize and charfont
1988 ##$paths{data0} -> dispose("plot(charsize=$config{plot}{charsize}, charfont=$config{plot}{charfont})", $dmode);
1989 $paths{data0} -> dispose("startup", $dmode);
1990
1991
1992 &set_recent_menu;
1993
1994 splash_message("Ready to start...");
1995 $top -> update;
1996 $splash -> Destroy;
1997
1998 &clean_old_trap_files;
1999 &initialize_project(1);
2000
2001 Echo($About_Ifeffit);
2002 $top -> after(2000, [\&Echo, "Artemis may be freely redistributed under the terms of its license."]);
2003 $top -> after(3500, [\&Echo, "Artemis comes with absolutely NO WARRANTY."]);
2004 if ($STAR_Parser_exists) {
2005 $top -> after(5500, \&show_hint);
2006 } else {
2007 $top -> after(5500, [\&Echo, "You cannot import CIF files because STAR::Parser is not installed."]);
2008 };
2009
2010 ##&bindDump($update);
2011
2012 ## make sure that the parameters will be updated the first time a plot
2013 ## or show is done.
2014 $parameters_changed = 1;
2015
2016 my $chdir_to = Cwd::cwd || $current_data_dir || dirname($0) || $ENV{IFEFFIT_DIR};
2017 $chdir_to = Cwd::abs_path($chdir_to);
2018 chdir $chdir_to;
2019
2020 delete $config{general}{devel_greetings} if (exists $config{general}{devel_greetings});
2021 ($config{general}{greetings} = "0.0.0") unless (exists $config{general}{greetings});
2022 my $vv = sprintf("%d.%2.2d%3.3d", split(/\./, $VERSION));
2023 my $vg = sprintf("%d.%2.2d%3.3d", split(/\./, $config{general}{greetings}));
2024
2025 if ($vv > $vg) {
2026 # my $text = <<EOH
2027 # EOH
2028 # ;
2029 # $text =~ s/\n/ /g;
2030 # $text =~ s/\| /\n\n/g;
2031
2032 # my $greeting = $top -> Toplevel(-class=>'horae');
2033 # $greeting -> protocol(WM_DELETE_WINDOW => sub{$greeting->destroy});
2034 # $greeting -> iconbitmap('@'.$iconbitmap);
2035 # $greeting -> title("Welcome to the new version Artemis");
2036 # my $textbox = $greeting -> Scrolled('ROText',
2037 # -scrollbars=>'oe',
2038 # -width=>80,
2039 # -height=>30,
2040 # -wrap=>'word',
2041 # -font=>'Courier 14')
2042 # -> pack(-side=>'top');
2043 # $textbox -> Subwidget("yscrollbar")
2044 # -> configure(-background=>$config{colors}{background});
2045 # $textbox -> insert('end', $text);
2046 # $greeting -> Button(-text=>'OK', -command=>sub{$greeting->destroy})
2047 # -> pack(-side=>'bottom');
2048 # $greeting -> waitWindow;
2049
2050 $config{general}{greetings} = $VERSION;
2051 $config_ref -> WriteConfig($personal_rcfile);
2052 };
2053
2054
2055 ## if ($is_windows) {
2056 ## open PARID, ">".$paths{data0} -> find('artemis', 'par');
2057 ## print PARID $ENV{PAR_TEMP}, $/;
2058 ## close PARID;
2059 ## };
2060
2061
2062 $top -> update;
2063 my $w = $mru{geometry}{uwidth} || 600;
2064 my $h = $mru{geometry}{uheight} || 300;
2065 $update->geometry(join("x", $w, $h));
2066
2067 my @geom = split(/[+x]/, $top->geometry);
2068 ## if (exists $mru{geometry}{uheight}) {
2069 ## my $w = ($mru{geometry}{uwidth} > $geom[0]) ? $mru{geometry}{uwidth} : $geom[0];
2070 ## my $h = ($mru{geometry}{uheight} > $geom[1]) ? $mru{geometry}{uheight} : $geom[1];
2071 ## $top->geometry(join("x", $w, $h));
2072 ## };
2073 my $extrabit = ($Tk::VERSION < 804) ? 30 : 0;
2074 ($extrabit = 0) if ($is_windows);
2075 $top -> minsize($geom[0], $geom[1]+$extrabit);
2076 $top -> update;
2077 if (exists $mru{geometry}{'x'}) {
2078 my $location = "+" . $mru{geometry}{'x'} . "+" . $mru{geometry}{'y'};
2079 #$mru{geometry}{height} . "x" . $mru{geometry}{width} .
2080 $top -> geometry($location);
2081 };
2082 if (exists $mru{geometry}{width}) {
2083 my $size = $mru{geometry}{width} . "x" . $mru{geometry}{height};
2084 $top -> geometry($size);
2085 };
2086
2087 $top -> update;
2088
2089
2090 $fat -> pack(-expand => 0);
2091 $fat -> packPropagate(0);
2092 $skinny2 -> packPropagate(0);
2093
2094
2095 # else {
2096 ## the next line serves to make the DPL a bit wider
2097 ##$top -> geometry(sprintf("%dx%d",$config{geometry}{window_multiplier}*$geom[0], $geom[1]+$extrabit));
2098 ##};
2099
2100 $top -> resizable(1,1);
2101 $top -> deiconify;
2102 $top -> raise;
2103
2104
2105 ## read a project specified from the command line or an actuve
2106 ## autosave file
2107 my $response = 'No';
2108 if (-e $autosave_filename) {
2109 my $message = "Artemis found an autosave file, perhaps from a previous failure of Artemis. Would you like to import it?";
2110 my $dialog =
2111 $top -> Dialog(-bitmap => 'questhead',
2112 -text => $message,
2113 -title => 'Artemis: Import autosave file?',
2114 -buttons => [qw/Yes No/],
2115 -default_button => 'Yes',
2116 -font => $config{fonts}{med},
2117 -popover => 'cursor');
2118 &posted_Dialog;
2119 $response = $dialog->Show();
2120 };
2121 if ($response eq 'Yes') {
2122 Echo("Importing autosave file ...");
2123 my $save_cdd = $current_data_dir;
2124 ##&dispatch_mru($autosave_filename, 0);
2125 &dispatch_read_data(0, $autosave_filename, 0);
2126 $current_data_dir = $save_cdd;
2127 $project_name = "";
2128 Echo("Importing autosave file ... done!");
2129 } elsif ($ARGV[0]) {
2130 Echo("Processing filename from command line");
2131 if ($ARGV[0] =~ /^-(\d+)$/) {
2132 &dispatch_mru($mru{mru}{$1});
2133 } elsif (-e $ARGV[0]) {
2134 my $arg = ($ARGV[0] =~ /^[\~\/]/) ? $ARGV[0] : File::Spec->catfile(Cwd::cwd, $ARGV[0]);
2135 $top -> after(500, sub{read_data(0, $arg)});
2136 #($project_name = $arg) if (&dispatch_mru($arg) eq "project");
2137 };
2138 };
2139
2140
2141 MainLoop();
2142