Changeset 910
- Timestamp:
- Dec 4, 2009 5:14:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsascmds.tcl
- Property rcs:date changed from 2006/03/29 03:52:11 to 2008/04/15 17:20:39
- Property rcs:lines changed from +11 -1 to +404 -12
- Property rcs:rev changed from 1.63 to 1.64
r876 r910 735 735 foreach phase $phaselist hist $histlist { 736 736 hapinfo $hist $phase proftype set $expgui(newpeaktype) 737 RecordMacroEntry "hapinfo $hist $phase proftype set $expgui(newpeaktype)" 0 737 738 hapinfo $hist $phase profterms set $expgui(newProfileTerms) 739 RecordMacroEntry "hapinfo $hist $phase profterms set $expgui(newProfileTerms)" 0 738 740 for {set i 1} {$i <= $expgui(newProfileTerms)} {incr i} { 739 741 hapinfo $hist $phase pterm$i set [$w.ent${i} get] 742 RecordMacroEntry "hapinfo $hist $phase pterm$i set [$w.ent${i} get]" 0 740 743 hapinfo $hist $phase pref$i set $expgui(ProfRef$i) 744 RecordMacroEntry "hapinfo $hist $phase pref$i set $expgui(ProfRef$i)" 0 741 745 } 742 746 set i [expr 1+$expgui(newProfileTerms)] 743 747 hapinfo $hist $phase pcut set [$w.ent$i get] 748 RecordMacroEntry "hapinfo $hist $phase pcut set [$w.ent$i get]" 0 744 749 incr expgui(changed) [expr 3 + $expgui(newProfileTerms)] 750 RecordMacroEntry "incr expgui(changed)" 0 745 751 } 746 752 } … … 1140 1146 # Save the current exp file 1141 1147 savearchiveexp 1148 CantRecordMacroEntry "bkgedit" 1142 1149 # disable the file change monitor if we will reload the .EXP file automatically 1143 1150 if {$expgui(autoexpload)} {set expgui(expModifiedLast) 0} … … 1158 1165 # run excledt 1159 1166 proc excledit {} { 1160 global expgui liveplot wishshellexpmap1167 global expgui liveplot expmap 1161 1168 set expnam [file root [file tail $expgui(expfile)]] 1162 1169 # which histograms are ready for use? … … 1336 1343 # run a GSAS program that does not require an experiment file 1337 1344 proc runGSASprog {proglist "concurrent 1"} { 1345 # save call to Macro file 1346 RecordMacroEntry "runGSASprog [list $proglist] $concurrent" 0 1338 1347 # if concurrent is 0, EXPGUI runs the GSAS program in background 1339 1348 # -- this is not currently needed anywhere where the .EXP file is not. … … 1358 1367 # run a GSAS program that requires an experiment file for input/output 1359 1368 proc runGSASwEXP {proglist "concurrent 0"} { 1369 # save call to Macro file 1370 RecordMacroEntry "runGSASwEXP [list $proglist] $concurrent" 0 1360 1371 # most programs that require the .EXP file change it and 1361 1372 # cannot be run concurrently … … 1393 1404 if {$tcl_platform(platform) == "windows"} { 1394 1405 append cmd " \"$expgui(gsasexe)/${prog}.exe $expnam \" " 1406 } elseif {$expgui(MacroRunning) && !$expgui(ShowGENLES)} { 1407 append cmd " \" [file join $expgui(gsasexe) $prog] $expnam \" " 1395 1408 } else { 1396 1409 if {$cmd != ""} {append cmd "\;"} … … 1398 1411 } 1399 1412 } 1400 forknewterm "$prog -- $expnam" $cmd [expr !$concurrent] 1 1413 if {$expgui(MacroRunning) && !$expgui(ShowGENLES)} { 1414 set outfile ${expnam}_macout.LST 1415 runnoterm $cmd $outfile 1416 } else { 1417 forknewterm "$prog -- $expnam" $cmd [expr !$concurrent] 1 1418 } 1401 1419 # load the changed .EXP file automatically? 1402 1420 if {$expgui(autoexpload)} { 1403 1421 # load the revised exp file 1404 1422 loadexp $expgui(expfile) 1423 } 1424 if {$expgui(MacroRunning)} { 1425 if {[file exists abort_${expnam}_macro.flag]} { 1426 file delete abort_${expnam}_macro.flag 1427 error "User requested to abort the macro" 1428 } 1429 update idletasks 1405 1430 } 1406 1431 } … … 2176 2201 if {$expgui(useflag_$i) != [histinfo $i use]} { 2177 2202 histinfo $i use set $expgui(useflag_$i) 2203 RecordMacroEntry "histinfo $i use set $expgui(useflag_$i)" 0 2178 2204 incr expgui(changed) 2205 RecordMacroEntry "incr expgui(changed)" 0 2179 2206 } 2180 2207 # } … … 2464 2491 return 2465 2492 } 2466 # N. B. pause is now hard coded in the .BAT file2467 #2468 2493 # loop over multiple commands 2469 2494 foreach cmd $command { … … 2493 2518 checklockfile expgui.lck .lock 2494 2519 } 2520 2521 # pause is hard coded in the GSASTCL.BAT file 2522 if {$expgui(execprompt)} { 2523 set script gsastcl.bat 2524 } else { 2525 set script gsasnowt.bat 2526 } 2527 2495 2528 # replace the forward slashes with backward 2496 2529 regsub -all / $cmd \\ cmd 2497 2530 if {[info command winutils::shell] != ""} { 2498 winutils::shell [file join $expgui(scriptdir) gsastcl.bat] $cmd2531 winutils::shell [file join $expgui(scriptdir) $script] $cmd 2499 2532 } else { 2500 2533 winexec -d [file nativename [pwd]] \ 2501 [file join $expgui(scriptdir) gsastcl.bat] $cmd 2534 [file join $expgui(scriptdir) $script] $cmd 2535 } 2536 if {$expgui(MacroRunning)} { 2537 update 2538 update idletasks 2502 2539 } 2503 2540 if {$wait} { … … 2532 2569 } 2533 2570 # pause is hard coded in the .BAT file 2571 if {$expgui(execprompt)} { 2572 set script gsastcl.bat 2573 } else { 2574 set script gsasnowt.bat 2575 } 2534 2576 2535 2577 if {$wait} { … … 2542 2584 regsub -all / $cmd \\ cmd 2543 2585 exec $env(COMSPEC) /c \ 2544 "start [file join $expgui(scriptdir) gsastcl.bat] $cmd"2586 "start [file join $expgui(scriptdir) $script] $cmd" 2545 2587 } 2546 2588 file delete -force expgui.lck … … 2555 2597 # run in background 2556 2598 exec $env(COMSPEC) /c \ 2557 "start [file join $expgui(scriptdir) gsastcl.bat] $cmd" & 2599 "start [file join $expgui(scriptdir) $script] $cmd" & 2600 if {$expgui(MacroRunning)} { 2601 update 2602 update idletasks 2603 } 2558 2604 } 2559 2605 } … … 2588 2634 set suffix {&} 2589 2635 } 2590 # 2591 #if $wait { 2636 2637 # hold window open after commands finish 2638 if {$expgui(execprompt)} { 2592 2639 append command "\; echo -n Press Enter to continue \; read x" 2593 #}2640 } 2594 2641 if {$wait && $expgui(autoiconify)} {wm iconify .} 2595 2642 catch {eval exec xterm $termopts -title [list $title] \ 2596 2643 -e /bin/sh -c [list $command] $suffix} errmsg 2597 2644 if $expgui(debug) {puts "xterm result = $errmsg"} 2645 if {$expgui(MacroRunning)} { 2646 update 2647 update idletasks 2648 } 2598 2649 if {$wait} { 2599 2650 if {$expgui(autoiconify)} {wm deiconify .} … … 2602 2653 } 2603 2654 } 2655 } 2656 2657 # run commands without a terminal window 2658 proc runnoterm {command outfile} { 2659 global env expgui tcl_platform 2660 if {$tcl_platform(platform) == "windows"} { 2661 # Windows environment variables 2662 set env(GSAS) [file nativename $expgui(gsasdir)] 2663 # PGPLOT_FONT is needed by PGPLOT 2664 set env(PGPLOT_FONT) [file nativename [file join $expgui(gsasdir) pgl grfont.dat]] 2665 # this is the number of lines/page in the .LST (etc.) file 2666 set env(LENPAGE) 60 2667 set pwd [file nativename [pwd]] 2668 # loop over multiple commands 2669 foreach cmd $command { 2670 # replace the forward slashes with backward 2671 regsub -all / $cmd \\ cmd 2672 exec $cmd >>& $outfile 2673 update 2674 update idletasks 2675 } 2676 } else { 2677 # UNIX environment variables 2678 set env(GSAS) [file nativename $expgui(gsasdir)] 2679 set env(gsas) [file nativename $expgui(gsasdir)] 2680 set env(GSASEXE) $expgui(gsasexe) 2681 set env(ATOMDATA) [file join $expgui(gsasdir) data atmdata.dat] 2682 set env(ATMXSECT) [file join $expgui(gsasdir) data atmxsect.dat] 2683 # PGPLOT_DIR is needed by PGPLOT 2684 set env(PGPLOT_DIR) [file join $expgui(gsasdir) pgl] 2685 # this is the number of lines/page in the .LST (etc.) file 2686 set env(LENPAGE) 60 2687 foreach cmd $command { 2688 catch {eval exec $cmd >>& $outfile} errmsg 2689 } 2690 update 2691 update idletasks 2692 } 2693 # check for changes in the .EXP file immediately 2694 #whenidle 2604 2695 } 2605 2696 … … 2652 2743 } 2653 2744 } 2745 2746 #------------------------------------------------------------------------------- 2747 # Macro Recording 2748 #------------------------------------------------------------------------------- 2749 set expgui(MacroBufferedCommand) "" 2750 set expgui(fpMacroFile) "" 2751 set expgui(MacroFile) "" 2752 # Turn on/off mode to save commands in MacroFile 2753 proc SetRecordMacroOnOff {args} { 2754 global expgui 2755 if {$expgui(RecordMacro)} { 2756 set expgui(fpMacroFile) "" 2757 set expgui(MacroBufferedCommand) "" 2758 while {$expgui(fpMacroFile) == ""} { 2759 set expgui(MacroFile) [tk_getSaveFile -initialdir [pwd] \ 2760 -parent . \ 2761 -filetypes {{"EXPGUI Macro file" .expmac}} \ 2762 -defaultextension .expmac \ 2763 -initialfile EXPGUI.expmac \ 2764 -title "Choose location to save macro"] 2765 if {$expgui(MacroFile) == ""} { 2766 # respond to cancel 2767 set expgui(fpMacroFile) "" 2768 set expgui(MacroFile) "" 2769 set expgui(RecordMacro) 0 2770 return 2771 } 2772 if {[catch { 2773 set expgui(fpMacroFile) [open $expgui(MacroFile) w] 2774 puts $expgui(fpMacroFile) "# [clock format [clock seconds] -format %Y-%m-%dT%T]" 2775 } errmsg]} { 2776 MyMessageBox -parent . -title "Error opening selected file" \ 2777 -message "Error opening macro file:\n$errmsg" \ 2778 -icon warning -type TryAgain -default tryagain 2779 catch {close $expgui(fpMacroFile)} 2780 set expgui(fpMacroFile) "" 2781 set expgui(MacroFile) "" 2782 set expgui(RecordMacro) 0 2783 } 2784 } 2785 } else { 2786 if {[string trim $expgui(MacroBufferedCommand)] != ""} { 2787 puts $expgui(fpMacroFile) $expgui(MacroBufferedCommand) 2788 } 2789 catch {close $expgui(fpMacroFile)} 2790 set expgui(fpMacroFile) "" 2791 set expgui(MacroFile) "" 2792 set expgui(MacroBufferedCommand) "" 2793 } 2794 } 2795 2796 # record a command in the Macro File 2797 proc RecordMacroEntry {command buffer} { 2798 global expgui 2799 if {! $expgui(RecordMacro)} return 2800 # in buffered mode: hold the last command in memory and compare to the 2801 # next. If two commands differ only in the final argument, then the 2802 # second command makes the previous redundant so only the latter version 2803 # is retained (This will happen when a user types a string into a box). 2804 # When the commands differ, then the previous is written to file 2805 # and the next is retained in memory. 2806 if {$buffer} { 2807 if {[string trim $expgui(MacroBufferedCommand)] == ""} { 2808 set expgui(MacroBufferedCommand) $command 2809 return 2810 } 2811 set diff 0 2812 # is command a repeat of previous? 2813 foreach a $command b $expgui(MacroBufferedCommand) { 2814 if {$diff} { 2815 # found a difference, other than in the last arg 2816 puts $expgui(fpMacroFile) $expgui(MacroBufferedCommand) 2817 break 2818 } 2819 if {$a != $b} {set diff 1} 2820 } 2821 set expgui(MacroBufferedCommand) $command 2822 } else { 2823 # no buffering on current command; write the old and new to file. 2824 if {[string trim $expgui(MacroBufferedCommand)] != ""} { 2825 puts $expgui(fpMacroFile) $expgui(MacroBufferedCommand) 2826 } 2827 puts $expgui(fpMacroFile) $command 2828 set expgui(MacroBufferedCommand) "" 2829 } 2830 } 2831 2832 proc CantRecordMacroEntry {comment} { 2833 global expgui 2834 if {! $expgui(RecordMacro)} return 2835 2836 # no buffering on current command; write the old and new to file. 2837 if {[string trim $expgui(MacroBufferedCommand)] != ""} { 2838 puts $expgui(fpMacroFile) $expgui(MacroBufferedCommand) 2839 } 2840 puts $expgui(fpMacroFile) "# unrecorded: $comment" 2841 set expgui(MacroBufferedCommand) "" 2842 MyMessageBox -parent . -title "No command record" \ 2843 -message "EXPGUI is not able to record this action in the macro file: $comment" \ 2844 -icon warning 2845 } 2846 2847 2848 # Play back commands in Macro File 2849 proc ReplayMacroFile {"lineatatime 0"} { 2850 global expgui 2851 set expnam [file root [file tail $expgui(expfile)]] 2852 file delete abort_${expnam}_macro.flag 2853 set expgui(MacroRunning) 0 2854 set MacroFile [tk_getOpenFile -initialdir [pwd] \ 2855 -parent . \ 2856 -filetypes {{"EXPGUI Macro file" .expmac} {Everything .*}} \ 2857 -defaultextension .expmac \ 2858 -title "Choose location to read macro"] 2859 if {$MacroFile == ""} return 2860 set expgui(MacroRunning) 1 2861 if {$lineatatime} { 2862 set expgui(MacroChanged) 0 2863 set top1 .macro 2864 catch {destroy $top1} 2865 toplevel $top1 2866 set txt $top1.t 2867 grid [text $txt -width 30 -height 20 -yscrollcommand "$top1.s set"] \ 2868 -column 0 -row 0 -sticky news 2869 wm title $top1 "File $MacroFile" 2870 grid [scrollbar $top1.s -command "$txt yview"] \ 2871 -column 1 -row 0 -sticky ns 2872 grid [frame $top1.b] -column 0 -columnspan 2 -row 1 -sticky ew 2873 grid columnconfig $top1 0 -weight 1 2874 grid rowconfig $top1 0 -weight 1 2875 grid [button $top1.b.e -text "Execute line" \ 2876 -command "MacroExecuteCurrentLine $txt"] \ 2877 -column 0 -row 0 -sticky w 2878 grid columnconfig $top1.b 1 -weight 1 2879 grid [button $top1.b.s -text "Save As" -state disabled \ 2880 -command "MacroResave $txt"] -column 1 -row 0 2881 set expgui(MacroSaveButton) $top1.b.s 2882 grid [button $top1.b.c -text "Close " \ 2883 -command "MacroCloseWindow $txt"] -column 2 -row 0 2884 $txt delete 0.0 end 2885 set fp [open $MacroFile r] 2886 $txt insert 0.0 [read $fp] 2887 close $fp 2888 MacroHighlightText $txt 1 2889 # deal with editing in the box 2890 $txt configure -undo 1 2891 $txt edit modified 0 2892 bind $txt <<Modified>> { 2893 $expgui(MacroSaveButton) configure -state normal 2894 set expgui(MacroChanged) 1 2895 } 2896 } else { 2897 close [open running_${expnam}_macro.flag w] 2898 set saveprompt $expgui(execprompt) 2899 set saveautold $expgui(autoexpload) 2900 set expgui(execprompt) 0 2901 set expgui(autoexpload) 1 2902 set expnam [file root [file tail $expgui(expfile)]] 2903 if {$expgui(MacroRunning) && !$expgui(ShowGENLES)} { 2904 set outfile ${expnam}_macout.LST 2905 # create an empty file 2906 catch {file delete $outfile} 2907 close [open $outfile w] 2908 # view it with LSTVIEW 2909 set outfile ${expnam}_macout 2910 exec $::wishshell [file join $expgui(scriptdir) lstview] $outfile & 2911 } else { 2912 # show status, offer abort with MACROMON 2913 exec $::wishshell [file join $expgui(scriptdir) macromon] $expnam & 2914 } 2915 2916 set expgui(MacroStatus) "starting script" 2917 pleasewait "\nrunning macro\n\nStatus:" expgui(MacroStatus) 2918 2919 if {[catch { 2920 source $MacroFile 2921 } errmsg]} { 2922 set txt $::errorInfo 2923 catch { 2924 set fp [open error.txt a] 2925 puts $fp "# [clock format [clock seconds] -format %Y-%m-%dT%T]" 2926 puts $fp $txt 2927 close $fp 2928 } 2929 donewait 2930 MyMessageBox -parent . -title "Error running Macro file" \ 2931 -message "Error running macro file:\n$errmsg\n(details in file error.txt)" \ 2932 -icon error -type OK -default ok 2933 } else { 2934 donewait 2935 } 2936 file delete running_${expnam}_macro.flag 2937 set expgui(execprompt) $saveprompt 2938 set expgui(autoexpload) $saveautold 2939 set expgui(MacroRunning) 0 2940 # show changes 2941 PaintEXPGUIpages 2942 # put comment in output file 2943 if {$expgui(MacroRunning) && !$expgui(ShowGENLES)} { 2944 set outfile ${expnam}_macout.LST 2945 set fp [open $outfile a] 2946 puts $fp "\n**** Macro ended ****" 2947 close $fp 2948 } 2949 } 2950 } 2951 2952 # highlight a line in the Macro file display 2953 proc MacroHighlightText {txt line} { 2954 $txt tag delete next 2955 $txt tag add next $line.0 $line.end 2956 $txt see $line.0 2957 $txt tag configure next -background yellow 2958 # tag all text 2959 $txt tag delete all 2960 $txt tag add all 0.0 end 2961 # double-click moves the current line 2962 $txt tag bind all <Double-1> "after idle [list MacroDoubleClick $txt]" 2963 } 2964 2965 # respond to a double click by moving the next line to be executed to 2966 # the line where the double click occurred 2967 proc MacroDoubleClick {txt} { 2968 set line [lindex [split [$txt tag ranges sel] "."] 0] 2969 MacroHighlightText $txt $line 2970 } 2971 2972 # respond to Execute button: execute the current line 2973 # close window after last command 2974 proc MacroExecuteCurrentLine {txt} { 2975 global expgui 2976 set linenum [lindex [split [$txt tag ranges next] "."] 0] 2977 if {$linenum == ""} {return} 2978 set line [$txt get $linenum.0 $linenum.end] 2979 # is this continued (ends with \)? 2980 while {[string range $line end end] == "\\" } { 2981 incr linenum 2982 # get rid of trailing backslash 2983 set line [string range $line 0 end-1] 2984 #append next line 2985 append line [$txt get $linenum.0 $linenum.end] 2986 } 2987 if {[catch $line errmsg]} { 2988 MyMessageBox -parent $txt -title "Error on line" \ 2989 -message "Error on line $linenum:\n$errmsg" \ 2990 -icon warning -type Continue -default continue 2991 } 2992 # show changes 2993 PaintEXPGUIpages 2994 # move forward in macrofile 2995 incr linenum 2996 MacroHighlightText $txt $linenum 2997 set linenum [lindex [split [$txt tag ranges next] "."] 0] 2998 # at end? 2999 if {$linenum == ""} {MacroCloseWindow $txt} 3000 } 3001 3002 # Save a modified macro file 3003 proc MacroResave {txt} { 3004 global expgui 3005 set MacroFile [tk_getSaveFile -initialdir [pwd] \ 3006 -parent $txt \ 3007 -filetypes {{"EXPGUI Macro file" .expmac}} \ 3008 -defaultextension .expmac \ 3009 -initialfile $expgui(MacroFile) \ 3010 -title "Choose location to save macro"] 3011 if {[string trim $MacroFile] == ""} {return} 3012 if {[catch { 3013 set fp [open $MacroFile w] 3014 puts $fp [string trim [$txt get 0.0 end]] 3015 close $fp 3016 } errmsg]} { 3017 MyMessageBox -parent $txt -title "Error writing to file" \ 3018 -message "Error writing macro file:\n$errmsg" \ 3019 -icon warning -type TryAgain -default tryagain 3020 return 3021 } 3022 set expgui(MacroChanged) 0 3023 # gray out the button 3024 $expgui(MacroSaveButton) configure -state disabled 3025 } 3026 3027 # close the window, but provide a chance to save the file first, if modified 3028 proc MacroCloseWindow {txt} { 3029 global expgui 3030 if {$expgui(MacroChanged)} { 3031 set ans [MyMessageBox -parent $txt -title "Save macro file?" \ 3032 -message "Macro file has been changed, do you want to save it?" \ 3033 -icon warning -type "Yes No" -default no] 3034 if {$ans != "no"} {MacroResave $txt} 3035 } 3036 set expgui(MacroRunning) 0 3037 destroy [winfo toplevel $txt] 3038 } 3039 3040 # Add a comment to a macro file 3041 proc AddCommentMacroFile {} { 3042 global expgui 3043 if {! $expgui(RecordMacro)} return 3044 RecordMacroEntry "# [getstring "comment for macro file"]" 0 3045 }
Note: See TracChangeset
for help on using the changeset viewer.