A more elegant way to start a multithread alarm in Rebol VID ? (What's the equivalent of load event?)

泄露秘密 提交于 2019-12-23 04:43:19

问题


I want to trigger an alarm when the GUI starts. I can't see what's the equivalent of load event of other language in Rebol VID, so I put it in the periodic handler which is quite circumvoluted. So how to do this more cleanly ?

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."
      ]

  ]

]

回答1:


If the question is how to make something happen when the gui starts, you can do this

view layout [ text "Here's my layout"

  do [
  .... initialization code ...    
  ] 

]



来源:https://stackoverflow.com/questions/2895458/a-more-elegant-way-to-start-a-multithread-alarm-in-rebol-vid-whats-the-equiv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!