TableMatrix(3)
π TableMatrix(3) π
bestie, this is the User Contributed Perl Documentation page for TableMatrix β the widget that creates and manipulates tables. It's giving "let me organize your cells and make it look cute," and we are going through every single detail. π
π NAME π
TableMatrix β create and manipulate tables.
β¨ Synopsis β¨
Okay so the whole thing starts here, and yes, the code is staying exactly as it is:
$table = $parent->TableMatrix(?options?);
π STANDARD OPTIONS π
These are the standard Tk options this widget rolls with β all of them, no cap:
-anchor-background-cursor-exportselection-font-foreground-highlightbackground-highlightcolor-highlightthickness-insertbackground-insertborderwidth-insertofftime-insertontime-insertwidth-invertselected-relief-takefocus-xscrollcommand-yscrollcommand
π Widget-specific Options π
These are the options that are so TableMatrix, literally its main character energy. Each one comes with its Switch, Name, and Class, and I'm keeping every single one. π«Ά
-autoclearβ Switch:-autoclearΒ· Name:autoClearΒ· Class:AutoClear. A boolean value that says whether the first keypress in a cell will delete whatever text was previously there. Defaults to0.-bordercursorβ Switch:-bordercursorΒ· Name:borderCursorΒ· Class:Cursor. Specifies the name of the cursor to show when over borders β a visual little hint that interactive resizing is allowed, so it's affected by the value of-resizeborders. Defaults tocrosshair.-borderwidth,-bdβ Switch:-borderwidthor-bdΒ· Name:borderWidthΒ· Class:BorderWidth. Specifies a non-negative pixel value or list of values indicating the width of the 3-D border to draw on interior table cells (if such a border is being drawn; the<Brelief>option typically determines this). If one value is specified, a rectangle of this width will be drawn. If two values are specified, then only the left and right edges of the cell will have borders. If four values are specified, then the values correspond to the{left right top bottom}edges. This can be overridden by a tag'sborderwidthoption. It can also be affected by the defined-drawmodefor the table. Each value in the list must have one of the forms acceptable toTk_GetPixels.-browsecommand,-browsecmdβ Switch:-browsecommandor-browsecmdΒ· Name:browseCommandΒ· Class:BrowseCommand. Specifies a command (callback) that will be evaluated anytime the active cell changes. The Previous Index and the Current index is passed to this command as arguments.-cacheβ Switch:-cacheΒ· Name:cacheΒ· Class:Cache. A boolean value that specifies whether an internal cache of the table contents should be kept. This greatly enhances speed performance when used with-commandbut uses extra memory. Can maintain state when both-commandand-variableare empty. The cache is automatically flushed whenever the value of-cacheor-variablechanges, otherwise you have to explicitly callclearon it. Defaults to off.-coloriginβ Switch:-coloriginΒ· Name:colOriginΒ· Class:Origin. Specifies what column index to interpret as the leftmost column in the table. This value is used for user indices in the table. Defaults to0.-colsβ Switch:-colsΒ· Name:colsΒ· Class:Cols. Number of cols in the table. Defaults to10.-colseparatorβ Switch:-colseparatorΒ· Name:colSeparatorΒ· Class:Separator. Specifies a separator character that will be interpreted as the column separator when cutting or pasting data in a table. By default, columns are separated as elements of a tcl list.-colstretchmodeβ Switch:-colstretchmodeΒ· Name:colStretchModeΒ· Class:StretchMode. Specifies one of the following stretch modes for columns to fill extra allocated window space:noneβ Columns will not stretch to fill the assigned window space. If the columns are too narrow, there will be a blank space at the right of the table. This is the default.unsetβ Only columns that do not have a specific width set will be stretched.allβ All columns will be stretched by the same number of pixels to fill the window space allocated to the table. This mode can interfere with interactive border resizing which tries to force column width.lastβ The last column will be stretched to fill the window space allocated to the table.fillβ (only valid for-rowstretchcurrently) The table will get more or less columns according to the window space allocated to the table. This mode has numerous quirks and may disappear in the future.
-coltagcommandβ Switch:-coltagcommandΒ· Name:colTagCommandΒ· Class:TagCommand. Provides the name of a procedure that will be evaluated by the widget to determine the tag to be used for a given column. When displaying a cell, the table widget will first check to see if a tag has been defined using thetag colwidget method. If no tag is found, it will evaluate the named procedure passing the column number in question as the sole argument. The procedure is expected to return the name of a tag to use, or a null string. Errors occurring during the evaluation of the procedure, or the return of an invalid tag name are silently ignored.
The Current column number is passed as an argument to the col command.
-colwidthβ Switch:-colwidthΒ· Name:colWidthΒ· Class:ColWidth. Default column width, interpreted as characters in the default font when the number is positive, or pixels if it is negative. Defaults to10.-commandβ Switch:-commandΒ· Name:commandΒ· Class:Command. Specified a command to use as a procedural interface to cell values. If-usecommandis true, this command will be used instead of any reference to the-variablearray. When retrieving cell values, the return value of the command is used as the value for the cell.
Args passed to this callback: The Set Flag (=1 if setting, else retrieving), the current row, the current col, the cell value (if setting).
-drawmodeβ Switch:-drawmodeΒ· Name:drawModeΒ· Class:DrawMode. Sets the table drawing mode to one of the following options:slowβ The table is drawn to an offscreen pixmap using the Tk bordering functions (double-buffering). This means there will be no flashing, but this mode is slow for larger tables.compatibleβ The table is drawn directly to the screen using the Tk border functions. It is faster, but the screen may flash on update. This is the default.fastβ The table is drawn directly to the screen and the borders are done with fast X calls, so they are always one pixel wide only. As a side effect, it restricts-borderwidthto a range of0or1. This mode provides best performance for large tables, but can flash on redraw and is not 100% Tk compatible on the border mode.singleβ The table is drawn to the screen as in fast mode, but only single pixel lines are drawn (not square borders).
-flashmodeβ Switch:-flashmodeΒ· Name:flashModeΒ· Class:FlashMode. A boolean value that specifies whether cells should flash when their value changes. The table tagflashwill be applied to these cells for the duration specified by-flashtime. Defaults to0.-flashtimeβ Switch:-flashtimeΒ· Name:flashTimeΒ· Class:FlashTime. The amount of time, in 1/4 second increments, for which a cell should flash when its value has changed.-flashmodemust be on. Defaults to2.-heightβ Switch:-heightΒ· Name:heightΒ· Class:Height. Specifies the desired height for the window, in rows. If zero or less, then the desired height for the window is made just large enough to hold all the rows in the table. The height can be further limited by-maxheight.-invertselectedβ Switch:-invertselectedΒ· Name:invertSelectedΒ· Class:InvertSelected. Specifies whether the foreground and background of an item should simply have their values swapped instead of merging theseltag options when the cell is selected. Defaults to0(mergeseltag).-ipadxβ Switch:-ipadxΒ· Name:ipadXΒ· Class:Pad. A pixel value specifying the internal offset X padding for text in a cell. This value does not grow the size of the cell, it just causes the text to be drawn further from the cell border. It only affects one side (depending on anchor). Defaults to0. See-padxfor an alternate padding style.-ipadyβ Switch:-ipadyΒ· Name:ipadYΒ· Class:Pad. A pixel value specifying the internal offset Y padding for text in a cell. This value does not grow the size of the cell, it just causes the text to be drawn further from the cell border. It only affects one side (depending on anchor). Defaults to0. See-padyfor an alternate padding style.-justifyβ Switch:-justifyΒ· Name:justifyΒ· Class:Justify. How to justify multi-line text in a cell. It must be one ofleft,right, orcenter. Defaults toleft.-maxheightβ Switch:-maxheightΒ· Name:maxHeightΒ· Class:MaxHeight. The max height in pixels that the window will request. Defaults to600.-maxwidthβ Switch:-maxwidthΒ· Name:maxWidthΒ· Class:MaxWidth. The max width in pixels that the window will request. Defaults to800.-multilineβ Switch:-multilineΒ· Name:multilineΒ· Class:Multiline. Specifies the default setting for the multiline tag option. Defaults to1.-padyβ Switch:-padyΒ· Name:padXΒ· Class:Pad. A pixel value specifying the offset X padding for a cell. This value causes the default size of the cell to increase by two times the value (one for each side), unless a specific pixel size is chosen for the cell with thewidthcommand. This will force an empty area on the left and right of each cell edge. This padding affects all types of data in the cell. Defaults to0. See-ipadxfor an alternate padding style.-padyβ Switch:-padyΒ· Name:padYΒ· Class:Pad. A pixel value specifying the offset Y padding for a cell. This value causes the default size of the cell to increase by two times the value (one for each side), unless a specific pixel size is chosen for the cell with theheightcommand. This will force an empty area on the top and bottom of each cell edge. This padding affects all types of data in the cell. Defaults to0. See-ipadxfor an alternate padding style.-resizebordersβ Switch:-resizebordersΒ· Name:resizeBordersΒ· Class:ResizeBorders. Specifies what kind of interactive border resizing to allow, must be one ofrow,col,both(default) ornone.-rowheightβ Switch:-rowheightΒ· Name:rowHeightΒ· Class:RowHeight. Default row height, interpreted as lines in the default font when the number is positive, or pixels if it is negative. Defaults to1.-roworiginβ Switch:-roworiginΒ· Name:rowOriginΒ· Class:Origin. Specifies what row index to interpret as the topmost row in the table. This value is used for user indices in the table. Defaults to0.-rowsβ Switch:-rowsΒ· Name:rowsΒ· Class:Rows. Number of rows in the table. Defaults to10.-rowseparatorβ Switch:-rowseparatorΒ· Name:rowSeparatorΒ· Class:Separator. Specifies a separator character that will be interpreted as the row separator when cutting or pasting data in a table. By default, rows are separated as tcl lists.-rowstretchmodeβ Name:rowStretchMode, Class:StretchMode. Sets the stretch modes for rows so they fill up extra allocated window space. For the valid options, go look at-colstretchmodeβ same energy, row edition.-rowtagcommandβ Name:rowTagCommand, Class:TagCommand. Gives the name of a procedure the widget can evaluate to figure out which tag to use for a given row. You have to define this procedure yourself so it accepts a single argument β the row number β and returns a tag name or a null string. It works similarly to-coltagcommand, except it applies to row tags. The current row number is passed as an argument to the row command.-selectioncommand,-selcmdβ Name:selectionCommand, Class:SelectionCommand. Specifies a command (callback) to evaluate when the selection is retrieved from a table via the selection mechanism (i.e. evaluatingselection get). The return value from this command becomes the string passed on by the selection mechanism. The callback gets these arguments: the number of rows in the selection, the number of columns in the selection, the selection string, and the number of cells in the selection.-selectmodeβ Name:selectMode, Class:SelectMode. Specifies one of several styles for manipulating the selection. The value may be arbitrary, but the default bindings expect it to be eithersingle,browse,multiple, orextended; the default value isbrowse. These styles are like the ones for the Tk listbox, except expanded for 2 dimensions.-selecttitleβ Name:selectTitles, Class:SelectTitles. Says whether title cells should be allowed in the selection. Defaults to0(disallowed).-selecttypeβ Name:selectType, Class:SelectType. Specifies one of several types of selection for the table. The value may berow,col,cell, orboth(meaningrow && col); the default value iscell. These types define whether an entire row/col is affected when a cellβs selection is changed (set or clear).-sparsearrayβ Name:sparseArray, Class:SparseArray. A boolean value that says whether an associated Tcl array should be kept as a sparse array (1, the default) or as a full array (0). If true, empty cell values get deleted from the array (taking less memory). If false, all values in the array are maintained.-stateβ Name:state, Class:State. Specifies one of two states for the entry:normalordisabled. If the table is disabled, the value may not be changed using widget commands and no insertion cursor will be displayed, even if the input focus is in the widget. Also, all insert or delete methods are ignored. Defaults tonormal.-titlecolsβ Name:titleCols, Class:TitleCols. Number of columns to use as a title area. Defaults to0.-titlerowsβ Name:titleRows, Class:TitleRows. Number of rows to use as a title area. Defaults to0.-usecommandβ Name:useCommand, Class:UseCommand. A boolean value that specifies whether to use thecommandoption. This value sets itself to zero ifcommandis used and returns an error. Defaults to1(will usecommandif specified).-validateβ Name:validate, Class:Validate. A boolean specifying whether validation should occur for the active buffer. Defaults to0.-validatecommand,-vcmdβ Name:validateCommand, Class:ValidateCommand. Specifies a command (callback) to execute when the active cell is edited. This command is expected to return a1or0. If it returns1, then the new value is assumed OK; otherwise the new value is rejected (the edition will not take place). Errors in this command are handled in the background. The callback gets these arguments: row, col, oldContents of cell, potential new contents of cell, Current Index in the cell.-variableβ Name:variable, Class:Variable. Global Tcl array variable to attach to the tableβs C array. It will be created if it doesnβt already exist or is a simple variable. Keys used by the table in the array are of the formrow,colfor cells and the special keyactive, which contains the value of the active cell buffer. The Tcl array is managed as a sparse array (the table doesnβt require all valid indices have values). No stored value for an index is equivalent to the empty string, and clearing a cell will remove that index from the Tcl array, unless the-sparsearrayoption is set to0.-widthβ Name:width, Class:Width. Specifies the desired width for the window, in columns. If zero or less, then the desired width for the window is made just large enough to hold all the columns in the table. The width can be further limited by-maxwidth.-wrapβ Name:wrap, Class:Wrap. Specifies the default wrap value for tags. Defaults to0.
π DESCRIPTION π
The TableMatrix command creates a 2-dimensional grid of cells. The table can use a Tcl array variable or Tcl command for data storage and retrieval. The widget has an active cell, the contents of which can be edited (when the state is normal). The widget supports a default style for the cells and also multiple tags, which can be used to change the style of a row, column, or cell (see TAGS for details). A cell flash can be set up so that changed cells will change color for a specified amount of time (βblinkβ). Cells can have embedded images or windows, as described in Tags and βEmbedded Windowsβ respectively.
One or more cells may be selected as described below. If a table is exporting its selection (see -exportselection option), then it will observe the standard X11 protocols for handling the selection. See βthe Selectionβ for details. It is not necessary for all the cells to be displayed in the table window at once; commands described below may be used to change the view in the window. Tables allow scrolling in both directions using the standard -xscrollcommand and -yscrollcommand options. They also support scanning, as described below.
In order to obtain good performance, the table widget supports multiple drawing modes, two of which are fully Tk compatible.
πΈ Indices πΈ
Many of the widget commands for tables take one or more indices as arguments. An index specifies a particular cell of the table, in any of the following ways:
number,numberβ Specifies the cell as a numerical index ofrow,colwhich corresponds to the index of the associated Perl Hash, where-roworigin,-colorigincorresponds to the first cell in the table (0,0by default). The values for row and column will be constrained to actual values in the table, which means a valid cell is always found.activeβ Indicates the cell that has the location cursor. It is specified with theactivatewidget command.anchorβ Indicates the anchor point for the selection, which is set with theselection anchorwidget command.bottomrightβ Indicates the bottom-rightmost cell visible in the table.endβ Indicates the bottom right cell of the table.originβ Indicates the top-leftmost editable cell of the table, not necessarily in the display. This takes into account the user specified origin and title area.topleftβ Indicates the top-leftmost editable cell visible in the table (this excludes title cells).@x,yβ Indicates the cell that covers the point in the table window specified byxandy(in pixel coordinates). If no cell covers that point, then the closest cell to that point is used. In the widget command descriptions below, arguments namedindex,first, andlastalways contain text indices in one of the above forms.
π·οΈ Tags π·οΈ
Okay so a tag is literally just a textual string thatβs associated with zero or more rows, columns, or cells in a table. Tags can contain arbitrary characters, but bestie, itβs probably best to avoid names that look like indices so you donβt confuse yourself later. There can be any number of tags in a table, but each row, column, or cell can only have one tag associated with it at a time. Every table also has several permanent tags that you can configure, and those determine the attributes for special cells:
activeβ this tag is given to the active cell.flashβ if flash mode is on, this tag is given to any recently edited cells.selβ this tag is given to any selected cells.titleβ this tag is given to any cells in the title rows and columns. This tag has-state disabledby default.
Tags control the way cells are displayed on the screen. Where appropriate, the default for displaying cells is determined by the options for the table widget. But display options can also be associated with individual tags using the tagConfigure method. If a cell, row, or column has been tagged, then the display options associated with the tag override the default display style. The following options are currently supported for tags:
-anchoranchor β anchor for item in the cell space.-background,-bgcolor β background color of the cell.-borderwidth,-bdpixel β borderwidth of the cell, of the same format for the table, but may also be empty to inherit the default table borderwidth value (the default).-fontfontName β font for text in the cell.-foreground,-fgcolor β foreground color of the cell.-justifyjustify β how to justify multi-line text in a cell. It must be one ofleft,right, orcenter.-imageimageName β an image to display in the cell instead of text.-multilineboolean β whether to display text with newlines on multiple lines.-reliefβ the relief for the cell. May be the empty string to cause this tag to not disturb the value.-showtextboolean β whether to show the text over an image.-statestate β the state of the cell, to allow for certain cells to be disabled. This prevents the cell from being edited by theinsertordeletemethods, but a directsetwill not be prevented.-wrapboolean β whether characters should wrap in a cell that is not wide enough.
A priority order is defined among tags based on creation order (first created tag has highest default priority), and this order is used in implementing some of the tag-related functions described below. When a cell is displayed, its properties are determined by the tags which are assigned to it. The priority of a tag can be modified by the tagLower and the tagRaise methods.
If a cell has several tags associated with it that define the same display options (eg - a title cell with specific row and cell tags), then the options of the highest priority tag are used. If a particular display option hasnβt been specified for a particular tag, or if it is specified as an empty string, then that option will not be used; the next-highest-priority tagβs option will be used instead. If no tag specifies a particular display option, then the default style for the widget will be used.
Images are used for display purposes only. Editing in that cell will still be enabled and any querying of the cell will show the text value of the cell, regardless of the value of -showtext.
Note: there can be only one tag for a given tag type. (Tag types = flash, active, sel, title, celltag rowtag, coltag.) For example, you canβt apply two cell tags to a single cell (or two row tags to a single row, etc) and expect the tagβs properties to be merged. The last tag-type applied will be the one that is used.
πͺ Embedded Windows πͺ
There may be any number of embedded windows in a table widget (one per cell), and any widget may be used as an embedded window (subject to the usual rules for geometry management, which require the table window to be the parent of the embedded window or a descendant of its parent). The embedded windowβs position on the screen will be updated as the table is modified or scrolled, and it will be mapped and unmapped as it moves into and out of the visible area of the table widget. Each embedded window occupies one cellβs worth of space in the table widget, and it is referred to by the index of the cell in the table. Windows associated with the table widget are destroyed when the table widget is destroyed.
Windows are used for display purposes only. A value still exists for that cell, but will not be shown unless the window is deleted in some way. If the window is destroyed or lost by the table widget to another geometry manager, then any data associated with it is lost (the cell it occupied will no longer appear in window names).
When an embedded window is added to a table widget with the window configure widget command, several configuration options may be associated with it. These options may be modified with later calls to the window configure widget command. The following options are currently supported:
-createcallback β NOT CURRENTLY SUPPORTED. Specifies a Tcl script that may be evaluated to create the window for the annotation. If no-windowoption has been specified for this cell then this script will be evaluated when the cell is about to be displayed on the screen. Script must create a window for the cell and return the name of that window as its result. If the cellβs window should ever be deleted, the script will be evaluated again the next time the cell is displayed.-background,-bgcolor β background color of the cell. If not specified, it uses the tableβs default background.-borderwidth,-bdpixelList β borderwidth of the cell, of the same format for the table, but may also be empty to inherit the default table borderwidth value (the default).-padxpixels β as defined in the Tk options man page.-padypixels β as defined in the Tk options man page.-reliefrelief β the relief to use for the cell in which the window lies. If not specified, it uses the tableβs default relief.-stickysticky β stickiness of the window inside the cell, as defined by thegridcommand.-window$widgetβ specifies the a window to display in the annotation. It must exist before being specified here.
πΈ the Selection πΈ
Table selections are available as type STRING. By default, the value of the selection will be the values of the selected cells in nested Tcl list form where each row is a list and each column is an element of a row list. You can change the way this value is interpreted by setting the -rowseparator and -colseparator options.
For example, default Excel format would be to set -rowseparator to "\n" and -colseparator to "\t". Changing these values affects both how the table sends out the selection and reads in pasted data, ensuring that the table should always be able to cut and paste to itself. It is possible to change how pastes are handled by editing the table library procedure tk_tablePasteHandler. This might be necessary if -selectioncommand is set.
π¦ Row/Col Spanning π¦
Individual cells can span multiple rows and/or columns. This is done via the spans command (see below for exact arguments). Cells in the title area that span are not permitted to span beyond the title area, and will be constrained accordingly. If the title area shrinks during a configure, sanity checking will occur to ensure the above. You may set spans on regular cells that extend beyond the defined row/col area. These spans will not be constrained, so that when the defined row/col area expands, the span will expand with it.
When setting a span, checks are made as to whether the span would overlap an already spanning or hidden cell. This is an error and it is not allowed. Spans can affect the overall speed of table drawing, although not significantly. If spans are not used, then there is no performance loss.
Cells hidden by spanning cells still have valid data. This will be seen during cut and paste operations that involve hidden cells, or through direct access by a command like get or set.
The drawing properties of spanning cells apply to only the visual area of the cell. For example, if a cell is center justified over 5 columns, then when viewing any portion of those columns, it will appear centered in the visible area. The non-visible column area will not be considered in the centering calculations.
π Command Substitution π
The various option based commands that the table supports all support the familiar Tk %-substitution model (see Tk::bind for more details). The following %-sequences are recognized and substituted by the table widget:
%cβ forSelectionCommand, it is the maximum number of columns in any row in the selection. Otherwise it is the column of the triggered cell.%Cβ a convenience substitution for%r,%c.%iβ forSelectionCommand, it is the total number of cells in the selection. ForCommand, it is0for a read (get) and1for a write (set). Otherwise it is the current cursor position in the cell.%rβ forSelectionCommand, it is the number of rows in the selection. Otherwise it is the row of the triggered cell.%sβ forValidateCommand, it is the current value of the cell being validated. ForSelectionCommand, it is the default value of the selection. ForBrowseCommand, it is the index of the last active cell. ForCommand, it is empty for reads (get) and the current value of the cell for writes (set).%Sβ forValidateCommand, it is the potential new value of the cell being validated. ForBrowseCommand, it is the index of the new active cell.%Wβ the pathname to the window for which the command was generated.
π Widget Methods π
The $window->TableMatrix method creates a widget object. This object supports the configure and cget methods described in Tk::options which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic Tk::Widget class.
The following additional methods are available for scale widgets:
$table->activate(index)β sets the active cell to the one indicated by index.$table->bbox(first, ?last?)β it returns the bounding box for the specified cell (range) as a 4-tuple of x, y, width and height in pixels. It clips the box to the visible portion, if any, otherwise an empty string is returned.$table->border(option, args)β this command is a voodoo hack to implement border sizing for tables. This is normally called through bindings, with the following as valid options:
π§΅ $table->borderMark(x, y, ?row|col?)
okay so this one records x and y, plus the row and/or column border that's sitting under that exact point in the table window β if there even is one, no promises. It's the setup bestie for the later border dragto commands. Typically you'd wire this up to a mouse button press in the widget. π
If row or col is not specified, it hands you back a tuple of both border indices (and an empty item in there means no border, periodt). Otherwise, you just get the one item you asked for.
π₯ $table->borderDragto(x, y)
This one does the math: it computes the difference between its x and y arguments and the x and y arguments from the last borderMark command for the widget, then it adjusts that previously marked border by the difference. It's the glow-up move you associate with mouse motion events in the widget, so you get that live interactive border-resizing effect. π¦
β¨ $table->cget(option)
Returns the current value of the configuration option given by option. option can be literally any of the values that the table command accepts. easy.
πΈ $table->clear(option, ?first?, ?last?)
A convenience routine that clears certain state info the table is managing for you. first and last are valid table indices. If neither one is specified, then the command operates on the whole table β the entire thing, bestie. π The following options are recognized:
π $table->clearCache(?first?, ?last?)
Clears the specified section of the cache β if the table has been keeping one at all. iykyk.
π $table->clearSizes(?first?, ?last?)
Clears the specified row and column areas of specific height/width dimensions. When just one index is specified β for example 2,0 β that is interpreted as row 2 and column 0.
π $table->clearTags(?first?, ?last?)
Clears the specified area of tags (all row, column and cell tags). all of them. gone.
π $table->clearAll(?first?, ?last?)
Performs all of the above clear functions on the specified area. the full combo, ate.
π $table->colWidth(?col?, ?value, col, value, ...?)
- No col specified β returns a list describing all cols that have a width set.
- col specified with no value β prints out the width of that col in characters (positive number) or pixels (negative number).
- One or more col-value pairs β sets each col to that width in characters (positive number) or pixels (negative number).
And if value is default, then that col just uses the default width, specified by -colwidth. π«Ά
β $table->configure(?option?, ?value, option, value, ...?)
Query or modify the configuration options of the widget. lowkey the classic.
- No option specified β returns a list describing all the available options for pathName (see
Tk_ConfigureInfofor the info on the format of this list). - option specified with no value β returns a list describing that one named option (identical to the corresponding sublist of the value you'd get with no option specified).
- One or more option-value pairs specified β modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. π
option may have any of the values accepted by the table command.
π $table->curselection(?value?)
With no arguments, it returns the sorted indices of the currently selected cells. Otherwise it sets all the selected cells to the given value. Heads up though: the set has no effect if there's no associated Tcl array, or if the state is disabled. π
π $table->curvalue(?value?)
If no value is given, you get back the value of the cell being edited (indexed by active); else it's set to the given value. simple as.
π $table->delete(option, arg, ?arg?)
The delete-everything command. It has several forms, depending on option:
π§ $table->deleteActive(index, ?index?)
Deletes text from the active cell. If only one index is given, it deletes the character after that index; otherwise it deletes from the first index to the second. index can be a number, insert or end.
π§ $table->deleteCols(?switches?, index, ?count?)
Deletes count cols starting at (and including) col index. The index gets constrained to the limits of the tables. If count is negative, it deletes cols to the left β otherwise it deletes cols to the right. count defaults to 1 (meaning just the column specified). The selection will be cleared. β οΈ At the moment, spans are not adjusted with this action. Optional switches are:
-holddimensionsβ causes the table cols to be unaffected by the deletion (empty cols may appear). By default the dimensions are adjusted by count.-holdtagsβ causes the tags specified by thetagmethod to not move along with the data. Also prevents specific widths set by thewidthmethod from being adjusted. By default, these tags are properly adjusted.-holdwindowsβ causes the embedded windows created with thewindowmethod to not move along with the data. By default, these windows are properly adjusted.-keeptitlesβ prevents title area cells from being changed. Otherwise they're treated just like regular cells and will move as specified.
π§ $table->deleteRows(?switches?, index, ?count?)
Deletes count rows starting at (and including) row index. If count is negative, it deletes rows going up; otherwise it deletes rows going down. The selection will be cleared. The switches are the same ones as for column deletion. π«‘
π¦ $table->get(first, ?last?)
Returns the value of the cells specified by the table indices first and (optionally) last, in a list. that's it, that's the command.
πΈ $table->hidden(?index?, ?index, ...?)
- No args β returns all the hidden cells (those cells covered by a spanning cell).
- One index β returns the spanning cell covering that index, if any.
- Multiple indices β returns
1if all indices are hidden cells,0otherwise.
β¨ $table->icursor(?arg?)
With no arguments, it prints out the location of the insertion cursor in the active cell. With one argument, it sets the cursor to that point in the string. 0 is before the first character, and you can also use insert or end for the current insertion point or the end of the text. And if there's no active cell, or the cell or table is disabled, this returns -1. π
π $table->index(index, ?row|col?)
Returns the integer cell coordinate that corresponds to index, in the form row,col. If row or col is specified, then only that row or column index comes back. π
π₯ $table->insert(option, arg, arg)
Used to insert various things into a table (yes, the original says "used to into various things", we don't ask questions π). It has several forms, depending on option:
π«Ά $table->insertActive(index, value)
The value is a text string that gets inserted at the index position of the active cell. The cursor is then positioned after the new text. index can be a number, insert or end.
π«Ά $table->insertCols(?switches?, index, ?count?)
Inserts count cols starting at col index. If count is negative, it inserts before the specified col; otherwise it inserts after the specified col. The selection will be cleared. The switches are the same as those for column deletion. π
π«Ά $table->insertRows(?switches?, index, ?count?)
Inserts count rows starting at row index. If count is negative, it inserts before the specified row; otherwise it inserts after the specified row. The selection will be cleared. The switches are the same as those for column deletion. fr fr.
π§΅ $table->reread()
Rereads the old contents of the cell back into the editing buffer. Super useful for a key binding when Escape is pressed to abort the edit (that's a default binding, bestie β it's already in there).
β $table->rowHeight(?row?, ?value, row, value, ...?)
- No row specified β returns a list describing all rows that have a height set.
- row specified with no value β prints out the height of that row in characters (positive number) or pixels (negative number).
- One or more row-value pairs β sets each row to that height in lines (positive number) or pixels (negative number).
And if value is default, then the row uses the default height, specified by -rowheight. π
π $table->scan(option, args)
This command is the whole implementation of scanning on tables. It has two forms, depending on option:
π $table->scanMark(x, y)
Records x and y and the current view in the table window; used in conjunction with later scan dragto commands. Typically associated with a mouse button press in the widget. It returns an empty string. π
π $table->scanDragto(x, y.)
This command computes the difference between its x and y arguments and the x and y arguments to the last scanMark command for the widget. It then adjusts the view by 5 times the difference in coordinates. π₯ Typically associated with mouse motion events in the widget, giving you that effect of dragging the list at high speed through the window. The return value is an empty string.
π¦ $table->see(index)
Adjusts the view in the table so that the cell given by index is positioned as the cell one off from top left (excluding title rows and columns) β if the cell isn't currently visible on the screen, that is. The actual cell may be different to keep the screen full. yeah, it's giving considerate. π
π $table->selection(option, arg)
Used to adjust the selection within a table. It has several forms, depending on option:
π $table->selectionAnchor(index)
Sets the selection anchor to the cell given by index. The selection anchor is the end of the selection that stays fixed while you drag out a selection with the mouse. The index anchor may be used to refer to the anchor cell.
π $table->selectionClear(first?last?)
If any of the cells between first and last (inclusive) are selected, they get deselected. The selection state is not changed for cells outside this range. first may be specified as all to remove the selection from all cells. π
π $table->selectionIncludes(index)
Returns 1 if the cell indicated by index is currently selected, 0 if it isn't. vibe check, answered.
π $table->selectionSet(first, ?last?)
Selects all of the cells in the range between first and last, inclusive, without affecting the selection state of cells outside that range. periodt. β¨
π§ perltk note: this needs to be perlized
okay so the methods keep rolling in β hereβs the next batch, and every single detail is staying, bestie π
$table->set(?row|col?, index, ?value?, ?index, value, ...?)β sets the specified index to the associated value. This method will not trigger table validation. Ifroworcolcomes before the list of index/value pairs, the value is assumed to be a Tcl list, and its values get split and set into the following columns (ifrowis specified) or rows (ifcolis specified). For example,set row 2,3 {2,3 2,4 2,5}sets 3 cells, from2,3to2,5. Setting cells is silently bounded by the known table dimensions.$table->spans(?index?, ?rows,cols, index, rows,cols, ...?)β this one handles row/col spans. With no arguments, it returns all known spans as a list of tuples shaped like{index span}. With only the index, it returns the span for that index only, if there is one. Otherwise, an even number of index rows,cols pairs are used to set spans. A span starts at the index and continues for the specified number of rows and cols. Negative spans are not supported. A span of0,0unsets any span on that cell. PeepEXAMPLESfor more info.$table->tag(option, ?arg, arg, ...?)β manipulates tags. The exact behavior depends on the option argument that follows thetagargument.cget,cell, androw|colcomplain about unknown tag names. The following forms are currently supported:$table->tagCell(tagName, ?index, ...?)β with no arguments, prints out the list of cells using the tag. Otherwise, it sets the specified cells to use the named tag, replacing any tag that may have been set with this method before. If tagName is'', the cells are reset to the default tag. Tags added during-*tagcommandevaluation do not register here. If tagName does not exist, it gets created with the default options.$table->tagCget(tagName, option)β returns the current value of the option named option associated with the tag given by tagName. option may be any of the values accepted by thetag configurewidget command.$table->tagCol(tagName, ?col, ...?)β with no arguments, prints out the list of cols using the tag. Otherwise, it sets the specified columns to use the named tag, replacing any tag that may have been set with this method before. If tagName is'', the cols are reset to the default tag. Tags added during-coltagcommandevaluation do not register here. If tagName does not exist, it gets created with the default options.$table->tagConfigure(tagName, ?option?, ?value?, ?option, value, ...?)β similar to theconfigurewidget command, except it modifies options associated with the tag given by tagName instead of options for the whole table widget. If no option is specified, it returns a list describing all available options for tagName (seeTk_ConfigureInfofor the format of that list). If option is specified with no value, it returns a list describing that one named option β identical to the corresponding sublist of the value youβd get with no option. If one or more option-value pairs are specified, it modifies the given option(s) to have the given value(s) in tagName; in this case it returns an empty string. SeeTAGSabove for details on the options available for tags.$table->tagDelete(tagName)β deletes a tag. No error if the tag does not exist.$table->tagExists(tagName)β returns1if the named tag exists,0otherwise.$table->tagIncludes(tagName, index)β returns1if the specified index has the named tag,0otherwise.$table->tagLower(tagName, ?belowThis?)β lowers the priority of the named tag. If belowThis is not specified, the tagβs priority drops to the bottom; otherwise it drops to one below belowThis.$table->tagNames(?pattern?)β with no pattern, shows the names of all defined tags. Otherwise pattern is used as a glob pattern to show only tags matching it. Tag names come back in priority order β highest priority tag first π.$table->tagRaise(tagName, ?aboveThis?)β raises the priority of the named tag. If aboveThis is not specified, the tagβs priority goes to the top; otherwise it goes to one above aboveThis.$table->tagRow(tagName, ?row, ...?)β with no arguments, prints out the list of rows using the tag. Otherwise, it sets the specified columns to use the named tag, replacing any tag that may have been set with this method before. If tagName is'', the rows are reset to use the default tag. Tags added during-rowtagcommandevaluation do not register here. If tagName does not exist, it gets created with the default options.
$table->validate(index)β explicitly validates the specified index based on the current-validatecommandand returns0or1depending on whether the cell was validated.$table->window(option, ?arg, arg, ...?)β manipulates embedded windows. The exact behavior depends on the option argument that follows thewindowargument. The following forms are currently supported:$table->windowCget(index, option)β returns the current value of the option named option associated with the window given by index. option may be any of the values accepted by thewindow configurewidget command.$table->windowConfigure(index, ?option?, ?value?, ?option, value, ...?)β similar to theconfigurewidget command, except it modifies options associated with the embedded window given by index instead of options for the whole table widget. If no option is specified, it returns a list describing all available options for index (seeTk_ConfigureInfofor the format of that list). If option is specified with no value, it returns a list describing that one named option β identical to the corresponding sublist of the value youβd get with no option. If one or more option-value pairs are specified, it modifies the given option(s) to have the given value(s) in index; in this case it returns an empty string. SeeEMBEDDED WINDOWSabove for details on the options available for windows.$table->windowDelete(index, ?index, ...?)β deletes an embedded window from the table. The associated window will also be deleted.$table->windowMove(indexFrom, indexTo)β moves an embedded window from one cell to another. If a window already exists in the target cell, it will be deleted.$table->windowNames(?pattern?)β with no pattern, shows the cells of all embedded windows. Otherwise pattern is used as a glob pattern to show only cells matching it.
$table->xview(args)β queries and changes the horizontal position of the information in the widgetβs window. It can take any of these forms:$table->xview()β returns a list of two elements. Each element is a real fraction between0and1; together they describe the horizontal span visible in the window. For example, if the first element is.2and the second is.6, then 20% of the tableβs text is off-screen to the left, the middle 40% is visible in the window, and 40% is off-screen to the right. These are the same values passed to scrollbars via the-xscrollcommandoption.$table->xview(index)β adjusts the view so the column given by index is displayed at the left edge of the window.$table->xviewMoveto(fraction)β adjusts the view so fraction of the total width of the table text is off-screen to the left. fraction must be between0and1.$table->xviewScroll(number, what)β shifts the view left or right according to number and what. number must be an integer. what must be eitherunitsorpages, or an abbreviation of one of those. If what isunits, the view adjusts left or right by number cells on the display; if it ispages, the view adjusts by number screenfuls. If number is negative, cells farther to the left become visible; if it is positive, cells farther to the right become visible.
$table->yview(?args?)β queries and changes the vertical position of the text in the widgetβs window. It can take any of these forms:$table->yview()β returns a list of two elements, both real fractions between0and1. The first element gives the position of the table element at the top of the window, relative to the table as a whole (0.5means halfway through the table, for example). The second element gives the position of the table element just after the last one in the window, relative to the table as a whole. These are the same values passed to scrollbars via the-yscrollcommandoption.$table->yview(index)β adjusts the view so the row given by index is displayed at the top of the window.$table->yviewMoveto(fraction)β adjusts the view so the element given by fraction appears at the top of the window. fraction is between0and1;0indicates the first element in the table,0.33indicates the element one-third of the way through the table, and so on.$table->yviewscroll(number, what)β adjusts the view up or down according to number and what. number must be an integer. what must be eitherunitsorpages. If what isunits, the view adjusts up or down by number cells; if it ispages, the view adjusts by number screenfuls. If number is negative, earlier elements become visible; if it is positive, later elements become visible.
π Default Bindings π
Okay so the initialization creates class bindings, and those give you the following default behaviour, bestie:
- Clicking
Button-1in a cell activates that cell. Clicking into an already active cell moves the insertion cursor to the character nearest the mouse. β¨ - Moving the mouse while
Button-1is pressed will stroke out a selection area. Exiting whileButton-1is pressed causes scanning to occur on the table along with selection. - Moving the mouse while
Button-2is pressed causes scanning to occur without any selection. - Home moves the table to have the origin in view.
- End moves the table to have the end cell in view.
- Control+Home moves the table to the origin and activates that cell.
- Control+End moves the table to the end and activates that cell.
- Shift+Control+Home extends the selection to the origin.
- Shift+Control+End extends the selection to the end.
- The left, right, up and down arrows move the active cell.
Shift-<arrow>extends the selection in that direction.Control-leftarrowandControl-rightarrowmove the insertion cursor within the cell.Control-slashselects all the cells.Control-backslashclears selection from all the cells.- Backspace deletes the character before the insertion cursor in the active cell.
- Delete deletes the character after the insertion cursor in the active cell.
- Escape rereads the value of the active cell from the specified data source, discarding any edits that have may been performed on the cell.
Control-amoves the insertion cursor to the beginning of the active cell.Control-emoves the insertion cursor to the end of the active cell.Control-minusandControl-equalsdecrease and increase the width of the column with the active cell in it.- Moving the mouse while
Button-3(the right button on Windows) is pressed while you are over a border will cause interactive resizing of that row and/or column to occur, based on the value of-resizeborders.
Some bindings may have slightly different behavior dependent on the -selectionmode of the widget. If the widget is disabled using the -state option, then its view can still be adjusted and cells can still be selected, but no insertion cursor will be displayed and no cell modifications will take place. The behavior of tables can be changed by defining new bindings for individual widgets or by redefining the class bindings. The default bindings are either compiled in the TableMatrix.pm file
β‘ Performance Issues β‘
The number of rows and columns in a table widget should not significantly affect the speed of redraw. Recalculation and redraw of table parameters and cells is restricted as much as possible. The display cell with the insert cursor is redrawn each time the cursor blinks, which causes a steady stream of graphics traffic. Set the -insertofftime option to 0 to avoid this. The use of a -command with the table without a cache can cause significant slow-down, as the command is called once for each request of a cell value. π
π§ͺ Examples π§ͺ
Set the topleft title area to be one spanning cell. This overestimates both row and column span by one, but the command does all the constraining for us:
$table span [$table cget -roworigin],[$table cget -colorigin] [$table cget -titlerows],[$table cget -titlecols]
Force a table window refresh (useful for the slight chance that a bug in the table is not causing proper refresh):
$table configure -padx [$table cget -padx]
π Keywords π
tablewidgetextension
That's the whole page, bestie β source/version perl v5.42.0, dated 2023-05-11. Slay, go build something iconic π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Tk-TableMatrix 1.29-bp160.1.13 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND TCL
- opensuse-leap 16.0: perl-Tk-TableMatrix 1.29-bp160.1.13 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND TCL
- opensuse-leap 16.0: perl-Tk-TableMatrix 1.29-bp160.1.13 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND TCL
- opensuse-leap 16.0: perl-Tk-TableMatrix 1.29-bp160.1.13 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms