From: Arcadio R. G. <arc...@gm...> - 2009-04-05 09:47:36
|
Hi all, I'm trying to build a very simple GUI for my Ruby application using Cocoa. I have no experience with Cocoa or ObjC, so that might be part of the problem. Anyway, I have a Ruby text application and I would like to add this GUI as an observer. So far I have other observers that for instance write a log to a file, but none of them are graphical. My problem is that I need to run the GUI in another thread since when I start it, the call to app.run (in the code below) never returns. As far as I know, I cannot use Ruby (green) threads. Note that due to the design my project, I cannot invert control and run my application within the thread created by Cocoa. Also, my code is not (yet) compatible with Ruby 1.9, so I have to stick to 1.8. Can anyone point how to execute app.run in another thread in the code shown below. I've tried using NSThread.detachNewThreadSelector_toTarget_withObject but haven't been successful. Thanks! require 'osx/cocoa' include OSX class AppDelegate < NSObject def init frame = [200.0, 300.0, 250.0, 100.0] @win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(frame, 15, 2, 0) @win.setTitle 'Test' @win.setLevel 0 @bar = NSProgressIndicator.alloc.initWithFrame [10.0, 10.0, 80.0, 80.0] @win.contentView.addSubview(@bar) @bar.setIndeterminate(false) @win.display @win.orderFrontRegardless end def step @bar.incrementBy(20) end end app = NSApplication.sharedApplication app.setDelegate(AppDelegate.alloc.init) app.run |