From 62b88e74454b8fc0494cec6a3fe0cf91a9d77a5f Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Sun, 29 Nov 2009 11:38:10 +0000 Subject: [PATCH] Enable theming on all dialogs. Signed-off-by: Pat Thoyts --- bin/sockspy.tcl | 136 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 97 insertions(+), 39 deletions(-) diff --git a/bin/sockspy.tcl b/bin/sockspy.tcl index 83ca11c..2138960 100644 --- a/bin/sockspy.tcl +++ b/bin/sockspy.tcl @@ -125,6 +125,15 @@ set extract(server) {^(HTTP/|Location: |Content-)} set extract(meta2) {.} #set extract(meta) {.} +proc ttk_toplevel {w args} { + variable useTile + eval [linsert $args 0 ::toplevel $w] + if {[info exists useTile] && $useTile} { + place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1 + } + return $w +} + ##+########################################################################## # # createMain -- Creates the display @@ -287,7 +296,7 @@ proc createExtract {} { return } - toplevel $top + ttk_toplevel $top wm withdraw $top wm title $top "SockSpy Extract" wm transient $top . @@ -386,29 +395,71 @@ proc togglesockname {} { # It uses the playback stream as its data source. # proc saveOutput {} { - global state but + global state + variable NS + set dlg [ttk_toplevel .what -class Dialog] + variable $dlg "" + variable but both + wm withdraw $dlg + wm title $dlg "SockSpy Save" + wm transient $dlg . + + set f [${NS}::labelframe $dlg.f -text "Select window"] + foreach name {server client both} { + set b [${NS}::radiobutton $f.$name -text $name \ + -variable ::but -value $name] + grid $b -sticky ew + } + grid columnconfigure $f 0 -weight 1 + + ${NS}::button $dlg.ok -text OK -default active \ + -command [list set [namespace which -variable $dlg] ok] + ${NS}::button $dlg.cancel -text Cancel \ + -command [list set [namespace which -variable $dlg] cancel] - set but -1 - set but [tk_dialog .what "SockSpy Save" "Save which window?" \ - questhead 2 server client both cancel] + grid $f - -sticky news -padx 2 -pady 2 + grid $dlg.ok $dlg.cancel -sticky se + grid columnconfigure $dlg 0 -weight 1 + grid rowconfigure $dlg 0 -weight 1 - if {$but == -1 || $but == 3} { - return + tk::PlaceWindow $dlg widget . + wm deiconify $dlg + tkwait variable [namespace which -variable $dlg] + if {[set $dlg] eq "ok"} { + set state(msg) "Saving ..." + busy hold $dlg + update idletasks + performSaveOutput $dlg $but + busy forget $dlg + set state(msg) "Save completed." } - set file [tk_getSaveFile -parent . -initialfile $state(fname)] + destroy $dlg + unset $dlg +} +proc busy {state w} { + if {[info commands tk::busy] ne {}} { + tk::busy $state . + } else { + set c [expr {$state eq "hold" ? "watch" : ""}] + . configure -cursor $c + $w configure -cursor $c + } +} +proc performSaveOutput {dlg which} { + global state + set file [tk_getSaveFile -parent $dlg -initialfile $state(fname)] if {$file == ""} return set state(fname) $file if {[catch {open $file w} fd]} { - tk_messageBox -message "file $file cannot be opened" -icon error \ - -type ok + tk_messageBox -icon error -type ok -title "SockSpy error" \ + -message "Cannot open file '$file'" return } fconfigure $fd -translation binary foreach {who data time} $state(playback) { if {$who == "meta" || $who == "meta2"} continue - if {$but == 2 || ($but == 0 && $who == "server") || \ - ($but == 1 && $who == "client")} { + if {$which eq "both" || $which == $who} { if {$state(time)} { puts $fd [timestamp $time] } @@ -416,8 +467,8 @@ proc saveOutput {} { } } close $fd - bell } + ##+########################################################################## # # printable -- Replaces all unprintable characters into dots. @@ -523,30 +574,34 @@ proc timestamp {time} { # proc timestampWindow {} { global state + variable NS set state(oldTimeFormat) $state(timeFormat) set w .tf2 destroy .tf - toplevel .tf + ttk_toplevel .tf wm title .tf "SockSpy Time Format" + wm transient .tf . + wm withdraw .tf - set txt "Edit the format used for timestamps. " - append txt "See Tcl's clock command documentation for a complete " - append txt "description of acceptable formats." + set txt "Edit the format used for timestamps. See the Tcl clock command\n" + append txt "documentation for a complete description of acceptable formats." - frame .tf.top -bd 2 -relief raised -padx 5 + ${NS}::labelframe .tf.top ;#-bd 2 -relief raised -padx 5 - message .tf.t -aspect 500 -text $txt - label .tf.l -text "Format: " - entry .tf.e -textvariable state(timeFormat) - button .tf.default -text Default -width 10 -command {tfButton default} - button .tf.ok -text OK -width 10 -command {tfButton ok} - button .tf.cancel -text Cancel -width 10 -command {tfButton cancel} + #message .tf.t -aspect 500 -text $txt + ${NS}::label .tf.t -text $txt + ${NS}::label .tf.l -text "Format: " + ${NS}::entry .tf.e -textvariable state(timeFormat) + ${NS}::button .tf.ok -text OK -default active -command {tfButton ok} + ${NS}::button .tf.default -text Default -underline 0 \ + -command {tfButton default} + ${NS}::button .tf.cancel -text Cancel -command {tfButton cancel} grid .tf.top -row 0 -column 0 -columnspan 4 -sticky ew -padx 10 -pady 10 grid columnconfigure .tf 0 -weight 1 - grid x .tf.default .tf.ok .tf.cancel -padx 5 -sticky ew + grid x .tf.ok .tf.default .tf.cancel -padx 5 -sticky ew grid rowconfigure .tf 2 -minsize 8 grid .tf.t - -in .tf.top -row 0 @@ -554,9 +609,15 @@ proc timestampWindow {} { grid columnconfigure .tf.top 1 -weight 1 grid columnconfigure .tf.top 2 -minsize 10 + bind .tf [list .tf.cancel invoke] + bind .tf [list .tf.ok invoke] + bind .tf [list .tf.default invoke] + focus .tf.e .tf.e icursor end .tf.e select range 0 end + tk::PlaceWindow .tf widget . + wm deiconify .tf } ##+########################################################################## # @@ -839,11 +900,12 @@ proc GetSetup {} { } destroy .dlg - toplevel .dlg + ttk_toplevel .dlg wm withdraw .dlg wm title .dlg "SockSpy Setup" wm transient .dlg . - wm geom .dlg +176+176 + #wm geom .dlg +176+176 + tk::PlaceWindow .dlg widget . ${NS}::label .dlg.top set msg "You can configure SockSpy to either forward data\n" @@ -877,8 +939,8 @@ proc GetSetup {} { ${NS}::entry .dlg.clvar -textvariable SP(cmdLine) # -state readonly doesn't seem to work, sigh - ${NS}::button .dlg.ok -text OK -width 10 -command ValidForm - ${NS}::button .dlg.cancel -text Cancel -width 10 -command [list destroy .dlg] + ${NS}::button .dlg.ok -text OK -default active -command ValidForm + ${NS}::button .dlg.cancel -text Cancel -command [list destroy .dlg] grid .dlg.top -row 0 -column 0 -columnspan 3 -sticky ew -padx 2 -pady 2 grid columnconfigure .dlg 0 -weight 1 @@ -912,13 +974,9 @@ proc GetSetup {} { grid rowconfigure .dlg.fforward 4 -minsize 10 raise .dlg - bind .dlg.forward [bind all ] - bind .dlg.proxy [bind all ] - bind .dlg.fe1 [bind all ] - bind .dlg.fe2 [bind all ] - bind .dlg.fe3 [list .dlg.ok invoke] - bind .dlg.pe1 [list .dlg.ok invoke] - + bind .dlg [list .dlg.ok invoke] + bind .dlg [list .dlg.cancel invoke] + GetSetup2 .dlg.pe1 icursor end .dlg.fe2 icursor end @@ -1095,11 +1153,11 @@ proc Help {} { variable NS set dlg .help destroy $dlg - toplevel $dlg -class Dialog + ttk_toplevel $dlg -class Dialog wm withdraw $dlg wm title $dlg "SockSpy Help" wm transient $dlg . - wm geom $dlg "+[expr {[winfo x .] + 50}]+[expr {[winfo y .] + 50}]" + tk::PlaceWindow $dlg widget . set txt [text $dlg.t -relief raised -wrap word -width 70 -height 25 \ -padx 10 -pady 10 -cursor {} -yscrollcommand [list $dlg.sb set]] @@ -1204,7 +1262,7 @@ proc Help {} { # About -- simple about box # proc About {} { - set m "SockSpy version $::state(version)\n" + set m "SockSpy version $::state(version)\n" append m "by Tom Poindexter and Keith Vetter\n" append m "Copyright 1998-[clock format [clock seconds] -format %Y]\n\n" append m "A program to eavesdrop on a tcp client server conversation." -- 2.23.0