how to get a beep, OS independent ?

S

Stef Mientki

hello,

I want to give a small beep,
for windows there's message-beep,
and there seems to be something like " curses" ,
but that package seems to be totally broken in P2.5 for windows.

Any other suggestions ?

thanks,
Stef Mientki
 
R

Rainy

hello,

I want to give a small beep,
for windows there's message-beep,
and there seems to be something like " curses" ,
but that package seems to be totally broken in P2.5 for windows.

Any other suggestions ?

thanks,
Stef Mientki

For win there's winsound, you have to check sys.platform and do
what's necessary for the platform in question. In linux I think
you can just print '\a' (or does that only work in terminals?).
If you know that ext. speakers are always on, you can do a nicer
beep by using some wav file, in linux it's probably easiest to
use an external program to play it, like wavplay. Basically,
there is no single answer, it depends on circumstances.
 
S

Stef Mientki

Rainy said:
For win there's winsound, you have to check sys.platform and do
what's necessary for the platform in question. In linux I think
you can just print '\a' (or does that only work in terminals?).
If you know that ext. speakers are always on, you can do a nicer
beep by using some wav file, in linux it's probably easiest to
use an external program to play it, like wavplay. Basically,
there is no single answer, it depends on circumstances.
'\a' or chr(7) prints an inverted "BEL".
So it looks that Python version independency is even worse than OS
independency ;-)
I'll take a look at wxPython and Pygame if there's something useful.

anyway thanks,
Stef
 
S

Stef Mientki

Chris said:
Inverted bell?
In the output window (stdout) which is black letters on white background,
it prints "bell" in white letters with a black background.
What do you mean? And what version dependency are you
referring to?
Well some of you actually hear something,
I don't,
so I expect that the Python version differs.

cheers,
Stef
 
J

Joe Strout

Python is just printing the ascii bell character: some environments
will
interpret that as a request to make a beep, some will do things like
flashing the whole screen, others just output a graphic character.
Python
doesn't know what your environment will do.

Agreed.

But invoking the standard system beep is such a basic function that it
ought to be easier than this. I'm pretty sure it's a single OS call
on all platforms. On OS X, for example, it's

void NSBeep(void);

declared in NSGraphics.h. I'm sure it's something similarly simple on
other platforms.

Where's the standard place for this sort of OS-abstraction function,
outside the standard Python library? I'm talking about something more
light-weight than wx, QT, or TK; something that just wraps standard
functions (like the system beep) and works in console apps or in any
flavor of GUI app. Is there such a module out there somewhere?

Best,
- Joe
 
I

info

hello,

I want to give a small beep,
for windows there's message-beep,
and there seems to be something like " curses" ,
but that package seems to be totally broken in P2.5 for windows.

Any other suggestions ?

thanks,
Stef Mientki

Not sure it's the simplest solution, but

import Tkinter
Tkinter.Tk().bell()

makes a beep
 
I

info

Sorry, with

import Tkinter
Tkinter.Tk().bell()

you get a new window for the same price...

So it's usefull only when using tkinter
 
M

Marc 'BlackJack' Rintsch

But invoking the standard system beep is such a basic function that it
ought to be easier than this. I'm pretty sure it's a single OS call on
all platforms. On OS X, for example, it's

void NSBeep(void);

declared in NSGraphics.h. I'm sure it's something similarly simple on
other platforms.

I'm not so sure. Under Unix the "system beep" is usually in the terminal
emulation and triggered by sending '\a' to it. AFAIK there is no
standard beep in X-Windows so every desktop environment implements
something like audio notifications.

Ciao,
Marc 'BlackJack' Rintsch
 
G

George Sakkis

In the output window (stdout) which is black letters on white background,
it prints "bell" in white letters with a black background.>  What do you mean? And what version dependency are you

Well some of you actually hear something,
I don't,
so I expect that the Python version differs.

Works for me on WinXP, Python 2.5:

C:\>python -c "print chr(7)"

makes a beep.

George
 
J

Joe Strout

What makes you think there is such a thing as "the standard system
beep"?

Because OS X (the platform with which I'm most familiar) certainly has
one, and REALbasic has had a "Beep" method for years which works on
all platforms. If RB can do it, we can do it too.

Best,
- Joe
 
P

Peter Pearson

I want to give a small beep,
for windows there's message-beep,
and there seems to be something like " curses" ,
but that package seems to be totally broken in P2.5 for windows.

Any other suggestions ?

Many people have suggested sending an ASCII 07 to your
terminal window, but sometimes you don't have a terminal
window.

Then there's the question of using the sound card versus
using the PC speaker. Too complicated for me.

I used a kluge: a short C program that beeps the way I want,
in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this
is Linux). The program has enough privileges to execute
even when run by unprivileged users, and of course can be
invoked by whatever language you're working in.
 
D

Diez B. Roggisch

Peter said:
Many people have suggested sending an ASCII 07 to your
terminal window, but sometimes you don't have a terminal
window.

Then there's the question of using the sound card versus
using the PC speaker. Too complicated for me.

I used a kluge: a short C program that beeps the way I want,
in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this
is Linux). The program has enough privileges to execute
even when run by unprivileged users, and of course can be
invoked by whatever language you're working in.

This can be done with python also, no need for C. See the module fcntl.
The privilege-problem persists of course.


Diez
 
S

Steven D'Aprano

Because OS X (the platform with which I'm most familiar) certainly has
one,


OS X, isn't that the operating system owned by Apple that runs on a
handful of more-or-less identical varieties of hardware all controlled by
Apple?

and REALbasic has had a "Beep" method for years which works on all
platforms. If RB can do it, we can do it too.

That would be a standard language beep then, not a standard system beep.
You're assuming that there is a standard way for any computer to make a
sound. I don't think that is true.

Of course, if you're volunteering to write such a standard system beep
for Python, I for one would be grateful.
 
D

D'Arcy J.M. Cain

Because OS X (the platform with which I'm most familiar) certainly has
one, and REALbasic has had a "Beep" method for years which works on
all platforms. If RB can do it, we can do it too.

It works on all platforms that RB runs on. A rather short list.
Certainly a subset of the platforms that Python runs on.
 
J

Joe Strout

Of course, if you're volunteering to write such a standard system beep
for Python, I for one would be grateful.

I am. But where should I put it? Assuming we don't want to wait for
the (understandably) lengthy and contentious process required to add
something to the Python system libraries, where would be the next best
place for this sort of simple OS abstraction layer?

Thanks,
- Joe
 
D

drobinow

I am.  But where should I put it?  Assuming we don't want to wait for  
the (understandably) lengthy and contentious process required to add  
something to the Python system libraries, where would be the next best  
place for this sort of simple OS abstraction layer?

Thanks,
- Joe

Host it on your web site and send an announcement to
comp.lang.python.announce
If you don't have a web site (I don't) you might try http://pypi.python.org/pypi.
See the tutorial there for instructions. If the setup.py requirement
is too difficult ask for help here.
 
G

Gabriel Genellina

G

Gabriel Genellina

M

malkarouri

hello,

I want to give a small beep,

Just to add to the options here. Where ncurses work you can use:

python -c 'from curses import *;wrapper(lambda s:beep())'

To try it just enter the whole line above in the command line..

Regards,

Muhammad Alkarouri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top