Changeset 43 for trunk


Ignore:
Timestamp:
Aug 16, 2005, 1:12:56 AM (19 years ago)
Author:
mmc
Message:
  • Added a new Rappture.result() function to the Python library. This makes it easy to finalize results. See examples/graph for example use.
  • Added examples/graph to illustrate a simple tool with a string and two numbers for input.
  • Fixed the XY graph to show crosshairs and pop-up info when you mouse over particular points.
  • Fixed Rappture::exec so that it doesn't add stray newlines when a program has lots (more than 8k) of output.
  • Fixed the analyzer to recognize the <tool><analyzer> tag. When set to "last", this automatically clears the last result. Handy for programs like SPICE, where you don't compare much, but keep running one new simulation after another.
  • Fixed <string> entries to enable the Simulate button after each editing keystroke.
Location:
trunk
Files:
4 added
8 edited

Legend:

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

    r23 r43  
    311311            set status [catch {load $file} msg]
    312312            if {$status != 0} {
    313                 set result $msg
     313                global errorInfo
     314                set result "$msg\n$errorInfo"
    314315            }
    315316        } else {
     
    329330        $itk_component(runinfo) delete 1.0 end
    330331        $itk_component(runinfo) insert end "Problem launching job:\n\n"
    331         $itk_component(runinfo) insert end $result
     332        _simOutput $result
    332333        $itk_component(runinfo) configure -state disabled
     334        $itk_component(runinfo) see 1.0
    333335    } else {
    334336        $itk_component(notebook) current analyze
     
    370372# ----------------------------------------------------------------------
    371373itcl::body Rappture::Analyzer::load {file} {
     374    # only show the last result? then clear first
     375    if {[$_tool xml get tool.analyzer] == "last"} {
     376        clear
     377    }
     378
    372379    # try to load new results from the given file
    373380    set xmlobj [Rappture::library $file]
     
    509516    set page [$itk_component(resultselector) value]
    510517    set page [$itk_component(resultselector) translate $page]
    511     set f [$itk_component(resultpages) page $page]
    512     $f.rviewer plot clear
    513     foreach {index opts} $_plotlist {
    514         $f.rviewer plot add $index $opts
     518    if {"" != $page} {
     519        set f [$itk_component(resultpages) page $page]
     520        $f.rviewer plot clear
     521        foreach {index opts} $_plotlist {
     522            $f.rviewer plot add $index $opts
     523        }
    515524    }
    516525}
  • trunk/gui/scripts/exec.tcl

    r23 r43  
    6363    }
    6464
    65     puts $message
    66     append execout $message "\n"
     65    puts -nonewline $message
     66    append execout $message
    6767}
  • trunk/gui/scripts/textentry.tcl

    r35 r43  
    3939
    4040    protected method _layout {}
     41    protected method _newValue {}
    4142
    4243    private variable _dispatcher "" ;# dispatcher for !events
     
    7071    if {[string length $hints] > 0} {
    7172        itk_component add hints {
    72             label $itk_interior.hints -anchor w -text $hints
     73            ::label $itk_interior.hints -anchor w -text $hints
    7374        } {
    7475            usual
     
    244245                -foreground $itk_option(-textforeground)
    245246
     247            bind $itk_component(entry) <KeyPress> [itcl::code $this _newValue]
     248
    246249            itk_component add emenu {
    247250                menu $itk_component(entry).menu -tearoff 0
     
    295298                -foreground $itk_option(-textforeground)
    296299            $itk_component(scrollbars) contents $itk_component(text)
     300
     301            bind $itk_component(text) <KeyPress> [itcl::code $this _newValue]
    297302
    298303            itk_component add tmenu {
     
    331336            -width $itk_option(-width) -height $itk_option(-width)
    332337    }
     338}
     339
     340# ----------------------------------------------------------------------
     341# USAGE: _newValue
     342#
     343# Invoked automatically whenever the value in the entry changes.
     344# Sends a <<Value>> event to notify clients of the change.
     345# ----------------------------------------------------------------------
     346itcl::body Rappture::TextEntry::_newValue {} {
     347    event generate $itk_component(hull) <<Value>>
    333348}
    334349
  • trunk/gui/scripts/tooltip.tcl

    r26 r43  
    9393
    9494# ----------------------------------------------------------------------
    95 # USAGE: show @<x>,<y>|<widget>+<x>,<y>
     95# USAGE: show @<x>,<y>|<widget>+/-<x>,<y>
    9696#
    9797# Clients use this to pop up the tooltip on the screen.  The position
    98 # should be either a <widget> name with an optional offset +<x>,<y>
     98# should be either a <widget> name with an optional offset +/-<x>,<y>
    9999# (tooltip pops up beneath widget by default), or a specific root
    100100# window coordinate of the form @x,y.
     
    106106itcl::body Rappture::Tooltip::show {where} {
    107107    set hull $itk_component(hull)
     108    set signx "+"
     109    set signy "+"
    108110
    109111    if {[regexp {^@([0-9]+),([0-9]+)$} $where match x y]} {
    110112        set xpos $x
    111113        set ypos $y
    112     } elseif {[regexp {^(.*)\+([0-9]+),([0-9]+)$} $where match win x y]} {
    113         set xpos [expr {[winfo rootx $win]+$x}]
    114         set ypos [expr {[winfo rooty $win]+$y}]
     114    } elseif {[regexp {^(.*)([-+])([0-9]+),([-+]?)([0-9]+)$} $where match win signx x signy y]} {
     115        if {$signy == ""} { set signy $signx }
     116        set xpos [expr {[winfo rootx $win] + $x}]
     117        set ypos [expr {[winfo rooty $win] + $y}]
    115118    } elseif {[winfo exists $where]} {
    116119        set xpos [expr {[winfo rootx $where]+10}]
    117120        set ypos [expr {[winfo rooty $where]+[winfo height $where]}]
    118121    } else {
    119         error "bad position \"$where\": should be widget name, +x,y, or @x,y"
     122        error "bad position \"$where\": should be widget+x,y, or @x,y"
    120123    }
    121124
     
    152155    # Make sure the tooltip doesn't go off screen.  Then, put it up.
    153156    #
    154     update
    155     if {$xpos+[winfo reqwidth $hull] > [winfo screenwidth $hull]} {
    156         set xpos [expr {[winfo screenwidth $hull]-[winfo reqwidth $hull]}]
    157     }
    158     if {$xpos < 0} { set xpos 0 }
    159 
    160     if {$ypos+[winfo reqheight $hull] > [winfo screenheight $hull]} {
    161         set ypos [expr {[winfo screenheight $hull]-[winfo reqheight $hull]}]
    162     }
    163     if {$ypos < 0} { set ypos 0 }
    164 
    165     wm geometry $hull +$xpos+$ypos
     157    update idletasks
     158    if {$signx == "+"} {
     159        if {$xpos+[winfo reqwidth $hull] > [winfo screenwidth $hull]} {
     160            set xpos [expr {[winfo screenwidth $hull]-[winfo reqwidth $hull]}]
     161        }
     162        if {$xpos < 0} { set xpos 0 }
     163    } else {
     164        if {$xpos-[winfo reqwidth $hull] < 0} {
     165            set xpos [expr {[winfo screenwidth $hull]-[winfo reqwidth $hull]}]
     166        }
     167        set xpos [expr {[winfo screenwidth $hull]-$xpos}]
     168    }
     169
     170    if {$signy == "+"} {
     171        if {$ypos+[winfo reqheight $hull] > [winfo screenheight $hull]} {
     172            set ypos [expr {[winfo screenheight $hull]-[winfo reqheight $hull]}]
     173        }
     174        if {$ypos < 0} { set ypos 0 }
     175    } else {
     176        if {$ypos-[winfo reqheight $hull] < 0} {
     177            set ypos [expr {[winfo screenheight $hull]-[winfo reqheight $hull]}]
     178        }
     179        set ypos [expr {[winfo screenheight $hull]-$ypos}]
     180    }
     181
     182    wm geometry $hull $signx$xpos$signy$ypos
    166183    update
    167184
     
    264281                if {[string index $loc 0] == "@"} {
    265282                    .rappturetooltip show $loc
    266                 } elseif {[string index $loc 0] == "+"} {
     283                } elseif {[regexp {^[-+]} $loc]} {
    267284                    .rappturetooltip show $widget$loc
    268285                } else {
  • trunk/gui/scripts/xyresult.tcl

    r25 r43  
    1616option add *XyResult.height 4i widgetDefault
    1717option add *XyResult.gridColor #d9d9d9 widgetDefault
    18 option add *XyResult.hiliteColor black widgetDefault
    1918option add *XyResult.controlBackground gray widgetDefault
    2019option add *XyResult.font \
     
    3332
    3433    itk_option define -gridcolor gridColor GridColor ""
    35     itk_option define -hilitecolor hiliteColor HiliteColor ""
    3634
    3735    constructor {args} { # defined below }
     
    5856    private variable _vmin ""      ;# autoscale min for y-axis
    5957    private variable _vmax ""      ;# autoscale max for y-axis
    60     private variable _hilite ""    ;# info from last _hilite operation
     58    private variable _hilite       ;# info from last _hilite operation
    6159}
    6260                                                                               
     
    104102
    105103    # special pen for highlighting active traces
    106     $itk_component(plot) element bind all <Enter> \
    107         [itcl::code $this _hilite on %x %y]
    108     $itk_component(plot) element bind all <Leave> \
     104    #$itk_component(plot) element bind all <Enter> \
     105    #    [itcl::code $this _hilite on %x %y]
     106    #$itk_component(plot) element bind all <Leave> \
     107    #    [itcl::code $this _hilite off %x %y]
     108    array set _hilite {
     109        elem ""
     110        color ""
     111    }
     112    bind $itk_component(plot) <Motion> \
     113        [itcl::code $this _hilite at %x %y]
     114    bind $itk_component(plot) <Leave> \
    109115        [itcl::code $this _hilite off %x %y]
    110 
    111     bind $itk_component(plot) <Leave> \
    112         [list Rappture::Tooltip::tooltip cancel]
    113116
    114117    Blt_ZoomStack $itk_component(plot)
     
    461464# ----------------------------------------------------------------------
    462465itcl::body Rappture::XyResult::_hilite {state x y} {
    463     set elem [$itk_component(plot) element get current]
     466    set g $itk_component(plot)
     467    if {$state == "at"} {
     468        if {[$g element closest $x $y info]} {
     469            set elem $info(name)
     470            set x [$g axis transform x $info(x)]
     471            set y [$g axis transform y $info(y)]
     472            set state 1
     473        } else {
     474            set state 0
     475        }
     476    }
     477
    464478    if {$state} {
     479        $g crosshairs configure -hide no -position @$x,$y
    465480        #
    466481        # Highlight ON:
     
    469484        # - pop up tooltip about data
    470485        #
    471         set t [$itk_component(plot) element cget $elem -linewidth]
    472         $itk_component(plot) element configure $elem -linewidth [expr {$t+2}]
    473 
    474         set _hilite [$itk_component(plot) element cget $elem -color]
    475         $itk_component(plot) element configure $elem \
    476             -color $itk_option(-hilitecolor)
     486        if {"" == $_hilite(elem)} {
     487            set t [$g element cget $elem -linewidth]
     488            $g element configure $elem -linewidth [expr {$t+2}]
     489            set _hilite(elem) $elem
     490        }
    477491
    478492        set tip ""
     
    480494            set curve $_elem2curve($elem)
    481495            set tip [$curve hints tooltip]
     496            if {[info exists info(y)]} {
     497                set units [$curve hints yunits]
     498                append tip "\n$info(y)$units"
     499
     500                if {[info exists info(x)]} {
     501                    set units [$curve hints xunits]
     502                    append tip " @ $info(x)$units"
     503                }
     504            }
     505            set tip [string trim $tip]
    482506        }
    483507        if {"" != $tip} {
    484             set x [expr {$x+4}]  ;# move the tooltip over a bit
    485             set y [expr {$y+4}]
    486             Rappture::Tooltip::text $itk_component(plot) $tip
    487             Rappture::Tooltip::tooltip show $itk_component(plot) +$x,$y
     508            if {$x > 0.5*[winfo width $g]} {
     509                set x "-[expr {$x-4}]"  ;# move tooltip to the left
     510            } else {
     511                set x "+[expr {$x+4}]"  ;# move tooltip to the right
     512            }
     513            if {$y > 0.5*[winfo height $g]} {
     514                set y "-[expr {$y-4}]"  ;# move tooltip to the top
     515            } else {
     516                set y "+[expr {$y+4}]"  ;# move tooltip to the bottom
     517            }
     518            Rappture::Tooltip::text $g $tip
     519            Rappture::Tooltip::tooltip show $g $x,$y
    488520        }
    489521    } else {
     
    494526        # - take down tooltip
    495527        #
    496         set t [$itk_component(plot) element cget $elem -linewidth]
    497         $itk_component(plot) element configure $elem -linewidth [expr {$t-2}]
    498 
    499         if {"" != $_hilite} {
    500             $itk_component(plot) element configure $elem -color $_hilite
     528        $g crosshairs configure -hide yes
     529
     530        if {"" != $_hilite(elem)} {
     531            set t [$g element cget $_hilite(elem) -linewidth]
     532            $g element configure $_hilite(elem) -linewidth [expr {$t-2}]
     533            set _hilite(elem) ""
    501534        }
    502535        Rappture::Tooltip::tooltip cancel
  • trunk/python/Rappture/__init__.py

    r9 r43  
    33from interface import interface
    44from number import number
     5from result import result
  • trunk/python/Rappture/library.py

    r22 r43  
    99# ======================================================================
    1010from xml.dom import minidom
    11 import re, string
     11import re, string, time
    1212
    1313class library:
  • trunk/python/setup.py

    r9 r43  
    44  description='Rapid Application Infrastructure library for nanoHUB.org',
    55  url='http://www.nanohub.org/',
    6   py_modules=['Rappture.library','Rappture.interface','Rappture.number'],
     6  py_modules=['Rappture.library','Rappture.interface','Rappture.number','Rappture.result'],
    77  )
Note: See TracChangeset for help on using the changeset viewer.