Mark2020H

Automation animation for Byian Cairns VoidRealms

May 4th, 2020
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #MD Harrington
  3.  
  4. import argparse
  5. import time
  6. import sys
  7. import os
  8. import subprocess
  9. import time
  10. import emoji
  11. import threading
  12.  
  13. from PIL import Image
  14. from subprocess import Popen, PIPE
  15.  
  16. #special effects  blink
  17. CBLINK      = ';5m'
  18. TEXTBL      ='\033[5m '
  19.  
  20.  
  21. #global color settings
  22. # Bold
  23. BBlack  ='\033[1;30m'       # Black
  24. BRed    ='\033[1;31m'         # Red
  25. BGreen  ='\033[1;32m'       # Green
  26. BYellow ='\033[1;33m'      # Yellow
  27. BBlue   ='\033[1;34m'        # Blue
  28. BPurple ='\033[1;35m'      # Purple
  29. BCyan   ='\033[1;36m'        # Cyan
  30. BWhite  ='\033[1;37'       # White
  31.  
  32. # Underline
  33. UBlack  =   '\033[4;30m'       # Black
  34. URed    =   '\033[4;31m'         # Red
  35. UGreen  =   '\033[4;32m'       # Green
  36. UYellow =   '\033[4;33m'      # Yellow
  37. UBlue   =   '\033[4;34m'        # Blue
  38. UPurple =   '\033[4;35m'      # Purple
  39. UCyan   =   '\033[4;36m'        # Cyan
  40. UWhite  =   '\033[4;37m'       # White
  41.  
  42. # Regular Colors
  43.  
  44. CBLACK  = '\033[30m'
  45. CRED    = '\033[31m'
  46. CGREEN  = '\033[32m'
  47. CYELLOW = '\033[33m'
  48. CBLUE   = '\033[34m'
  49. CVIOLET = '\033[35m'
  50. CBEIGE  = '\033[36m'
  51. CWHITE  = '\033[37m'
  52. CYAN    = '\033[36m'
  53.  
  54. # Background
  55. CBLACKBG    =   '\033[40m'      # Black
  56. CREDBG      =   '\033[41m'      # Red
  57. CGREENBG    =   '\033[42m'      # Green
  58. CYELLOWBG   =   '\033[43m'      # Yellow
  59. CBLUEBG     =   '\033[44m'      # Blue
  60. CVIOLETBG   =   '\033[45m'      # Purple
  61. CCYAN       =   '\033[46m'      # Cyan
  62. CWHITEBG    =   '\033[47m'      # White
  63.  
  64.  
  65. # High Intensty
  66. IBlack      =   '\033[0;90m'       # Black
  67. IRed        =   '\033[0;91m'         # Red
  68. IGreen      =   '\033[0;92m'       # Green
  69. IYellow     =   '\033[0;93m'      # Yellow
  70. IBlue       =   '\033[0;94m'        # Blue
  71. IPurple     =   '\033[0;95m'      # Purple
  72. ICyan       =   '\033[0;96m'        # Cyan
  73. IWhite      =   '\033[0;97m'       # White
  74.  
  75. # Bold High Intensty
  76. BIBlack     ='\033[1;90m'      # Black
  77. BIRed       ='\033[1;91m'        # Red
  78. BIGreen     ='\033[1;92m'      # Green
  79. BIYellow    ='\033[1;93m'     # Yellow
  80. BIBlue      ='\033[1;94m'       # Blue
  81. BIPurple    ='\033[1;95m'     # Purple
  82. BICyan      ='\033[1;96m'       # Cyan
  83. BIWhite     ='\033[1;97m'      # White
  84.  
  85. CGREY    = '\33[90m'
  86. CRED2    = '\33[91m'
  87. CGREEN2  = '\33[92m'
  88. CYELLOW2 = '\33[93m'
  89. CBLUE2   = '\33[94m'
  90. CVIOLET2 = '\33[95m'
  91. CBEIGE2  = '\33[96m'
  92. CWHITE2  = '\33[97m'
  93.  
  94. CGREYBG    = '\33[100m'
  95. CREDBG2    = '\33[101m'
  96. CGREENBG2  = '\33[102m'
  97. CYELLOWBG2 = '\33[103m'
  98. CBLUEBG2   = '\33[104m'
  99. CVIOLETBG2 = '\33[105m'
  100. CBEIGEBG2  = '\33[106m'
  101. CWHITEBG2  = '\33[107m'
  102. ENDC       = '\033[0m'
  103.  
  104. parser = argparse.ArgumentParser(description='Open file .')
  105. parser.add_argument('v1', type = str , help='input your file to be opened')
  106.  
  107.  
  108. args=parser.parse_args();
  109.  
  110. m_file =  args.v1
  111. m_file2 = '/home/mark/python_scripts/bye.txt'
  112.  
  113. ## create a sting list object
  114. prompt_strings =[]
  115.  
  116. ## here we apppend prompt text strings
  117.  
  118.  
  119. #0
  120. prompt_strings.append('Ok lets have a look at the desktop recording of this all in  action \n  ' )
  121.                    
  122. #1                  
  123. prompt_strings.append('Starting java threadnamed  t1 ,  calling t1.start()  aha thats how hmmm  ...  \n')
  124. #2
  125. prompt_strings.append('Opening Video automated   on new thread  named t2 , calling t2.start() Amazing what you can do with threads in python !! ...   \n' )
  126. #3
  127. prompt_strings.append(" \n")
  128. #4
  129. prompt_strings.append('About to get data and write our data to file start new thread  , calling t3.start()  \n ')
  130. #5
  131. prompt_strings.append('t3.join()  Back to main thread File  is written  with data Cool.  Moving on  \n '+ \
  132.                      ' Quick add some smiley faces ,,, \n ' )
  133.                      
  134. #6
  135. prompt_strings.append('... Incredible  \n ' + \
  136.                       "Up pops my friend the Unicode robot ' Wonder if its clicked yet '\n " + \
  137.                       "Cold war ... beep ...beep  ... cold war  Isn't this exciting ..  Golly !! Real James bondage stuff  eh  \n ")
  138. #7
  139. prompt_strings.append('Now lets have a look and see what component we need to place next... \n ' + \
  140.                       'So going to the diagram we see that  \n ' + \
  141.                       '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 ' +\
  142.                       "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 " + \
  143.                       "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 " + \
  144.                       "Watch how I do this \n ")
  145.                      
  146. #8
  147. prompt_strings.append('Ok next we need a wire link to connect ground side of diode of the negative end to pin 8 \n '+ \
  148.                       'So Im going to show you how do this \n '+\
  149.                       'When  done you need to press escape key to exit drawing line tool  ..... Watch ? \n ' + \
  150.                       'Thats it folks for today .....  Not that hard is it ?? \n ' + \
  151.                       'Cheers  all ....  End of part 3  \n ')
  152. #9                    
  153. prompt_strings.append('Code will be place with links on this post  \n '+ \
  154.                       'These will include makefile '+\
  155.                       'and links to github \n ' + \
  156.                       'as well as pastebin for quick glance ' )
  157.                                            
  158.  
  159. localtime = time.asctime( time.localtime(time.time()) )+ '\n\n '
  160.  
  161.  
  162.  
  163. def f_clearscreen(time_delay):
  164.     os.system('clear')
  165.     time.sleep(time_delay)
  166.     for x in range(2):
  167.         print('')
  168.    
  169.    
  170.  
  171.  
  172. def f_openfile(fileopen):
  173.      # make this global so that functions can see this
  174.     global lines
  175.     f = open(fileopen, 'r')
  176.         # use readlines to read all lines in the file
  177.         # The variable 'lines' is a list containing all lines in the file
  178.     lines = f.readlines()
  179.    
  180.     # close the file after reading the lines.
  181.     fileopen =''
  182.     f.close()
  183.    
  184.  
  185. def slowPrintFromFile(time_sleep ,G_COLOR):
  186.    
  187.     for line in lines:
  188.         for mychar in line:
  189.             sys.stdout.write(G_COLOR + mychar)
  190.             sys.stdout.flush()
  191.             time.sleep(time_sleep)
  192.     sys.stdout.write(ENDC)
  193.     sys.stdout.flush()
  194.  
  195. def slowPrint(usrstring ,time_sleep, col):
  196.    
  197.    
  198.     for mychar in usrstring:
  199.         sys.stdout.write(col + mychar)
  200.         sys.stdout.flush()
  201.         time.sleep(time_sleep)
  202.         sys.stdout.write(ENDC)
  203.         sys.stdout.flush()
  204.  
  205.  
  206. def run_cmd(bashCommand):
  207.     process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
  208.     output, error = process.communicate()
  209.    
  210.    
  211.  
  212. def run_executable(m_filename , m_abs_pathtoexe):
  213.     '''
  214.     Run  process  that takes no arguments
  215.     '''
  216.     ## Shell=False helps the process terminate
  217.     os.chdir(m_abs_pathtoexe)
  218.    
  219.     process = subprocess.Popen(m_filename, shell=False)
  220.    
  221.     ## Get exit codes
  222.     out, err = process.communicate()
  223.     errcode = process.returncode
  224.     print(errcode)
  225.    
  226.     '''
  227.     #  NOT PART FO CODE AS YET TRYING SOMETHING OUT HERE
  228.     #pid = subprocess.check_output(['xdotool', 'getactivewindow', 'getwindowpid']).decode('utf-8').strip()
  229.     #print(pid)
  230.    '''
  231.  
  232.  
  233. def clearScreen():
  234.     os.system('clear')
  235.    
  236.  
  237.  
  238. def printemoji(GCOLOR,time_sleep, numfaces):
  239.    
  240.     for x in range(numfaces):
  241.         sys.stdout.write(GCOLOR + emoji.emojize(':grinning_face_with_big_eyes:')) ,
  242.         sys.stdout.flush()
  243.         time.sleep(time_sleep)
  244.         sys.stdout.write(ENDC)
  245.         sys.stdout.flush()
  246.     print('\n')
  247.    
  248. def playvcr(fileVideoPath):
  249.     pipes = dict(stdin=PIPE, stdout=PIPE, stderr=PIPE)
  250.     mplayer = Popen(["mplayer", fileVideoPath], **pipes)
  251.     # to control u can use Popen.communicate
  252.     mplayer.communicate(input=b">")
  253.     sys.stdout.flush()     
  254.  
  255.  
  256. def openFileforCords(fname):
  257.     f= open(fname,'a+')
  258.     inputx = raw_input('\n enter x start point of component  ::  ' )
  259.     inputy = raw_input('\n enter y start point of component  ::  ' )
  260.     inputValue = raw_input('\n enter the value of the  component  ::  ' )
  261.     f.write('x,y =  %s, %s \n' % (inputx , inputy ))
  262.     f.write('device =  %s  \n' % (inputValue ))
  263.     f.close()
  264.     slowPrint('Co ordinates entered  and file saved \n' ,0.08,CRED2)
  265.    
  266.      
  267.  
  268.  ## the main method  of script starts here ##
  269. def main():
  270.     f_clearscreen(5)
  271.    
  272.    
  273.     ## time ,  speed of typing ,  color
  274.     slowPrint(localtime,0.035,ICyan )
  275.     f_openfile(m_file)
  276.    
  277.    
  278.     # welcome nessage
  279.     print('\n')
  280.     slowPrintFromFile(0.06 ,CYELLOW2)
  281.     print('\n')
  282.    
  283.     ## bit of fun print emojo to screen
  284.     printemoji(ICyan,0.08,20)
  285.     time.sleep(2)
  286.     clearScreen()
  287.    
  288.    
  289.    
  290.        
  291.     ## change to correct directory
  292.     ## os.chdir('/home/mark/blackboard')
  293.     ## invoke java command in a thread of its own
  294.     ## t1 = threading.Thread(target=run_cmd , args = ('konsole -e java -Dsun.java2d.opengl=true -jar dist/lib/BlackBoard.jar' ,))
  295.     ## tell user what we are doing
  296.     slowPrint(prompt_strings[0] , 0.08 ,CGREEN2)
  297.    
  298.     ## Now we  start the thread
  299.     ##slowPrint(prompt_strings[1] , 0.08,CGREEN2)
  300.     ## t1.start()
  301.        
  302.     print('\n')
  303.     time.sleep(4)
  304.     ## open our image file
  305.     ## tell user what we are doing
  306.     slowPrint(prompt_strings[2] , 0.08 ,ICyan)
  307.        
  308.     ##create a new thread
  309.     t2 = threading.Thread(target=playvcr, args=('/home/mark/Videos/rpi3.mp4',))
  310.    
  311.    
  312.     t2.start()
  313.     time.sleep(4)
  314.     printemoji(CYELLOW2,0.08, 20)
  315.    
  316.    
  317.    
  318.     #change directory
  319.     ##os.chdir('/home/mark/python_scripts/lesson3')
  320.    
  321.     ## tell user what we are doing  placing IC
  322.     ##slowPrint(prompt_strings[3] , 0.08 ,ICyan)
  323.    
  324.    
  325.    
  326.    
  327.     #START THREAD T3
  328.     ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
  329.    
  330.     # get some data from user and write to file
  331.     ## tell user what we are doing
  332.     ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)  
  333.     ##t3.start()
  334.    
  335.     ##t3.join()
  336.     ## tell user what we have done  created file should be saved with  x,y , device
  337.     ##slowPrint(prompt_strings[5] , 0.08,ICyan)
  338.    
  339.     ##printemoji(CYELLOW2,0.08, 20)
  340.    
  341.    
  342.     #6 message just add some humour here and there
  343.     ##slowPrint(prompt_strings[6] , 0.08,CGREEN2)
  344.    
  345.     #open the file and show them Next place diode
  346.     ##slowPrint(prompt_strings[7] , 0.08,CYELLOW2)
  347.     ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
  348.    
  349.     # get some data from user and write to file
  350.     ## tell user what we are doing
  351.     ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)  
  352.     ##t3.start()
  353.    
  354.    
  355.     ##t3.join()
  356.     ##slowPrint(prompt_strings[5] , 0.08,ICyan)
  357.     ##printemoji(CWHITE2,0.08, 20)
  358.    
  359.     ##time.sleep(2)
  360.     ##clearScreen()
  361.    
  362.     ## about to show how we place link  
  363.     ##slowPrint(prompt_strings[8] , 0.08,CRED2)
  364.     ##t3 = threading.Thread(target=openFileforCords, args=('circuit.txt',))
  365.    
  366.     # get some data from user and write to file
  367.     ## tell user what we are doing
  368.     ##slowPrint(prompt_strings[4] , 0.08,CWHITE2)  
  369.     ##t3.start()
  370.    
  371.    
  372.     ##t3.join()
  373.     ##slowPrint(prompt_strings[5] , 0.08,ICyan)
  374.     ##printemoji(ICyan,0.08, 20)
  375.     time.sleep(2)
  376.     clearScreen()
  377.    
  378.    
  379.     ## wait for threads to complete this happens when user closes each window in thread spawned
  380.     print('\n')
  381.     ##printemoji(CRED2,0.08, 20)
  382.     print('\n')
  383.    
  384.     t2.join()  
  385.    
  386.    
  387.     slowPrint(prompt_strings[9] , 0.05,CYELLOW2)
  388.    
  389.     time.sleep(4)
  390.     os.system('clear')
  391.    
  392.     ## the end  
  393.    
  394.     slowPrint('Thank you for your interest Have a a good week  bye for now  Mark Harrington  \n\n',0.05 , ICyan)
  395.     slowPrint(localtime,0.035,CGREEN2 )
  396.     print('\n')
  397.     printemoji(CRED2,0.08, 20)
  398.     print('\n')
  399.     time.sleep(4)
  400.     os.system('clear')
  401.    
  402.  
  403.  
  404.  
  405. if __name__ == '__main__':
  406.     main()
Add Comment
Please, Sign In to add comment