I'm quite new at using vtcl and am running V 1.06. What follows may be because
of my inexperience with vtcl, but in the documentation vacuum :) I thought I'd ask the
people on the mailing list.
I often use a "compound" widget when I'm coding Tk by hand, and I've been
playing with the compound widget feature of vtcl 1.06. Let me use an example:
Building a "combobox like widget" consisting of a label, an entry widget and a
button that can bring up a pick list of possible choices to enter into the entry
widget. The following output from vtcl when the compound widget is saved produces a
good approximation of what I want:
set vTcl(cmpd,list) "combo"
set {vTcl(cmpd:combo)} {{frame {-borderwidth 1 -height 30 -relief raised -width
30} {place {-x 5 -relx 0 -y 5 -rely 0 -width 275 -height 25 -anchor nw -bordermo
de ignore}} {} {} {{button {-font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*
-*-*-* -highlightthickness 0 -padx 3 -pady 0 -takefocus 0 -text v} {pack {-ancho
r center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side right}} {{
<ButtonRelease-1> {cmp:makeCombo %W listname}}} {} {} .01 {}} {entry {-backgroun
d #f0f0f0 -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -width 0} {
pack {-anchor center -expand 1 -fill x -ipadx 0 -ipady 0 -padx 0 -pady 0 -side r
ight}} {} {} {} .02 {}} {label {-font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*
-*-*-*-*-* -relief groove -text label} {pack {-anchor center -expand 0 -fill non
e -ipadx 0 -ipady 0 -padx 0 -pady 0 -side right}} {} {} {} .03 {}} } {} {}} {{.t
op1.fra2.but3 .01} {.top1.fra2.ent4 .02} {.top1.fra2.lab5 .03} {.top1.fra2 }}}
The cmp:makeCombo proc looks like this for those who are interested.
------------------------------
proc cmp:makeCombo {button listname} {
upvar #0 $listname lst
# Arbitrary max size of drop-down listbox. Change if
# some other size is more suitable.
set maxHeight 10
# The button variable is the name of the button pressed.
# It's part of a compound widget made up of a label, an entry
# widget and this button. The first step is to get the widget
# name for the entry widget.
foreach i [winfo children [winfo parent $button]] {
# this is a very crude way to find the entry widget
# it's the only one with insertwidth as a configuration option
if {! [catch { $i cget -insertwidth }]} {
set w $i
break
}
}
# find the location for the drop down list
set x [winfo rootx $w]
set y [expr [winfo rooty $w] + [winfo height $w]]
# If already visible, destroy the widget
if {! [catch { destroy $w.t }]} {
return
}
# must set cursor type for new toplevel
toplevel $w.t -cursor left_ptr
# no window decoration on listbox
wm overrideredirect $w.t true
# the list stuff
frame $w.t.f
scrollbar $w.t.f.s -command "$w.t.l yview" -width 10
# Limit the size of the listbox if necessary
if {$maxHeight < [set height [llength $lst]]} {
set height $maxHeight
}
listbox $w.t.f.l -yscroll "$w.t.f.s set" \
-width [$w cget -width] -height $height \
-relief raised -bd 1
set command {[%W get [%W curselection]]}
# the after command in the binding is needed to provide a
# 'breathing space' so that commands are done before the widget
# is destroyed.
bind $w.t.f.l <ButtonRelease-1> "
$w delete 0 end
$w insert end $command
after 10 {destroy $w.t}
"
# Insert the list items in the listbox.
foreach choice $lst {
$w.t.f.l insert end $choice
}
pack $w.t.f.s -side right -expand true -fill y
pack $w.t.f.l -side right -expand true -fill both
pack $w.t.f
wm geom $w.t +$x+$y
}
-------------------------
<ButtonRelease-1> on the button is bound to a function
"cmp:makeCombo %W listname" and the idea was that for each combo compound that I
insert into my vtcl window I would create a list using the variable editor and change
the button binding to point to that listname. And it works.
My problem is this: every time I want to use this with vtcl, I have to load
the cmp:makeCombo proc into vtcl by using a cut and paste into the vtcl function
editor. This seems rather awkward. Since the notion of compound widgets is one that
can yield high efficiency, would it be possible to have vtcl load a library of procs
in association with the compound widgets? (Or perhaps honour the auto_path variable or
something?)
As I said, I'm new here, so perhaps there's something I'm missing. I'd
appreciate it if someone could find a way to simplify this procedure.
I _do_ like vtcl, and it has made the programs I've produced with it look much
better, because I have some time to "pretty things up" a bit. Thanks to Stewart Allen
for the program and the ongoing support he's offering for it.
--
Glen Walker, Edmonton Alberta Canada