Pack , bind, & scrollbar help
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Pack , bind, & scrollbar help

From: Ray <ray.mosley@gmail.com>
Date: Sun Feb 26 2006 - 03:37:43 CET

1) I can't figure out how to get things positioned. I want the items
positioned like:
                        Selection frame
                        Result frame
                        Buttons
    but instead I get
                      Selection frame Result Frame
                                    Buttons
2) This code generates a funky looking horinzontal scroll bar on the
far right, but it is
    small and looks really strange.
3) Finally, the bind <Double-1> works, but why can't I just change
"double" to "Button"
    and select things with a single click?

Thanks in advance for the help.
Ray

We are forced to use RH Linux 8.0, which has Tcl 8.3 loaded. I can't
change that environment.
--------------------------------------------------------------------------------------------

#
# script to display query results: RH Linux
#

proc execQuery {W} {
    set X 0
    tk_messageBox -icon error -message "Selected \"$::selTable\""
    if [string length $::selTable]==0 {
        tk_messageBox -icon error -title "No Table Selected" \\
            -type OK -message "You must select a table name."
    } else {
        set qSelect [format "Select * from %s;" $::selTable]
        puts [set qfd [open $::qFile w]] $qSelect
        close $qfd
        set qResData [exec psql -d DATASTORE -U dssadmin -f $::qFile]
        set curTimeStamp [clock format [clock seconds] -format
"%Y%m%d_%H%M%S"]
        set qResFile [file join $::homeDirTmp [format
"%s_%s_queryResult.txt" $curTimeStamp $::selTable]]
        set qfd [open $qResFile w]
        set dt [clock format [clock seconds] -format "%A %D %T %Z"]
        puts $qfd [format "%s Table Query: Date & Time=%s\nQuery
Executed=\"%s\"" $::selTable $dt $qSelect]
        set qRecList [split $qResData "\n"]
        $W.frame.rlist insert end " ============= Query: \"$qSelect\"
==========="
        foreach rec $qRecList {
            puts $qfd [string trim $rec]
            $W.frame.rlist insert end $rec
        }
        puts $qfd [set eString " ============= End Of $::selTable Query
===============\n"]
        $W.frame.rlist insert end $eString
        close $qfd
        update
    }
}
###--- end of procedure execQuery

# initialize
set ::homeDir {/home/tester}
set ::homeDirTmp [file join $::homeDir tmp]
file mkdir $::homeDirTmp
set ::homeDirBin [file join $::homeDir bin]
set ::qFile [file join $homeDirTmp query.txt]
set testName [file rootname [file tail [info script]]]
set fileIni "datastore.ini"
set iniFileName [file join $::homeDirBin $fileIni]
if [file exists $iniFileName] {
    # assume the table list is saved
    set fd [open $iniFileName r]
    set tableData [read $fd]
    close $fd
    set table [split $tableData "\n"]
} else {
    # initialization file does not exist; build it and save it
    set fd [open [file join <path-to-crfeate-table-script>-postgre.sql]
r]
    set searchStr "CREATE TABLE "
    set searchLng [string length $searchStr]
    set sqlFile [read $fd]
    close $fd
    set fd [open $iniFileName w]
    set sPtr 0
    while {$sPtr>=0} {
        if [set sPtr [string first $searchStr $sqlFile $sPtr]]>=0 {
            incr sPtr $searchLng
            set ePtr [string first " " $sqlFile $sPtr]
            lappend table [set tName [string trim [string range $sqlFile $sPtr
$ePtr]]]
            puts $fd $tName
        }
    }
    close $fd
}

set X 0

set ::selTable ""
# build the window
eval destroy [winfo child .]

toplevel [set w .q]
wm title $w "Query"

label $w.lbl -font {Arial 12} -text "Double-Click Table Name to Select"
-relief groove
pack $w.lbl -side top

frame $w.buttons
pack $w.buttons -side bottom -fill x -pady 2m
button $w.buttons.eb -text Exit -command "destroy $w"
button $w.buttons.exec -font {Arial 12} -text "Execute Query" -command
[list execQuery $w]
pack $w.buttons.eb $w.buttons.exec -side left -expand 1

frame $w.frame -borderwidth 10
pack $w.frame -side top -expand yes -fill y

scrollbar $w.frame.scroll -command "$w.frame.list yview"
listbox $w.frame.list -yscroll "$w.frame.scroll set" \
        -width 50 -height 10 -setgrid 1
pack $w.frame.list $w.frame.scroll -side left -fill y -expand 1

bind $w.frame.list <Double-1> {
    set ::selTable [string trim [selection get]]
}
###bind $w.frame.list <Button-1> {
### set ::selTable [string trim [selection get]]
###}
foreach t [lsort $table] {
    if [string length [string trim $t]] {
        $w.frame.list insert end $t
    }
}

scrollbar $w.frame.vscroll -command "$w.frame.rlist yview"
scrollbar $w.frame.hscroll -command "$w.frame.rlist xview"
listbox $w.frame.rlist -yscroll "$w.frame.vscroll set" \
        -xscroll "$w.frame.hscroll set" -width 100 -height 30 -setgrid 1
pack $w.frame.rlist $w.frame.vscroll -side left -fill y -expand 1
pack $w.frame.hscroll -side bottom -fill x -expand 1
Received on Sun Apr 30 02:15:54 2006