Set up Eclipse to Beep when done (Python, Linux)

I tuned my applications to beeps when I finished (multitasking for long runs helps me). In the 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 that I recently switched to Linux and a simple beep does not work. Printing '\a'doesn't work either. Help?

+3
source share
2 answers

The main reason is that most modern Linux distributions turn off annoying beeps by default.
Potential solutions use pygame or use 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()

, :

import os
os.system("/usr/bin/canberra-gtk-play --id='system-ready'")

Ubuntu :

ls /usr/share/sounds/ubuntu/stereo
0

sys.stdout.write('\007') print '\a'

0

Source: https://habr.com/ru/post/1783193/


All Articles