Name

Grid

tixGrid pathname [option value...]

The tixGrid command creates a new tixGrid widget named pathName. A tix-Grid widget presents a 2D grid of cells. Each cell may contain one Tix display item and can be formatted with a wide range of attributes.

Standard Options

-background

-borderwidth

-cursor

-font

-foreground

-highlightbackground

-highlightcolor

-highlightthickness

-padx

-pady

-relief

-selectbackground

-selectborderwidth

-selectforeground

-takefocus

-xscrollcommand

-yscrollcommand

 

Widget-Specific Options

-editdonecmd tclCommand (editDoneCmd, EditDoneCmd)

Command to call when the user has edited a grid cell. The column and row numbers of the cell are appended as arguments.

-editnotifycmd tclCommand (editNotifyCmd, EditNotifyCmd)

Command to call when the user tries to edit a grid cell. The column and row numbers of the cell are appended as arguments. The command should Return a boolean value to indicate whether the cell is editable.

-formatcmd tclCommand (formatCmd, FormatCmd)

Command to call when the grid cells need to be formatted on the screen. Five arguments are appended: Type x1 y1 x2 y2. type is the logical type of the region. It may be one of x-region (the horizontal margin), y-region (the vertical margin), s-region (area where margins are joined), or main (any other region). The last four arguments give the column and row numbers of the top left cell and bottom right cell of the af fected region.

-height integer (height, Height)

Number of rows in the grid. The default is 10.

-itemtype tclCommand (itemType, ItemType)

The default item type for a cell when set with the set method. The default is text.

-leftmargin integer (leftMargin, LeftMargin)

Number of cell columns, starting at column 0, that make up the vertical margin. The default is 1. Left margin columns are not scrolled.

-selectmode mode (selectMode, SelectMode)

Specifies one of several styles understood by the default bindings for manipulation of the selection. Supported styles are single, browse, multiple, and extended. Any arbitrary string is allowed, but the programmer must extend the bindings to support it.

-selectunit tclCommand (selectUnit, SelectUnit)

The unit of selection. Valid values are cell, column, or row.

-sizecmd tclCommand (sizeCmd, SizeCmd)

Command to call whenever the grid is resized or the size of a row or column is changed with the size method.

-state tclCommand (state, State)

Current state of the grid. Valid values are normal and disabled.

-topmargin tclCommand (topMargin, TopMargin)

Number of cell rows, starting from row 0, that make up the horizontal margin. The default is 1. Rows in the top margin are not scrolled.

-width integer (width, Width)

Number of columns in the grid. The default is 4.

Methods

pathName anchor operation [args...]

Manipulate the anchor cell of the grid. Available operations are:

clear

Make no cell the anchor cell.

get

Return the column and row of the anchor cell as a two-item list. A result of {−1 −1} indicates there is no anchor cell.

set x y

Set the anchor cell to the cell at column x and row y.

pathName delete what from [to]

Delete specified rows or columns. What may be row or column. If to is omitted, only the row (or column) at from is deleted. Otherwise, all rows (or columns) from position from through to, inclusive, are deleted.

pathName edit apply

Un-highlight any cell currently being edited and apply the changes.

pathName edit set x y

Highlight the cell at column x, row y for editing.

pathName entrycget x y option

Similar to the cget method, but operates on the cell at x y. Option may have any of the values accepted by the set method used for that cell.

pathName entryconfigure x y [option value...]

Similar to the configure method, but operates on the cell at x y. Option may have any of the values accepted by the set method for that cell.

pathName format borderType x1 y1 x2 y2 [option value...]

Format the grid cells contained in the rectangular region with its top left cell at x1,y1 and bottom right cell at x2,y2. This command can only be called from the format command handler set with the -formatcmd option. The borderType argument may be either border or grid. The following options are supported by both border types:

-background color (background, Background)

Background color for 3D borders when border type is border. When -filled is true, the background of the cell is also drawn in this color for both types. Otherwise, the tixGrid widget’s background color is used.

-borderwidth amount (borderWidth, BorderWidth)

Width of the border.

-filled boolean (filled, Filled)

Whether the -background and -selectbackground options should override the tixGrid widget’s options. The default is false.

-selectbackground color (selectBackground, Foreground)

The background color of the cell when it is selected. Used only when -filled is true.

-xon xon (xon, Xon)

Using the -xon, -xoff, -yon, and -yoff options, borders can be drawn around groups of cells. The given region is divided into subregions, starting from the top left cell, that are xon +xoff cells wide by yon +yoff cells high. Within this subregion, the border is drawn only around the rectangular regions in the top left corner that are xon cells wide and yon cells high. The default values are 1 for -xon and -yon and 0 for -xoff and -yoff, which results in borders being drawn around each individual cell.

-xoff xoff (xoff, Xoff)

See -xon.

-yon yon (yon, Yon)

See -xon.

-yoff yoff (yoff, Yoff)

See -xon.

When borderType is border, cell borders are standard Tk 3D borders. Available options are as follows:

-relief relief (relief, Relief)

3D effect for border.

When borderType is grid, cell borders are plain grid lines. Available options are as follows:

-anchor anchorPos (anchor, Anchor)

For grid lines, only one or two of the border’s sides are actually drawn. AnchorPos identifies on which sides of the rectangular region the grid lines are drawn. For example, ne states that grid lines are drawn on the top and right sides, whereas e states that a grid line is drawn only on the right side.

-bordercolor color (borderColor, BorderColor)

Color of the grid lines.

pathName info exists x y

Return a 1 if the cell at row x, column y contains a display item. Otherwise, return 0.

pathName move what from to offset

Move the specified rows or columns. What may be row or column. Move rows (or columns) from position from through to, inclusive, by the distance offset.

pathName nearest x y

Return the row and column of the cell nearest to coordinates x y inside the grid.

pathName set x y [-itemtype type] [option value. . .]

Create a new display item at row x, column y. If given, type specifies the type of the display item. Valid options are those allowed for the selected display item type. If a display item already exists in the cell, it will be deleted automatically.

pathName size what index [option value. . .]

Query or set the size of the row or column. What may be row or column. Index may be the integer position of the row (or column) or the string default, which sets the default size for all rows (or columns). Available options are as follows:

-pad0 pixels

Padding to the left of a column or the top of a row.

-pad1 pixels

Padding to the right of a column or the bottom of a row.

-size amount

Width of a column or height of a row. Amount may be a real number in screen units or one of the following:

auto

Autosize to largest cell in column or row.

default

Use the default size (10 times the average character widths for columns and 1.2 times the average character height for rows).

nchar

Set the size to n times the average character width for columns and n times the average character height for rows.

pathName unset x y

Remove the display item from the cell at row x, column y.

pathName xview

Return a two-element list describing the currently visible horizontal region of the widget. The elements are real numbers representing the fractional distance that the view’s left and right edges extend into the horizontal span of the widget. Columns in the left margin are not part of the scr ollable region.

pathName xview moveto fraction

Adjust the visible region of the widget so that the point indicated by fraction along the widget’s horizontal span appears at the region’s left edge.

pathName xview scroll number what

Horizontally scroll the visible columns outside the left margin by number. If what is units, then number is in units of columns. If what is pages, then number isi in units of the visible region’s width.

pathName yview

Return a two-element list describing the currently visible vertical region of the widget. The elements are real numbers representing the fractional distance that the view’s top and bottom edges extend into the vertical span of the widget. Rows in the top margin are not part of the scrollable region.

pathName yview moveto fraction

Adjust the visible region of the widget so that the point indicated by fraction along the widget’s vertical span appears at the region’s top edge.

pathName yview scroll number what

Vertically scroll the visible rows outside the top margin by number. If what is units, then number is in units of rows. If what is pages, then number is in units of the visible region’s height.

Example

proc SimpleFormat {w area x1 y1 x2 y2} {
  array set bg {s-margin gray65 x-margin gray65 
      y-margin gray65 main gray20 }
  case $area {
    main { $w format grid $x1 $y1 $x2 $y2 -anchor se -fill 0 
                -relief raised -bd 1 -bordercolor $bg($area)
    }
    {x-margin y-margin s-margin} {
           $w format border $x1 $y1 $x2 $y2 
                -fill 1 -relief raised -bd 1 -bg $bg($area)
        }
    }
}
set grid [[tixScrolledGrid .sg -bd 0] subwidget grid]
$grid configure -formatcmd "SimpleFormat $grid"
for {set x 0} {$x < 10} {incr x} {
    $grid size col $x -size auto
    for {set y 0} {$y < 10} {incr y} {
        $grid set $x $y -itemtype text -text ($x,$y)
    }
}
$grid size col 0 -size 10char
pack .sg -expand true -fill both
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset