Changeset 5592 for trunk


Ignore:
Timestamp:
May 21, 2015 4:28:27 AM (9 years ago)
Author:
ldelgass
Message:

Merge r5557:5561,r5574:5575 from 1.3 branch

Location:
trunk
Files:
9 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/gui/scripts/balloon.tcl

    r4661 r5592  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: Balloon - toplevel popup window, like a cartoon balloon
     
    4747
    4848    protected method _createStems {}
     49    protected method _place {where placement w h sw sh}
    4950
    5051    protected variable _stems   ;# windows for cartoon balloon stems
     
    123124}
    124125
     126
     127# ----------------------------------------------------------------------
     128# USAGE: _place <where> <place> <pw> <ph> <screenw> <screenh>
     129#
     130# Called by activate. Returns the exact location information given
     131# the parameters.  If the window will not fit on the screen with the
     132# requested placement, will loop through all possible placements to
     133# find the best alternative.
     134# ----------------------------------------------------------------------
     135itcl::body Rappture::Balloon::_place {where place pw ph screenw screenh} {
     136    # pw and ph are requested balloon window size
     137
     138    # set placement preference order
     139    switch $place {
     140        left {set plist {left above below right}}
     141        right {set plist {right above below left}}
     142        above {set plist {above below right left}}
     143        below {set plist {below above right left}}
     144    }
     145
     146    set ph_orig $ph
     147    set pw_orig $pw
     148
     149    foreach placement $plist {
     150        set pw $pw_orig
     151        set ph $ph_orig
     152        if {[winfo exists $where]} {
     153            # location of top-left corner of root window
     154            set rx [winfo rootx $where]
     155            set ry [winfo rooty $where]
     156
     157            # size of widget we want to popup over
     158            set width  [winfo width $where]
     159            set height [winfo height $where]
     160
     161            # x and y will be location for popup
     162            set x [expr {$rx + $width/2}]
     163            set y [expr {$ry + $height/2}]
     164
     165            switch -- $placement {
     166                left { set x [expr {$rx + 5}] }
     167                right { set x [expr {$rx + $width - 5}] }
     168                above { set y [expr {$ry + 5}] }
     169                below { set y [expr {$ry + $height - 5}] }
     170            }
     171        } elseif {[regexp {^@([0-9]+),([0-9]+)$} $where match x y]} {
     172            # got x and y
     173        } else {
     174            error "bad location \"$where\": should be widget or @x,y"
     175        }
     176
     177        # compute stem image size
     178        set s $_stems($placement)
     179        set sw [image width $_fills($placement)]
     180        set sh [image height $_fills($placement)]
     181        set offscreen 0
     182
     183        switch -- $placement {
     184            left {
     185                set sx [expr {$x-$sw+3}]
     186                set sy [expr {$y-$sh/2}]
     187                set px [expr {$sx-$pw+3}]
     188                set py [expr {$y-$ph/2}]
     189
     190                # make sure that the panel doesn't go off-screen
     191                if {$py < 0} {
     192                    incr offscreen [expr -$py]
     193                    set py 0
     194                }
     195                if {$py+$ph > $screenh} {
     196                    incr offscreen [expr {$py + $ph - $screenh}]
     197                    set py [expr {$screenh - $ph}]
     198                }
     199                if {$px < 0} {
     200                    incr offscreen [expr -$px]
     201                    set pw [expr {$pw + $px}]
     202                    set px 0
     203                }
     204            }
     205            right {
     206                set sx $x
     207                set sy [expr {$y-$sh/2}]
     208                set px [expr {$x+$sw-3}]
     209                set py [expr {$y-$ph/2}]
     210
     211                # make sure that the panel doesn't go off-screen
     212                if {$py < 0} {
     213                    incr offscreen [expr -$py]
     214                    set py 0
     215                }
     216                if {$py+$ph > $screenh} {
     217                    incr offscreen [expr {$py + $ph - $screenh}]
     218                    set py [expr {$screenh-$ph}]
     219                }
     220                if {$px+$pw > $screenw} {
     221                    incr offscreen [expr {$px + $pw - $screenw}]
     222                    set pw [expr {$screenw-$px}]
     223                }
     224            }
     225            above {
     226                set sx [expr {$x-$sw/2}]
     227                set sy [expr {$y-$sh+3}]
     228                set px [expr {$x-$pw/2}]
     229                set py [expr {$sy-$ph+3}]
     230
     231                # make sure that the panel doesn't go off-screen
     232                if {$px < 0} {
     233                    incr offscreen [expr -$px]
     234                    set px 0
     235                }
     236                if {$px+$pw > $screenw} {
     237                    incr offscreen [expr {$px + $pw - $screenw}]
     238                    set px [expr {$screenw-$pw}]
     239                }
     240                if {$py < 0} {
     241                    incr offscreen [expr -$py]
     242                    set ph [expr {$ph+$py}]
     243                    set py 0
     244                }
     245            }
     246            below {
     247                set sx [expr {$x-$sw/2}]
     248                set sy $y
     249                set px [expr {$x-$pw/2}]
     250                set py [expr {$y+$sh-3}]
     251
     252                # make sure that the panel doesn't go off-screen
     253                if {$px < 0} {
     254                    incr offscreen [expr -$px]
     255                    set px 0
     256                }
     257                if {$px+$pw > $screenw} {
     258                    incr offscreen [expr {$px + $pw - $screenw}]
     259                    set px [expr {$screenw-$pw}]
     260                }
     261                if {$py+$ph > $screenh} {
     262                    incr offscreen [expr {$py + $py - $screenh}]
     263                    set ph [expr {$screenh-$py}]
     264                }
     265            }
     266        }
     267        set res($placement) [list $placement $offscreen $pw $ph $px $py $sx $sy]
     268        if {$offscreen == 0} {
     269            return "$placement $pw $ph $px $py $sx $sy"
     270        }
     271    }
     272
     273    # In the unlikely event that we arrived here, it is because no
     274    # placement allowed the entire balloon window to be displayed.
     275    # Loop through the results and return the best-case placement.
     276    set _min 10000
     277    foreach pl $plist {
     278        set offscreen [lindex $res($pl) 1]
     279        if {$offscreen < $_min} {
     280            set _min $offscreen
     281            set _min_pl $pl
     282        }
     283    }
     284    return "$_min_pl [lrange $res($_min_pl) 2 end]"
     285}
     286
    125287# ----------------------------------------------------------------------
    126288# USAGE: activate <where> <placement>
     
    129291# <where> location, which should be a widget name or @X,Y.  The
    130292# <placement> indicates whether the panel should be left, right,
    131 # above, or below the <where> coordinate.
     293# above, or below the <where> coordinate. Plecement is considered
     294# a suggestion and may be changed to fit the popup in the screen.
    132295# ----------------------------------------------------------------------
    133296itcl::body Rappture::Balloon::activate {where placement} {
     
    135298        error "bad placement \"$placement\": should be [join [lsort [array names _stems]] {, }]"
    136299    }
    137     set s $_stems($placement)
    138     set sw [image width $_fills($placement)]
    139     set sh [image height $_fills($placement)]
     300
     301    # if the panel is already up, take it down
     302    deactivate
     303
    140304    set p $itk_component(hull)
    141305    set screenw [winfo screenwidth $p]
    142306    set screenh [winfo screenheight $p]
    143 
    144     if {[winfo exists $where]} {
    145         set x [expr {[winfo rootx $where]+[winfo width $where]/2}]
    146         set y [expr {[winfo rooty $where]+[winfo height $where]/2}]
    147         switch -- $placement {
    148             left { set x [expr {[winfo rootx $where]+5}] }
    149             right { set x [expr {[winfo rootx $where]+[winfo width $where]-5}] }
    150             above { set y [expr {[winfo rooty $where]+5}] }
    151             below { set y [expr {[winfo rooty $where]+[winfo height $where]-5}] }
    152         }
    153     } elseif {[regexp {^@([0-9]+),([0-9]+)$} $where match x y]} {
    154         # got x and y
    155     } else {
    156         error "bad location \"$where\": should be widget or @x,y"
    157     }
    158 
    159     # if the panel is already up, take it down
    160     deactivate
    161307
    162308    set pw [winfo reqwidth $p]
     
    165311    if {$ph > $screenh} { set ph [expr {$screenh-10}] }
    166312
    167     switch -- $placement {
    168         left {
    169             set sx [expr {$x-$sw+3}]
    170             set sy [expr {$y-$sh/2}]
    171             set px [expr {$sx-$pw+3}]
    172             set py [expr {$y-$ph/2}]
    173 
    174             # make sure that the panel doesn't go off-screen
    175             if {$py < 0} { set py 0 }
    176             if {$py+$ph > $screenh} { set py [expr {$screenh-$ph}] }
    177             if {$px < 0} { set pw [expr {$pw+$px}]; set px 0 }
    178         }
    179         right {
    180             set sx $x
    181             set sy [expr {$y-$sh/2}]
    182             set px [expr {$x+$sw-3}]
    183             set py [expr {$y-$ph/2}]
    184 
    185             # make sure that the panel doesn't go off-screen
    186             if {$py < 0} { set py 0 }
    187             if {$py+$ph > $screenh} { set py [expr {$screenh-$ph}] }
    188             if {$px+$pw > $screenw} { set pw [expr {$screenw-$px}] }
    189         }
    190         above {
    191             set sx [expr {$x-$sw/2}]
    192             set sy [expr {$y-$sh+3}]
    193             set px [expr {$x-$pw/2}]
    194             set py [expr {$sy-$ph+3}]
    195 
    196             # make sure that the panel doesn't go off-screen
    197             if {$px < 0} { set px 0 }
    198             if {$px+$pw > $screenw} { set px [expr {$screenw-$pw}] }
    199             if {$py < 0} { set ph [expr {$ph+$py}]; set py 0 }
    200         }
    201         below {
    202             set sx [expr {$x-$sw/2}]
    203             set sy $y
    204             set px [expr {$x-$pw/2}]
    205             set py [expr {$y+$sh-3}]
    206 
    207             # make sure that the panel doesn't go off-screen
    208             if {$px < 0} { set px 0 }
    209             if {$px+$pw > $screenw} { set px [expr {$screenw-$pw}] }
    210             if {$py+$ph > $screenh} { set ph [expr {$screenh-$py}] }
    211         }
    212     }
    213     if {[info exists _masks($placement)]} {
    214         shape set $s -bound photo $_masks($placement)
    215     }
     313    foreach {place pw ph px py sx sy} [_place $where $placement $pw $ph $screenw $screenh] break
     314
     315    set s $_stems($place)
     316    if {[info exists _masks($place)]} {
     317        shape set $s -bound photo $_masks($place)
     318    }
     319
    216320    if { $pw < 1 || $ph < 1 }  {
    217321        # I really don't know why this is happenning.  I believe this occurs
     
    308412            #
    309413            #     --------  ---       LEFT STEM
    310             #    |..##    |  ^ 
     414            #    |..##    |  ^
    311415            #    |  ..##  |  |        . = light color
    312416            #    |    ..##|  | s      @ = dark color
  • trunk/gui/scripts/histogram.tcl

    r3330 r5592  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
    2  
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
     2
    33# ----------------------------------------------------------------------
    44#  COMPONENT: histogram - extracts data from an XML description of a field
     
    3737    protected method Build {}
    3838    private method Clear { {comp ""} }
    39     private method ParseData { comp } 
     39    private method ParseData { comp }
    4040
    4141    private variable _xmlobj ""  ;# ref to lib obj with histogram data
    4242    private variable _hist ""    ;# lib obj representing this histogram
    43     private variable _widths     ;# array of vectors of bin widths 
    44     private variable _yvalues    ;# array of vectors of bin heights along 
     43    private variable _widths     ;# array of vectors of bin widths
     44    private variable _yvalues    ;# array of vectors of bin heights along
    4545                                 ;# y-axis.
    46     private variable _xvalues    ;# array of vectors of bin locations along 
     46    private variable _xvalues    ;# array of vectors of bin locations along
    4747                                 ;# x-axis.
    4848    private variable _xlabels    ;# array of labels
     
    7474    # don't destroy the _xmlobj! we don't own it!
    7575    itcl::delete object $_hist
    76     Clear 
    77 }
    78 
    79 # ----------------------------------------------------------------------
    80 # USAGE: mesh 
     76    Clear
     77}
     78
     79# ----------------------------------------------------------------------
     80# USAGE: mesh
    8181#
    8282# Returns the vector for the histogram bin locations along the
     
    9191
    9292# ----------------------------------------------------------------------
    93 # USAGE: heights 
     93# USAGE: heights
    9494#
    9595# Returns the vector for the histogram bin heights along the y-axis.
     
    103103
    104104# ----------------------------------------------------------------------
    105 # USAGE: widths 
     105# USAGE: widths
    106106#
    107107# Returns the vector for the specified histogram component <name>.
     
    117117
    118118# ----------------------------------------------------------------------
    119 # USAGE: xlabels 
     119# USAGE: xlabels
    120120#
    121121# Returns the vector for the specified histogram component <name>.
     
    188188    }
    189189
    190     blt::vector create tmp 
     190    blt::vector create tmp
    191191    blt::vector create zero
    192192    foreach comp [array names _comphist] {
     
    257257            xdesc   xaxis.description
    258258            xunits  xaxis.units
    259             xorient xaxis.orientation 
     259            xorient xaxis.orientation
    260260            xscale  xaxis.scale
    261261            xmin    xaxis.min
     
    342342#       Parse the components data representations.  The following
    343343#       elements may be used <xy>, <xhw>, <namevalue>, <xvector>,
    344 #       <yvector>.  Only one element is used for data. 
     344#       <yvector>.  Only one element is used for data.
    345345#
    346346itcl::body Rappture::Histogram::ParseData { comp } {
     
    354354    if { $xydata != "" } {
    355355        set count 0
    356         foreach line [split $xydata \n] {
    357             if {[llength $line] == 2} {
    358                 foreach {name value} $line break
    359                 $_yvalues($comp) append $value
    360                 $_xvalues($comp) append $count
    361                 lappend _xlabels($comp) $name
    362                 incr count
    363             }
    364         }           
     356        foreach {name value} [regsub -all "\[ \t\n]+" $xydata { }] {
     357            $_yvalues($comp) append $value
     358            $_xvalues($comp) append $count
     359            lappend _xlabels($comp) $name
     360            incr count
     361        }
    365362        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    366363        return
     
    369366    if { $xhwdata != "" } {
    370367        set count 0
    371         foreach line [split $xhwdata \n] {
    372             set n [scan $line {%s %s %s} name h w]
    373             if {$n >= 2} {
    374                 lappend _xlabels($comp) $name
    375                 $_xvalues($comp) append $count
    376                 $_yvalues($comp) append $h
    377                 if { $n == 3 } {
    378                     $_widths($comp) append $w
    379                 }
    380                 incr count
    381             }
    382         }           
     368        foreach {name h w} [regsub -all "\[ \t\n]+" $xhwdata { }] {
     369            lappend _xlabels($comp) $name
     370            $_xvalues($comp) append $count
     371            $_yvalues($comp) append $h
     372            $_widths($comp) append $w
     373            incr count
     374        }
    383375        set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    384376        return
    385 
    386         # FIXME:  There must be a width specified for each bin location.
    387         #         If this isn't true, we default to uniform widths
    388         #         (zero-length _widths vector == uniform).
    389         if { [$_xvalues($comp) length] != [$_widths($comp) length] } {
    390             $_widths($comp) set {}
    391         }
    392         set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    393         return
    394     }
    395     set xv [$_hist get $comp.xvector]
    396     set yv [$_hist get $comp.yvector]
    397     if { $xv != "" && $yv != "" } {
    398         $_yvalues($comp) set $yv
    399         $_xvalues($comp) seq 0 [$yv length]
    400         set _xlabels($comp)
    401     }
     377    }
     378
     379    # If we reached here, must be <yvector>
     380    $_yvalues($comp) set [$_hist get ${comp}.yvector]
     381    $_xvalues($comp) length [$_yvalues($comp) length]
     382    $_xvalues($comp) seq 1 [$_yvalues($comp) length]
     383    set _xlabels($comp) [$_hist get ${comp}.xvector]
    402384    set _comp2hist($comp) [list $_xvalues($comp) $_yvalues($comp)]
    403385}
     
    422404    }
    423405    if { [info exists _widths($comp)] } {
    424         blt::vector destroy $_widths($comp) 
     406        blt::vector destroy $_widths($comp)
    425407    }
    426408    if { [info exists _yvalues($comp)] } {
    427         blt::vector destroy $_yvalues($comp) 
     409        blt::vector destroy $_yvalues($comp)
    428410    }
    429411    if { [info exists _xvalues($comp)] } {
    430         blt::vector destroy $_xvalues($comp) 
     412        blt::vector destroy $_xvalues($comp)
    431413    }
    432414    array unset _xvalues $comp
  • trunk/lang/python/README

    r3177 r5592  
    3838 Python scripts.
    3939
    40  Rappture applications load their data from a library object.  You can
    41  load a library as follows:
     40 Rappture applications load their data from a an XML driver file.
     41 In the tool.xml file, you should have something like
     42
     43 <command> @tool/path/to/executable @driver </command>
     44
     45The "@driver" pattern is replaced by the driver xml file generated by
     46Rappture.  This driver file will contain the values to use for the
     47parameters in your application.  See
     48https://nanohub.org/infrastructure/rappture/wiki/rappture_xml_elements
     49for more information.
     50
     51The first thing your application should do is load the driver file.
    4252
    4353   import Rappture
    44    lib = Rappture.library('example.xml')
    45    print lib.xml()
    46  
     54   rx = Rappture.PyXml('example.xml')
     55
     56You can see the xml contents by doing
     57   print rx.xml()
     58
    4759 The "import" statement loads the Rappture toolkit into your Python
    4860 application.  The next line creates a library object representing
     
    5466
    5567   import Rappture
    56    lib = Rappture.library('example.xml')
     68   lib = Rappture.PyXml('example.xml')
    5769   tval = lib.get('group(ambient).number(temp).current')
     70or alternatively
     71   tval = lib['group(ambient).number(temp).current'].value
    5872
    5973 The get() method follows a path through the XML.  In this example,
     
    6882
    6983   tval += 10
    70    lib.put('group(ambient).number(temp).current',str(tval))
     84   lib.put('group(ambient).number(temp).current', tval)
     85or
     86   lib[group(ambient).number(temp).current'] = tval
    7187
    7288 This changes the text within the <current>...</current> tag,
    73  replacing it with the new value.  Note that the value must be a
    74  string, so we use str(tval), rather than tval itself, when inserting
    75  a value.
     89 replacing it with the new value, converted to a string if necessary.
    7690
    7791 You can also append to an existing value.  For example,
     
    7993   lib.put('group(ambient).number(temp).current', 'more text', append=1)
    8094
    81  This adds the string 'more text' after the value (tval) within the
    82  <current>...</current> tag.
     95 This adds the string 'more text' after the value (tval) within the
     96 <current>...</current> tag.  Use of append in a loop is not
     97 recommended because it can be very slow.  It is faster to collect
     98 data in python and put it all at once.
    8399
    84  Suppose we wanted to add another number to the "ambient" group.
    85  We could do that by requesting "number#".  The # sign indicates
    86  that you'd like to create a new number element (number1, number2,
    87  etc.).  For example, we could add a number for a damping factor:
    88 
    89    lib.put('group(ambient).number#(damping).current','0.25')
    90 
    91  This creates a new element <number id="damping"> within
    92  <group id="ambient">, positioned just after the existing
    93  <number id="temp">.
  • trunk/lang/python/Rappture/PyRpLibrary.cc

    r3638 r5592  
    4848
    4949
    50 static int 
     50static int
    5151getArgCount(PyObject *args, PyObject *keywds, int *argc)
    5252{
     
    129129
    130130static int
    131 PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName, 
     131PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName,
    132132                  int *resultPtr)
    133133{
     
    147147        value = PyObject_IsTrue(objPtr);
    148148        if (value < 0) {
    149              PyErr_Format(PyExc_ValueError, 
     149             PyErr_Format(PyExc_ValueError,
    150150                "PyObjectToBoolean: bad boolean object");
    151151            return RP_ERROR;
     
    168168    } else if (PyString_Check(objPtr)) {
    169169        const char *string;
    170        
     170
    171171        string = PyString_AsString(objPtr);
    172172        if (string == NULL) {
     
    370370
    371371PyDoc_STRVAR(ElementProcDoc,
    372 "element ([path=\'\'][, as=\'object\']) -> returns string or Rappture Library Object\n\
     372"element ([path=\'\'][, type=\'object\']) -> returns string or Rappture Library Object\n\
    373373\n\
    374374Clients use this to query a particular element within the \n\
     
    381381By default, this method returns an object representing the \n\
    382382DOM node referenced by the path.  This is changed by setting \n\
    383 the \"as\" argument to \"id\" (for name of the tail element), \n\
     383the \"type\" argument to \"id\" (for name of the tail element), \n\
    384384to \"type\" (for the type of the tail element), to \"component\" \n\
    385385(for the component name \"type(id)\"), or to \"object\" \n\
     
    391391{
    392392    char* path = (char *)"";
    393     char* as = (char *)"object";
     393    char* type = (char *)"object";
    394394    RpLibrary* retlib = NULL;
    395395    PyObject* retVal = NULL;
     
    398398    static char *kwlist[] = {
    399399        (char *)"path",
    400         (char *)"as",
     400        (char *)"type",
    401401        NULL
    402402    };
     
    422422
    423423    if (!PyArg_ParseTupleAndKeywords(args, keywds, "|ss",
    424                 kwlist, &path, &as)) {
     424                kwlist, &path, &type)) {
    425425        /* incorrect input values */
    426426        // tested with ElementTests.testArguments_ArgsWrongType2()
    427         PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, as=\'object\'])");
     427        PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, type=\'object\'])");
    428428        return retVal;
    429429    }
     
    432432
    433433    if (retlib != NULL) {
    434         if ((as == NULL) || ((*as == 'o') && (strcmp("object",as) == 0)) ) {
     434        if ((type == NULL) || ((*type == 'o') && (strcmp("object",type) == 0)) ) {
    435435            // tested with ElementTests.testArguments_PathArg()
    436436            retVal = RpLibraryObject_FromLibrary(retlib);
    437         } else if ((*as == 'c') && (strcmp("component",as) == 0)) {
     437        } else if ((*type == 'c') && (strcmp("component",type) == 0)) {
    438438            // tested with ElementTests.testArguments_TwoArgs()
    439439            retVal = PyString_FromString(retlib->nodeComp().c_str());
    440         } else if ((*as == 'i') && (strcmp("id",as) == 0)) {
    441             // tested with ElementTests.testArguments_AsId()
     440        } else if ((*type == 'i') && (strcmp("id",type) == 0)) {
     441            // tested with ElementTests.testArguments_typeId()
    442442            retVal = PyString_FromString(retlib->nodeId().c_str());
    443         } else if ((*as == 't') && (strcmp("type",as) == 0)) {
    444             // tested with ElementTests.testArguments_AsKeywordArgs()
     443        } else if ((*type == 't') && (strcmp("type",type) == 0)) {
     444            // tested with ElementTests.testArguments_typeKeywordArgs()
    445445            retVal = PyString_FromString(retlib->nodeType().c_str());
    446         } else if ((*as == 'p') && (strcmp("path",as) == 0)) {
     446        } else if ((*type == 'p') && (strcmp("path",type) == 0)) {
    447447            // tested with ElementTests.testArguments_TwoKeywordArgs()
    448448            retVal = PyString_FromString(retlib->nodePath().c_str());
    449449        } else {
    450             // tested with ElementTests.testArguments_UnrecognizedAs()
     450            // tested with ElementTests.testArguments_Unrecognizedtype()
    451451            PyErr_Format(PyExc_ValueError,
    452                 "element() \'as\' arg must be \'object\' or \'component\' or \'id\' or \'type\' or \'path\'");
     452                "element() \'type\' arg must be \'object\' or \'component\' or \'id\' or \'type\' or \'path\'");
    453453        }
    454454    }
     
    649649        NULL
    650650    };
     651
    651652    appendFlag = compressFlag = FALSE;
    652653    strObjPtr = appendObjPtr = valueObjPtr = compressObjPtr = NULL;
     
    670671        return NULL;
    671672    }
    672     if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path, 
     673    if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path,
    673674        &valueObjPtr, &id, &appendObjPtr, &type, &compressObjPtr)) {
    674675        return NULL;
     
    690691    strObjPtr = PyObject_Str(valueObjPtr);
    691692    if (RpLibraryObject_IsValid(valueObjPtr)) {
    692         self->lib->put( std::string(path), 
     693        self->lib->put( std::string(path),
    693694                RpLibraryObject_AsLibrary(valueObjPtr), "", appendFlag);
    694695    } else if (strObjPtr != NULL) {
     
    704705                                std::string(string), "", appendFlag);
    705706            } else {
    706                 self->lib->putData( std::string(path), string, length, 
     707                self->lib->putData( std::string(path), string, length,
    707708                        appendFlag);
    708709            }
     
    755756
    756757    static char *kwlist[] = {
    757         (char *)"status", 
     758        (char *)"status",
    758759        NULL
    759760    };
  • trunk/lang/python/Rappture/__init__.py

    r790 r5592  
    11# Rappture package
    22from library import library
     3from pyxml import PyXml
    34from interface import interface
    45from number import number
     
    910import Utils
    1011import encoding
     12
     13# encoding/decoding flags
     14RPENC_Z   = 1
     15RPENC_B64 = 2
     16RPENC_ZB64 = 3
     17RPENC_RAW = 8
  • trunk/lang/python/Rappture/library.py

    r3177 r5592  
    4343
    4444    # ------------------------------------------------------------------
    45     def element(self, path="", as="object"):
     45    def element(self, path="", type="object"):
    4646        """
    4747        Clients use this to query a particular element within the
     
    5454        By default, this method returns an object representing the
    5555        DOM node referenced by the path.  This is changed by setting
    56         the "as" argument to "id" (for name of the tail element),
     56        the "type" argument to "id" (for name of the tail element),
    5757        to "type" (for the type of the tail element), to "component"
    5858        (for the component name "type(id)"), or to "object"
     
    6464            return None
    6565
    66         if as == 'object':
     66        if type == 'object':
    6767            return library(node)
    68         elif as == 'component':
     68        elif type == 'component':
    6969            return self._node2comp(node)
    70         elif as == 'id':
     70        elif type == 'id':
    7171            return self._node2name(node)
    72         elif as == 'type':
     72        elif type == 'type':
    7373            return node.tagName
    7474
    75         raise ValueError, "bad as value '%s': should be component, id, object, type" % as
    76 
    77     # ------------------------------------------------------------------
    78     def children(self, path="", as="object", type=None):
     75        raise ValueError, "bad type value '%s': should be component, id, object, type" % type
     76
     77    # ------------------------------------------------------------------
     78    def children(self, path="", type="object", rtype=None):
    7979        """
    8080        Clients use this to query the children of a particular element
    8181        within the entire data structure.  This is just like the
    8282        element() method, but it returns the children of the element
    83         instead of the element itself.  If the optional type argument
     83        instead of the element itself.  If the optional rtype argument
    8484        is specified, then the return list is restricted to children
    8585        of the specified type.
    8686
    8787        By default, this method returns a list of objects representing
    88         the children.  This is changed by setting the "as" argument
     88        the children.  This is changed by setting the "type" argument
    8989        to "id" (for tail names of all children), to "type" (for the
    9090        types of all children), to "component" (for the path component
     
    9999        nlist = [n for n in node.childNodes if not n.nodeName.startswith('#')]
    100100
    101         if type:
    102             nlist = [n for n in nlist if n.nodeName == type]
    103 
    104         if as == 'object':
     101        if rtype:
     102            nlist = [n for n in nlist if n.nodeName == rtype]
     103
     104        if type == 'object':
    105105            return [library(n) for n in nlist]
    106         elif as == 'component':
     106        elif type == 'component':
    107107            return [self._node2comp(n) for n in nlist]
    108         elif as == 'id':
     108        elif type == 'id':
    109109            return [self._node2name(n) for n in nlist]
    110         elif as == 'type':
     110        elif type == 'type':
    111111            return [n.tagName for n in nlist]
    112112
    113         raise ValueError, "bad as value '%s': should be component, id, object, type" % as
     113        raise ValueError, "bad type value '%s': should be component, id, object, type" % type
    114114
    115115    # ------------------------------------------------------------------
     
    276276
    277277        If you include "#" instead of a specific number, a node
    278         will be created automatically with a new number.  For example, 
     278        will be created automatically with a new number.  For example,
    279279        the path "foo.bar#" called the first time will create "foo.bar",
    280280        the second time "foo.bar1", the third time "foo.bar2" and
  • trunk/lang/python/Rappture/pyxml.py

    r5561 r5592  
    5454            val = ' '.join(map(str, val.ravel('F').tolist()))
    5555        elif type(val) == list or type(val) == tuple:
    56             val = ' '.join(map(str, (itertools.chain(*zip(*val)))))
     56            val = ' '.join(map(repr, (itertools.chain(*zip(*val)))))
     57            # we need the strings double quoted for tcl
     58            val = val.replace("'", '"')
    5759        self.lib.put(path, val, **kwargs)
    5860
  • trunk/lang/python/Rappture/unittest_library.py

    r3177 r5592  
    151151
    152152    def testToPathId(self):
    153         e = self.lib.element("input.string",as="object")
     153        e = self.lib.element("input.string", type="object")
    154154        self.lib.copy("estring(qqq)","",e)
    155155        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
     
    183183
    184184    def testToPathNoIdFromPathId(self):
    185         e = self.lib.element("input.string",as="object")
     185        e = self.lib.element("input.string",type="object")
    186186        self.lib.copy("estring","",e)
    187187        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
     
    241241
    242242    def testArguments_TwoKeywordArgs(self):
    243         ele = self.lib.element(path="input.string",as="path")
     243        ele = self.lib.element(path="input.string",type="path")
    244244        self.assertEqual(ele,"input.string(test)")
    245245
    246246    def testArguments_AsKeywordArgs(self):
    247         ele = self.lib.element("input.string",as="type")
     247        ele = self.lib.element("input.string",type="type")
    248248        self.assertEqual(ele,"string")
    249249
    250250    def testArguments_AsId(self):
    251         ele = self.lib.element(path="input.string",as="id")
     251        ele = self.lib.element(path="input.string",type="id")
    252252        self.assertEqual(ele,"test")
    253253
     
    477477
    478478    def testPutObject(self):
    479         e = self.lib.element("input.string",as="object")
     479        e = self.lib.element("input.string",type="object")
    480480        self.lib.put("output.estring(qqq)",e)
    481481        self.assertEqual(self.lib.get("output.estring(qqq).current"),'<sdfsfs>sdfs')
  • trunk/lang/python/setup.py.in

    r1584 r5592  
    4141                     'Rappture.signalHandler',
    4242                     'Rappture.tools',
    43                      'Rappture.result'],
     43                     'Rappture.result',
     44                     'Rappture.pyxml'],
    4445        ext_modules=[ encode_module,
    4546                      library_module,
Note: See TracChangeset for help on using the changeset viewer.