COMB WIDGET EXAMPLES
Popup Container.
Popup container (pop) is a comb-widget for handling a popup window.
A popup widget is a toplevel window with no decorative frames. It is a
container and may be used to display a popup window for menu, label, button,
canvas and etc. A typical use is to display a popup label with additional
information around a button widget.
EXAMPLE: This example shows how to use a popup container
with other comb-widgets to implement a Tcl user-login session. The first
four lines create an image of gimg type with a Tcl logo picture.
The image is created with an option -tile set to 1. The procedure
popup.desktop
is invoked to display the image in a popup window as a wall paper to block
the whole screen at the front. The procedure popup.passwd is bound
to events when any key or a button of the mouse is pressed to create a
user-login popup window. The entry of the user-login window is bound to
a procedure password, which requests a user to type in a password
popup
in order to login. The label "User Login" of the user-login window is bound
to a procedure popup.message, which popups up a label widget to display
a message of password when the mouse cursor moves into the label. Scripts
of popup.desktop, password, popup.passwd and popup.message
are attached at the end of this document.
global tk_library
set imgFile [file join $tk_library demos images tcllogo.gif]
set width [winfo screenwidth .]
set height [winfo screenheight .]
image create gimg tclLogo -file $imgFile \
-sc 4 -maxw 54 -sr 8 -maxh 88 -tw $width \
-th $height -tile 1
popup.desktop .tp tclLogo "popup.passwd .tp popup"
A Tcl login session written with popup comb-widgets
CLASS NAME: pop
COMB-WIDGET OPTIONS
-pop options It specifies options for a non-decorated
Toplevel
window. This is popup toplevel window to be used as a container for any
other windgets.
User-defined options: an option may be defined by a user after
a widget is added into a popup widget.
WIDGET API
popup.create pathname ?options? This command
creates a popup window with no decoration frames. The ?options? can be
any valid options for a toplevel window.
popup.add pathname -varName creator ?options? This command
adds an item (a widget) into a popup widget. The varName is used to identify
a child widget inside the popup widget for a comb-widget operation. The
creator is a widget or comb-widget command. The ?options? are configuration
pairs to be used in creating the child widget inside the popup window.
popup.addItems pathname args This command adds a group
of items into a popup widget identified by pathname. Each arg in the args
list is a list of "-varName creator ?options?" as defined in popup.add
command for creating a new widget inside the popup widget.
popup.delete pathname -varName This command deletes a
child widget inside the popup window.
popup.post pathname reference ?option? This command posts
a popup widget at a reference position. The reference can be either a list
of {x y} for a upper left position of the popup widget or a reference widget.
If a reference widget is used, an opitional anchor value may be specified,
i.e., north, south, east, west, northeast,
nortwest,
southeast,
soutwest
(n, s, e, w, ne, nw, se, sw for short). An anchor is always relative
to the reference widget. The default anchor is northwest. Since
a popup window is a toplevel, a utility of XBit, ctrwin, which centers
a toplevel at the screen, can be used to post a popup window at the screen
center.
popup.hide pathname This command hides a popup widget.
RELATED PROCEDURES
The followings are procedures used in a popup widget implementation
and test. A user may access to these procedures through the a popup
widget API, and should never use these procedures directly in an application
program.
popup.free pathname.
popup.freeItem pathname ds msg.
PROCEDURE SCRIPTS USED IN THE EXAMPLE
proc popup.desktop {w img btnPressScripts} {
global tk_library
catch "destroy $w"
update
set width [image width $img]
set height [image height $img]
popup.create $w
wm geom $w ${width}x$height
pack [popup.add $w -label label "-image $img"] -fill both -expand
1
bind $w <ButtonPress> $btnPressScripts
bind $w <KeyPress> $btnPressScripts
popup.post $w "0 0"
}
proc popup.passwd {popup {passwd xbit}} {
set tp $popup.pwd
if ![winfo exists $tp] {
popup.create $tp -pop
{-bd 2 -relief raise}
set frm [popup.add $tp -frm frm.create
\
"-label {-text {User
Login}} -pad {-bd 10}"]
pack $frm -padx 10 -pady 10
set w [frm.add $frm -ment ment.create \
-title {Welcome to TclTk/XBit}
\
-btns {{-text Ok} {-text
Cancel}} \
-vars {{Type in password:
}}"]
ment.config $w -v0 "-show * -textv _comb($popup,pwd)"
ment.config $w -btn0 "-comm {password $popup}"
ment.config $w -btn1 "-comm {destroy $tp}"
ment.bind $w <Key-Return> "password $popup
$passwd" -v0
pack $w -expand 1 -fill both
set label [comb.id $frm -label]
popup.message $label.info $label east \
"The password is $passwd."
ctrwin $tp
}
}
proc password {w {passwd xbit}} {
global _comb
if {$_comb($w,pwd) == $passwd} {
destroy $w
} else {bell}
}
proc popup.message {w ref anchor msg} {
set popup [popup.create $w]
pack [popup.add $popup -info label \
"-text {$msg} -anchor nw -bg yellow"]
bind $ref <Enter> "+popup.post $popup $ref $anchor"
bind $ref <ButtonPress> "+popup.hide $popup"
bind $ref <Leave> "+popup.hide $popup"
}
[HOME][CONTENTS][DOWNLOAD] |