Configure Eclipse to Beep when done (Python, Linux)
I configured my applications to beep when done (helps me multitask on long runs). On windows it was simple:
def beep_please():
"""Beep on Windows"""
if os.name == 开发者_运维知识库'nt':
import winsound #@UnresolvedImport
winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
import atexit
atexit.register(beep_please)
The problem is I recently switched to Linux and simple beeping doesn't work.
Printing '\a'
doesn't work either.
Help?
Try doing sys.stdout.write('\007')
instead of print '\a'
Root cause is that most modern Linux distros turn off the annoying default "beep".
Potential solutions are using pygame, or using one of the installed "players" directly.
Using Pygame looks like this:
import pygame
pygame.init()
pygame.mixer.music.load("my_sound_file.ogg")
pygame.mixer.music.play()
pygame.event.wait()
But I did not want the new external dependency for the sake of a non-run-time utility, so what I ended up doing is:
import os
os.system("/usr/bin/canberra-gtk-play --id='system-ready'")
There are plenty of other sound files in the Ubuntu theme:
ls /usr/share/sounds/ubuntu/stereo
精彩评论