Managing windows

Hi,

I have these two handlers:

on windowSplashShow_(sender)
activate me
pWindowMain's orderOut:me
pWindowSplash's makeKeyAndOrderFront:me
my performSelector:"windowSplashClose" withObject:(missing value) afterDelay:2
end windowSplashShow_:
	
on windowSplashClose()
pWindowSplash's orderOut:me
pWindowMain's makeKeyAndOrderFront:me
end windowSplashClose

The handler windowSplashShow is called at startup inside the applicationDidFinishLaunching in this way:

on applicationDidFinishLaunching:notification
initialize()
updateInterface_(me)
windowSplashShow_(me)
verifyPrivileges()
end applicationDidFinishLaunching:

I “discovered” that after calling the windowSplashShow_, the execution of code continue immediately with verifyPrivileges handler. Without waiting the amount of seconds defined.
I my mind when code call windowSplashShow_ the handler wait the delay defined and only after this the window is closed.
After again the verifyPrivileges routine is called.

I miss something? Where is the error?

Stefano - Ame

That is correct. If you don’t want verifyPrivileges() to happen until after the window is closed, call it from windowSplashClose().

When you call performSelector:withObject:afterDelay:, the method is queued to be called in two seconds, but your other code continues to run.

Hi Shane,

As usually, many thanks for clarification and confirmation.
So a workaround is to use do shell script sleep X instead of performSelector
Exists an equivalent do shell script sleep in Cocoa (in ASS we used delay X) to wait execution of the code?

Stefano - AME

Hi,

think asynchronously or in terms of handlers.
Put the verifyPrivileges() call in the windowSplashClose() handler


on windowSplashShow:sender
	activate me
	pWindowMain's orderOut:me
	pWindowSplash's makeKeyAndOrderFront:me
	my performSelector:"windowSplashClose" withObject:(missing value) afterDelay:2
end windowSplashShow:

on windowSplashClose()
	pWindowSplash's orderOut:me
	pWindowMain's makeKeyAndOrderFront:me
	verifyPrivileges()
end windowSplashClose

on applicationDidFinishLaunching:notification
	initialize()
	updateInterface_(me)
	windowSplashShow_(me)
end applicationDidFinishLaunching:

Stefan has given you the correct answer to the original problem, but in answer to this, you can use:

current application's NSThread's sleepForTimeInterval:2

But you should rarely do that – certainly not in your example. You don’t want to freeze things totally.

Hi Shane and Stefan,

I understand that now I have to move verifyPrivileges() inside the windowSplashClose() because performSelector works as sheet window where execution of code don’t stop but continue.
My mind is again on ASS where for this case I used delay that (correct me if I’m wrong) like do shell sleep, freeze the execution for x second and continue with next handler.
In my case the showSplash/close splash is also called when user choose “About this app…” in addition to startup.
What I would like to do is to have only verify privileges at startup.
Basically the app is launched, a splash appear for few seconds and after splash close, permission via network to use the app are verified. If the user is not enabled a modal dialog appear and after OK the app terminate.

Is more simple to manage (but this is my opinion), to have a sleep after an handler and continue with next handler instead of put a particular handler inside another “generic” handler like close.
Probably using Cocoa “scripter” like me need to understand much more about some Cocoa mechanism.

Ame

You can probably use a sleepForTimeInterval: without any problems in that particular case, although you should use modal windows rather than makeKeyAndOrderFront:.

The problem with sleeping is that your interface can’t do anything at all while you have stopped the main thread. That means if the user starts banging keys or something, there’s a chance that the number of pending events will build up too much, and result in the spinning beachball cursor. You don’t want that.