From edecd810469ccf7068c62feae8cebaf39d16718c Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Wed, 14 Dec 2022 17:38:19 -0500 Subject: [PATCH] Modified the toolkit add_selection procedure to take an extra optional argument that is a callback function, so that the act of selecting something from the drop-down menu can cause things to happen such as changing the GUI window contents for the item selected. --- tcltk/toolkit.tcl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tcltk/toolkit.tcl b/tcltk/toolkit.tcl index 2e3a1619..5188e574 100644 --- a/tcltk/toolkit.tcl +++ b/tcltk/toolkit.tcl @@ -1162,9 +1162,13 @@ proc magic::add_message {pname ptext parameters {color blue}} { #---------------------------------------------------------- # Add a selectable-list parameter to the gencell window +# Added 12/14/2022: Optional argument "func" specifies a +# callback procedure to trigger when a menu item is +# selected. #---------------------------------------------------------- -proc magic::add_selectlist {pname ptext all_values parameters {itext ""}} { +proc magic::add_selectlist {pname ptext all_values parameters {itext ""} \ + {func {}}} { if [dict exists $parameters $pname] { set value [dict get $parameters $pname] @@ -1180,9 +1184,11 @@ proc magic::add_selectlist {pname ptext all_values parameters {itext ""}} { grid .params.edits.${pname}_sel -row $numrows -column 1 -sticky wns menu .params.edits.${pname}_sel.menu -tearoff 0 foreach item ${all_values} { + set cmdtxt ".params.edits.${pname}_sel configure -text $item" + if {$func != {}} {set cmdtxt "$cmdtxt ; $func"} .params.edits.${pname}_sel.menu add radio -label $item \ -variable magic::${pname}_val -value $item \ - -command ".params.edits.${pname}_sel configure -text $item" + -command $cmdtxt } set magic::${pname}_val $value }