[macruby-changes] [467] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 21 21:32:09 PDT 2008
Revision: 467
http://trac.macosforge.org/projects/ruby/changeset/467
Author: lsansonetti at apple.com
Date: 2008-08-21 21:32:09 -0700 (Thu, 21 Aug 2008)
Log Message:
-----------
adding status_bar example with mappings for status bar, item and speech synthesizer
Added Paths:
-----------
MacRuby/trunk/lib/hotcocoa/mappings/speech_synthesizer.rb
MacRuby/trunk/lib/hotcocoa/mappings/status_bar.rb
MacRuby/trunk/lib/hotcocoa/mappings/status_item.rb
MacRuby/trunk/sample-macruby/HotCocoa/status_bar.rb
Added: MacRuby/trunk/lib/hotcocoa/mappings/speech_synthesizer.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/speech_synthesizer.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/mappings/speech_synthesizer.rb 2008-08-22 04:32:09 UTC (rev 467)
@@ -0,0 +1,25 @@
+HotCocoa::Mappings.map :speech_synthesizer => :NSSpeechSynthesizer do
+
+ def init_with_options(obj, options)
+ if voice = options.delete(:voice)
+ obj.initWithVoice voice
+ else
+ obj.init
+ end
+ end
+
+ custom_methods do
+
+ def speak(what, to=nil)
+ if to
+ url = to.is_a?(String) ? NSURL.fileURLWithPath(to) : to
+ startSpeakingString(what, toURL:url)
+ else
+ startSpeakingString(what)
+ end
+ end
+
+ end
+
+end
+
Added: MacRuby/trunk/lib/hotcocoa/mappings/status_bar.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/status_bar.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/mappings/status_bar.rb 2008-08-22 04:32:09 UTC (rev 467)
@@ -0,0 +1,7 @@
+HotCocoa::Mappings.map :status_bar => :NSStatusBar do
+
+ def alloc_with_options(options)
+ NSStatusBar.systemStatusBar
+ end
+
+end
Added: MacRuby/trunk/lib/hotcocoa/mappings/status_item.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/status_item.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/mappings/status_item.rb 2008-08-22 04:32:09 UTC (rev 467)
@@ -0,0 +1,9 @@
+HotCocoa::Mappings.map :status_item => :NSStatusItem do
+
+ defaults :length => NSVariableStatusItemLength
+
+ def alloc_with_options(options)
+ status_bar.statusItemWithLength options.delete(:length)
+ end
+
+end
Added: MacRuby/trunk/sample-macruby/HotCocoa/status_bar.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/status_bar.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/status_bar.rb 2008-08-22 04:32:09 UTC (rev 467)
@@ -0,0 +1,12 @@
+require 'hotcocoa'
+include HotCocoa
+
+application :name => 'Speak or Quit' do
+ m = menu do |main|
+ main.item :speak,
+ :on_action => proc { speech_synthesizer.speak('I have a lot to say.') }
+ main.item :quit, :key => 'q', :modifiers => [:command],
+ :on_action => proc { speech_synthesizer.speak('I have nothing more to say.') }
+ end
+ status_item :title => 'Speak or Quit', :menu => m
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080821/53a3801a/attachment.html
More information about the macruby-changes
mailing list