source: branches/blt4_trunk/gui/scripts/xyprint.tcl @ 6682

Last change on this file since 6682 was 6682, checked in by dkearney, 7 years ago

updating xyprint widget to the version from mygeohub's geoexplorer_dev version of rappture to resolve compatibility issues with the development version of blt that this branch is built with.

File size: 58.2 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: xyprint - Print X-Y plot.
4#
5# ======================================================================
6#  AUTHOR:  Michael McLennan, Purdue University
7#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8#
9#  See the file "license.terms" for information on usage and
10#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11# ======================================================================
12package require Itk
13package require BLT
14
15#option add *XyPrint.width 3i widgetDefault
16#option add *XyPrint.height 3i widgetDefault
17option add *XyPrint.gridColor #d9d9d9 widgetDefault
18option add *XyPrint.activeColor blue widgetDefault
19option add *XyPrint.dimColor gray widgetDefault
20option add *XyPrint.controlBackground gray widgetDefault
21option add *XyPrint*Font "Arial 9" widgetDefault
22option add *XyPrint*Entry*width "6" widgetDefault
23option add *XyPrint*Entry*background "white" widgetDefault
24
25itk::usual BltComboMenu {
26    #empty
27}
28itk::usual BltComboEntry {
29    #empty
30}
31
32itcl::class Rappture::XyPrint {
33    inherit itk::Widget
34
35    constructor {args} {}
36    destructor {}
37
38    private variable _graph "";         # Original graph.
39    private variable _clone "";         # Cloned graph.
40    private variable _preview "";       # Preview image.
41    private variable _savedSettings;    # Array of settings.
42    private variable _outputFormatType "";
43    private variable _formatIcon "";
44    private variable _colorIcon "";
45    private variable _colorText "";
46
47    private common _oldSettingsFile "~/.rpsettings"
48    private common _settingsFile "~/.rp_settings"
49
50    public method print { graph toolName plotName }
51    public method reset {}
52
53    private method CopyOptions { cmd orig clone {exclude {}}}
54    private method CloneGraph { orig }
55
56    private method BuildGeneralTab {}
57    private method BuildLayoutTab {}
58    private method BuildLegendTab {}
59    private method BuildAxisTab {}
60    private method SetOption { opt }
61    private method SetComponentOption { comp opt }
62    private method SetNamedComponentOption { comp name opt }
63    private method GetAxis {}
64    private method GetElement { args }
65    private method RegeneratePreview {}
66    private method InitClone {}
67    private method Pixels2Inches { pixels }
68    private method Inches2Pixels { inches {defValue ""}}
69    private method Color2RGB { color }
70
71    private method ApplyGeneralSettings {}
72    private method ApplyLegendSettings {}
73    private method ApplyAxisSettings {}
74    private method ApplyElementSettings {}
75    private method ApplyLayoutSettings {}
76    private method InitializeSettings {}
77    private method CreateSettings { toolName plotName }
78    private method RestoreSettings { toolName plotName }
79    private method SaveSettings { toolName plotName }
80    private method DestroySettings {}
81    private method ResetSettings { }
82    private method GetOutput {}
83    private method SetWaitVariable { state }
84    private method SetLayoutOption { option }
85    private method GetAxisType { axis }
86    private method restore { toolName plotName data }
87    private method AddColorToMenu { menu name color }
88
89    # Same dialog may be used for different graphs
90    private common _settings
91    private common _wait
92}
93
94# ----------------------------------------------------------------------
95# CONSTRUCTOR
96# ----------------------------------------------------------------------
97itcl::body Rappture::XyPrint::constructor { args } {
98    Rappture::dispatcher _dispatcher
99    $_dispatcher register !rebuild
100    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
101   
102    set w [winfo pixels . 2.5i]
103    set h [winfo pixels . 2i]
104    set _preview [image create picture -width $w -height $h]
105    itk_component add tabs {
106        blt::tabset $itk_interior.tabs \
107            -highlightthickness 0 -tearoff 0 -side top \
108            -outerborderwidth 0 -gap 0 -borderwidth 1 \
109            -outerpad 1 -troughcolor grey
110    } {
111        keep -cursor
112        ignore -highlightthickness -borderwidth -background
113    }
114    set inner [frame $itk_interior.frame -bg grey]
115    itk_component add preview {
116        label $inner.preview \
117            -highlightthickness 0 -bd 0 -image $_preview -width 2.5i \
118                -height 2.5i -background grey
119    } {
120        ignore -background
121    }
122    itk_component add ok {
123        button $itk_interior.ok -text "Save" \
124            -highlightthickness 0 -pady 2 -padx 0 \
125            -command [itcl::code $this SetWaitVariable 1] \
126            -compound left \
127            -image [Rappture::icon download]
128    }
129    itk_component add cancel {
130        button $itk_interior.cancel -text "Cancel" \
131            -highlightthickness 0 -pady 2 -padx 0 \
132            -command [itcl::code $this SetWaitVariable 0] \
133            -compound left \
134            -image [Rappture::icon cancel]
135    }
136    blt::table $itk_interior \
137        0,0 $inner -fill both \
138        0,1 $itk_component(tabs) -fill both -cspan 2 \
139        1,2 $itk_component(cancel) -padx 2 -pady 2 -width .9i -fill y \
140        1,1 $itk_component(ok) -padx 2 -pady 2 -width .9i -fill y
141    blt::table $inner \
142        0,0 $itk_component(preview) -fill both -padx 10 -pady 10
143
144    #blt::table configure $itk_interior c1 c2 -resize none
145    blt::table configure $itk_interior c0 -resize both
146    BuildGeneralTab
147    BuildAxisTab
148    BuildLegendTab
149    BuildLayoutTab
150    eval itk_initialize $args
151}
152
153# ----------------------------------------------------------------------
154# DESTRUCTOR
155# ----------------------------------------------------------------------
156itcl::body Rappture::XyPrint::destructor {} {
157    destroy $_clone
158    image delete $_preview
159    array unset _settings $this-*
160}
161
162itcl::body Rappture::XyPrint::DestroySettings {} {
163    destroy $_clone
164    set _clone ""
165    set _graph ""
166}
167
168itcl::body Rappture::XyPrint::reset {} {
169    SetWaitVariable 0
170}
171
172itcl::body Rappture::XyPrint::SetWaitVariable { state } {
173    set _wait($this) $state
174}
175
176itcl::body Rappture::XyPrint::print { graph toolName plotName } {
177    set _graph $graph
178    CloneGraph $graph
179    InitClone
180    RestoreSettings $toolName $plotName
181    InitializeSettings
182    SetWaitVariable 0
183    tkwait variable [itcl::scope _wait($this)]
184    SaveSettings $toolName $plotName
185    set output ""
186    if { $_wait($this) } {
187        set output [GetOutput]
188    }
189    DestroySettings
190    return $output
191}
192
193itcl::body Rappture::XyPrint::GetOutput {} {
194    # Get the selected format of the download.
195    set page $itk_component(graph_page)
196    set m $page.format.menu
197    set format [$m item cget $_settings($this-general-format) -value]
198    if { $format == "jpg" } {
199        set img [image create picture]
200        $_clone snap $img
201        $img export jpg -quality 100 -data bytes
202        image delete $img
203        return [list .jpg $bytes]
204    } elseif { $format == "png" } {
205        set img [image create picture]
206        $_clone snap $img
207        $img export png -data bytes
208        image delete $img
209        return [list .png $bytes]
210    } elseif { $format == "gif" } {
211        set img [image create picture]
212        $_clone snap $img
213        $img export gif -data bytes
214        image delete $img
215        return [list .gif $bytes]
216    }
217
218    # Handle encapsulated postscript or portable document format.
219
220    # Append an "i" for the graph postscript component.
221    set w $_settings($this-layout-width)i
222    set h $_settings($this-layout-height)i
223
224    $_clone postscript configure \
225        -decoration yes \
226        -center yes \
227        -width $w -height $h
228   
229    set psdata [$_clone postscript output]
230
231    if 0 {
232        set f [open "junk.raw" "w"]
233        puts -nonewline $f $psdata
234        close $f
235    }
236    if { $format == "eps" } {
237        return [list .$format $psdata]
238    }
239
240    set cmd ""
241    # | eps2eps << $psdata
242    lappend cmd "|" "/usr/bin/gs" \
243        "-q" "-sDEVICE=epswrite" "-sstdout=%stderr" \
244        "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \
245        "-dDEVICEWIDTH=250000" "-dDEVICEHEIGHT=250000" "-" "<<" "$psdata"
246    if { $format == "pdf" } {
247        # | eps2eps << $psdata | ps2pdf
248        lappend cmd "|" "/usr/bin/gs" \
249            "-q" "-sDEVICE=pdfwrite" "-sstdout=%stderr" \
250            "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \
251            "-dCompatibilityLevel=1.4" "-c" ".setpdfwrite" "-f" "-"
252    }
253    if { [catch {
254        set f [open $cmd "r"]
255        fconfigure $f -translation binary -encoding binary
256        set output [read $f]
257        close $f
258    } err ] != 0 } {
259        global errorInfo
260        puts stderr "failed to generate file: $err\n$errorInfo"
261        return ""
262    }
263    if 0 {
264        set f [open "junk.$format" "w"]
265        fconfigure $f -translation binary -encoding binary
266        puts -nonewline $f $output
267        close $f
268    }
269    return [list .$format $output]
270}
271
272itcl::body Rappture::XyPrint::CopyOptions { cmd orig clone {exclude {}} } {
273    set all [eval $orig $cmd]
274    set configLine $clone
275    foreach name $exclude {
276        set ignore($name) 1
277    }
278    foreach arg $cmd {
279        lappend configLine $arg
280    }
281    foreach option $all {
282        if { [llength $option] != 5 } {
283            continue
284        }
285        set switch [lindex $option 0]
286        set initial [lindex $option 3]
287        set current [lindex $option 4]
288        if { [info exists ignore($switch)] } {
289            continue
290        }
291        if { [string compare $initial $current] == 0 } {
292            continue
293        }
294        lappend configLine $switch $current
295    }
296    eval $configLine
297}
298
299itcl::body Rappture::XyPrint::CloneGraph { orig } {
300    set top $itk_interior
301    if { [winfo exists $top.graph] } {
302        destroy $top.graph
303    }
304    set _clone [blt::graph $top.graph]
305    CopyOptions "configure" $orig $_clone
306    # Axis component
307    foreach axis [$orig axis names] {
308        if { $axis == "z" } {
309            continue
310        }
311        if { [$orig axis cget $axis -hide] } {
312            continue
313        }
314        if { [$_clone axis name $axis] == "" } {
315            $_clone axis create $axis
316        }
317        CopyOptions [list axis configure $axis] $orig $_clone
318    }
319    foreach axis { x y x2 y2 } {
320        $_clone ${axis}axis use [$orig ${axis}axis use]
321    }
322    # Pen component
323    foreach pen [$orig pen names] {
324        if { [$_clone pen name $pen] == "" } {
325            $_clone pen create $pen
326        }
327        CopyOptions [list pen configure $pen] $orig $_clone
328    }
329    # Marker component
330    foreach marker [$orig marker names] {
331        $_clone marker create [$orig marker type $marker] -name $marker
332        CopyOptions [list marker configure $marker] $orig $_clone -name
333    }
334    # Element component
335    foreach elem [$orig element names] {
336        set oper [$orig element type $elem]
337        $_clone $oper create $elem
338        CopyOptions [list $oper configure $elem] $orig $_clone -data
339        if { [$_clone $oper cget $elem -hide] } {
340            $_clone $oper configure $elem -label ""
341        }
342    }
343    # Fix element display list
344    $_clone element show [$orig element show]
345    # Legend component
346    CopyOptions {legend configure} $orig $_clone
347    # Postscript component
348    CopyOptions {postscript configure} $orig $_clone
349    # Crosshairs component
350    CopyOptions {crosshairs configure} $orig $_clone
351
352    # Create markers representing lines at zero for the x and y axis.
353    $_clone marker create line -name x-zero \
354        -coords "0 -Inf 0 Inf" -dashes 1 -hide yes
355    $_clone marker create line -name y-zero \
356        -coords "-Inf 0 Inf 0" -dashes 1 -hide yes
357}
358
359itcl::body Rappture::XyPrint::InitClone {} {
360   
361    $_clone configure -width 3.4i -height 3.4i -background white \
362        -borderwidth 0 \
363        -leftmargin 0 \
364        -rightmargin 0 \
365        -topmargin 0 \
366        -bottommargin 0
367   
368    # Kill the title and create a border around the plot
369    $_clone configure \
370        -title "" \
371        -plotborderwidth 1 -plotrelief solid  \
372        -plotbackground white -plotpadx 0 -plotpady 0
373
374    set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]]
375    set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]]
376
377    set _settings($this-legend-fontfamily) helvetica
378    set _settings($this-legend-fontsize)   10
379    set _settings($this-legend-fontweight) normal
380    set _settings($this-legend-fontslant)  roman
381    set font "helvetica 10 normal roman"
382    $_clone legend configure \
383        -position right \
384        -font $font \
385        -hide yes -borderwidth 0 -background white -relief solid \
386        -anchor nw -activeborderwidth 0
387    #
388    set _settings($this-axis-ticks-fontfamily) helvetica
389    set _settings($this-axis-ticks-fontsize)   10
390    set _settings($this-axis-ticks-fontweight) normal
391    set _settings($this-axis-ticks-fontslant)  roman
392    set _settings($this-axis-title-fontfamily) helvetica
393    set _settings($this-axis-title-fontsize)   10
394    set _settings($this-axis-title-fontweight) normal
395    set _settings($this-axis-title-fontslant)  roman
396    foreach axis [$_clone axis names] {
397        if { $axis == "z" } {
398            continue
399        }
400        if { [$_clone axis cget $axis -hide] } {
401            continue
402        }
403        set _settings($this-$axis-ticks-fontfamily) helvetica
404        set _settings($this-$axis-ticks-fontsize)   10
405        set _settings($this-$axis-ticks-fontweight) normal
406        set _settings($this-$axis-ticks-fontslant)  roman
407        set _settings($this-$axis-title-fontfamily) helvetica
408        set _settings($this-$axis-title-fontsize)   10
409        set _settings($this-$axis-title-fontweight) normal
410        set _settings($this-$axis-title-fontslant)  roman
411        set tickfont "helvetica 10 normal roman"
412        set titlefont "helvetica 10 normal roman"
413        $_clone axis configure $axis -ticklength 5  \
414            -majorticks {} -minorticks {}
415        $_clone axis configure $axis \
416            -tickfont $tickfont \
417            -titlefont $titlefont
418    }
419    set count 0
420    foreach elem [$_clone element names] {
421        if { [$_clone element type $elem] == "bar" } {
422            continue
423        }
424        incr count
425        if { [$_clone element cget $elem -linewidth] > 1 } {
426            $_clone element configure $elem -linewidth 1 -pixels 3
427        }
428    }
429    if { $count == 0 } {
430        # There are no "line" elements in the graph.
431        # Remove the symbol and dashes controls.
432        set page $itk_component(legend_page)
433        # May have already been forgotten.
434        catch {
435            blt::table forget $page.symbol_l
436            blt::table forget $page.symbol
437            blt::table forget $page.dashes_l
438            blt::table forget $page.dashes
439        }
440    }
441}
442
443itcl::body Rappture::XyPrint::SetOption { opt } {
444    set new $_settings($this$opt)
445    set old [$_clone cget $opt]
446    set code [catch [list $_clone configure $opt $new] err]
447    if { $code != 0 } {
448        bell
449        global errorInfo
450        puts stderr "$err: $errorInfo"
451        set _settings($this$opt) $old
452        $_clone configure $opt $old
453    }
454}
455
456itcl::body Rappture::XyPrint::SetComponentOption { comp opt } {
457    set new $_settings($this-$comp$opt)
458    set old [$_clone $comp cget $opt]
459    set code [catch [list $_clone $comp configure $opt $new] err]
460    if { $code != 0 } {
461        bell
462        global errorInfo
463        puts stderr "$err: $errorInfo"
464        set _settings($this-$comp$opt) $old
465        $_clone $comp configure $opt $old
466    }
467}
468
469itcl::body Rappture::XyPrint::SetNamedComponentOption { comp name opt } {
470    set new $_settings($this-$comp$opt)
471    set old [$_clone $comp cget $name $opt]
472    set code [catch [list $_clone $comp configure $name $opt $new] err]
473    if { $code != 0 } {
474        bell
475        global errorInfo
476        puts stderr "$err: $errorInfo"
477        set _settings($this-$comp$opt) $old
478        $_clone $comp configure $name $opt $old
479    }
480}
481
482itcl::body Rappture::XyPrint::RegeneratePreview {} {
483    update
484    set img [image create picture]
485    set w [Inches2Pixels $_settings($this-layout-width) 3.4]
486    set h [Inches2Pixels $_settings($this-layout-height) 3.4]
487    $_clone snap $img -width $w -height $h
488
489    set pixelsPerInch [winfo pixels . 1i]
490    set cw [winfo width $itk_component(preview)]
491    set ch [winfo height $itk_component(preview)]
492    set rw [expr 2.5*$pixelsPerInch]
493    set rh [expr 2.5*$pixelsPerInch]
494    set maxwidth $rw
495    set maxheight $rh
496    if { $maxwidth > $cw } {
497        set maxwidth $cw
498    }
499    if { $maxheight > $ch } {
500        set maxheight $ch
501    }
502    set sx [expr double($maxwidth)/$w]
503    set sy [expr double($maxheight)/$h]
504    set s [expr min($sx,$sy)]
505
506    set pw [expr int(round($s * $w))]
507    set ph [expr int(round($s * $h))]
508    $_preview configure -width $pw -height $ph
509    #.labeltest.label configure -image $img
510    $_preview resample $img -filter box
511    image delete $img
512}
513
514itcl::body Rappture::XyPrint::Pixels2Inches { pixels } {
515    if { [llength $pixels] == 2 } {
516        set pixels [lindex $pixels 0]
517    }
518    set pixelsPerInch [winfo pixels . 1i]
519    set inches [expr { double($pixels) / $pixelsPerInch }]
520    return [format %.3g ${inches}]
521}
522
523itcl::body Rappture::XyPrint::Inches2Pixels { inches {defValue ""}} {
524    set n [scan $inches %g dummy]
525    if { $n != 1  && $defValue != "" } {
526        set inches $defValue
527    }
528    return  [winfo pixels . ${inches}i]
529}
530
531itcl::body Rappture::XyPrint::Color2RGB { color } {
532    foreach { r g b } [winfo rgb $_clone $color] {
533        set r [expr round($r / 257.0)]
534        set g [expr round($g / 257.0)]
535        set b [expr round($b / 257.0)]
536    }
537    return [format "\#%02x%02x%02x" $r $g $b]
538}
539
540itcl::body Rappture::XyPrint::GetAxisType { axis } {
541    foreach type { x y x2 y2 } {
542        set axes [$_clone ${type}axis use]
543        if { [lsearch $axes $axis] >= 0 } {
544            return [string range $type 0 0]
545        }
546    }
547    return ""
548}
549
550itcl::body Rappture::XyPrint::GetAxis {} {
551    set axis [$itk_component(axis_combo) current]
552    foreach option { -min -max -loose -title -stepsize -subdivisions } {
553        set _settings($this-axis$option) [$_clone axis cget $axis $option]
554    }
555    foreach attr { fontfamily fontsize fontweight fontslant } {
556        set specific $this-$axis-ticks
557        set general $this-axis-ticks
558        set _settings(${general}-${attr}) $_settings(${specific}-${attr})
559        set specific $this-$axis-title
560        set general $this-axis-title
561        set _settings(${general}-${attr}) $_settings(${specific}-${attr})
562    }
563    set type [GetAxisType $axis]
564    set _settings($this-axis-plotpad${type}) \
565        [Pixels2Inches [$_clone cget -plotpad${type}]]
566    set _settings($this-axis-zero) [$_clone marker cget ${type}-zero -hide]
567}
568
569itcl::body Rappture::XyPrint::GetElement { args } {
570    set index 1
571    set page $itk_component(legend_page)
572    array unset _settings $this-element-*
573    foreach elem [$_clone element show] {
574        set _settings($this-element-$index) $elem
575        incr index
576    }
577    set index [$itk_component(element_slider) get]
578    set elem $_settings($this-element-$index)
579    set _settings($this-element-label) [$_clone element cget $elem -label]
580
581    set color [$_clone element cget $elem -color]
582    set found 0
583    set m $page.color.menu
584    foreach item [$m names] {
585        set c [$m item cget $item -value]
586        if { $c == $color } {
587            set color $item
588            set found 1
589            break
590        }
591    }
592    if { !$found } {
593        AddColorToMenu $m $color $color
594    }
595    $m select $color
596
597    if { [$_clone element type $elem] != "bar" } {
598        set _settings($this-element-symbol) [$_clone element cget $elem -symbol]
599        set _settings($this-element-dashes) [$_clone element cget $elem -dashes]
600    }
601    if { [$_clone element type $elem] != "bar" } {
602        $page.symbol value [$page.symbol label $_settings($this-element-symbol)]
603        $page.dashes value [$page.dashes label $_settings($this-element-dashes)]
604    }
605    #FixElement
606}
607
608itcl::body Rappture::XyPrint::BuildLayoutTab {} {
609    itk_component add layout_page {
610        frame $itk_component(tabs).layout_page
611    }
612    set page $itk_component(layout_page)
613    $itk_component(tabs) insert end "layout" \
614        -text "Layout" -padx 2 -pady 2 -window $page -fill both
615
616    label $page.width_l -text "width" 
617    entry $page.width -width 6 \
618        -textvariable [itcl::scope _settings($this-layout-width)]
619    bind  $page.width <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
620    Rappture::Tooltip::for $page.width \
621        "Set the width (inches) of the output image. Must be a positive number."
622
623    label $page.height_l -text "height"
624    entry $page.height -width 6 \
625        -textvariable [itcl::scope _settings($this-layout-height)]
626    bind  $page.height <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
627    Rappture::Tooltip::for $page.height \
628        "Set the height (inches) of the output image. Must be a positive number"
629
630    label $page.margin_l -text "Margins" 
631
632    label $page.left_l -text "left"
633    entry $page.left -width 6 \
634        -textvariable [itcl::scope _settings($this-layout-leftmargin)]
635    bind  $page.left <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
636    Rappture::Tooltip::for $page.left \
637        "Set the size (inches) of the left margin. If zero, the size is automatically determined."
638
639    label $page.right_l -text "right"
640    entry $page.right -width 6 \
641        -textvariable [itcl::scope _settings($this-layout-rightmargin)]
642    bind  $page.right <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
643    Rappture::Tooltip::for $page.right \
644        "Set the size (inches) of the right margin. If zero, the size is automatically determined."
645
646
647    label $page.top_l -text "top"
648    entry $page.top -width 6 \
649        -textvariable [itcl::scope _settings($this-layout-topmargin)]
650    bind  $page.top <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
651    Rappture::Tooltip::for $page.top \
652        "Set the size (inches) of the top margin. If zero, the size is automatically determined."
653
654    label $page.bottom_l -text "bottom"
655    entry $page.bottom -width 6 \
656        -textvariable [itcl::scope _settings($this-layout-bottommargin)]
657    bind  $page.bottom <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
658    Rappture::Tooltip::for $page.bottom \
659        "Set the size (inches) of the bottom margin. If zero, the size is automatically determined."
660
661
662    label $page.map -image [Rappture::icon graphmargins]
663    blt::table $page \
664        0,0 $page.width_l -anchor e \
665        0,1 $page.width -fill x  \
666        1,0 $page.height_l -anchor e \
667        1,1 $page.height -fill x \
668        3,0 $page.left_l -anchor e \
669        3,1 $page.left -fill x  \
670        4,0 $page.right_l -anchor e \
671        4,1 $page.right -fill x \
672        5,0 $page.top_l -anchor e \
673        5,1 $page.top -fill x \
674        6,0 $page.bottom_l -anchor e \
675        6,1 $page.bottom -fill x  \
676        0,2 $page.map -fill both -rspan 7 -padx 2
677
678    blt::table configure $page c0 r* -resize none
679    blt::table configure $page c1 r2 -resize both
680}
681
682
683itcl::body Rappture::XyPrint::BuildGeneralTab {} {
684    itk_component add graph_page {
685        frame $itk_component(tabs).graph_page
686    }
687    set page $itk_component(graph_page)
688    $itk_component(tabs) insert end "graph" \
689        -text "General" -padx 2 -pady 2 -window $page -fill both
690
691    label $page.format_l -text "format"
692    set m $page.format.menu
693    blt::comboentry $page.format \
694        -width 1i \
695        -textvariable [itcl::scope _settings($this-general-format)] \
696        -editable no -menu $m \
697        -iconvariable [itcl::scope _formatIcon] \
698        -command [itcl::code $this ApplyGeneralSettings]
699    blt::combomenu $m \
700        -xscrollbar $m.xs \
701        -yscrollbar $m.ys  \
702        -textvariable [itcl::scope _settings($this-general-format)] \
703        -iconvariable [itcl::scope _formatIcon] \
704        -height { 0 2i }
705    blt::tk::scrollbar $m.xs
706    blt::tk::scrollbar $m.ys
707    $m add -value "pdf" -text "PDF Portable Document Format"  \
708        -icon [Rappture::icon pdf]
709    $m add -value "ps"  -text "PS PostScript Format"  \
710        -icon [Rappture::icon ps]
711    $m add -value "eps" -text "EPS Encapsulated PostScript"  \
712        -icon [Rappture::icon eps]
713    $m add -value "jpg" -text "JPEG Joint Photographic Experts Group Format"  \
714        -icon [Rappture::icon jpg]
715    $m add -value "png" -text "PNG Portable Network Graphics Format"  \
716        -icon [Rappture::icon png]
717    $m add -value "gif" -text "GIF Graphics Interchange Format" \
718        -icon [Rappture::icon gif]
719    Rappture::Tooltip::for $page.format_l "Set the format of the image."
720
721    label $page.style_l -text "style"
722    set m $page.style.menu
723    blt::comboentry $page.style \
724        -width 1i \
725        -textvariable [itcl::scope _settings($this-general-style)] \
726        -editable no -menu $m \
727        -command [itcl::code $this ApplyGeneralSettings]
728    blt::combomenu $m \
729        -xscrollbar $m.xs \
730        -yscrollbar $m.ys  \
731        -textvariable [itcl::scope _settings($this-general-style)] \
732        -height { 0 2i }
733    blt::tk::scrollbar $m.xs
734    blt::tk::scrollbar $m.ys
735    $m add -value "ieee"  -text "IEEE Journal" 
736    $m add -value "gekco" -text  "G Klimeck" 
737    $m item configure all \
738        -variable [itcl::scope _settings($this-general-style)]
739    Rappture::Tooltip::for $page.style_l "Set the style template."
740
741    blt::tk::checkbutton $page.remember -text "remember settings" \
742        -variable [itcl::scope _settings($this-general-remember)] 
743    Rappture::Tooltip::for $page.remember \
744        "Remember the settings. They will be override the default settings."
745
746    button $page.revert -text "revert" -image [Rappture::icon revert] \
747        -compound left -padx 3 -pady 1 -overrelief raised -relief flat \
748        -command [itcl::code $this ResetSettings]
749    Rappture::Tooltip::for $page.revert \
750        "Revert to the default settings."
751
752    blt::table $page \
753        2,0 $page.format_l -anchor e \
754        2,1 $page.format -fill x -cspan 2 \
755        3,0 $page.style_l -anchor e \
756        3,1 $page.style -fill x -cspan 2 \
757        5,0 $page.remember -cspan 2 -anchor w \
758        5,2 $page.revert -anchor e
759    blt::table configure $page r* -resize none  -pady { 0 2 }
760    blt::table configure $page r4 -resize both
761
762}
763   
764itcl::body Rappture::XyPrint::BuildLegendTab {} {
765    itk_component add legend_page {
766        frame $itk_component(tabs).legend_page
767    }
768    set page $itk_component(legend_page)
769    $itk_component(tabs) insert end "legend" \
770        -text "Legend" -padx 2 -pady 2 -window $page -fill both
771
772    blt::tk::checkbutton $page.show -text "show legend" \
773        -offvalue 1 -onvalue 0 \
774        -variable [itcl::scope _settings($this-legend-hide)]  \
775        -command [itcl::code $this ApplyLegendSettings]
776    Rappture::Tooltip::for $page.show \
777        "Display the legend."
778
779    blt::tk::label $page.position_l -text "position"
780    Rappture::Combobox $page.position -width 15 -editable no
781    $page.position choices insert end \
782        "leftmargin" "left margin"  \
783        "rightmargin" "right margin"  \
784        "bottommargin" "bottom margin"  \
785        "topmargin" "top margin"  \
786        "plotarea" "inside plot"
787    bind $page.position <<Value>> [itcl::code $this ApplyLegendSettings]
788    Rappture::Tooltip::for $page.position \
789        "Set the position of the legend.  This option and the anchor determine the legend's location."
790
791    Rappture::Combobox $page.anchor -width 10 -editable no
792    $page.anchor choices insert end \
793        "nw" "northwest"  \
794        "n" "north"  \
795        "ne" "northeast"  \
796        "sw" "southwest"  \
797        "s" "south"  \
798        "se" "southeast"  \
799        "c" "center"  \
800        "e" "east"  \
801        "w" "west" 
802    bind $page.anchor <<Value>> [itcl::code $this ApplyLegendSettings]
803    Rappture::Tooltip::for $page.anchor \
804        "Set the anchor of the legend.  This option and the anchor determine the legend's location."
805
806    blt::tk::checkbutton $page.border -text "border" \
807        -variable [itcl::scope _settings($this-legend-borderwidth)] \
808        -onvalue 1 -offvalue 0 \
809        -command [itcl::code $this ApplyLegendSettings]
810    Rappture::Tooltip::for $page.border \
811        "Display a solid border around the legend."
812
813    label $page.slider_l -text "legend\nentry"  -justify right
814    itk_component add element_slider {
815        ::scale $page.slider -from 1 -to 1 \
816            -orient horizontal -width 12 \
817            -command [itcl::code $this GetElement]
818    }
819    Rappture::Tooltip::for $page.slider \
820        "Select the current entry."
821
822    blt::tk::label $page.label_l -text "label"
823    entry $page.label \
824        -background white \
825        -textvariable [itcl::scope _settings($this-element-label)]
826    bind  $page.label <KeyPress-Return> [itcl::code $this ApplyElementSettings]
827    Rappture::Tooltip::for $page.label \
828        "Set the label of the current entry in the legend."
829
830    blt::tk::label $page.color_l -text "color"
831    set m $page.color.menu
832    blt::comboentry $page.color \
833        -width 1i \
834        -textvariable [itcl::scope _colorText] \
835        -iconvariable [itcl::scope _colorIcon] \
836        -editable no -menu $m \
837        -command [itcl::code $this ApplyElementSettings]
838    blt::combomenu $m \
839        -xscrollbar $m.xs \
840        -yscrollbar $m.ys  \
841        -textvariable [itcl::scope _colorText] \
842        -iconvariable [itcl::scope _colorIcon] \
843        -height { 0 2i }
844    blt::tk::scrollbar $m.xs
845    blt::tk::scrollbar $m.ys
846    foreach {rgb name} {
847        "#000000" "black"
848        "#ffffff" "white"
849        "#0000cd" "blue"
850        "#cd0000" "red"
851        "#00cd00" "green"
852        "#3a5fcd" "royal blue"
853        "#cdcd00" "yellow"
854        "#cd1076" "deep pink"
855        "#009acd" "deep sky blue"
856        "#00c5cd" "turquoise"
857        "#a2b5cd" "light steel blue"
858        "#7ac5cd" "cadet blue"
859        "#66cdaa" "aquamarine"
860        "#a2cd5a" "dark olive green"
861        "#cd9b9b" "rosy brown"
862        "#0000ff" "blue1"
863        "#ff0000" "red1"
864        "#00ff00" "green1"
865    } {
866        AddColorToMenu $m $name $rgb
867    }
868    Rappture::Tooltip::for $page.color \
869        "Set the color of the current entry."
870
871    if 0 {
872    label $page.color_l -text "color "
873    Rappture::Combobox $page.color -width 15 -editable no
874    $page.color choices insert end \
875        "#000000" "black" \
876        "#ffffff" "white" \
877        "#0000cd" "blue" \
878        "#cd0000" "red" \
879        "#00cd00" "green" \
880        "#3a5fcd" "royal blue" \
881        "#cdcd00" "yellow" \
882        "#cd1076" "deep pink" \
883        "#009acd" "deep sky blue" \
884        "#00c5cd" "torquise" \
885        "#a2b5cd" "light steel blue" \
886        "#7ac5cd" "cadet blue" \
887        "#66cdaa" "aquamarine" \
888        "#a2cd5a" "dark olive green" \
889        "#cd9b9b" "rosy brown" \
890        "#0000ff" "blue1" \
891        "#ff0000" "red1" \
892        "#00ff00" "green1"
893    bind $page.color <<Value>> [itcl::code $this ApplyElementSettings]
894    Rappture::Tooltip::for $page.color \
895        "Set the color of the current entry."
896    }
897    blt::tk::label $page.dashes_l -text "line style"
898    Rappture::Combobox $page.dashes -width 15 -editable no
899    $page.dashes choices insert end \
900        "" "solid"  \
901        "1" "dot" \
902        "5 2" "dash" \
903        "2 4 2" "dashdot" \
904        "2 4 2 2" "dashdotdot"
905    bind $page.dashes <<Value>> [itcl::code $this ApplyElementSettings]
906    Rappture::Tooltip::for $page.dashes \
907        "Set the line style of the current entry."
908
909    blt::tk::label $page.symbol_l -text "symbol"
910    Rappture::Combobox $page.symbol -editable no
911    $page.symbol choices insert end \
912        "none" "none"  \
913        "square" "square" \
914        "circle" "circle" \
915        "diamond" "diamond" \
916        "plus" "plus" \
917        "cross" "cross" \
918        "splus" "skinny plus"  \
919        "scross" "skinny cross" \
920        "triangle" "triangle"
921    bind $page.symbol <<Value>> [itcl::code $this ApplyElementSettings]
922    Rappture::Tooltip::for $page.symbol \
923        "Set the symbol of the current entry. \"none\" display no symbols."
924
925    blt::tk::label $page.font_l -text "font"
926    set m $page.fontfamily.menu
927    blt::comboentry $page.fontfamily \
928        -width 1i \
929        -textvariable [itcl::scope _settings($this-legend-fontfamily)] \
930        -editable no -menu $m \
931        -command [itcl::code $this ApplyLegendSettings]
932    blt::combomenu $m \
933        -xscrollbar $m.xs \
934        -yscrollbar $m.ys  \
935        -textvariable [itcl::scope _settings($this-legend-fontfamily)] \
936        -height { 0 2i }
937    blt::tk::scrollbar $m.xs
938    blt::tk::scrollbar $m.ys
939    $m style create "courier" -font "{courier new} 9"
940    $m style create "helvetica" -font "{arial} 9"
941    $m style create "newcentury" -font "{new century schoolbook} 9"
942    $m style create "times" -font "{times new roman} 9"
943    $m add -text "courier" -value "courier" -style "courier"
944    $m add -text "helvetica" -value "helvetica"  -style "helvetica"
945    $m add -text "new century schoolbook" -value "new*century*schoolbook" \
946        -style "newcentury"
947    $m add -text "symbol" -value "symbol"
948    $m add -text "times" -value "times" -style "times"
949    $m item configure all -icon [Rappture::icon font]
950    Rappture::Tooltip::for $page.fontfamily \
951        "Set the font of entries in the legend."
952
953    set m $page.fontsize.menu
954    blt::comboentry $page.fontsize \
955        -width 0.5i \
956        -textvariable [itcl::scope _settings($this-legend-fontsize)] \
957        -editable no -menu $m \
958        -command [itcl::code $this ApplyLegendSettings]
959    blt::combomenu $m \
960        -xscrollbar $m.xs \
961        -yscrollbar $m.ys  \
962        -textvariable [itcl::scope _settings($this-legend-fontsize)] \
963        -height { 0 2i }
964    blt::tk::scrollbar $m.xs
965    blt::tk::scrollbar $m.ys
966    foreach size { "8" "9" "10" "11" "12" "14" "17" "18" "20" } {
967        $m add -text $size -value $size
968    }
969    Rappture::Tooltip::for $page.fontsize \
970        "Set the size (in points) of the legend font."
971
972    blt::tk::pushbutton $page.fontweight \
973        -width 18 -height 18 \
974        -onimage [Rappture::icon font-bold] \
975        -offimage [Rappture::icon font-bold] \
976        -onvalue "bold" -offvalue "normal" \
977        -command [itcl::code $this ApplyLegendSettings] \
978        -variable [itcl::scope _settings($this-legend-fontweight)]
979    Rappture::Tooltip::for $page.fontweight \
980        "Use the bold version of the font."
981
982    blt::tk::pushbutton $page.fontslant \
983        -width 18 -height 18 \
984        -onimage [Rappture::icon font-italic] \
985        -offimage [Rappture::icon font-italic] \
986        -onvalue "italic" -offvalue "roman" \
987        -command [itcl::code $this ApplyLegendSettings] \
988        -variable [itcl::scope _settings($this-legend-fontslant)]
989    Rappture::Tooltip::for $page.fontslant \
990        "Use the italic version of the font."
991
992    blt::table $page \
993        1,0 $page.show -cspan 2 -anchor w \
994        1,2 $page.border -cspan 2 -anchor w \
995        2,0 $page.position_l -anchor e \
996        2,1 $page.position -fill x \
997        2,2 $page.anchor -fill x  -cspan 3 \
998        3,0 $page.font_l -anchor e \
999        3,1 $page.fontfamily -fill x \
1000        3,2 $page.fontsize -fill x \
1001        3,3 $page.fontweight -anchor e \
1002        3,4 $page.fontslant -anchor e \
1003        4,0 $page.slider_l -anchor e \
1004        4,1 $page.slider -fill x -cspan 5 \
1005        5,0 $page.label_l -anchor e \
1006        5,1 $page.label -fill x -cspan 5 \
1007        6,0 $page.color_l -anchor e \
1008        6,1 $page.color -fill x \
1009        6,2 $page.symbol_l -anchor e \
1010        6,3 $page.symbol -fill both -cspan 3 \
1011        7,0 $page.dashes_l -anchor e \
1012        7,1 $page.dashes -fill x \
1013
1014    blt::table configure $page r* -resize none -pady { 0 2 }
1015    blt::table configure $page c3 c4 -resize none
1016    blt::table configure $page r8 -resize both
1017
1018}
1019
1020itcl::body Rappture::XyPrint::BuildAxisTab {} {
1021    itk_component add axis_page {
1022        frame $itk_component(tabs).axis_page
1023    }
1024    set page $itk_component(axis_page)
1025    $itk_component(tabs) insert end "axis" \
1026        -text "Axis" -padx 2 -pady 2 -window $page -fill both
1027   
1028    blt::tk::label $page.axis_l -text "axis"
1029    itk_component add axis_combo {
1030        Rappture::Combobox $page.axis -width 20 -editable no
1031    }
1032    bind $itk_component(axis_combo) <<Value>> [itcl::code $this GetAxis]
1033    Rappture::Tooltip::for $page.axis \
1034        "Select the current axis."
1035
1036    blt::tk::label $page.title_l -text "title"
1037    entry $page.title \
1038        -textvariable [itcl::scope _settings($this-axis-title)]
1039    bind  $page.title <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
1040    Rappture::Tooltip::for $page.title \
1041        "Set the title of the current axis."
1042
1043    blt::tk::label $page.min_l -text "min"
1044    entry $page.min -width 10 \
1045        -textvariable [itcl::scope _settings($this-axis-min)]
1046    bind  $page.min <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
1047    Rappture::Tooltip::for $page.min \
1048        "Set the minimum limit for the current axis. If empty, the minimum is automatically determined."
1049
1050    blt::tk::label $page.max_l -text "max"
1051    entry $page.max -width 10 \
1052        -textvariable [itcl::scope _settings($this-axis-max)]
1053    bind  $page.max <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
1054    Rappture::Tooltip::for $page.max \
1055        "Set the maximum limit for the current axis. If empty, the maximum is automatically determined."
1056
1057    blt::tk::label $page.subdivisions_l -text "subdivisions"
1058    entry $page.subdivisions \
1059        -textvariable [itcl::scope _settings($this-axis-subdivisions)]
1060    bind  $page.subdivisions <KeyPress-Return> \
1061        [itcl::code $this ApplyAxisSettings]
1062    Rappture::Tooltip::for $page.subdivisions \
1063        "Set the number of subdivisions (minor ticks) for the current axis."
1064
1065    blt::tk::label $page.stepsize_l -text "step size"
1066    entry $page.stepsize \
1067        -textvariable [itcl::scope _settings($this-axis-stepsize)]
1068    bind  $page.stepsize <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
1069    Rappture::Tooltip::for $page.stepsize \
1070        "Set the interval between major ticks for the current axis. If zero, the interval is automatically determined."
1071
1072    blt::tk::checkbutton $page.loose -text "loose limits" \
1073        -onvalue "always" -offvalue "0" \
1074        -variable [itcl::scope _settings($this-axis-loose)] \
1075        -command [itcl::code $this ApplyAxisSettings]
1076    Rappture::Tooltip::for $page.loose \
1077        "Set major ticks outside of the limits for the current axis."
1078
1079    blt::tk::label $page.plotpad_l -text "pad" 
1080    entry $page.plotpad -width 6 \
1081        -textvariable [itcl::scope _settings($this-axis-plotpad)]
1082    bind  $page.plotpad <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
1083    Rappture::Tooltip::for $page.plotpad \
1084        "Set padding (points) between the current axis and the plot."
1085
1086    blt::tk::checkbutton $page.grid -text "show grid lines" \
1087        -variable [itcl::scope _settings($this-axis-grid)] \
1088        -command [itcl::code $this ApplyAxisSettings]
1089    Rappture::Tooltip::for $page.grid \
1090        "Display grid lines for the current axis."
1091
1092    blt::tk::checkbutton $page.zero -text "mark zero" \
1093        -offvalue 1 -onvalue 0 \
1094        -variable [itcl::scope _settings($this-axis-zero)] \
1095        -command [itcl::code $this ApplyAxisSettings]
1096    Rappture::Tooltip::for $page.zero \
1097        "Display a line at zero for the current axis."
1098
1099    blt::tk::label $page.tickfont_l -text "tick font"
1100    set m $page.tickfontfamily.menu
1101    blt::comboentry $page.tickfontfamily \
1102        -width 1i \
1103        -textvariable [itcl::scope _settings($this-axis-ticks-fontfamily)] \
1104        -editable no -menu $m \
1105        -command [itcl::code $this ApplyAxisSettings]
1106    blt::combomenu $m \
1107        -xscrollbar $m.xs \
1108        -yscrollbar $m.ys  \
1109        -textvariable [itcl::scope _settings($this-axis-ticks-fontfamily)] \
1110        -height { 0 2i }
1111    blt::tk::scrollbar $m.xs
1112    blt::tk::scrollbar $m.ys
1113    $m style create "courier" -font "{courier new} 9"
1114    $m style create "helvetica" -font "{arial} 9"
1115    $m style create "newcentury" -font "{new century schoolbook} 9"
1116    $m style create "times" -font "{times new roman} 9"
1117    $m add -text "courier" -value "courier" -style "courier"
1118    $m add -text "helvetica" -value "helvetica"  -style "helvetica"
1119    $m add -text "new century schoolbook" -value "new*century*schoolbook" \
1120        -style "newcentury"
1121    $m add -text "symbol" -value "symbol"
1122    $m add -text "times" -value "times" -style "times"
1123    $m item configure all -icon [Rappture::icon font]
1124    Rappture::Tooltip::for $page.tickfontfamily \
1125        "Set the font of the ticks for the current axis."
1126
1127    set m $page.tickfontsize.menu
1128    blt::comboentry $page.tickfontsize \
1129        -width 0.5i \
1130        -textvariable [itcl::scope _settings($this-axis-ticks-fontsize)] \
1131        -editable no -menu $m \
1132        -command [itcl::code $this ApplyLegendSettings]
1133    blt::combomenu $m \
1134        -xscrollbar $m.xs \
1135        -yscrollbar $m.ys  \
1136        -textvariable [itcl::scope _settings($this-axis-ticks-fontsize)] \
1137        -height { 0 2i }
1138    blt::tk::scrollbar $m.xs
1139    blt::tk::scrollbar $m.ys
1140    foreach size { "8" "9" "10" "11" "12" "14" "17" "18" "20" } {
1141        $m add -text $size -value $size
1142    }
1143    Rappture::Tooltip::for $page.tickfontsize \
1144        "Set the size (in points) of the tick font."
1145
1146    blt::tk::pushbutton $page.tickfontweight \
1147        -width 18 -height 18 \
1148        -onimage [Rappture::icon font-bold] \
1149        -offimage [Rappture::icon font-bold] \
1150        -onvalue "bold" -offvalue "normal" \
1151        -command [itcl::code $this ApplyAxisSettings] \
1152        -variable [itcl::scope _settings($this-axis-ticks-fontweight)]
1153    Rappture::Tooltip::for $page.tickfontweight \
1154        "Use the bold version of the tick font."
1155
1156    blt::tk::pushbutton $page.tickfontslant \
1157        -width 18 -height 18 \
1158        -onimage [Rappture::icon font-italic] \
1159        -offimage [Rappture::icon font-italic] \
1160        -onvalue "italic" -offvalue "roman" \
1161        -command [itcl::code $this ApplyAxisSettings] \
1162        -variable [itcl::scope _settings($this-axis-ticks-fontslant)]
1163    Rappture::Tooltip::for $page.tickfontslant \
1164        "Use the italic version of the tick font."
1165
1166    blt::tk::label $page.titlefont_l -text "title font"
1167    set m $page.titlefontfamily.menu
1168    blt::comboentry $page.titlefontfamily \
1169        -width 1i \
1170        -textvariable [itcl::scope _settings($this-axis-title-fontfamily)] \
1171        -editable no -menu $m \
1172        -command [itcl::code $this ApplyAxisSettings]
1173    blt::combomenu $m \
1174        -xscrollbar $m.xs \
1175        -yscrollbar $m.ys  \
1176        -textvariable [itcl::scope _settings($this-axis-title-fontfamily)] \
1177        -height { 0 2i }
1178    blt::tk::scrollbar $m.xs
1179    blt::tk::scrollbar $m.ys
1180    $m style create "courier" -font "{courier new} 9"
1181    $m style create "helvetica" -font "{arial} 9"
1182    $m style create "newcentury" -font "{new century schoolbook} 9"
1183    $m style create "times" -font "{times new roman} 9"
1184    $m add -text "courier" -value "courier" -style "courier"
1185    $m add -text "helvetica" -value "helvetica"  -style "helvetica"
1186    $m add -text "new century schoolbook" -value "new*century*schoolbook" \
1187        -style "newcentury"
1188    $m add -text "symbol" -value "symbol"
1189    $m add -text "times" -value "times" -style "times"
1190    $m item configure all -icon [Rappture::icon font]
1191    Rappture::Tooltip::for $page.titlefontfamily \
1192        "Set the font of the title for the current axis."
1193
1194    set m $page.titlefontsize.menu
1195    blt::comboentry $page.titlefontsize \
1196        -width 0.5i \
1197        -textvariable [itcl::scope _settings($this-axis-title-fontsize)] \
1198        -editable no -menu $m \
1199        -command [itcl::code $this ApplyLegendSettings]
1200    blt::combomenu $m \
1201        -xscrollbar $m.xs \
1202        -yscrollbar $m.ys  \
1203        -textvariable [itcl::scope _settings($this-axis-title-fontsize)] \
1204        -height { 0 2i }
1205    blt::tk::scrollbar $m.xs
1206    blt::tk::scrollbar $m.ys
1207    foreach size { "8" "9" "10" "11" "12" "14" "17" "18" "20" } {
1208        $m add -text $size -value $size
1209    }
1210    Rappture::Tooltip::for $page.titlefontsize \
1211        "Set the size (in points) of the title font."
1212
1213    blt::tk::pushbutton $page.titlefontweight \
1214        -width 18 -height 18 \
1215        -onimage [Rappture::icon font-bold] \
1216        -offimage [Rappture::icon font-bold] \
1217        -onvalue "bold" -offvalue "normal" \
1218        -command [itcl::code $this ApplyAxisSettings] \
1219        -variable [itcl::scope _settings($this-axis-title-fontweight)]
1220    Rappture::Tooltip::for $page.titlefontweight \
1221        "Use the bold version of the title font."
1222
1223    blt::tk::pushbutton $page.titlefontslant \
1224        -width 18 -height 18 \
1225        -onimage [Rappture::icon font-italic] \
1226        -offimage [Rappture::icon font-italic] \
1227        -onvalue "italic" -offvalue "roman" \
1228        -command [itcl::code $this ApplyAxisSettings] \
1229        -variable [itcl::scope _settings($this-axis-title-fontslant)]
1230    Rappture::Tooltip::for $page.titlefontslant \
1231        "Use the italic version of the title font."
1232
1233    blt::table $page \
1234        1,1 $page.axis_l -anchor e  -pady 6 \
1235        1,2 $page.axis -fill x -cspan 6 \
1236        2,1 $page.title_l -anchor e \
1237        2,2 $page.title -fill x -cspan 5 \
1238        3,1 $page.min_l -anchor e \
1239        3,2 $page.min -fill x \
1240        3,3 $page.stepsize_l -anchor e \
1241        3,4 $page.stepsize -fill x -cspan 3 \
1242        4,1 $page.max_l -anchor e \
1243        4,2 $page.max -fill x \
1244        4,3 $page.subdivisions_l -anchor e \
1245        4,4 $page.subdivisions -fill x -cspan 3  \
1246        5,1 $page.titlefont_l -anchor e \
1247        5,2 $page.titlefontfamily -fill x -cspan 2 \
1248        5,4 $page.titlefontsize -fill x \
1249        5,5 $page.titlefontweight -anchor e \
1250        5,6 $page.titlefontslant -anchor e \
1251        6,1 $page.tickfont_l -anchor e \
1252        6,2 $page.tickfontfamily -fill x -cspan 2 \
1253        6,4 $page.tickfontsize -fill x \
1254        6,5 $page.tickfontweight -anchor e \
1255        6,6 $page.tickfontslant -anchor e \
1256        7,1 $page.loose -cspan 2 -anchor w \
1257        7,3 $page.grid -anchor w -cspan 2 \
1258        8,1 $page.zero -cspan 2 -anchor w \
1259        8,3 $page.plotpad_l -anchor e \
1260        8,4 $page.plotpad -fill both -cspan 3
1261
1262    blt::table configure $page  r* c0 c4 c5 c6 c7 c8 -resize none
1263    blt::table configure $page  r* -pady 1
1264    blt::table configure $page r9 -resize both
1265}
1266
1267itcl::body Rappture::XyPrint::ApplyGeneralSettings {} {
1268    RegeneratePreview
1269}
1270
1271itcl::body Rappture::XyPrint::ApplyLegendSettings {} {
1272    set page $itk_component(legend_page)
1273
1274    set _settings($this-legend-position)  [$page.position current]
1275    set _settings($this-legend-anchor)    [$page.anchor current]
1276    foreach option { -hide -position -anchor -borderwidth } {
1277        SetComponentOption legend $option
1278    }
1279    lappend font $_settings($this-legend-fontfamily)
1280    lappend font $_settings($this-legend-fontsize)
1281    lappend font $_settings($this-legend-fontweight)
1282    lappend font $_settings($this-legend-fontslant)
1283    $_clone legend configure -font fixed -font $font
1284
1285    # Set the font of the comboentry to the selected legend font.
1286    set m $page.fontfamily.menu
1287    set style [$m item cget $_settings($this-legend-fontfamily) -style]
1288    set font [$m style cget $style -font]
1289    $page.fontfamily configure -font $font
1290    ApplyElementSettings
1291}
1292
1293itcl::body Rappture::XyPrint::ApplyAxisSettings {} {
1294    set axis [$itk_component(axis_combo) current]
1295    set type [GetAxisType $axis]
1296    set page $itk_component(axis_page)
1297    $_clone configure -plotpad${type} $_settings($this-axis-plotpad)
1298    foreach option { -grid -min -max -loose -title -stepsize -subdivisions } {
1299        SetNamedComponentOption axis $axis $option
1300    }
1301    set tickfont {}
1302    set titlefont {}
1303
1304    foreach attr { fontfamily fontsize fontweight fontslant } {
1305        set specific $this-$axis-ticks
1306        set general  $this-axis-ticks
1307        set _settings(${specific}-${attr}) $_settings(${general}-${attr})
1308        lappend tickfont $_settings(${general}-${attr})
1309        set specific $this-$axis-title
1310        set general  $this-axis-title
1311        set _settings(${specific}-${attr}) $_settings(${general}-${attr})
1312        lappend titlefont $_settings(${general}-${attr})
1313    }
1314    # Set the font of the comboentry to the selected tick font.
1315    set m $page.tickfontfamily.menu
1316    set style [$m item cget $_settings($this-axis-ticks-fontfamily) -style]
1317    set font [$m style cget $style -font]
1318    $page.tickfontfamily configure -font $font
1319
1320    # Set the font of the comboentry to the selected title font.
1321    set m $page.titlefontfamily.menu
1322    set style [$m item cget $_settings($this-axis-title-fontfamily) -style]
1323    set font [$m style cget $style -font]
1324    $page.titlefontfamily configure -font $font
1325
1326    $_clone axis configure $axis -tickfont $tickfont -titlefont $titlefont
1327    $_clone marker configure ${type}-zero -hide $_settings($this-axis-zero)
1328
1329    RegeneratePreview
1330}
1331
1332itcl::body Rappture::XyPrint::ApplyElementSettings {} {
1333    set index [$itk_component(element_slider) get]
1334    set page $itk_component(legend_page)
1335    if { $_clone != "" } {
1336        set elem $_settings($this-element-$index)
1337        if { [$_clone element type $elem] != "bar" } {
1338            set _settings($this-element-symbol) [$page.symbol current]
1339            set _settings($this-element-dashes) [$page.dashes current]
1340            foreach option { -symbol -dashes } {
1341                SetNamedComponentOption element $elem $option
1342            }
1343        }
1344        foreach option { -color -label } {
1345            SetNamedComponentOption element $elem $option
1346        }
1347        RegeneratePreview
1348    }
1349}
1350
1351itcl::body Rappture::XyPrint::SetLayoutOption { opt } {
1352    set new [Inches2Pixels $_settings($this-layout$opt)]
1353    $_clone configure $opt $new
1354}
1355
1356itcl::body Rappture::XyPrint::ApplyLayoutSettings {} {
1357    foreach opt { -width -height -leftmargin -rightmargin -topmargin
1358        -bottommargin } {
1359        set old [$_clone cget $opt]
1360        set code [catch { SetLayoutOption $opt } err]
1361        if { $code != 0 } {
1362            bell
1363            global errorInfo
1364            puts stderr "$err: $errorInfo"
1365            set _settings($this-layout$opt) [Pixels2Inches $old]
1366            $_clone configure $opt [Pixels2Inches $old]
1367        }
1368    }
1369    RegeneratePreview
1370}
1371
1372
1373itcl::body Rappture::XyPrint::InitializeSettings {} {
1374    # General settings
1375    set page $itk_component(graph_page)
1376
1377    # Always set to "jpg" "ieee"
1378    set _settings($this-general-format)   \
1379        "JPEG Joint Photographic Experts Group Format"
1380    $page.format.menu select "JPEG Joint Photographic Experts Group Format"
1381    set _settings($this-general-style)    ieee
1382    set _settings($this-general-remember) 0
1383
1384    # Layout settings
1385    set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]]
1386    set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]]
1387    set _settings($this-layout-leftmargin) \
1388        [Pixels2Inches [$_clone cget -leftmargin]]
1389    set _settings($this-layout-rightmargin) \
1390        [Pixels2Inches [$_clone cget -rightmargin]]
1391    set _settings($this-layout-topmargin) \
1392        [Pixels2Inches [$_clone cget -topmargin]]
1393    set _settings($this-layout-bottommargin) \
1394        [Pixels2Inches [$_clone cget -bottommargin]]
1395
1396    # Legend settings
1397    set page $itk_component(legend_page)
1398
1399    set names [$_clone element show]
1400    $itk_component(element_slider) configure -from 1 -to [llength $names]
1401    set state [expr  { ([llength $names] < 2) ? "disabled" : "normal" } ]
1402    $page.slider configure -state $state
1403    $page.slider_l configure -state $state
1404    # Always initialize the slider to the first entry in the element list.
1405    $itk_component(element_slider) set 1
1406    # Always set the borderwidth to be not displayed
1407    set _settings($this-legend-borderwidth) 0
1408
1409    if { $_settings($this-legend-fontweight) == "bold" } {
1410        set _settings($this-legend-font-bold) 1
1411    }
1412    set _settings($this-legend-hide) [$_clone legend cget -hide]
1413    set _settings($this-legend-position) [$_clone legend cget -position]
1414    set _settings($this-legend-anchor) [$_clone legend cget -anchor]
1415    $page.position value \
1416        [$page.position label $_settings($this-legend-position)]
1417    $page.anchor value [$page.anchor label $_settings($this-legend-anchor)]
1418    GetElement
1419
1420    # Axis settings
1421    set page $itk_component(axis_page)
1422    set names [lsort [$_clone axis names]]
1423    $itk_component(axis_combo) choices delete 0 end
1424    foreach axis $names {
1425        if { $axis == "z" } {
1426            continue
1427        }
1428        if { ![$_clone axis cget $axis -hide] } {
1429            $itk_component(axis_combo) choices insert end $axis $axis
1430        }
1431        lappend axisnames $axis
1432    }
1433    set axis [lindex $names 0]
1434
1435    # Always hide the zero line.
1436    set _settings($this-axis-zero) 1
1437    set _settings($this-axis-plotpad) [Pixels2Inches [$_clone cget -plotpadx]]
1438    # Pick the first axis to initially display
1439    set axis [lindex $axisnames 0]
1440    $itk_component(axis_combo) value $axis
1441    GetAxis
1442    RegeneratePreview
1443}
1444
1445
1446itcl::body Rappture::XyPrint::restore { toolName plotName data } {
1447    set key [list $toolName $plotName]
1448    set _savedSettings($key) $data
1449}
1450
1451itcl::body Rappture::XyPrint::RestoreSettings { toolName plotName } {
1452    if { ![file readable $_settingsFile] } {
1453        return;                         # No file or not readable
1454    }
1455    if { [file exists $_oldSettingsFile] } {
1456        file delete $_oldSettingsFile
1457    }
1458    # Read the file by sourcing it into a safe interpreter The only commands
1459    # executed will be "xyprint" which will simply add the data into an array
1460    # _savedSettings.
1461    set parser [interp create -safe]
1462    $parser alias xyprint [itcl::code $this restore]
1463    set f [open $_settingsFile "r"]
1464    set code [read $f]
1465    close $f
1466    $parser eval $code
1467   
1468    # Now see if there's an entry for this tool/plot combination.  The data
1469    # associated with the variable is itself code to update the graph (clone).
1470    set key [list $toolName $plotName]
1471    if { [info exists _savedSettings($key)] }  {
1472        $parser alias "preview" $_clone
1473        $parser eval $_savedSettings($key)
1474    }
1475    # Restore settings to this instance
1476    foreach {name value} [$parser eval "array get settings"] {
1477        set _settings($this-$name) $value
1478    }
1479    interp delete $parser
1480}
1481
1482itcl::body Rappture::XyPrint::ResetSettings {} {
1483    set graph $_graph
1484    DestroySettings
1485    set _graph $graph
1486    CloneGraph $graph
1487    InitClone
1488    InitializeSettings
1489}
1490
1491itcl::body Rappture::XyPrint::SaveSettings { toolName plotName } {
1492    if { !$_settings($this-general-remember) } {
1493        return
1494    }
1495    if { [catch { open $_settingsFile "w" 0600 } f ] != 0 } {
1496        puts stderr "$_settingsFile isn't writable: $f"
1497        bell
1498        return
1499    }
1500    set key [list $toolName $plotName]
1501    set _savedSettings($key) [CreateSettings $toolName $plotName]
1502    # Write the settings out
1503    foreach key [lsort [array names _savedSettings]] {
1504        set tool [lindex $key 0]
1505        set plot [lindex $key 1]
1506        puts $f "xyprint \"$tool\" \"$plot\" \{"
1507        set settings [string trim $_savedSettings($key) \n]
1508        puts $f "$settings"
1509        puts $f "\}\n"
1510    }
1511    close $f
1512}
1513
1514itcl::body Rappture::XyPrint::CreateSettings { toolName plotName } {
1515    # Create stanza associated with tool and plot title.
1516    # General settings
1517    set length [string length "${this}-"]
1518    append out "    array set settings {\n"
1519    foreach item [array names _settings ${this}-*] {
1520        set field [string range $item $length end]
1521        if { [regexp {^element-[0-9]+$} $field] } {
1522            continue
1523        }
1524        set value $_settings($item)
1525        append out "        [list $field] [list $value]\n"
1526    }
1527    append out "    }\n"
1528    # Legend font
1529    lappend legendfont $_settings($this-legend-fontfamily)
1530    lappend legendfont $_settings($this-legend-fontsize)
1531    lappend legendfont $_settings($this-legend-fontweight)
1532    lappend legendfont $_settings($this-legend-fontslant)
1533    # Axis tick font
1534    lappend axistickfont $_settings($this-axis-ticks-fontfamily)
1535    lappend axistickfont $_settings($this-axis-ticks-fontsize)
1536    lappend axistickfont $_settings($this-axis-ticks-fontweight)
1537    lappend axistickfont $_settings($this-axis-ticks-fontslant)
1538    # Axis title font
1539    lappend axistitlefont $_settings($this-axis-title-fontfamily)
1540    lappend axistitlefont $_settings($this-axis-title-fontsize)
1541    lappend axistitlefont $_settings($this-axis-title-fontweight)
1542    lappend axistitlefont $_settings($this-axis-title-fontslant)
1543    append out "\n"
1544
1545    # Layout settings
1546    append out "    preview configure"
1547    foreach opt { -width -height -leftmargin -rightmargin -topmargin
1548        -bottommargin -plotpadx -plotpady } {
1549        set value [list [$_clone cget $opt]]
1550        append out " $opt $value"
1551    }
1552    append out "\n"
1553
1554    # Legend settings
1555    append out "    preview legend configure"
1556    foreach opt { -position -anchor -borderwidth -hide } {
1557        set value [list [$_clone legend cget $opt]]
1558        append out " $opt $value"
1559    }
1560    append out " -font \"$legendfont\"\n"
1561
1562    # Element settings
1563    foreach elem [$_clone element show] {
1564        set label [$_clone element cget $elem -label]
1565        if { $label == "" } {
1566            continue
1567        }
1568        append out "    if \{ \[preview element exists \"$label\"\] \} \{\n"
1569        append out "        preview element configure \"$label\""
1570        if { [$_clone element type $elem] != "bar" } {
1571            set options { -symbol -color -dashes -label }
1572        } else {
1573            set options { -color -label }
1574        }
1575        foreach opt $options {
1576            set value [list [$_clone element cget $elem $opt]]
1577            append out " $opt $value"
1578        }
1579        append out "    \}\n"
1580    }
1581   
1582    # Axis settings
1583    foreach axis [$_clone axis names] {
1584        if { [$_clone axis cget $axis -hide] } {
1585            continue
1586        }
1587        append out "    if \{ \[preview axis names \"$axis\"\] == \"$axis\" \} \{\n"
1588        append out "        preview axis configure \"$axis\""
1589        foreach opt { -grid -hide -min -max -loose -title -stepsize -subdivisions } {
1590            set value [list [$_clone axis cget $axis $opt]]
1591            append out " $opt $value"
1592        }
1593        append out " -tickfont \"$axistickfont\""
1594        append out " -titlefont \"$axistitlefont\"\n"
1595        set hide [$_clone marker cget ${axis}-zero -hide]
1596        append out "        preview marker configure \"${axis}-zero\" -hide $hide\n"
1597        append out "    \}\n"
1598    }   
1599    return $out
1600}
1601
1602itcl::body Rappture::XyPrint::AddColorToMenu { m name color } {
1603    set icon [image create picture -width 19 -height 17]
1604    $icon blank 0x0
1605    $icon draw circle 7 7 8 -color black \
1606        -antialiased 1 -linewidth 0 -shadow { -width 1 -offset 1 }
1607    $icon draw circle 7 7 7 -color $color \
1608        -antialiased 1 -linewidth 0
1609    $m add -text $name -icon $icon -value $color \
1610        -variable [itcl::scope _settings($this-element-color)]
1611}
Note: See TracBrowser for help on using the repository browser.