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
Database class: ClientData
Acts as a data storage for a widgets. User can store any data and this will not have any effect on widget property.
-help
Database name: help
Database class: Text
Specifies the text or help message that displays when the cursor moves over the widget.
-helpcommand
Database name: helpcommand
Database class: Command
Dynamic help which calls an assigned -helpcommand when the user moves the mouse on the widget. The text which is returned by the -helpcommand will be in turn be displayed on the tooltip.
-state
Database name: state
Database class: State
May be set to normal or disabled to control the disabled state bit.

Widget Specific Options

-cancelcommand
Database name: cancelcommand
Database class: Command
Define a command to be called when search is cancelled. Called from the cancel button or the cancel command.
-command
Database name: command
Database class: Command
Define a command to be called when search is invoked. Called from invoke command or Enter in the entry field.
-idletext
Database name: idletext
Database class: Text
Text to be displayed when widget does not have focus or user defined text.
-showapplycancel
Database name: showapplycancel
Database class: Showapplycancel
Boolean option. If true, will show a button on the searchentry that will clear the current text input.
-showrecent
Database name: showrecent
Database class: Showrecent
Boolean option. If true, will show a button that provides a drop-down list of recently entered searches that can be used to search again.

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:
setchanges[pathNamestatespec]
pathNamestate$changes
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.

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