Overview of Item Types
grid
sub-command. Note that rows and columns start from the top left corner of the grid (as in the Tk grid). The complete grid sub-command is described in this section.Grids are created with widget commands of the following form:
pathName create grid [slaves...]Grid creation is slightly different from creation of other pad objects. Instead of the normal command-line option-value pairs a list of slaves and their grid configuration can be specified (see the section below on sub-commands and slave configuration). Grids are special group objects and inherit much of the group functionality and support the "-divisible" option which can be set (using itemconfigure) once the grid is created:
-divisible
[16] True if events go through a group to its members
pathName grid slave [slave...] option value [option value...] pathName grid command arg [arg...]If the first argument of the grid command is a slave object then the remainder of the command line is processed in the same way as the grid configure command. The "-in" option can be used to add a slave to a grid. The following grid sub-commands are allowed:
$PAD grid arrange master
$PAD grid bbox master column row
$PAD grid columnconfigure master index [-option value...]
$PAD grid configure slave [slave ...] [options]
Insert the slave so that it occupies the nth column in the grid. Column numbers start with 0. If this option is not supplied, then the slave is arranged just to the right of previous slave specified on this call to grid, or column "0" if it is the first slave. For each x that immediately precedes the slave, the column position is incremented by one. Thus the x represents a blank column for this row in the grid.
Insert the slave so that it occupies n columns in the grid. The default is one column, unless the slave is followed by a -, in which case the columnspan is incremented once for each immediately following -.
Insert the slave(s) in the grid object given by other (which must be an existing grid).
The amount specifies how much horizontal external padding to leave on each side of the slave(s). The amount defaults to 0.
The amount specifies how much vertical external padding to leave on the top and bottom of the slave(s). The amount defaults to 0.
Insert the slave so that it occupies the nth row in the grid. Row numbers start with 0. If this option is not supplied, then the slave is arranged on the same row as the previous slave specified on this call to grid, or the first unoccupied row if this is the first slave.
Insert the slave so that it occupies n rows in the grid. The default is one row. If the next grid command contains ^ characters instead of slaves that line up with the columns of this slave, then the rowspan of this slave is extended by one.
If a slave's parcel is larger than its requested dimensions, this option may be used to position (or stretch) the slave within its cavity. Style is a string that contains zero or more of the characters n, s, e or w. The string can optionally contains spaces or commas, but they are ignored. Each letter refers to a side (north, south, east, or west) that the slave will "stick" to. If both n and s (or e and w) are specified, the slave will be stretched to fill the entire height (or width) of its cavity. The sticky option subsumes the combination of -anchor and -fill that is used by pack. The default is {}, which causes the slave to be centered in its cavity, at its requested size.
$PAD grid forget slave [slave ...]
$PAD grid info slave
$PAD grid location master x y
$PAD grid rowconfigure master index [-option value...]
$PAD grid size master
$PAD grid slaves master [-option value]
When no column or row information is specified for a slave, default values are chosen for column, row, columnspan and rowspan at the time the slave is managed. The values are chosen based upon the current layout of the grid, the position of the slave relative to other slaves in the same grid command, and the presence of the characters -, ^, and ^ in grid command where slave names are normally expected.
arrange
command for forcing grid arrangement.
set obj1 [.pad create rectangle 0 0 50 50] set obj2 [.pad create rectangle 50 50 100 100] set obj3 [.pad create rectangle 100 100 150 150] set obj4 [.pad create rectangle 150 150 200 200] set thegrid [.pad create grid $obj1 $obj2 -padx 10 -pady 10] .pad grid $obj3 $obj4 -in $thegrid -row 1 -padx 10 -pady 102) read objects from pad files in a directory and place them in a Nx2 grid (this can be useful for creating palettes):
proc read_files {PAD dir} { set objs "" # Go though list of files foreach file [glob $dir/*.pad] { # Read file and put all its object in a group (Pad_ObjectList will be # set to list of objects read from file). $PAD read $file set group [$PAD create group -members $Pad_ObjectList] lappend objs $group } return $objs } proc create_palette {PAD objs} { # Create the grid object set thegrid [$PAD create grid] set row 0 set col 0 # Go through objects and place them two per row foreach obj $objs { # Add obj to the grid $PAD grid $obj -in $thegrid -row $row -column $col -padx 10 -pady 5 # Set row and column position for next object if {$col == 0} { incr col } else { set col 0 incr row } } # Have the grid arrange itself now $PAD grid arrange $thegrid return $thegrid } create_palette .pad [read_files .pad $env(PADHOME)/draw/scrapbook]Alternatively,
proc create_palette {PAD objs} { # create the grid object set thegrid [$PAD create grid] # go through list of objects and place them two per row set numobjs [llength $objs] for {set i 0} {$i < $numobjs} {incr i 2} { set obj1 [lindex $objs $i] if {$i < [expr $numobjs-1]} { set obj2 [lindex $objs [expr $i+1]] } else { set obj2 "" } $PAD grid $obj1 $obj2 -in $thegrid -padx 10 -pady 5 } $PAD grid arrange $thegrid return $thegrid } create_palette .pad [read_files .pad $env(PADHOME)/draw/scrapbook]3) Draw horizontal and vertical grid lines and a bounding rectangle for an existing grid. Make a group for the line objects and the existing grid. Assume the grid is a normal MxN table (i.e. all rows have N columns and all columns have M rows).
proc create_gridlines { PAD thegrid } { # Get bounding box, width and height and location of the grid set gbbox [$PAD bbox $thegrid] set gwidth [expr [lindex $gbbox 2] - [lindex $gbbox 0]] set gheight [expr [lindex $gbbox 3] - [lindex $gbbox 1]] set gx [lindex $gbbox 0] set gy [lindex $gbbox 1] # Get number of rows and columns set numrows [lindex [$PAD grid size $thegrid] 1] set numcols [lindex [$PAD grid size $thegrid] 0] # Create the bounding rectangle set grect [eval $PAD create rectangle $gbbox] set items "$grect" set scale [$PAD scale $thegrid] # Create horizontal lines by looking at the <r, 0> grid elemments. for {set r 1} {$r < $numrows} {incr r} { # Get location of the <r, 0> element (including padding) set rinfo [$PAD grid bbox $thegrid 0 $r] set x1 [expr [lindex $rinfo 0]*$scale + $gx] # Transform the y coord for pad (grid's is from top left corner) set y1 [expr ($gheight - [lindex $rinfo 1]*$scale) + $gy] set x2 [expr $x1 + $gwidth] set y2 $y1 lappend items [$PAD create line $x1 $y1 $x2 $y2 -tags gridrowline_$thegrid] } # Draw vertical lines by looking at the <0, c> elements for {set c 1} {$c < $numcols} {incr c} { set cinfo [$PAD grid bbox $thegrid $c 0] set x1 [expr [lindex $cinfo 0]*$scale + $gx] set y1 [expr ($gheight - [lindex $cinfo 1]*$scale) + $gy] set x2 $x1 set y2 [expr $y1 - $gheight] lappend items [$PAD create line $x1 $y1 $x2 $y2 -tags gridcolline_$thegrid] } # Create a group for all the grid lines set glines [$PAD create group -members $items -divisible 0 \ -tags gridlines_$thegrid] # Create a group for the lines and the grid set newgrp [$PAD create group -members "$glines $thegrid" -tags grid_$thegrid \ -divisible 1] return $newgrp } set thegrid [create_palette .pad [read_files .pad ./draw/scrapbook]] create_gridlines .pad $thegrid
Copyright Computer Science Department, The University of New Mexico