a way to use menus while waiting

From: Brian Denheyer <briand_at_deldotd.com>
Date: Sat, 27 Feb 1999 06:14:44 -0800 (PST)

A while back I had a question which I explained rather poorly. Well I
figured out how to do what I was trying to do, so I thought I'd
contribute the answer :-)

What I have is a typical situation :

menu-item A => proc A => tkwait ...

Now, the problem is how to have the invocation of another menu item
"interrupt" proc A. Here is the answer :

1. have proc A tkwait on a global
2. menu-item B changes the global
3. menu-item B then scedules execution of proc B using after 'idle
4. when the menu command is done, tkwait is "exited" and then the new
   proc starts

See end of e-mail for simple example code.

Hope this is useful. It's probably basic to anyone who already knows
Tk. Obviously that woudln't be me ;-)

Brian

(require "Tk-classes")

(define *signal* #f)
(define *finished* #f)

(define event1
  (lambda ()
    (format #t "Entering event 1...\n")
    (tkwait 'variable '*signal*)
    (format #t "Event 1 exiting...\n")))

(define event2
  (lambda ()
    (format #t "Entering event 2...\n")
    (tkwait 'variable '*signal*)
    (format #t "Event 2 exiting...\n")))

(let* ((drawing-menu-bar
        `(("Document"
           ("Start Event 1" ,(lambda ()
                               (set! *signal* (not *signal*))
                               (after 'idle event1)))
           ("Start Event 2" ,(lambda ()
                               (set! *signal* (not *signal*))
                               (after 'idle event2)))
           ("")
           ("Stop Event" ,(lambda ()
                            (set! *signal* (not *signal*))
                            (format #t "Stop Event selected\n")))
           ("")
           ("Quit" ,(lambda ()
                      (format #t "changing *signal*\n")
                      (set! *signal* (not *signal*))
                      (set! *finished* #t)
                      (format #t "Quit selected.\n"))))))
       (menu-frame (make-menubar *root* drawing-menu-bar)))

  (pack menu-frame))

(format #t "Waiting on *finished*...\n")

(tkwait 'variable '*finished*)

(format #t "Program exiting...\n")
(exit)
Received on Sat Feb 27 1999 - 15:16:30 CET

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