From: "Albert L. Wagner" Date: 2001-11-21T23:31:15+09:00 Subject: [ruby-talk:26024] Re: sounding the alarm ? Tk has a beep. But it doesn't seem to work on windows. Probably not worth requiring Tk mjbjr@beaudesign.com wrote: > > In the past, I have used Xdialog(s?) to create quick and dirty pop-up alarm > dialogs with a bit of text and a few beeps. I installed Rh7.2, and have > decided to use Ruby to recreate these alarms. > > The problem I'm having doing this with ruby is one that I have had with other > scripting languages I've used, getting multiple audible beeps to sound at the > appropriate time, when the dialog box opens. Frequently, the dialog box ends > up preventing the beeps until the user hits the 'OK' button, to acknowledge the > alarm, and killing the dialog. > > I've always found it somewhat weird that a "programmer" has to, frequently, > resort to using a "print \a", or something else "cheap", to get a beep. > Sometimes, you have to create a console just to be able to do the beep. > > Ruby doesn't seem to have a beep object. Have I missed one? > > Below, is my quick attempt to accomplish this using ruby. > > The version before this one did not create a class and def's, but used the > code objects in a procedural manner. I created the class in hopes of delaying > the dialog box creation until after the sound had occurred, but no go. > Once the window actually gets created, no beeps until it's killed. > > You'll see variations that I have tried commented out at the bottom. > > Is there some quick and dirty way to do this without complicating things with > threads? > > Ideas? > > Thank you. > > here's the code: > > #!/usr/local/bin/ruby > > # > # > # > > require 'tk' > > class MyAlarmBox > > def soundalarm() > print "\a" > end > > def showmsg > window = TkRoot.new { title "Alarm" } > > window.geometry("200x70+20+30") > > label = TkLabel.new(window) \ > { > justify 'center' > text ' testing ' > relief 'ridge' > fg 'red' > bg 'white' > pack('side'=>'top', 'padx'=>10, 'pady'=>10) > } > > TkButton.new(window) \ > { > text "OK" > command proc { exit } > pack('side'=>'bottom', 'padx'=>10, 'pady'=>4) > } > > Tk.mainloop > end > end > > print "\a" > > # sleep 3 > > # mab=MyAlarmBox.new > # mab.soundalarm > > # sleep 3 > > # mab.showmsg > > -- > - Martin J. Brown, Jr. - > - mjbjr@beaudesign.com - > > Public PGP Key ID: 0xB29EDDCADB184F7B keyserver: http://certserver.pgp.com/ > > ----------------------------------------------------------------- > Part 1.2Type: application/pgp-signature -- "It requires wisdom to understand wisdom: the music is nothing if the audience is deaf." - Walter Lippman