Clear screen and beep for Python 3.x using STANDARD Python.

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Clear screen and beep for Python 3.x using STANDARD Python.

Postby Bazza » Mon Oct 11, 2010 8:08 pm

Hi all...

"clr3x.py" a Python 3.x Linux only derivative of my "clr.py"
for versions 1.4x to 2.7x for multi-platforms.

Another STANDARD Python freebie to clear a terminal/console
window running Python and/or give an error beep also.

Tested on Python 3.1.2 for PCLinuxOS 2009 and issued as PD
for LXF.

If it is of any use to you Python coders you may do with it
as you please.

Watch for wordwrapping etc...


Code: Select all
# Clear screen and beep for Python 3.x+ in Linux...
# Original idea copyright, (C)2010, B.Walker, G0LCU.
# Issued as PD for LXF, October 2010.
# You may do with this code as you please...
#
# Tested on Python 3.1.2 inside PCLinuxOS 2009.
#
# Filename is "clr3x.py" and placed in the Python "Lib" drawer.
#
# ====================
# Usage:-
# -------
# >>> import clr3x[RETURN/ENTER]
# ====================
# Called as:-
# -----------
# clr3x.clrscn()
# To clear a terminal/console window.
#
# clr3x.beep()
# To generate an error beep 0.5 seconds long, (sinewave).
#
# clr3x.both()
# To generate a beep and then clear a terminal/console window.
# ====================

# Import "os" only as "sys" is not needed for this version.
# import sys
import os

# This is the beep function.
def beep():
    # Set up the binary code as a crude sinewave.
    waveform=b'\x0f\x2d\x3f\x2d\x0f\x03\x00\x03'
    # Set audio timing to zero, "0".
    count=0
    # Open up the audio device to write to.
    audio=open('/dev/audio', 'wb')
    # A "count" value of 1 = 1mS, so 500 = 0.5S.
    while count<500:
        # Send 8 bytes of data to the audio device 500 times.
        # This is VERY close to 1KHz.
        audio.write(waveform)
        count=count+1
    # Close the audio device access.
    audio.close()

# This clears the terminal/console window where python is run from.
def clrscn():
    print(os.system('clear'), chr(13), "  ", chr(13),)

# This does a beep first followed by a clear screen.
def both():
    beep()
    clrscn()
# Beep and clear screen function end.



That`s all there is to it... :)
73...

Bazza, G0LCU...

Team AMIGA...
User avatar
Bazza
LXF regular
 
Posts: 1483
Joined: Sat Mar 21, 2009 11:16 am
Location: Loughborough

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests