Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #MD Harrington
- import argparse
- import time
- import sys
- import os
- import subprocess
- import time
- import emoji
- import threading
- from PIL import Image
- from subprocess import Popen, PIPE
- #special effects blink
- CBLINK = ';5m'
- TEXTBL ='\033[5m '
- #global color settings
- # Bold
- BBlack ='\033[1;30m' # Black
- BRed ='\033[1;31m' # Red
- BGreen ='\033[1;32m' # Green
- BYellow ='\033[1;33m' # Yellow
- BBlue ='\033[1;34m' # Blue
- BPurple ='\033[1;35m' # Purple
- BCyan ='\033[1;36m' # Cyan
- BWhite ='\033[1;37' # White
- # Underline
- UBlack = '\033[4;30m' # Black
- URed = '\033[4;31m' # Red
- UGreen = '\033[4;32m' # Green
- UYellow = '\033[4;33m' # Yellow
- UBlue = '\033[4;34m' # Blue
- UPurple = '\033[4;35m' # Purple
- UCyan = '\033[4;36m' # Cyan
- UWhite = '\033[4;37m' # White
- # Regular Colors
- CBLACK = '\033[30m'
- CRED = '\033[31m'
- CGREEN = '\033[32m'
- CYELLOW = '\033[33m'
- CBLUE = '\033[34m'
- CVIOLET = '\033[35m'
- CBEIGE = '\033[36m'
- CWHITE = '\033[37m'
- CYAN = '\033[36m'
- # Background
- CBLACKBG = '\033[40m' # Black
- CREDBG = '\033[41m' # Red
- CGREENBG = '\033[42m' # Green
- CYELLOWBG = '\033[43m' # Yellow
- CBLUEBG = '\033[44m' # Blue
- CVIOLETBG = '\033[45m' # Purple
- CCYAN = '\033[46m' # Cyan
- CWHITEBG = '\033[47m' # White
- # High Intensty
- IBlack = '\033[0;90m' # Black
- IRed = '\033[0;91m' # Red
- IGreen = '\033[0;92m' # Green
- IYellow = '\033[0;93m' # Yellow
- IBlue = '\033[0;94m' # Blue
- IPurple = '\033[0;95m' # Purple
- ICyan = '\033[0;96m' # Cyan
- IWhite = '\033[0;97m' # White
- # Bold High Intensty
- BIBlack ='\033[1;90m' # Black
- BIRed ='\033[1;91m' # Red
- BIGreen ='\033[1;92m' # Green
- BIYellow ='\033[1;93m' # Yellow
- BIBlue ='\033[1;94m' # Blue
- BIPurple ='\033[1;95m' # Purple
- BICyan ='\033[1;96m' # Cyan
- BIWhite ='\033[1;97m' # White
- CGREY = '\33[90m'
- CRED2 = '\33[91m'
- CGREEN2 = '\33[92m'
- CYELLOW2 = '\33[93m'
- CBLUE2 = '\33[94m'
- CVIOLET2 = '\33[95m'
- CBEIGE2 = '\33[96m'
- CWHITE2 = '\33[97m'
- CGREYBG = '\33[100m'
- CREDBG2 = '\33[101m'
- CGREENBG2 = '\33[102m'
- CYELLOWBG2 = '\33[103m'
- CBLUEBG2 = '\33[104m'
- CVIOLETBG2 = '\33[105m'
- CBEIGEBG2 = '\33[106m'
- CWHITEBG2 = '\33[107m'
- ENDC = '\033[0m'
- parser = argparse.ArgumentParser(description='Open file .')
- parser.add_argument('v1', type = str , help='input your file to be opened')
- args=parser.parse_args();
- m_file = args.v1
- m_file2 = '/home/mark/python_scripts/bye.txt'
- ## create a sting list object
- prompt_strings =[]
- ## here we apppend prompt text strings
- #0
- prompt_strings.append('Ok lets have a look at the desktop recording of this all in action \n ' )
- #1
- prompt_strings.append('Starting java threadnamed t1 , calling t1.start() aha thats how hmmm ... \n')
- #2
- prompt_strings.append('Opening Video automated on new thread named t2 , calling t2.start() Amazing what you can do with threads in python !! ... \n' )
- #3
- prompt_strings.append(" \n")
- #4
- prompt_strings.append('About to get data and write our data to file start new thread , calling t3.start() \n ')
- #5
- prompt_strings.append('t3.join() Back to main thread File is written with data Cool. Moving on \n '+ \
- ' Quick add some smiley faces ,,, \n ' )
- #6
- prompt_strings.append('... Incredible \n ' + \
- "Up pops my friend the Unicode robot ' Wonder if its clicked yet '\n " + \
- "Cold war ... beep ...beep ... cold war Isn't this exciting .. Golly !! Real James bondage stuff eh \n ")
- #7
- prompt_strings.append('Now lets have a look and see what component we need to place next... \n ' + \
- 'So going to the diagram we see that \n ' + \
- 'D1 is connected to pin 2 of the IC Thats the hot end or the positive end of the diode and the other side of the diode \n ' +\
- "is connected to ground I'm going to select a diode from the parts inventory and place this from pin 2 track which is also pin2 IC and then connect the \n " + \
- "the other side of the diode , 'ground ' to a track connection then to pin 8 of the IC which if you look at the diagram is also ground \n " + \
- "Watch how I do this \n ")
- #8
- prompt_strings.append('Ok next we need a wire link to connect ground side of diode of the negative end to pin 8 \n '+ \
- 'So Im going to show you how do this \n '+\
- 'When done you need to press escape key to exit drawing line tool ..... Watch ? \n ' + \
- 'Thats it folks for today ..... Not that hard is it ?? \n ' + \
- 'Cheers all .... End of part 3 \n ')
- #9
- prompt_strings.append('Code will be place with links on this post \n '+ \
- 'These will include makefile '+\
- 'and links to github \n ' + \
- 'as well as pastebin for quick glance ' )
- localtime = time.asctime( time.localtime(time.time()) )+ '\n\n '
- def f_clearscreen(time_delay):
- os.system('clear')
- time.sleep(time_delay)
- for x in range(2):
- print('')
- def f_openfile(fileopen):
- # make this global so that functions can see this
- global lines
- f = open(fileopen, 'r')
- # use readlines to read all lines in the file
- # The variable 'lines' is a list containing all lines in the file
- lines = f.readlines()
- # close the file after reading the lines.
- fileopen =''
- f.close()
- def slowPrintFromFile(time_sleep ,G_COLOR):
- for line in lines:
- for mychar in line:
- sys.stdout.write(G_COLOR + mychar)
- sys.stdout.flush()
- time.sleep(time_sleep)
- sys.stdout.write(ENDC)
- sys.stdout.flush()
- def slowPrint(usrstring ,time_sleep, col):
- for mychar in usrstring:
- sys.stdout.write(col + mychar)
- sys.stdout.flush()
- time.sleep(time_sleep)
- sys.stdout.write(ENDC)
- sys.stdout.flush()
- def run_cmd(bashCommand):
- process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
- def run_executable(m_filename , m_abs_pathtoexe):
- '''
- Run process that takes no arguments
- '''
- ## Shell=False helps the process terminate
- os.chdir(m_abs_pathtoexe)
- process = subprocess.Popen(m_filename, shell=False)
- ## Get exit codes
- out, err = process.communicate()
- errcode = process.returncode
- print(errcode)
- '''
- # NOT PART FO CODE AS YET TRYING SOMETHING OUT HERE
- #pid = subprocess.check_output(['xdotool', 'getactivewindow', 'getwindowpid']).decode('utf-8').strip()
- #print(pid)
- '''
- def clearScreen():
- os.system('clear')
- def printemoji(GCOLOR,time_sleep, numfaces):
- for x in range(numfaces):
- sys.stdout.write(GCOLOR + emoji.emojize(':grinning_face_with_big_eyes:')) ,
- sys.stdout.flush()
- time.sleep(time_sleep)
- sys.stdout.write(ENDC)
- sys.stdout.flush()
- print('\n')
- def playvcr(fileVideoPath):
- pipes = dict(stdin=PIPE, stdout=PIPE, stderr=PIPE)
- mplayer = Popen(["mplayer", fileVideoPath], **pipes)
- # to control u can use Popen.communicate
- mplayer.communicate(input=b">")
- sys.stdout.flush()
- def openFileforCords(fname):
- f= open(fname,'a+')
- inputx = raw_input('\n enter x start point of component :: ' )
- inputy = raw_input('\n enter y start point of component :: ' )
- inputValue = raw_input('\n enter the value of the component :: ' )
- f.write('x,y = %s, %s \n' % (inputx , inputy ))
- f.write('device = %s \n' % (inputValue ))
- f.close()
- slowPrint('Co ordinates entered and file saved \n' ,0.08,CRED2)
- ## the main method of script starts here ##
- def main():
- f_clearscreen(5)
- ## time , speed of typing , color
- slowPrint(localtime,0.035,ICyan )
- f_openfile(m_file)
- # welcome nessage
- print('\n')
- slowPrintFromFile(0.06 ,CYELLOW2)
- print('\n')
- ## bit of fun print emojo to screen
- printemoji(ICyan,0.08,20)
- time.sleep(2)
- clearScreen()
- ## change to correct directory
- ## os.chdir('/home/mark/blackboard')
- ## invoke java command in a thread of its own
- ## t1 = threading.Thread(target=run_cmd , args = ('konsole -e java -Dsun.java2d.opengl=true -jar dist/lib/BlackBoard.jar' ,))
- ## tell user what we are doing
- slowPrint(prompt_strings[0] , 0.08 ,CGREEN2)
- ## Now we start the thread
- ##slowPrint(prompt_strings[1] , 0.08,CGREEN2)
- ## t1.start()
- print('\n')
- time.sleep(4)
- ## open our image file
- ## tell user what we are doing
- slowPrint(prompt_strings[2] , 0.08 ,ICyan)
- ##create a new thread
- t2 = threading.Thread(target=playvcr, args=('/home/mark/Videos/rpi3.mp4',))
- t2.start()
- time.sleep(4)
- printemoji(CYELLOW2,0.08, 20)
- #change directory
- ##os.chdir('/home/mark/python_scripts/lesson3')
- ## tell user what we are doing placing IC
- ##slowPrint(prompt_strings[3] , 0.08 ,ICyan)
- #START THREAD T3
- ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
- # get some data from user and write to file
- ## tell user what we are doing
- ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)
- ##t3.start()
- ##t3.join()
- ## tell user what we have done created file should be saved with x,y , device
- ##slowPrint(prompt_strings[5] , 0.08,ICyan)
- ##printemoji(CYELLOW2,0.08, 20)
- #6 message just add some humour here and there
- ##slowPrint(prompt_strings[6] , 0.08,CGREEN2)
- #open the file and show them Next place diode
- ##slowPrint(prompt_strings[7] , 0.08,CYELLOW2)
- ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
- # get some data from user and write to file
- ## tell user what we are doing
- ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)
- ##t3.start()
- ##t3.join()
- ##slowPrint(prompt_strings[5] , 0.08,ICyan)
- ##printemoji(CWHITE2,0.08, 20)
- ##time.sleep(2)
- ##clearScreen()
- ## about to show how we place link
- ##slowPrint(prompt_strings[8] , 0.08,CRED2)
- ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
- # get some data from user and write to file
- ## tell user what we are doing
- ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)
- ##t3.start()
- ##t3.join()
- ##slowPrint(prompt_strings[5] , 0.08,ICyan)
- ##printemoji(ICyan,0.08, 20)
- time.sleep(2)
- clearScreen()
- ## wait for threads to complete this happens when user closes each window in thread spawned
- print('\n')
- ##printemoji(CRED2,0.08, 20)
- print('\n')
- t2.join()
- slowPrint(prompt_strings[9] , 0.05,CYELLOW2)
- time.sleep(4)
- os.system('clear')
- ## the end
- slowPrint('Thank you for your interest Have a a good week bye for now Mark Harrington \n\n',0.05 , ICyan)
- slowPrint(localtime,0.035,CGREEN2 )
- print('\n')
- printemoji(CRED2,0.08, 20)
- print('\n')
- time.sleep(4)
- os.system('clear')
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment