##+################################################### # NAME snitfinddialog # SYNOPSIS # snitfindialog path ?args? # DESCRIPTION # snitfilendialog provides a standard find dialog layout # all buttons and the entries are accessable via the subcommand # the components are: find, next (standard tk buttons), entry (standard tk entry) # STANDARD OPTIONS # delegated is -textvariable to the entry component # all other options if required must be send via a subcommand # WIDGET OPTIONS # -findcmd The command to invoke if "Find" is pressed. # -findnextcmd The command to invoke if "Find Next" is pressed. # -case Case sensitivity of search either true or false. Defaults to false. # -word Matches whole words only true or false. Defaults to false. # -forward Forward (true) or backward (false) searches. Defaults to true. # WIDGET COMMAND # pathName componentname ?args? # without args it returns the component path to be saved inside a variable # with args it evaluates args in the context of the component # if the first argument of args is bind a binding for the component is created # AUTHOR # Dr. Detlef Groth nospamdgroth@molgen.mpg.de # HISTORY # 20/11/2003 Version 0.1 initial release # 25/11/2003 Version 0.1.1 changed puts to wm title . # 27/11/2003 Version 0.2 update to snit 0.91 removing the component subcommand instead # using expose # 31/12/2005 Version 0.2.1 - added "tkwait" and "grab" to force dialog over other windows + added button to launch package require snit 0.91 snit::widget snitfinddialog { hulltype toplevel expose entry expose find expose next delegate option -findcmd to find as -command delegate option -findnextcmd to next as -command delegate option -textvariable to entry option -case 0 option -word 0 option -forward yes constructor {args} { wm resizable $win false false pack [frame $win.left] -side left -padx 5 -pady 5 -ipadx 5 -ipady 5 \ -expand yes -fill both pack [frame $win.right] -side left -padx 5 -pady 5 -ipadx 5 -ipady 5 \ -expand yes -fill both install find using button $win.right.search -text " Find " -width 15 pack $find -side top -padx 5 -pady 8 install next using button $win.right.searchnext -text " Find Next " -width 15 pack $next -side top -padx 5 -pady 12 install entry using entry $win.left.entry pack $entry -side top -padx 5 -pady 5 -expand yes -fill x pack [frame $win.left.bottom] -side top pack [frame $win.left.bottom.left] -side left pack [checkbutton $win.left.bottom.left.words -text "Whole Words ? " \ -variable [varname options(-word)]] -side top -padx 5 -pady 5 -anchor w pack [checkbutton $win.left.bottom.left.uclc -text "Case sensitive ?" \ -variable [varname options(-case)]] -side top -padx 5 -pady 5 -anchor w pack [labelframe $win.left.bottom.right -text " Direction "] -side left \ -expand yes -fill both pack [radiobutton $win.left.bottom.right.forward -text "Forward " \ -variable [varname options(-forward)] -value yes] -side top -anchor w -padx 5 pack [radiobutton $win.left.bottom.right.backward -text "Backward" \ -variable [varname options(-forward)] -value no] -side top -anchor w -padx 5 $self configurelist $args } } # EXAMPLE of usage proc Test_Find {} { global textvar # testing mFind proc Next {} { global textvar wm title .s "Next $textvar words: [.s cget -word]" puts "Next $textvar words: [.s cget -word]" } proc Find {} { global textvar wm title .s "Find $textvar words: [.s cget -word]" puts "Find $textvar words: [.s cget -word]" } set textvar test snitfinddialog .s -case 1 -findnextcmd Next -findcmd Find -textvariable textvar wm title .s "Search " .s find configure -bg red set btn [.s find] $btn configure -bg blue bind [.s find] <Enter> {wm title .s "Yeah Here Find, I am entered!" ; puts "Yeah Here Find, I am entered!"} bind [.s next] <Enter> {wm title .s "Yeah Here Next, I am entered!" ; puts "Yeah Here Next, I am entered!"} catch {tkwait visibility .s} catch {grab .s} } pack [button .b -text "Launch Find Dialog" -command Test_Find]---DDG: Any suggestions, improvements ? Welcome!escargo 20 Nov 2003 - Just a couple of things. I have a Windows XP laptop with ActiveState ActiveTcl 8.4.4 installed. That includes tcllib1.5. Apparently the package require snit 0.9 is satisfied with the 0.82 version included in tcllib. You might want to change the require to package require -exact snit 0.9 to avoid that problem (which, admittedly causes a different problem in the future).Second, since I'm running on Windows, the puts in Test_find have nowhere to go. I changed the bindings on the find and next buttons to change color on enter and leave events instead. You might consider putting some Windows-toleration code in there for people running without consoles.Re. 0.9 vs. 0.82, note that 9 < 82. If snit was at 0.81 at some point, then a new release should have been bumped to 0.90, not 0.9. The issue could be resolved by releasing 0.91 and never ever using "package require snit 0.9" anywhere -jcwMea culpa. I've got some changes to make anyway. -- WHDDDG: If running on windows why not simply run a wish. Copy the code into the console and see what it's putting! That's the way I Test_Find!escargo 24 Nov 2003 - I use wish-reaper to download code onto my Windows laptop; I might review what I get with ASED, but then I just want to double-click on the file to run it. Many pages on the wiki are reapable, so that they can run just as they appear. That's a lot simpler than having to start wish, open the code with some application, and copy it into the console. Why make it harder than it needs to be.DDG 25 Nov 2003 - Aha, I think this wiki is always interesting. So the code should be now reapable and I changed the puts statements.DDG 27 Nov 2003 - with Snit 0.91 its possible to expose components. So I could delete the components array and the components subcommand. That's simplifies design a lot. Thanks to Will.
See also Snit's Not Incr Tcl, snitbrowser.
Is this widget something that might be useful to provide in tklib?