[squeak-dev] How do I "sleep 5"?

Eduardo Ochs eduardoochs at gmail.com
Tue Feb 21 22:57:29 UTC 2023

Hi Vanessa!
Thanks! =) This works in a workspace,

  "Create a SimpleSwitchMorph with label 'Toggle'
      and a SimpleButtonMorph with label 'Flash'.
      The button will be placed below the switch."

  sm := SimpleSwitchMorph new.
  sm openInWorld.
  bm := SimpleButtonMorph new.
  bm openInWorld.
  bm position: bm position + (0 at 32).

  "Three ways of toggling the color of the switch:"

  sm toggleState.

  bl := [ sm toggleState ].
  bl value.

  bm target: bl.
  bm actionSelector: #value.
  bm doButtonAction.

  "Two ways of toggling the switch after 1000ms:"

  sm addAlarm: #toggleState after: 1000.
  bm addAlarm: #doButtonAction after: 1000.

but this doesn't:

  bm2 := SimpleButtonMorph new.
  bm2 target: bl.
  bm2 actionSelector: #value.
  bm2 addAlarm: #doButtonAction after: 1000.

What is the right way to add an alarm to a morph that is not shown on
the screen? Also, can I create a new invisible morph every time that I
want to run an alarm? Are they going to be garbage collected?

  Thanks in advance!
    Eduardo Ochs

On Tue, 21 Feb 2023 at 02:16, Vanessa Freudenberg <vanessa at codefrau.net>

> The best way to do this in Morphic is with "alarms":
>     self addAlarm: #changeKeyboardFocus after: 5000.
> which would execute the morph's changeKeyboardFocus method 5 seconds later.
> The way of sleeping you suggest is possible too but more tricky, since you
> would have to move your wait code to an extra process to not block the UI
> process, but then make sure that the actual work is done in the UI process
> again (Morphic is not multithreaded, although Squeak is).
> Vanessa
> On Mon, Feb 20, 2023 at 8:49 PM Eduardo Ochs <eduardoochs at gmail.com>
> wrote:
>> Hi list,
>> a few days ago I asked for help on how to send a "synthetic" keyboard
>> event to a morph, and Karl Ramberg gave me exactly the right hints in
>> this thread:
>> http://lists.squeakfoundation.org/pipermail/squeak-dev/2023-February/223473.html
>> My code is ready except for documentation and comments - I'll work on
>> that in the next few days and then post the result here and on the
>> wiki...
>> ...but there's a feature that I want to add to it that - again =( -
>> needs something that I'm not being able to discover by myself. How do
>> I write a line of code that waits for 5 seconds, sort of like running
>> "sleep 5" in a shell, and that doesn't block the rest of the system?
>> If I have that I'll be able to run these two lines in a workspace,
>>   self mySleep: 5000.
>>   kf := self currentHand keyboardFocus.
>> switch the keyboard focus to something else by clicking on it, and
>> then the variable kf will be set to this "something else"...
>> Thanks in advance!
>>   Eduardo Ochs
>>   http://anggtwu.net/eev-squeak.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20230221/25c94cdb/attachment.html>

More information about the Squeak-dev mailing list