~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gcl-tk/demos/mkDialog.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# mkDialog w msgArgs list list ...
 
2
#
 
3
# Create a dialog box with a message and any number of buttons at
 
4
# the bottom.
 
5
#
 
6
# Arguments:
 
7
#    w -        Name to use for new top-level window.
 
8
#    msgArgs -  List of arguments to use when creating the message of the
 
9
#               dialog box (e.g. text, justifcation, etc.)
 
10
#    list -     A two-element list that describes one of the buttons that
 
11
#               will appear at the bottom of the dialog.  The first element
 
12
#               gives the text to be displayed in the button and the second
 
13
#               gives the command to be invoked when the button is invoked.
 
14
 
 
15
proc mkDialog {w msgArgs args} {
 
16
    catch {destroy $w}
 
17
    toplevel $w -class Dialog
 
18
    wm title $w "Dialog box"
 
19
    wm iconname $w "Dialog"
 
20
 
 
21
    # Create two frames in the main window. The top frame will hold the
 
22
    # message and the bottom one will hold the buttons.  Arrange them
 
23
    # one above the other, with any extra vertical space split between
 
24
    # them.
 
25
 
 
26
    frame $w.top -relief raised -border 1
 
27
    frame $w.bot -relief raised -border 1
 
28
    pack $w.top $w.bot -side top -fill both -expand yes
 
29
 
 
30
    # Create the message widget and arrange for it to be centered in the
 
31
    # top frame.
 
32
    
 
33
    eval message $w.top.msg -justify center \
 
34
            -font -Adobe-times-medium-r-normal--*-180* $msgArgs
 
35
    pack $w.top.msg -side top -expand yes -padx 3 -pady 3
 
36
 
 
37
    # Create as many buttons as needed and arrange them from left to right
 
38
    # in the bottom frame.  Embed the left button in an additional sunken
 
39
    # frame to indicate that it is the default button, and arrange for that
 
40
    # button to be invoked as the default action for clicks and returns in
 
41
    # the dialog.
 
42
 
 
43
    if {[llength $args] > 0} {
 
44
        set arg [lindex $args 0]
 
45
        frame $w.bot.0 -relief sunken -border 1
 
46
        pack $w.bot.0 -side left -expand yes -padx 10 -pady 10
 
47
        button $w.bot.0.button -text [lindex $arg 0] \
 
48
                -command "[lindex $arg 1]; destroy $w"
 
49
        pack $w.bot.0.button -expand yes -padx 6 -pady 6
 
50
        bind $w <Return> "[lindex $arg 1]; destroy $w"
 
51
        focus $w
 
52
 
 
53
        set i 1
 
54
        foreach arg [lrange $args 1 end] {
 
55
            button $w.bot.$i -text [lindex $arg 0] \
 
56
                    -command "[lindex $arg 1]; destroy $w"
 
57
            pack $w.bot.$i -side left -expand yes -padx 10
 
58
            set i [expr $i+1]
 
59
        }
 
60
    }
 
61
    bind $w <Any-Enter> [list focus $w]
 
62
    focus $w
 
63
}