3

I am experimenting with ruby and found a gui toolkit called Shoes.

I am using Windows 8 and I would like to create a button in Shoes and have it play an audio file when clicked.

The non-shoes ruby code I am using is the following. Keep in mind that for this to work I had to installed this gem: https://rubygems.org/gems/win32-sound

require 'win32/sound'
include Win32

puts "Hit Enter"   
makeSound = gets.chomp  

while makeSound
Sound.play('c:\users\william\desktop\oink.wav') 
makeSound = gets.chomp  
end

The code I am attempting to launch with Shoes is:

require 'win32/sound'
include Win32


 Shoes.app {
    @push = button "Push me"
    @push.click {
      Sound.play('c:\users\william\desktop\oink.wav')
    }
  }

Now of course this does not work but I am inquiring as to how to approach and/or remedy this problem.

enter image description here

William
  • 4,422
  • 17
  • 55
  • 108
  • So the non-Shoes code works on its own? – Max Sep 11 '14 at 13:45
  • It works. I edited my post to mentioned that I had to install this gem: https://rubygems.org/gems/win32-sound – William Sep 11 '14 at 14:03
  • I'm guessing that Shoes doesn't include your gem dir in its load path. The solution could be as simple as setting `$LOAD_PATH` manually before you `require 'win32/sound'` (or require the absolute path) – Max Sep 11 '14 at 14:12

1 Answers1

1

I assume that you are using Red Shoes (which is apparent from the above snapshot). Shoes would not be able to require the gems that you have installed in your machine directly. You need to tell Shoes extensively that you are going to use some gem and let shoes set it up before app starts.

You can do it in following way, put the below code at top of your shoes code:

Shoes.setup do
 gem 'win32-sound'
end
#Now you can require gem and do the rest as you need...
require 'win32/sound'
include Win32 

Hope it helps :)

Harsh Trivedi
  • 1,594
  • 14
  • 27