[plt-scheme] MrEd - Menubar
--- Laurent <Ouaibou at gmail.com> wrote:
> Hello,
>
> I have a question about the menu-items.
> I want to modify a variable when I click above a menu-item.
>
> So, i use this :
>
> (define menu-item-sound-effects (new menu-item%
> (parent menu-option)
> (label (if SOUND-EFFECT
> "Désactiver les
> effets
> sonores"
> "Activer les effets
> sonores"))
> (shortcut #\123)
> (callback (lambda (item event)
> (set! SOUND-EFFECT
> (not SOUND-EFFECT))))))
>
> But the following line seems not to perform.
> I don't understand why.
>
> Could somebody explain me?
The expression for the menu item's label is only evaluated once, when
the menu item is created. You need to change the menu item's label
yourself.
Probably the best way to do this is to supply a demand-callback that
sets the label to the right thing. The demand-callback gets called
whenever the menu item is "demanded", that is, when it's about to be
shown. Here's an example (untested) of using demand-callback:
;; sound-text : boolean -> string
;; Text for setting SOUND-EFFECT *to* the boolean value.
(define (sound-text status)
(if status
"Activer les effets sonores"
"Désactiver les effets sonores"))
(define menu-item-sound-effects
(new menu-item%
(parent menu-option)
(label (not SOUND-EFFECT))
(shortcut #\123)
(callback
(lambda (item event)
(set! SOUND-EFFECT (not SOUND-EFFECT))))
(demand-callback
(lambda (item)
(send item set-label
(sound-text (not SOUND-EFFECT)))))))
Ryan
>
> Thanks,
> Laurent
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news