Version 0 of edit_val

Updated 2016-01-29 13:37:39 by HJG

Summary

HJG 2016-01-28: This is a fork of A little value dialog by Richard Suchenwirth, a small edit-value-dialog.

The immediate upcoming intended use is in MINISS - Mini Spread Sheet, together with that m+-menu routine.

Description

I have some ideas on how to modify the original value_dialog - routine, so I made a separate page here:

  • Avoid double-returning the result (return + global var)
  • Undo/discard when pressing the Cancel-button
  • controlling the position of the dialog

...


# Input-Dialog: (from http://wiki.tcl.tk/8692 "A little value dialog" by R.Suchenwirth)

proc value_dialog {string } {
 puts "value_dialog:<$::val>"
   #set w [toplevel .[clock seconds]]
    set w [toplevel .edit]
   #wm resizable $w 0 0
    wm title $w "Edit cell"

    label  $w.l -text    $string
   #entry  $w.e -textvar $w -bg white
    entry  $w.e -textvariable ::val -width 20
    bind   $w.e <Return> {set done 1}
    set old $::val

    button $w.ok     -text OK     -command {set done 1}
    button $w.c      -text Clear  -command "set ::val {}"
    button $w.cancel -text Cancel -command "set ::val $old; set done 1"

    grid $w.l  -    -        -sticky news
    grid $w.e  -    -        -sticky news
    grid $w.ok $w.c $w.cancel
    focus $w.e

    vwait done
    destroy $w
   #set ::$w
    set ::val;   # ??
}

# Demo:

 set val 123
 set test [edit_val "Enter value:"]
#puts test:$test
#puts  val:$val
 pack [ label .l -text "Value: '$test'/'$val' " -pady 30 -padx 30 ]
 focus -f .
#raise .

Comments

...

See also