TixGrid(3pm)
π Tk::TixGrid β the TixGrid era π
okay bestie, sit down, hydrate, because we're about to talk about Tk::TixGrid, from the TixGrid(3pm) page (User Contributed Perl Documentation, iykyk). This is part 1 and it's giving main character widget energy.
β¨ NAME β¨
Tk::TixGrid β create and manipulate Tix Grid widgets. that's the whole vibe. π«Ά
πΈ SYNOPSIS πΈ
$tixgrid = $parent->TixGrid?(options)?;
that's it. that's the whole spell. look at her go β¨
π¦ DESCRIPTION π¦
so basically this widget is the blueprint for "spread sheet"-coded interfaces β the whole point is that it shows its content in a two-dimensional "grid" of cells, like a little spreadsheet situation but make it Perl/Tk. π₯
every single cell can hold one Tix display item, and that item can be in text, graphics, or other formats. if you wanna know more about Tix display items, go read Tk::DItem β she has the lore. because these "items" don't have to be "windows", you can handle huge grids without devouring all of your display system resources. no cap. it's actually so efficient of her. π
individual cells, or whole groups of cells, can be formatted with a wide range of attributes β color, relief, border, the whole glam routine. BUT. and this is the tea β β because the widget is built to handle large grids, the mechanisms to pull that off are lower level and way more callback-oriented than other widgets. the assumption here is that to avoid storing display details for a giant number of cells, the data gets re-computed as needed. so it's lazy in the most iconic way possible. β¨
now, real talk: the port of the Tix C code and some of the bindings to perl/Tk is done, but it still needs further work. π§ in several places the intent of the Tix code isn't understood yet β like, for example, the 'edit' interface is clearly intended for spread-sheet-like cell content editing in an auxillary "entry" widget or similar, but how that should actually work is not yet clear. so we're all just vibing with the mystery. π
the TixGrid method creates a new TixGrid window and returns a blessed reference of this TixGrid widget. extra options (described below, keep scrolling bestie) may be specified on the command line or in the option database to configure aspects of the TixGrid widget. π
π STANDARD OPTIONS π
here's the classic lineup, the standard-issue queens:
-background -borderwidth -cursor -font -foreground
-height -highlightbackground -highlightcolor
-highlightthickness -padx -pady -relief
-selectbackground -selectborderwidth -selectforeground
-state -takefocus -width -xscrollcommand
-yscrollcommand
for the details of these standard options, go peek at Tk::options. she explains all of them, slay. π
π WIDGET-SPECIFIC OPTIONS π
these are the options that make TixGrid her. π
- Name:
browseCmdβ Class:BrowseCmdβ Switch:-browsecmd
if you define this, it gives you a perl/Tk callback that fires when the user browses a grid cell (normally that's when the user clicks on an entry). when this callback gets called, it's passed two additional parameters: x y, where (x,y) is the location of the cell that just got clicked. so you always know exactly which little cell caught the vibe. π
- Name:
Commandβ Class:Commandβ Switch:-command
if you define this, it gives you a perl/Tk callback that fires when the user double-clicks a grid cell. when it's called, it gets two additional parameters: x y, where (x,y) is the location of the cell that just got clicked. double-click behavior, unlocked. π₯
- Name:
editDoneCmdβ Class:EditDoneCmdβ Switch:-editdonecmd
if you define this, it gives you a perl/Tk callback that fires when the user has edited a grid cell. when it's called, it gets two additional parameters: x y, where (x,y) is the location of the cell that just got edited. so it's the little "ok done, edited βοΈ" notification of your dreams.
- Name:
editNotifyCmdβ Class:EditNotifyCmdβ Switch:-editnotifycmd
if you define this, it gives you a perl/Tk callback that fires when the user tries to edit a grid cell. when it's called, it gets two additional parameters: x y, where (x,y,) is the location of the cell. this callback should return a boolean value: true means the cell is editable, false means it is not. yes, she's asking permission first. consent queen. π«Ά
- Name:
FloatingColsβ Class:floatingColsβ Switch:-floatingcols
defines the number of extra columns beyond the existing grid that can be brought into view by scrolling. extra columns, on demand. β¨
- Name:
FloatingRowsβ Class:floatingRowsβ Switch:-floatingrows
defines the number of extra rows beyond the the existing grid that can be brought into view by scrolling. yes, the original says "the the". we don't fix, we stan. π
- Name:
formatCmdβ Class:FormatCmdβ Switch:-formatcmd
if you define this, it gives you a perl/Tk callback that fires when the grid cells need to be displayed on the screen. its primary purpose is to draw the background of the region before the cells get rendered on top. normally you'd achieve that by calling formatGrid or formatBorder (see below, bestie). but other uses can be made of this low-level callback β for example, it can be used to "lazily" populate the grid by calling the set method only as cells come into view. lazy-populate icon behavior, honestly. πΈ
when this callback is called, it's passed five additional parameters: type x1 y1 x2 y2.
x1 y1 x2 y2 gives the extent of the region that needs formatting.
type gives the logical type of the region in the grid. it may be one of the following:
x_marginβ the horizontal margin.y_marginβ the vertical margin.s_marginβ the area in the top left corner where the horizontal and vertical margins are joined.mainβ the main body, i.e. all the cells that do not fall into the above three types.
- Name:
leftMarginβ Class:LeftMarginβ Switch:-leftmargin
gives the width of vertical margin in cells (columns). a zero indicates that no vertical margin exists. a positive value N indicates that the first N columns are "labels" and are always displayed and not scrolled. they're the frozen-header queens, they never leave. π
- Name:
itemTypeβ Class:ItemTypeβ Switch:-itemtype
default item type for cells. simple, clean, iconic.
- Name:
selectModeβ Class:SelectModeβ Switch:-selectmode
specifies one of several styles for manipulating the selection. the value of the option may be arbitrary, but the default bindings expect it to be either single, browse, multiple, or extended; the default value is single. pick your fighter. π
- Name:
selectUnitβ Class:SelectUnitβ Switch:-selectunit
specifies the selection unit. valid values are cell, column or row. so you can select like a little individual cell, or go full column, or full row. range of drama available. π
- Name:
sizeCmdβ Class:SizeCmdβ Switch:-sizecmd
callback is called (with no extra arguments) when grid sizes are re-computed. for example if the window changes size, a different font is specified, etc. it's called just after scrollbars (if present) are updated. so the order is: scrollbars get their glow-up first, then this callback. noted, bestie. π
- Name:
topMarginβ Class:TopMarginβ Switch:-topmargin
gives the width of horizontal margin in cells (rows). a zero indicates that no horizontal margin exists. a positive value N indicates that the first N rows are "labels" and are always displayed and not scrolled. frozen top rows, forever holding it down. β
okay that's part 1 and there's still more coming, so don't go anywhere β the rest of the glow-up is on the way. πβ¨
π WIDGET METHODS π
okay so the TixGrid method makes a TixGrid widget and hands you back a blessed reference to it. π That reference is literally your key to doing stuff to the widget, and it's got one general shape:
$tixgrid->method?(arg, arg, ...)?
the args decide exactly how the method behaves, bestie. no cap.
This object also supports the configure and cget methods from Tk::options, which you can use to peek at and change the options we talked about earlier. It also inherits everything from the generic Tk::Widget class. π«Ά
And here are the extra methods you get with TixGrid widgets:
$tixgrid->anchorGet(x, y)$tixgrid->anchorSet(x, y)$tixgrid->anchorClearβ these three mess with the anchor cell of the TixGrid widget. The anchor cell is the end of the selection that stays fixed while the user drags out a selection with the mouse. π($bd,$col,$row) = $tixgrid->bdtype(x,y ?,xDelta,yDelta?)β figures out whether the screen (pixel) positionx,yis sitting in a border. super useful for changing the mouse cursor when the user points at a border β like, to hint that the border can be adjusted interactively. π
If you are in a border, you get back a list of three elements. The first one is 'xy', 'x' or 'y', and the next two are integers. (What those values actually mean is not understood β they seem to indicate which column and row of the border the screen position corresponds to?)
If you're not in a border, you get an empty list. π
$tixgrid->delete(dim, from?, to?)$tixgrid->deleteColumn(from?, to?)$tixgrid->deleteRow(from?, to?)βdimcan beroworcolumn. Iftoisn't given, it deletes a single row (or column) at positionfrom. Iftois given, it deletes the whole range of rows (or columns) from positionfromthroughto. π gone. deleted.$tixgrid->dragsite(option, x, y)$tixgrid->dropsite(option, x, y)β Tcl/Tix has (or was going to have) Drag&Drop support. What this means for perl/Tk is not clear yet. π$tixgrid->editApplyβ if any cell is being edited, it de-highlights the cell and applies the changes. β¨$tixgrid->editSet(x, y)β highlights the cell at(x,y)for editing, but only if the-editnotifycallback returns true for this cell.$tixgrid->entrycget(x, y, '-option')$tixgrid->entryconfigure(x, y?, -option??=>value, -option=>value, ...?)β these give you a configure-style interface to cells in the grid. The-optionsyou can use depend on the item type of the cell. π¦$tixgrid->formatBorder(x1,y1, x2,y2, options);$tixgrid->formatGrid(x1,y1, x2,y2, options);β theformatBorderandformatBordermethods can only be called by the-formatcmdcallback of the tixGrid widget. They draw the background of the region described byx1,y1, x2,y2according to the options you supply. One call to the-formatcmdcallback can make multiple calls toformatBorderand/orformatBorderfor different sub-regions. π¨
formatBorder draws the background using Tk relief style; formatGrid also draws grid lines between the cells. It only makes sense to call one or the other for a particular sub-region, since one will over-write the other.
The options allowed are:
-background/-bg-borderwidth/-bd-filled-relief-selectbackground-xoff-xon-yoff-yon
The -xon/-xoff and -yon/-yoff options are obscure. If anyone can figure out how to do something interesting given what pTk/tixGrFmt.c is doing with them please let Nick know!. π
$tixgrid->geometryinfo(?width, height?)β returns a list of four values β two sets of two floating point numbers. First set is the scrollbar fractions for the x direction, second set is the scrollbar fractions for the y direction. Ifwidthandheightare specified then the fractions are based on as if the window size was of the specified size (in pixels, but not allowing normal GetPixels units). Otherwise the fractions are based on the current size of the window.
Usage obscure. π
$tixgrid->index(xcoord, ycoord)β returns(x, y)of the entry at position($coordx, $coordy). Either coordinate may be'max', which is the largest existing entry in that direction;'end', which is one beyond the largest existing entry; or a number. (This is how you find out how big the grid is.) π$tixgrid->infoBbox(x,y)β returns the pixel bounding box of the cell atx,y.$tixgrid->infoExists(x,y)β returns true if there's an item in the cell atx,y. It throws an exception (dies π) ifx,yis outside the grid β this may change (Nick doesn't like it).$tixgrid->move(dim, from, to, offset)$tixgrid->moveColumn(from, to, offset)$tixgrid->moveRow(from, to, offset)βdimmay beroworcolumn. Moves the range of rows (or columns) from positionfromthroughtoby the distance indicated byoffset. For example,$tixgrid->moveRow(2, 4, 1)moves the rows 2,3,4 to rows 3,4,5. π$tixgrid->nearest(x, y)β screen pos (pixels) to entry(nx,ny)translation.$tixgrid->selectionAdjust(x1, y1 ?,x2, y2?)$tixgrid->selectionClear(x1, y1 ?,x2, y2?)$tixgrid->selectionIncludes(x1, y1 ?,x2, y2?)$tixgrid->selectionSet(x1, y1 ?,x2, y2?)$tixgrid->selectionToggle(x1, y1 ?,x2, y2?)β selection support methods β probably buggy. π
x1 (y1) has not to be greater than x2 (y2), but only x2 and y2 can be 'max'.
BUG: selectionIncludes: has no visible effect (as in Tix). Eh???
BUG:selectionClear: only works for0, 0, max, max(as in Tix). Eh???
When x2, y2 are not given they default to x1, y1, respectively.
$tixgrid->set(x, y?, -itemtype=>type??, -option=>value, ...?)β creates a new display item at the cell at(x,y). The optional-itemtypeparameter gives the type of the display item. An additional list of option-value pairs specify options of the display item. If a display item already exists at this cell, the old item will be deleted automatically. πΈ$tixgrid->size(dim, index?, -option??=>value, ...?)$tixgrid->sizeColumn(index?, -option??=>value, ...?)$tixgrid->sizeRow(index?, -option??=>value, ...?)β queries or sets the size of the row or column given bydimandindex.Dimmay beroworcolumn.Indexmay be any non-negative integer that gives the position of a given row (or column).Indexcan also be the stringdefault; in this case, this method queries or sets the default size of all rows (or columns). When no option-value pair is given, this method returns a list containing the current size setting of the given row (or column). When option-value pairs are given, the corresponding options of the size setting of the given row are changed.-optionmay be one of the following:-pad0=> pixels β Specifies the paddings to the left of a column or the top of a row.-pad1=> pixels β Specifies the paddings to the right of a column or the bottom of a row.-size=> val β Specifies the width of a column or the height of a row.Valmay be:autoβ the width of the column is set the widest cell in the column; a valid Tk screen distance unit (seeTk_GetPixels); or a real number following by the wordchars(e.g.3.4chars) that sets the width of the column to the given number of characters. π
$tixgrid->sort(dimension, start, end, ?args ...?)β?docu here?(not supported on Win* OSs up to now)$tixgrid->unset(x, y)β clears the cell at(x,y)by removing its display item. π§Ή$tixgrid->xviewβ Normal horizontal scrollbar method.$tixgrid->yviewβ Normal vertical scrollbar method.
π BINDINGS π
To be done β only the most obvious basic bindings work. The Tcl/Tix code was coded as a "state machine" which is not easy to follow. π iykyk.
π¦ SEE ALSO π¦
Tk::DItem Tk::callbacks Tk::FloatEntry
π BUGS π
Tcl/Tix was/is not finished and both the C code and the bindings of TixGrid have some bugs. π periodt.
β KEYWORDS β
tix, tixgrid, table, display item, spreadsheet
okay bestie that's the whole thing!! π this page ships with perl v5.40.1 and is dated 2025-04-13, so go forth and grid responsibly, you absolute icon πβ¨π«Ά
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms