hwtk::searchentry
A search entry widget that provides a cancel button and a dropdown to select previous searched. Searches indicate text and execute a command.
Format
hwtk::searchentry - pathName ?option value? …
Standard Options
- -clientdata
- Database name: clientData
- -help
- Database name: help
- -helpcommand
- Database name: helpcommand
- -state
- Database name: state
Widget Specific Options
- -cancelcommand
- Database name: cancelcommand
- -command
- Database name: command
- -idletext
- Database name: idletext
- -showapplycancel
- Database name: showapplycancel
- -showrecent
- Database name: showrecent
Widget Commands
- pathName cancel
- Executes cancel command defined by -cancelcommand option
- pathName cget option
- Returns the current value of the configuration option given by option.
- pathName configure ?option? ?value option value …?
- Query or modify the configuration options of the widget. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. If option is specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If no option is specified, returns a list describing all of the available options for pathName.
- pathName get
- Returns current text value of entry field.
- pathName identify element x y
- Returns the name of the element under the point given by x and y, or an empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget. Some widgets accept other identify subcommands.
- pathName invoke
- Executes command provided by -command option.
- pathName instate statespec ?script?
- Test the widget’s state. If script is not specified, returns 1 if the
widget state matches statespec and 0 otherwise. If script is specified,
equivalent to
if{[pathNameinstatestateSpec]}script
- pathName set string
- Sets the search string to string
- pathName state ?stateSpec?
- Modify or inquire widget state. If stateSpec is
present, sets the widget state: for each flag in
stateSpec, sets the corresponding flag or clears it
if prefixed by an exclamation point. Returns a new state spec indicating
which flags were changed:
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.setchanges[pathNamestatespec]
pathNamestate$changes
Example
#::hwtk::searchentry
proc textSearch {w string tag} {
$w tag remove search 0.0 end
if {$string == ""} {
return
}
set cur 1.0
while 1 {
set cur [$w search -count length $string $cur end]
if {$cur == ""} {
break
}
$w tag add $tag $cur "$cur + $length char"
set cur [$w index "$cur + $length char"]
}
eval $w tag configure search -background black -foreground white
}
::hwtk::dialog .dlg -title "::hwtk::searchentry" -height 8
set w [.dlg recess]
frame $w.string
label $w.string.label -text "Search string:" -width 10 -anchor w
hwtk::searchentry $w.string.entry \
-command [list textSearch $w.text %P search] \
-cancelcommand {puts "CANCEL %W %P"} -idletext "Enter search string"
pack $w.string.label -side left;
pack $w.string.entry -side left -fill x -expand true;
text $w.text -setgrid false -height 10 -width 52
pack $w.string -side top -fill x -pady 2 -padx 4;
pack $w.text -expand true -fill both
$w.text insert 1.0 \
{This window demonstrates how to use the searchentry widget.
Enter a search string and hit Return.}
$w.text mark set insert 0.0
.dlg post