hubtable - A Dmhwidget for displaying table data


dmhwidgets::hubtable pathName ?options?


itk::Widget <- iwidgets::Labeledwidget <- iwidgets::Scrolledwidget <- iwidgets::Scrolledlistbox <- dmhwidgets::Hubtable


activebackground background borderwidth cursor exportselection foreground highlightcolor highlightthickness relief selectbackground selectborderwidth selectforeground

See the options manual entry for details on the standard options.


activerelief dblclickcommand disabledforeground elementborderwidth height hscrollmode jump labelbitmap labelfont labelimage labelmargin labelpos labeltext labelvariable sbwidth scrollmargin selectioncommand selectmode state textbackground textfont troughcolor visibleitems vscrollmode width

See the scrolledlistbox manual entry.


Name: datacmd  Class: Datacmd  Command-Line Switch: -datacmd

The -datacmd option is used to specify Tcl code to be evaluated to obtain the table data to be displayed. The Tcl code should be an SQL selection statement or any command that returns table data in the Tcl reply format. For example,
-datacmd {SQL {select * from dc_runrule}}
The hubtable is designed to be used with either the -datacmd option specified, or the -subscription option specified. The -datacmd option is used when the displayed data is to be static or manually refreshed. Typically when using the -datacmd option, the bind command is used to have <F5> invoke pathName refresh.

Name: rhs_cols  Class: Rhs_cols  Command-Line Switch: -rhs_cols

The -rhs_cols option is used to specify a list of column indexes for which the data should be right-justified when padding with spaces for alignment. The default alignment for column data is the lefthand side. When displaying numeric data, it is often desirable to align the data on the right so that decimals and digit places are aligned.

Name: sortkeys  Class: Sortkeys  Command-Line Switch: -sortkeys 

If the -sortkey option is not used, default sorting applies. The default sorting when the -subscription option is used, is to determine the data types of the key columns, and properly sort character and numeric data in the key order of table. The default sorting when the -datacmd is used, is to display the data with the original order preserved. The original order may not be to your liking if you are using an SQL query that selects numeric columns because the SQL command orders data using string comparisons. You are able to specify the desired sorting order using the -sortkeys option. The syntax of the -sortkeys value is:
[index type]+ [{ascending | descending}]
where index is the list element index into the data row(s), and type is one of the literal terms ascii, int, or real to indicate what kind of data comparison is appropriate. For example:
pathName configure -sortkeys {{2 real} {0 ascii} {1 ascii} ascending}

Warning - if you redefine the sorting, and you are using -subscription the subscription notifications may not work correctly unless all of the table keys are included in the sort.

Name: subscription  Class: Subscription  Command-Line Switch: -subscription 

The -subscription option is used to configure an in-memory SQL table as the source of the displayed data. The data display is then kept current with the data in the table using a data subscription. This option is used as an alternative to the -datacmd option. The syntax of the -subscription value is:
table [column_list [where_clause]]
where column_list is an optional list of column names, and where_clause is an optional clause to specify a selection condition. If the where_clause is specified, it should start with the SQL keyword where and include the boolean conditions that normally follow the where keyword in an SQL selection statement. For example:
pathName configure -subscription {dc_item_use * {where spc_alarm<>0}}


The hubtable command creates a widget that displays table data, and a new Tcl command whose name is pathname. The command is then used to invoke various methods of the widget. The command has the general form:

pathName option ?arg arg ... arg?

One of the -datacmd or -subscription options is used to specify the data to be displayed. If you use the -datacmd, you may want to bind <F5> to the refresh action.

The -width and -height options are in terms of overall pixels. You probably want to use -visibleitems to specify a ColumnsxRows value used to set the size of the table display.

You should only specify a fixed pitch font for the data.


pathName bindtag
This method is a simplified means of getting the data listbox tag which is needed to add bindings for right-click actions. For example,
bind [$hubtab bindtag] <Button-3> "tk_popup $my_menu %X %Y"

pathName reformat_data
This method can be called when using the -subscription option. It causes the spacing to be adjusted for the displayed data. The method is called internally to improve the displayed format if the table is drawn before many data rows exist. It can also be called by you.

pathName refresh
This method can be called when using the -datacmd option. It causes the -datacmd code to be evaluated, and the displayed data to be refreshed using the new query results.


package require dmh
package require Dmhwidgets

SQL "create table dc_runrules (name varchar(10),description \
 varchar(80),primary key(name))"
SQL "insert into dc_runrules (name,description) values ('1sigma',\
 'Western Electric #3 - 4 of 5 points above +1 sigma or below -1 sigma')"
SQL "insert into dc_runrules (name,description) values ('1sigmaH',\
 '4 of 5 points higher than +1 sigma')"
SQL "insert into dc_runrules (name,description) values ('1sigmaL',\
 '4 of 5 points lower than -1 sigma')"
SQL "insert into dc_runrules (name,description) values ('2sigma',\
 'Western Electric #2 - 2 of 3 points above +2 sigma or below -2 sigma')"

dmhwidgets::hubtable .hubtable -subscription dc_runrules -visibleitems 40x10\
 -labelfont {Helvetica 12 bold} -labelpos nw -labeltext "Table dc_runrules"
pack .hubtable -side top -expand 1 -fill both
bind [.hubtable bindtag] <Button-3> "puts {rt-click action}"


Hume Integration Software,


SQL, datahub, table, widget