I'm trying to build a simple Cocoa app using RubyCocoa.
I've no experience with Cocoa, but I'm not trying to make anything
fancy. In short, I'd like to create a window that acts as an observer
for my terminal app. It'll give feedback to the user with a progress
bar and a few more things.
I now I cannot use Ruby threads within RubyCocoa code, and I'm stuck
using Cocoa worker threads. I've done this, but it doesn't work:
class AppRunner < NSObject
def run
pool = NSAutoreleasePool.alloc.init
app = NSApplication.sharedApplication
app.setDelegate(AppDelegate.alloc.init)
app.run
pool.release
end
end
I'm trying to build a simple Cocoa app using RubyCocoa.
I've no experience with Cocoa, but I'm not trying to make anything
fancy. In short, I'd like to create a window that acts as an observer
for my terminal app. It'll give feedback to the user with a progress
bar and a few more things.
Now the problem is that app.run never returns:
app = NSApplication.sharedApplication
that looks ok
app.setDelegate(AppDelegate.alloc.init)
this doesn't look right; you'd typically want one of your classes to act as the NSApplicationDelegate object. Is AppDelegate one of your classes?
app.run
I now I cannot use Ruby threads within RubyCocoa code, and I'm stuck
using Cocoa worker threads. I've done this, but it doesn't work:
class AppRunner < NSObject
def run
pool = NSAutoreleasePool.alloc.init
I wouldn't think you'd have to alloc and init the NSAuto... class, typically any object you'd want auto released you could just call autorelease on, and you're not making any other calls involving the pool var before you release it at the end of your method def, so why is it there?
app = NSApplication.sharedApplication
app.setDelegate(AppDelegate.alloc.init)
app.run
pool.release
end
end
Yes, it is necessary to run the app in a separate thread. I have a big
text app and the Cocoa window is intended to be registered as an
observer to that app. There are other non-graphical observers too.
Inverting this would change the design a lot.
The thing is that as app.run never returns (which is ok) I need to run
the app in another thread (or process, but that would make things more
complex).
As to the above code, AppDelegate is one of my classes (the one that
creates the window). The rest is something I took from a RubyCocoa
doc, but I'm not sure if it's ok (it seems to be wrong actually).