|
From: Jonathan P. <jp...@dc...> - 2005-04-13 17:47:44
|
On 13 Apr 2005, at 18:20, kimura wataru wrote:
> The method NSApplication#beginSheet... is asynchronous. You not need
> to create a new thread.
I understand that beginSheet... is asynchronous, but the problem is
that I want the Cocoa GUI to continue to respond to user interaction
(other windows, menus, etc) whilst the ruby code that's doing the
processing is working.
Let's assume that the ruby method is called from the action of a button
on a window. The method shows the sheet, does some lengthy processing,
then hides the sheet.
Therefore the call hierarchy is:
run loop waiting for events
handling mouse click event
passing that to button
button invokes action on its target
<<ruby method here, doesn't return until lengthy processing
complete>>
The problem is that the lengthy processing (in your example the 1..3
sleep loop) doesn't allow for any GUI events to be processed. The run
loop is suspended (handling our click event) until the ruby method
returns. I don't want the GUI to lock up like this.
What I wanted to be able to do was:
def buttonHandler(sender)
...beginSheet(...)
Thread.new do
<<lengthy processing>>
...orderOut(...)
...endSheet(...)
end
end
This fails (sometimes) because calling the Cocoa methods (orderOut,
endSheet) from the non-main Ruby thread is unsafe.
I'm sorry that I wasn't very clear in my first message. Does this
explain the situation any better?
> NSApplication#endSheet does not close the sheet. We must call
> "orderOut"
> of the sheet in delegate method.
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/Sheets/
> Tasks/UsingCustomSheets.html
You're right - I had forgotten about that in my example code.
Many thanks for your help.
Jonathan
|