Changeset 1598 for trunk/gui/scripts/xyprint.tcl
- Timestamp:
- Oct 28, 2009, 3:24:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/xyprint.tcl
r1597 r1598 39 39 private variable _clone ""; # Cloned graph. 40 40 private variable _preview ""; # Preview image. 41 42 public method print { graph } 41 private variable _savedSettings; # Array of settings. 42 43 public method print { graph toolName plotName } 43 44 44 45 private method CopyOptions { cmd orig clone } … … 66 67 private method ApplyLayoutSettings {} 67 68 private method InitializeSettings {} 68 private method RestoreSettings { file } 69 private method CreateSettings { toolName plotName } 70 private method RestoreSettings { toolName plotName } 71 private method SaveSettings { toolName plotName } 69 72 private method ResetSettings { } 70 private method SaveSettings { file }71 73 private method GetOutput {} 72 74 private method Done { state } 73 75 private method DestroySettings {} 76 private method restore { toolName plotName data } 74 77 private common _settings 75 78 private common _wait … … 155 158 } 156 159 157 itcl::body Rappture::XyPrint::print { graph } {160 itcl::body Rappture::XyPrint::print { graph toolName plotName } { 158 161 set _graph $graph 159 162 set _clone [CloneGraph $graph] 160 163 InitClone 161 164 InitializeSettings 162 # RestoreSettings 165 # RestoreSettings $toolName $plotName 163 166 set _wait($this) 0 164 167 tkwait variable [itcl::scope _wait($this)] … … 167 170 set output [GetOutput] 168 171 } 169 SaveSettings dummy170 DestroySettings 172 # SaveSettings $toolName $plotName 173 DestroySettings 171 174 return $output 172 175 } … … 206 209 207 210 set psdata [$_clone postscript output] 208 set f [open "junk.raw" "w"] 209 puts -nonewline $f $psdata 210 close $f 211 212 if { $format == "eps" } { 213 set cmd [list | /usr/bin/gs -q -sDEVICE=epswrite -sstdout=%stderr -sOutputFile=- -dNOPAUSE -dBATCH -dSAFER -dDEVICEWIDTH=250000 -dDEVICEHEIGHT=250000 - << $psdata] 214 #set cmd [list | /usr/bin/eps2eps - - << $psdata] 215 } elseif { $format == "pdf" } { 216 set cmd [list | /usr/bin/gs -q -sDEVICE=epswrite -sstdout=%stderr -sOutputFile=- -dNOPAUSE -dBATCH -dSAFER -dDEVICEWIDTH=250000 -dDEVICEHEIGHT=250000 - << $psdata | /usr/bin/gs -dSAFER -dCompatibilityLevel=1.4 -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sstdout=%stderr -sOutputFile=- -dSAFER -dCompatibilityLevel=1.4 -c .setpdfwrite -f -] 217 #set cmd [list | /usr/bin/eps2eps - - << $psdata | /usr/bin/ps2pdf - -] 211 212 if 1 { 213 set f [open "junk.raw" "w"] 214 puts -nonewline $f $psdata 215 close $f 216 } 217 218 set cmd "" 219 # | eps2eps << $psdata 220 lappend cmd "|" "/usr/bin/gs" \ 221 "-q" "-sDEVICE=epswrite" "-sstdout=%stderr" \ 222 "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \ 223 "-dDEVICEWIDTH=250000" "-dDEVICEHEIGHT=250000" "-" "<<" "$psdata" 224 if { $format == "pdf" } { 225 # | eps2eps << $psdata | ps2pdf 226 lappend cmd "|" "/usr/bin/gs" \ 227 "-q" "-sDEVICE=pdfwrite" "-sstdout=%stderr" \ 228 "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \ 229 "-dCompatibilityLevel=1.4" "-c" ".setpdfwrite" "-f" "-" 218 230 } 219 231 if { [catch { … … 320 332 -plotbackground white -plotpadx 0 -plotpady 0 321 333 # 334 set _fonts(legend) [font create -family times -size 10 -weight normal] 335 update 322 336 $_clone legend configure \ 323 337 -position right \ 324 -font "*-helvetica-medium-r-normal-*-10-*"\338 -font $_fonts(legend) \ 325 339 -hide yes -borderwidth 0 -background white -relief solid \ 326 340 -anchor nw -activeborderwidth 0 … … 330 344 continue 331 345 } 346 set _fonts($axis-ticks) [font create -family courier -size 10 \ 347 -weight normal -slant roman] 348 set _fonts($axis-title) [font create -family symbol -size 10 \ 349 -weight normal -slant roman] 350 puts stderr "tick fonts $_fonts($axis-ticks): [font configure $_fonts($axis-ticks)]" 351 puts stderr "title fonts $_fonts($axis-title): [font configure $_fonts($axis-title)]" 352 update 332 353 $_clone axis configure $axis -ticklength 5 \ 333 354 -majorticks {} -minorticks {} 334 355 $_clone axis configure $axis \ 335 -tickfont "*-helvetica-medium-r-normal-*-10-*"\336 -titlefont "*-helvetica-medium-r-normal-*-10-*"356 -tickfont $_fonts($axis-ticks) \ 357 -titlefont $_fonts($axis-title) 337 358 } 338 359 #$_clone grid off … … 761 782 -command [itcl::code $this ApplyAxisSettings] 762 783 784 label $page.tickfont_l -text "tick font" 785 Rappture::Combobox $page.tickfontfamily -width 10 -editable no 786 $page.tickfontfamily choices insert end \ 787 "courier" "Courier" \ 788 "helvetica" "Helvetica" \ 789 "new*century*schoolbook" "New Century Schoolbook" \ 790 "symbol" "Symbol" \ 791 "times" "Times" 792 bind $page.tickfontfamily <KeyPress-Return> \ 793 [itcl::code $this ApplyAxisSettings] 794 795 Rappture::Combobox $page.tickfontsize -width 4 -editable no 796 $page.tickfontsize choices insert end \ 797 "8" "8" \ 798 "10" "10" \ 799 "11" "11" \ 800 "12" "12" \ 801 "14" "14" \ 802 "17" "17" \ 803 "18" "18" \ 804 "20" "20" 805 bind $page.tickfontsize <KeyPress-Return> \ 806 [itcl::code $this ApplyAxisSettings] 807 808 Rappture::PushButton $page.tickfontbold \ 809 -onimage [Rappture::icon format-text-bold] \ 810 -offimage [Rappture::icon format-text-bold] \ 811 -command [itcl::code $this ApplyAxisSettings] \ 812 -variable [itcl::scope _settings($this-axis-tickfont-bold)] 813 814 Rappture::PushButton $page.tickfontitalic \ 815 -onimage [Rappture::icon format-text-italic] \ 816 -offimage [Rappture::icon format-text-italic] \ 817 -command [itcl::code $this ApplyAxisSettings] \ 818 -variable [itcl::scope _settings($this-axis-tickfont-italic)] 819 763 820 blt::table $page \ 764 821 1,0 $page.axis_l -anchor e -pady 4 \ … … 780 837 7,1 $page.loose -cspan 2 -anchor w \ 781 838 7,3 $page.grid -anchor w -cspan 2 \ 782 8,1 $page.zero -cspan 2 -anchor w 783 839 8,1 $page.zero -cspan 2 -anchor w \ 840 9,1 $page.tickfont_l -anchor e \ 841 9,2 $page.tickfontfamily -fill x \ 842 9,3 $page.tickfontsize -fill x \ 843 9,4 $page.tickfontbold -anchor e \ 844 9,5 $page.tickfontitalic -anchor e 784 845 } 785 846 … … 915 976 916 977 917 itcl::body Rappture::XyPrint::RestoreSettings { file } { 918 # Get the settings associated with the tool and plot title 919 n} 978 itcl::body Rappture::XyPrint::restore { toolName plotName data } { 979 set key [list $toolName $plotName] 980 set _savedSettings($key) $data 981 } 982 983 itcl::body Rappture::XyPrint::RestoreSettings { toolName plotName } { 984 if { ![file readable "~/.rappture"] } { 985 return; # No file or not readable 986 } 987 # Read the file by sourcing it into a safe interpreter The only commands 988 # executed will be "xyprint" which will simply add the data into an array 989 # _savedSettings. 990 set parser [interp create -safe] 991 $parser alias xyprint [itcl::code $this restore] 992 set f [open $file "r"] 993 set code [read $f] 994 close $f 995 $parser eval $code 996 997 # Now see if there's an entry for this tool/plot combination. The data 998 # associated with the variable is itself code to update the graph (clone). 999 set key [list $toolName $plotName] 1000 if { [info exists _savedSettings($key)] } { 1001 $parser alias "xygraph" $_clone 1002 $parser eval $_savedSettings($key) 1003 } 1004 foreach {name value} [$parser eval "array get general"] { 1005 set _settings($this-graph-$name) $value 1006 } 1007 interp delete $parser 1008 } 920 1009 921 1010 itcl::body Rappture::XyPrint::ResetSettings {} { … … 927 1016 } 928 1017 929 itcl::body Rappture::XyPrint::SaveSettings { file } { 1018 itcl::body Rappture::XyPrint::SaveSettings { toolName plotName } { 1019 if { ![file writable "~/.rappture"] } { 1020 return 1021 } 1022 set out [CreateSettings $toolName $plotName] 1023 # Write the settings out 1024 set f [open ".rappture" "w" 0600] 1025 foreach key [lsort [array names _savedSettings]] { 1026 set tool [lindex $key 0] 1027 set plot [lindex $key 1] 1028 if { $plotName == "plot" && $toolName == "$tool" } { 1029 continue 1030 } 1031 puts $f "xyprint \"$tool\" \"$plot\" \{" 1032 puts $f "$_savedSettings($key)" 1033 puts $f "\}\n" 1034 } 1035 # Now write the new setting 1036 puts $f "xyprint \"$toolName\" \"$plotName\" \{" 1037 puts $f "$out" 1038 puts $f "\}\n" 1039 close $f 1040 } 1041 1042 itcl::body Rappture::XyPrint::CreateSettings { toolName plotName } { 930 1043 # Create stanza associated with tool and plot title. 931 1044 # General settings 932 1045 append out "\n" 933 append out " set settings(\$tool:\$label)\{\n"1046 append out "xyprint \"\$toolName\" \"\$plotName\" \{\n" 934 1047 append out " set general(format) $_settings($this-general-format)\n" 935 1048 append out " set general(style) $_settings($this-general-style)\n" … … 937 1050 938 1051 # Layout settings 939 append out " \$graph configure \\\n"1052 append out " xygraph configure \\\n" 940 1053 append out " -width \"[Pixels2Inches [$_clone cget -width]]\" \\\n" 941 1054 append out " -height \"[Pixels2Inches [$_clone cget -height]]\" \\\n" … … 948 1061 949 1062 # Legend settings 950 append out " \$graph legend configure \\\n"1063 append out " xygraph legend configure \\\n" 951 1064 append out " -position \"[$_clone legend cget -position]\" \\\n" 952 1065 append out " -anchor \"[$_clone legend cget -anchor]\" \\\n" … … 956 1069 # Element settings 957 1070 foreach elem [$_clone element show] { 958 append out " if \{ \[ \$graph element exists \"$elem\"\] \} \{\n"959 append out " \$graph element configure \"$elem\" \\\n"1071 append out " if \{ \[xygraph element exists \"$elem\"\] \} \{\n" 1072 append out " xygraph element configure \"$elem\" \\\n" 960 1073 append out " -symbol \"[$_clone element cget $elem -symbol]\" \\\n" 961 1074 append out " -color \"[$_clone element cget $elem -color]\" \\\n" … … 971 1084 continue 972 1085 } 973 append out " if \{ \[ \$graph axis names \"$axis\"\] == \"$axis\" \} \{\n"974 append out " \$graph axis configure \"$axis\" \\\n"1086 append out " if \{ \[xygraph axis names \"$axis\"\] == \"$axis\" \} \{\n" 1087 append out " xygraph axis configure \"$axis\" \\\n" 975 1088 append out " -hide \"[$_clone axis cget $axis -hide]\" \\\n" 976 1089 append out " -min \"[$_clone axis cget $axis -min]\" \\\n" … … 981 1094 append out " -subdivisions \"[$_clone axis cget $axis -subdivisions]\"\n" 982 1095 set hide [$_clone marker cget ${axis}-zero -hide] 983 append out " \$graph marker configure \"${axis}-zero\" -hide $hide\n"1096 append out " xygraph marker configure \"${axis}-zero\" -hide $hide\n" 984 1097 append out " \}\n" 985 1098 } 986 set cmd {} 987 append out " \$graph grid configure \\\n" 1099 append out " xygraph grid configure \\\n" 988 1100 append out " -hide \"[$_clone grid cget -hide]\" \\\n" 989 1101 append out " -mapx \"[$_clone grid cget -mapx]\" \\\n" 990 1102 append out " -mapy \"[$_clone grid cget -mapy]\"\n" 991 1103 append out "\}\n" 992 # Write the settingsout993 puts stderr "savesettings=$out" 994 } 1104 return $out 1105 } 1106
Note: See TracChangeset
for help on using the changeset viewer.