Ignore:
Timestamp:
Oct 28, 2009, 3:24:15 PM (15 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/xyprint.tcl

    r1597 r1598  
    3939    private variable _clone "";         # Cloned graph.
    4040    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 }
    4344
    4445    private method CopyOptions { cmd orig clone }
     
    6667    private method ApplyLayoutSettings {}
    6768    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 }
    6972    private method ResetSettings { }
    70     private method SaveSettings { file }
    7173    private method GetOutput {}
    7274    private method Done { state }
    7375    private method DestroySettings {}
     76    private method restore { toolName plotName data }
    7477    private common _settings
    7578    private common _wait
     
    155158}
    156159
    157 itcl::body Rappture::XyPrint::print { graph } {
     160itcl::body Rappture::XyPrint::print { graph toolName plotName } {
    158161    set _graph $graph
    159162    set _clone [CloneGraph $graph]
    160163    InitClone
    161164    InitializeSettings
    162     # RestoreSettings
     165    # RestoreSettings $toolName $plotName
    163166    set _wait($this) 0
    164167    tkwait variable [itcl::scope _wait($this)]
     
    167170        set output [GetOutput]
    168171    }
    169     SaveSettings dummy
    170     DestroySettings
     172    # SaveSettings $toolName $plotName
     173    DestroySettings 
    171174    return $output
    172175}
     
    206209   
    207210    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" "-"
    218230    }
    219231    if { [catch {
     
    320332        -plotbackground white -plotpadx 0 -plotpady 0
    321333    #
     334    set _fonts(legend) [font create -family times -size 10 -weight normal]
     335    update
    322336    $_clone legend configure \
    323337        -position right \
    324         -font "*-helvetica-medium-r-normal-*-10-*" \
     338        -font $_fonts(legend) \
    325339        -hide yes -borderwidth 0 -background white -relief solid \
    326340        -anchor nw -activeborderwidth 0
     
    330344            continue
    331345        }
     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
    332353        $_clone axis configure $axis -ticklength 5  \
    333354            -majorticks {} -minorticks {}
    334355        $_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)
    337358    }
    338359    #$_clone grid off
     
    761782        -command [itcl::code $this ApplyAxisSettings]
    762783
     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
    763820    blt::table $page \
    764821        1,0 $page.axis_l -anchor e  -pady 4 \
     
    780837        7,1 $page.loose -cspan 2 -anchor w \
    781838        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
    784845}
    785846
     
    915976
    916977
    917 itcl::body Rappture::XyPrint::RestoreSettings { file } {
    918     # Get the settings associated with the tool and plot title
    919 n}
     978itcl::body Rappture::XyPrint::restore { toolName plotName data } {
     979    set key [list $toolName $plotName]
     980    set _savedSettings($key) $data
     981}
     982
     983itcl::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}
    9201009
    9211010itcl::body Rappture::XyPrint::ResetSettings {} {
     
    9271016}
    9281017
    929 itcl::body Rappture::XyPrint::SaveSettings { file } {
     1018itcl::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
     1042itcl::body Rappture::XyPrint::CreateSettings { toolName plotName } {
    9301043    # Create stanza associated with tool and plot title.
    9311044    # General settings
    9321045    append out "\n"
    933     append out "set settings(\$tool:\$label) \{\n"
     1046    append out "xyprint \"\$toolName\" \"\$plotName\" \{\n"
    9341047    append out "  set general(format) $_settings($this-general-format)\n"
    9351048    append out "  set general(style) $_settings($this-general-style)\n"
     
    9371050
    9381051    # Layout settings
    939     append out "  \$graph configure \\\n"
     1052    append out "  xygraph configure \\\n"
    9401053    append out "    -width \"[Pixels2Inches [$_clone cget -width]]\" \\\n"
    9411054    append out "    -height \"[Pixels2Inches [$_clone cget -height]]\" \\\n"
     
    9481061
    9491062    # Legend settings
    950     append out "  \$graph legend configure \\\n"
     1063    append out "  xygraph legend configure \\\n"
    9511064    append out "    -position \"[$_clone legend cget -position]\" \\\n"
    9521065    append out "    -anchor \"[$_clone legend cget -anchor]\" \\\n"
     
    9561069    # Element settings
    9571070    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"
    9601073        append out "      -symbol \"[$_clone element cget $elem -symbol]\" \\\n"
    9611074        append out "      -color \"[$_clone element cget $elem -color]\" \\\n"
     
    9711084            continue
    9721085        }
    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"
    9751088        append out "      -hide \"[$_clone axis cget $axis -hide]\" \\\n"
    9761089        append out "      -min \"[$_clone axis cget $axis -min]\" \\\n"
     
    9811094        append out "      -subdivisions \"[$_clone axis cget $axis -subdivisions]\"\n"
    9821095        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"
    9841097        append out "  \}\n"
    9851098    }   
    986     set cmd {}
    987     append out "  \$graph grid configure \\\n"
     1099    append out "  xygraph grid configure \\\n"
    9881100    append out "    -hide \"[$_clone grid cget -hide]\" \\\n"
    9891101    append out "    -mapx \"[$_clone grid cget -mapx]\" \\\n"
    9901102    append out "    -mapy \"[$_clone grid cget -mapy]\"\n"
    9911103    append out "\}\n"
    992     # Write the settings out
    993     puts stderr "savesettings=$out"
    994 }
     1104    return $out
     1105}
     1106
Note: See TracChangeset for help on using the changeset viewer.