I'm still trying to get a handle on Cocoa (both in Obj-C and MacRuby), and I'd really appreciate seeing how to download a file with ASIHTTPRequest (or without it) and MacRuby. Ideally, I'd like to be able show the progress inside a progress bar too.
Must use a cocoa method for downloading, since open-uri in MacRuby is borken.
Thanks for your help.
Here is an example app doing exactly that using HotCocoa: http://github.com/richkilmer/hotcocoa/tree/master/examples/download_and_progress_indicator
You would have to convert it to normal Cocoa but if you look at http://github.com/richkilmer/hotcocoa/blob/master/examples/download_and_progress_indicator/lib/application.rb you will see the main callbacks defined.
You might want to ask your questions in the MacRuby mailing so people involved with the project can help.
Matt
p.s: The cocoa IO methods are way more stable and efficient than Ruby's. Also keep in mind that you want to do async calls, something net/http won't help you with.
Here are more explanations and an example from the book I'm writting: http://macruby.labs.oreilly.com/ch03.html#_urls_requests_connections Hopefully that will help.
Related
I'm trying to create a Mac version of an iPhone app, and specifically I need to be able to pick a person from the user's Address Book, akin to the ABPeoplePicker on iOS. The look of the interface isn't particularly important (be it a separate popup window or a subview etc), I just need to pull up a list from Address Book and have the user select a row, and then feed the First and Last names from that contact back into my code.
But from what I can tell, that functionality doesn't exist for Mac, or else it isn't nearly as user-friendly and intuitive to implement.
Can anyone shed any light on how I might do this? Are there built-in functions I haven't found yet, or any good 3rd party code sources you can recommend?
PS I know enough to be dangerous, but I'm still very much a beginner. Code samples and tutorial links are very much appreciated!
Perhaps Apple's CocoaPeoplePicker demo can help you.
Here's the AddressBook framework reference
I am looking for a way to easyly load images from the web in Cocoa (for mac, not iOS)
Any pointer?
Thanks
I know this is late to answer, but i made a NSImageView subclass to downloads images asynchronously. It's the PVAsyncImageView.Check it out here: PVAsyncImageView
NSURLConnection is the Cocoa API for the job.
However, some people prefer ASIHTTPRequest (I'm one of them) so you should check that out too. The developers of this library have really good docs as well!
CGDataProviderCreateWithURL can be used to create a CGImageRef. using this, you shouldn't have to set up with your own url connections (but you should not call it in realtime or from the drawing thread because it will block).
once you have a CGImageRef, you can either use the result directly or use it to create an NSImage.
Anyone found out if it's possible to "embed" an instance of Terminal into an app? It would be awesome if it also just inherited the tab functionality and drag-drop-ness as well. I saw a couple similar questions on here that mentioned iTerm but it seems like there should be an easier way. Like a NSTerminal object I can pop into a view.
I asked the Panic guys about this. They have a terminal window in Coda that for all intents and purposes looks/functions exactly like Terminal.app running standalone on the desktop. However, their response was that they had to write that themselves from scratch. I'm hoping someone has figured out a better way!
Thanks!
You can do this with the Pathfinder SDK from Cocoatech.
No such thing AFAIK. I don't think embedding a full-featured terminal into an unrelated app is a common enough need that anybody would have made a control like that — even Panic only use it in the one app.
I am using Ruby 1.9.1p430 (2010-08-16 revision 28998) on MS Ws7 with MS Office 2010
I have launched a copy of Word from Ruby using WIN32OLE:
wd = WIN32OLE.new('Word.Application')
All works fine, I can manipulate my document as required.
However, the Word window is in the background and I would like to bring it to the foreground so that the user sees the window and can interact with it as necessary.
I have done some reading but cannot find a way to do this using Ruby.
Any help or pointers in the right direction greatly appreciated.
You are using
wd.visible = true
And it is still in the background?
Good luck :-)
Unfortunately, that sort of thing is both os specific, and not in the standard libs, so it is going to be tough. First thing is dig through the WIN32OLE docs a bit http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/index.html, but I don't think it will be there.
after that, I would poke around github a bit (although I wouldn't hold out too much hope).
After that, I would look at http://www.autoitscript.com/autoit3/index.shtml (or something like it), and see if I could use that or integrate with it somehow.
finally, I would look at how http://win32utils.rubyforge.org/ handles api wrapping, figure out the win32 api call you need, and then write a c extension wrapper for it.
I'd like to create a progress bar to indicate the status of an a batch job in Ruby.
I've read some tutorials / libraries on using (n)curses, none of which were particularly helpful in explaining how to create an "animated" progress bar in the terminal or using curses with Ruby.
I'm already aware of using a separate thread to monitor the progress of a given job, I'm just not sure how to proceed with drawing a progress bar.
Update
ProgressBar class was incredibly straight-forward, perfectly solved my problem.
You might be able to get some implementation ideas from the Ruby/ProgressBar library, which generates text progress bars. I stumbled across it a couple of months back but haven't made any use of it.
Very late answer and sorry for self promotion, but I created library to show progress in terminal.
Personally I think curses is overkill in this case. While the curses lib is nice (and I frequently use it myself) it's a PITA to relearn every time I haven't needed it for 12 months which has to be the sign of a bad interface design.
If for some reason you can't get on with the progress bar lib Joey suggested roll your own and release it under a pretty free licence for instant kudos :)
On windows, curses works out of the box, ncurses doesn't, and for a progress bar curses should be sufficient. So, use curses instead of ncurses.
Also, both curses and ncurses are wafer-thin wrappers around the c library - that means you don't really need Ruby-specific tutorials.
However, on the site for the PickAxe you can download all the code examples for the book. The file "ex1423.rb" contains a curses demo which plays Pong - that should give you plenty of material to get you going.