SnowCrash

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

SnowCrash

Postby sjt on Sat Nov 07, 2015 6:16 pm

Exploring -- for pedagogy -- the theme of the simplest possible app, I drafted the world's worst screensaver, attached.

I'm both using ⎕NEW instead of ⎕WC, and writing a class that inherits the GUI Form. I figure this approach most familiar to a non-APL reader. It's years since I last... and I've forgotten how to... and I've failed to rediscover from the user manuals...

1. Clicking the Kill button invokes the callback ShutShop. That worked: when I interrupt I find closed set to 1. But the app continues to loop.

2. I should be able to run the main event loop from a Timer with a callback to WhiteNoise instead of the dumb loop on ⎕DL. So far I've failed to create a Timer using ⎕NEW.

Any advice or thoughtswelcome.

SJT
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: SnowCrash

Postby sjt on Sun Nov 08, 2015 9:51 am

Of course not attached. Class here.

      :Class SnowCrash:'Form'

∇ Make0;points;cmap;bits
:Access Public
:Implements Constructor
(Coord Size points)←'Pixel'(300 400)(0 0)
cmap←0 128 192 255['0234'⍳16 3⍴'000200020220002202022222333400040440004404044444'] ⍝ 16-colour map
bits←Size⍴0
im←⎕NEW'Image'(('Points'points)('Picture'(⎕NEW'Bitmap'(⊂'Bits'bits))))
im.Picture.(Points CMap Bits)←points cmap bits
closed←0
onClose←'ShutShop'
⍝ onTimer←'WhiteNoise'
⍝ tm←⎕NEW'Timer'(⊂'Interval'(1000÷24))
:Repeat
im.Picture.Bits←15×(?Size⍴2)-×⎕DL÷24 ⍝ 24 frames per second
:Until closed
⎕←'all done'


∇ Z←ShutShop
Z←closed←1


⍝ ∇ WhiteNoise
⍝ im.Picture.Bits←15×(?Size⍴2)-1
⍝ ∇

:EndClass
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: SnowCrash

Postby Dick Bowman on Mon Nov 09, 2015 3:37 pm

Off the top of my head all I see that's strange is your onTimer line (which seems to be in the wrong place and have the wrong parent - but I may bemisunderstanding).

tm←⎕NEW 'Timer' (⊂'Interval' (1000+24))

behaves itself for me.

But I'd expect to follow that with tm.onTimer to make exciting things happen.

Bitter experience tells me to heed the warning in the Timer object documentation.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: SnowCrash

Postby Vince|Dyalog on Wed Nov 11, 2015 3:23 pm

Hi Stephen,

I think that you need some sort of ⎕DQ in the :repeat :until loop so that Dyalog can process the event messages.

Kai has a ∆DQ method which Paul Mansour posted in this thread: Automated GUI Testing viewtopic.php?f=19&t=913#p3533

I've taken out your image code and I use a label with a timer which updates the label's text.

      :Class SnowCrash:'Form'

∇ Make0;points;cmap;bits
:Access Public
:Implements Constructor
(Coord Size points)←'Pixel'(300 400)(0 0)

bits←Size⍴0

closed←0
onClose←'ShutShop'

lb←⎕NEW'Label'(⊂'size'(30 200))
tm←⎕NEW'Timer'(⊂'Interval'(1000÷24))
tm.onTimer←'WhiteNoise'
:Repeat
1 ∆DQ ⎕THIS
:Until closed
2 ⎕NQ ⎕THIS'Close'
⎕←'all done'


∆DQ←{ ⍝ Dequeue form ⍵ for ⍺ seconds
⍺←0 ⍝ Default delay
6::1
_←⍵.⎕WS'Event' 9955 1 ⍝ Exit ⎕DQ on 9955
_←⍺{_←⎕DL ⍺ ⋄ ⎕NQ ⍵ 9955}&⍵ ⍝ Thread enqueued event
_←⍵.Wait ⍝ Wait for ⍺ seconds
_←0
}

∇ Z←ShutShop
closed←1
⎕←'ShutShop called'
Z←0 ⍝ we'll close it ourselves


∇ WhiteNoise

lb.Caption←⍕⎕TS



Regards,

Vince
Vince|Dyalog
 
Posts: 412
Joined: Wed Oct 01, 2008 9:39 am


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest