Forum: Ruby RubyCocoa and Mac System Icons

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
36bf799ff5c72c2b8966787a4df91c8d?d=identicon&s=25 Tom Medhurst (Guest)
on 2009-02-04 13:07
(Received via mailing list)
Hi There,

I am trying to create an NSImage which contains the system kComputer
icon. Unfortunately RubyCocoa can't resolve kComputer or
use :kComputer or it's header value 'root'.. I have tried the
following:

1. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
(:root))
2. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
(:kComputer))
3. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
(kComputer))
4. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
(NSNumber.numberWithUnsignedLong('root')))

5. NSWorkspace.sharedWorkspace.iconForFileType(:root)
6. NSWorkspace.sharedWorkspace.iconForFileType(:kComputer)
7. NSWorkspace.sharedWorkspace.iconForFileType(kComputer)
etc...

Has anybody got this to work in RubyCocoa?
Many Thanks
*Tom Medhurst*
Eacf5ed623e72db0b87707baabd6f21a?d=identicon&s=25 Adam Gardner (adamgardner)
on 2009-02-21 00:06
Tom Medhurst wrote:
> Hi There,
>
> I am trying to create an NSImage which contains the system kComputer
> icon. Unfortunately RubyCocoa can't resolve kComputer or
> use :kComputer or it's header value 'root'.. I have tried the
> following:
>
> 1. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
> (:root))
> 2. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
> (:kComputer))
> 3. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
> (kComputer))
> 4. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode
> (NSNumber.numberWithUnsignedLong('root')))
>
> 5. NSWorkspace.sharedWorkspace.iconForFileType(:root)
> 6. NSWorkspace.sharedWorkspace.iconForFileType(:kComputer)
> 7. NSWorkspace.sharedWorkspace.iconForFileType(kComputer)
> etc...
>
> Has anybody got this to work in RubyCocoa?
> Many Thanks
> *Tom Medhurst*

First off, since in Ruby all constants begin with a capital letter, all
the constants like kSuchAndSuch morph into OSX::KSuchAndSuch.

Second of all, where on earth is kComputer defined? I can't find it
documented *anywhere*; in particular, it's not in this list:
http://developer.apple.com/documentation/Carbon/Re...

Third, it seems to me that the iconForFileType method of NSWorkspace
takes a string representing either a filename extension or a HFS file
type. So if anything of these is going to work, it'd be:

OSX::NSWorkspace.sharedWorkspace.iconForFileType('root')

which does, in fact, return an NSImage instance for me. Of course, I get
an NSImage with every string I've tried, including the empty string - I
haven't tried drawing it on screen to see if it's the one you want,
since I don't have anywhere to draw it to, as it were. But it should be
a good place for you to start.
36bf799ff5c72c2b8966787a4df91c8d?d=identicon&s=25 Tom Medhurst (Guest)
on 2009-02-21 23:55
(Received via mailing list)
Hi Adam,
Thanks for looking into this for me!
kComputer is defined in the IconsCore.h header file in
CoreServices.framework/LaunchServices.framework. (tried referencing it
as
KComputer, but that didn't work)

I tried your example and it just returned the generic "unknown
file-type"
icon. :(

I am trying to load the system icon for the computer... it's really easy
in
Ubuntu to load stock (system) icons, so I am really frustrated when I
can't
seem to figure this out on my lovely mac :'(

Any ideas..?
Thanks
Tom
Eacf5ed623e72db0b87707baabd6f21a?d=identicon&s=25 Adam Gardner (adamgardner)
on 2009-02-24 02:00
Tom Medhurst wrote:
> Hi Adam,
> Thanks for looking into this for me!
> kComputer is defined in the IconsCore.h header file in
> CoreServices.framework/LaunchServices.framework. (tried referencing it
> as
> KComputer, but that didn't work)
>
> I tried your example and it just returned the generic "unknown
> file-type"
> icon. :(
>
> I am trying to load the system icon for the computer... it's really easy
> in
> Ubuntu to load stock (system) icons, so I am really frustrated when I
> can't
> seem to figure this out on my lovely mac :'(
>
> Any ideas..?
> Thanks
> Tom

On my machine, the constant is kComputerIcon, not kComputer, and yes, it
evaluates to Root. RubyCocoa isn't going to recognize the Ruby constant
KComptuerIcon or anything like it, though, because at least on my
machine all that stuff is pure C stuff (not Objective-C) which isn't
accounted for yet by custom bridge-support files. You can try fooling
around with bridge-support, but I'd just skip kComputerIcon entirely and
use what it evaluates to, the string 'root'.

That out of the way, according this source: [1], the correct line in
Objective-C would be
   SImage* macIcon = [[NSWorkspace sharedWorkspace] iconForFileType:
NSFileTypeForHFSTypeCode(kComputerIcon)];

To me, that translates as:
OSX::NSWorkspace.sharedWorkspace.iconForFileType(OSX::NSFileTypeForHFSTypeCode('root'))

so, try that out.


[1] http://zathras.de/angelweb/blog-get-standard-syste...
36bf799ff5c72c2b8966787a4df91c8d?d=identicon&s=25 Tom Medhurst (Guest)
on 2009-03-13 18:14
(Received via mailing list)
Hi Adam,Sorry it has taken me a while to reply; I have been away from my
precious Mac for a couple of weeks (it's been tough! :))

When I ran the ruby code you suggested I got:

*ServerListViewBrowserItem#imageRepresentation: ArgumentError: invalid
value
for Integer: "root"*

*
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/serverlistviewbrowseritem.rb:42:in
`NSFileTypeForHFSTypeCode'*

*
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/serverlistviewbrowseritem.rb:42:in
`imageRepresentation'*

*
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/rb_main.rb:26:in
`NSApplicationMain'*


It would appear that NSFileTypeForHFPTypeCode is expecting an integer
value
instead of 'root'.


Any ideas?

Many Thanks,

Tom
Eacf5ed623e72db0b87707baabd6f21a?d=identicon&s=25 Adam Gardner (adamgardner)
on 2009-03-14 01:43
Tom Medhurst wrote:
> Hi Adam,Sorry it has taken me a while to reply; I have been away from my
> precious Mac for a couple of weeks (it's been tough! :))
>
> When I ran the ruby code you suggested I got:
>
> *ServerListViewBrowserItem#imageRepresentation: ArgumentError: invalid
> value
> for Integer: "root"*
>
> *
> 
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/serverlistviewbrowseritem.rb:42:in
> `NSFileTypeForHFSTypeCode'*
>
> *
> 
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/serverlistviewbrowseritem.rb:42:in
> `imageRepresentation'*
>
> *
> 
/Users/tom/dev/proj/bonjour-graphviz/gui-tools/mac/ZeroConfNetworkBrowser/build/Debug/ZeroConfNetworkBrowser.app/Contents/Resources/rb_main.rb:26:in
> `NSApplicationMain'*
>
>
> It would appear that NSFileTypeForHFPTypeCode is expecting an integer
> value
> instead of 'root'.
>
>
> Any ideas?
>
> Many Thanks,
>
> Tom
Ok, my final suggestion then is to try using 1919905652 instead of
'root'. On my system (PowerPC 32-bit), that number is the integer
interpretation of those four chars. I'm not really sure if that how this
works... I don't really know C all that well. Also, if you are on an
intel machine, you may want to figure out what kComputerIcon evaluates
to yourself.
This topic is locked and can not be replied to.