"Fossies" - the Fresh Open Source Software Archive

Member "ical-tcl/tcllib/dg_yn.tcl" (15 Apr 2019, 1444 Bytes) of package /linux/privat/ical-3.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dg_yn.tcl" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 1993 by Sanjay Ghemawat
    2 #############################################################################
    3 # Yes/No Dialog
    4 #
    5 # Commands
    6 #
    7 #       yes_or_no <leader> <message> <yes-text>? <no-text>?
    8 #               Confirm with user.
    9 
   10 # Hidden global variables
   11 #
   12 #       yn_done                 Is yes_or_no interaction finished
   13 
   14 set yn_done 0
   15 
   16 proc yes_or_no {leader message {y Okay} {n Cancel}} {
   17     yn_make
   18     return [yn_interact $leader $message $y $n]
   19 }
   20 
   21 proc yn_make {} {
   22     set f .yn_dialog
   23     if [winfo exists $f] {return}
   24 
   25     toplevel $f -class Dialog
   26     wm title $f Confirm
   27     wm protocol $f WM_DELETE_WINDOW {set yn_done 0}
   28 
   29     frame $f.top -class Pane
   30 
   31     message $f.text -aspect 400 -text {Uninitialized message}
   32     make_buttons $f.bot 1 {
   33         {Cancel         {set yn_done 0}}
   34         {Okay           {set yn_done 1}}
   35     }
   36 
   37     pack $f.text -in $f.top -side right -expand 1 -fill both -padx 5m -pady 5m
   38     pack $f.top -side top -expand 1 -fill both
   39     pack $f.bot -side bottom -fill both
   40 
   41     bind $f <Control-c> {set yn_done 0}
   42     bind $f <Return> {set yn_done 1}
   43 
   44     wm withdraw $f
   45     update
   46 }
   47 
   48 proc yn_interact {leader message y n} {
   49     global yn_done
   50     set f .yn_dialog
   51 
   52     # Fix dialog contents
   53     $f.text configure -text $message
   54     $f.bot.b0 configure -text $n
   55     $f.bot.b1 configure -text $y
   56 
   57     # Run dialog
   58     set yn_done -1
   59     dialog_run $leader $f yn_done
   60 
   61     return $yn_done
   62 }