Visit Our UNIX and Linux User Community

My original Python Campimeter code, originall for OSX 10.7.5.

Thread Tools Search this Thread
Operating Systems OS X (Apple) My original Python Campimeter code, originall for OSX 10.7.5.
# 1  
Old 01-30-2020
My original Python Campimeter code, originall for OSX 10.7.5.

Hi all...

This was the original code I created to expand a terminal on the fly using Python 2.6.x to the now 3.8.0 without modification under OSX 10.7.5.
I had no idea at the time that the MBP terminal could be full screen until here: for macOS
So now i am doing a 'bash' version...
# I needed the facility to have a maximised Terminal window on OSX 10.7.5 and this was the result...
# A DEMO to show how to increase the size of a Terminal window and obtain the maximum usable size on a _desktop_.
# The Terminal window must be initially set manually at the uppermost left hand corner and Python started inside
# this window. The colours for this DEMO inside OSX 10.7.5, are grey background, red square and yellow asterisk/characters...
# Written in such a way as anyone can understand how it works, youngsters too.
# To run type from the Python prompt:-
# >>> exec(open("/full/path/to/<CR>
# Where "/full/path/to/" is where you have saved this code; then have a little fun...
# This code generates a crude Campimeter... ...and is used to check
# visual field. Just focus on the red square as close as possible to the screen in the centre of the window
# after pressing <CR> from the initial window and then press Ctrl-C immediately after you see an asterisk flash.
# It is possible to get the Ctrl-C to _crash_ out and stop the DEMO if Ctrl-C is pressed at any other time than 
# just after seeing the asterisk flash. The cursor has not been turned off and will be seen on the left hand
# side of the window, so try to ignore it.
# $VER: Campimeter.py_Version_0.00.10_(C)2012_B.Walker_G0LCU.
# This code is issued as Public Domain and you may do with it as you please.
# I have not reset the Terminal back to its original state although all of the information how to do it is in
# this code. Colours are easily reset in Python but not included in the code also...
# Designed and tested on a Macbook Pro, OSX 10.7.5 using Python Versions 2.6.7 and 2.7.1. Also tested on Debian
# Linux 6.0.x using Python versions 2.6.6, 2.7.2 and 3.1.3, AND, now 3.8.0 on 30-01-2020...
# It would be interesting to see which other platform variants this idea works on; just add a comment...

# All imports required.
import os
import sys
import random
import time

# Ensure Python Version 3.x.x is included...
if sys.version[0]=="3": raw_input=input

# Set some values as global, my choice! ;o)
global row
global column
global attempts

# Allocate initial Terminal window values to be much greater than the allowed Terminal size on the desktop...

# Set the Terminal window size larger than its default!

# Set up a basic user window starting with a grey, cleared window...
# Add a delay to allow settings to settle...
print("\n$VER: Campimeter.py_Version_0.00.10_(C)2012_B.Walker_G0LCU.\n")
print("Press the <CR> key to start. After this window is exited focus on")
print("the centred, coloured square. Position yourself until you are both")
print("comfortable and the screen presents a wide field of view. Use the two")
print("keys Ctrl-C if and when you see a randomly positioned _*_ displayed.\n")
print("The larger the display used the better, have fun...\n")
# time.sleep(1)
raw_input("Press the <CR> key to continue...")

# Now get the _new_ real size of the Terminal window...
rows,columns=os.popen("stty size","r").read().split()

def locate(user_string="$VER: Campimeter.py_Version_0.00.10_(C)2012-2013_B.Walker_G0LCU.",x=0,y=0):
    # Don't allow any user errors. Python's own error detection will check for
    # syntax and concatination, etc, etc, errors.
    if x>=255: x=255
    if y>=255: y=255
    if x<=0: x=0
    if y<=0: y=0
    # Plot the user_string at the starting position HORIZ, VERT...

def main():
    # Ensure certain _variables_ remain global, my choice... ;o)
    global row
    global column
    global attempts

    # Note:- row and colour are already set.

    # Clear the window for the test.

    # Set the centred red square for the start...
    locate("\033[0;41;41m  \033[1;93;100m ",int(column/2),int(row/2))

    # This is set for 5 possible attempts only. Just change the number 5 to your number of attempts.
    for n in range(0,5,1):
            # Have a random start waiting time...
            # Display a coloured asterisk randomly on screen for a brief period...
            locate("\033[1;93;100m*\033[1;93;100m ",coloured_spot_column,coloured_spot_row)
            # This is the timer to display the asterisk and is made relatively easy...
            # Clear this displayed asterisk...
            locate("\033[1;93;100m \033[1;93;100m ",coloured_spot_column,coloured_spot_row)
            # Because this code does not detect whether the red square might be overwritten,
            # ensure that it is redrawn at the centre of the Terminal window.
            locate("\033[0;41;41m  \033[1;93;100m ",int(column/2),int(row/2))
            # Hold long enough to react to Ctrl-C...
        except KeyboardInterrupt:
            # After pressing Ctrl-C ensure ^c or ^C is not seen on the screen and update.
            print("\b\b\b\b    ")

    # Give the results for this fun project and re-run if required...
    print("You had "+str(attempts)+" successes out of "+str((n+1))+" possible attempts...\n")
    again=raw_input("Do you want to try again? (Y/N):- ")
    if again=="y" or again=="Y": main()

# It is easy to reset the Terminal back to the default size AND colours using the methods already shown.
# I have not bothered, as the intent of this DEMO is to show how to increase the size of the Terminal
# window and obtain the real, new size too.

# End of DEMO.
# Enjoy finding simple solutuions to often very difficult problems...

Yet another of my bizarre coding projects...

This User Gave Thanks to wisecracker For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #122
Difficulty: Easy
Linux has been certified as UNIX (2019).
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Two problems with my python code

Hello everyone , I need your help to end my python code. I've this code in python : from ipywidgets import interact, Dropdown from ipywidgets import * from ipywidgets.embed import embed_minimal_html import pandas as pd import os import sys #################### Dropdown servers... (1 Reply)
Discussion started by: Tim2424
1 Replies

2. Programming for macOS

Hi Neo... This is me too except for the attention span. As soon as I find a solution to something I let others better it. And as for doing something different I have done some bizarre stuff on here... <wink> /Me awaits the mickey take... ;oD OT: Here is a small snippet for a terminal window... (3 Replies)
Discussion started by: wisecracker
3 Replies

3. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./", line 20, in <module> y = DerivedClass("Manu") File "./", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies

4. Shell Programming and Scripting

Simple Python Code Question

I have the following code: #!/usr/bin/env python mylist = def printWithoutNewlines(): for objects in mylist: #print(objects) objects = objects.replace('hello', "hi") print objects When executed, it gives the following output: ## ./ hi... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

conversion of code in perl and python

How to convert below bash code in perl and python. for BLOCK in /sys/block/emcpow* do echo "100000" > "$BLOCK"/queue/nr_requests echo "noop" > "$BLOCK"/queue/scheduler done (2 Replies)
Discussion started by: learnbash
2 Replies

6. Programming

Compiling and running Python code

Hey there, First post here in the Unix forums, but I have used them a lot for research over the last year. Anyways, to why I'm here now: I'm working on a project and I'll be using the AIS Parser SDK by Brian C. Lane (can't post the link, but google that and the first 8 links will be relevant) ... (4 Replies)
Discussion started by: pmd006
4 Replies

7. Shell Programming and Scripting

Help with Python Code Whitespace

Hello All, I have some python code that pulls together titles and displays them on web pages. Here is the section of code I am struggling with: #string to grab title titlePattern =r'''\s*(\(+\))?(?P<title>.*)''' #returns the title part of the subject line def getTitle... (0 Replies)
Discussion started by: jhampt
0 Replies

8. Shell Programming and Scripting

python code...convert to ksh or sh

Helloo... I am not much familiar with python..I found this small script in python I even do not have python on my computer...can anyone help me out to convert this into ksh or sh.. PLEASE any help I will appreciate.. here is python code.. #!/usr/bin/env python import random # Get a... (3 Replies)
Discussion started by: amon
3 Replies

9. Shell Programming and Scripting

Code conversion from JSP to PYTHON

Guys I need to convert a code from JSP (Java Tags are also there inside JSP) to PYTHON. I have OK kind of knowledge in PYTHON, but dont have a muck knowledge in JAVA/JSP. Any idea how to approach? Thanks in advance to all C Saha (1 Reply)
Discussion started by: csaha
1 Replies

10. Linux

Where can I download the original Linux code for free?

Where can I download the original Linux code for free? (1 Reply)
Discussion started by: Super Apollo
1 Replies

Featured Tech Videos