Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1462
Location: Loughborough

PostPosted: Mon Oct 11, 2010 9:08 pm    Post subject: Clear screen and beep for Python 3.x using STANDARD Python. Reply with quote

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:

# 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... Smile
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast