我想在GUI启动时触发警报。我无法在Rebol VID中看到其他语言的load事件的等价物,所以我把它放在周期性的处理程序中,这个处理器非常环绕。那么如何更干净地做到这一点?
alarm-data: none
set-alarm: func [
"Set alarm for future time."
seconds "Seconds from now to ring alarm."
message [string! unset!] "Message to print on alarm."
] [
alarm-data: reduce [now/time + seconds message]
]
ring: func [
"Action for when alarm comes due."
message [string! unset!]
] [
set-face monitor either message [message]["RIIIING!"]
; Your sound playing can also go here (my computer doesn't have speakers).
]
periodic: func [
"Called every second, checks alarms."
fact action event
] [
either alarm-data [
; Update alarm countdown.
set-face monitor rejoin [
"Alarm will ring in "
to integer! alarm-data/1 - now/time
" seconds."
]
; Check alarm.
if now/time > alarm-data/1 [
ring alarm-data/2
;alarm-data: none ; Reset once fired.
]
][
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
]
]
alarm: func[seconds message [string! unset!]][
system/words/seconds: seconds
if value? 'message [
system/words/message: message
]
view layout [
monitor: text 256 ""
rate 1 feel [engage: :periodic]
button 256 "re/start countdown" [
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
set-face monitor "Alarm set."
]
]
]
答案 0 :(得分:3)
如果问题是如何在gui启动时发生某些事情,你可以这样做
查看布局[ 文字“这是我的布局”
do [ .... initialization code ... ]