Bug in dialog.stk?

From: Harvey J. Stein <abel_at_netvision.net.il>
Date: Tue, 12 Nov 1996 16:38:35 +0200

I think there's a bug in dialog.stk. The comment says:

;; If grabbing is set, this procedure returns the button pressed index.

But, it always seems to return -1.

I think the problem is that you have the following code so that if the
window inadvertently gets destroyed, the system doesn't pause forever:

        ;; Add a binding that sets the result to -1 if the window is detroyed
        (bind w "<Destroy>" (lambda () (set! stk::button-pressed -1)))

        (Tk:tkwait 'variable 'stk::button-pressed)

The problem is that the command on each button is:

        (Tk:button name :text (caar but)
                           :command (lambda ()
                                   (if old-focus (Tk:focus old-focus))
                                   (set! stk::button-pressed i)
                                   (Tk:destroy w)
                                   (apply (cadar but) '())))

This means that when a button is pressed, stk::button-pressed gets
set, then the window gets destroyed, thus causing stk::button-pressed
to be reset to -1.

A simple fix is to switch the order of (tk:destroy w) and (set!
stk::button-presed) in the above call to Tk:button.

Or, on the <destroy> binding, one could only set stk::button-pressed
if it's false.

I'm not sure which is better, or if maybe they're both not so hot,
because I'm a little fuzzy on exactly how the destroy binding will
interract with the button command. But, they both worked for me in a
quick test.

Also, isn't it the case that now that all the commands & bindings are
closures, that stk::button-pressed can now be defined in the topmost
let clause of stk:make-dialog (as opposed to being a global variable)?

Finally, a suggestion. I hacked stk:make-dialog to make something I
call STk:query-dialog. It's exactly the same as stk:make-dialog, but
includes an entry widget in the middle, and returns a list of the
value of the entry widget followed by the button number pressed. I
find it quite useful as a quick way to pop up a window which requests
input from the user. Usage would be something like:

(define (query-data text)
  (let ((result
         (stk:query-dialog :title "Query..."
                            :text text
                            :default 0
                            :grab #t
                            :buttons `(("Ok" ,(lambda () ()))
                                       ("Cancel" ,(lambda () ()))))))
    (if (= 0 (cadr result)) (car result) #f)))

(define (delete-node-cmd)
  (let ((node (query-data "Delete node...")))
    (if node
        (destroy-node (hash-table-get ctb-node-hash
                                      (string->symbol node))))))


Dr. Harvey J. Stein
Berger Financial Research
Received on Tue Nov 12 1996 - 16:05:52 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST