def __init__(self): self.wheels = [{0: 13, 1: 25, 2: 5, 3: 9, 4: 14, 5: 6, 6: 21, 7: 11, 8: 8, 9: 24, 10: 22, 11: 15, 12: 3, 13: 10, 14: 20, 15: 16, 16: 18, 17: 12, 18: 7, 19: 1, 20: 19, 21: 4, 22: 2, 23: 23, 24: 17, 25: 0}, {0: 5, 1: 17, 2: 23, 3: 1, 4: 6, 5: 24, 6: 13, 7: 3, 8: 0, 9: 16, 10: 14, 11: 7, 12: 21, 13: 2, 14: 12, 15: 8, 16: 10, 17: 4, 18: 25, 19: 19, 20: 11, 21: 22, 22: 20, 23: 15, 24: 9, 25: 18}, {0: 0, 1: 12, 2: 18, 3: 22, 4: 1, 5: 19, 6: 8, 7: 24, 8: 21, 9: 11, 10: 9, 11: 2, 12: 16, 13: 23, 14: 7, 15: 3, 16: 5, 17: 25, 18: 20, 19: 14, 20: 6, 21: 17, 22: 15, 23: 10, 24: 4, 25: 13}, {0: 21, 1: 22, 2: 23, 3: 24, 4: 25, 5: 0, 6: 1, 7: 2, 8: 3, 9: 4, 10: 5, 11: 6, 12: 7, 13: 8, 14: 9, 15: 10, 16: 11, 17: 12, 18: 13, 19: 14, 20: 15, 21: 16, 22: 17, 23: 18, 24: 19, 25: 20}] txt = ["\n\n\n", "*-"*12+'\n'+" Mini_enigma\n\n by Nathan R Smith\n github.com/NSMobileCS\n [email protected]\n"+'-*'*12, '\n\n', "This script simulates one version of the historical Enigma", "encryption device that Alan Turing helped break during WWII.", "It encodes & decodes text using 4 virtual code-wheels.\n", "For historical accuracy, text displays in all caps.", '\nVerbose mode allows you to \'see it working\' by ', "printing program state every cycle", "(0)verbose mode off (1)normal verbose mode (2)ultra verbose mode"] self.verbose = 1 for line in txt: print(line) zzz(1.1) seeitworking = input("Selection (press Enter for default): ") if seeitworking == '1': pass elif seeitworking == '2': self.verbose = 2 else: self.verbose = 0
def clearBoard(self): self.running = 0 self.prevStatesStack = [] for row in self.gridCellList: for cell in row: self.ui.boardGrid.removeWidget(cell) zzz(0.05) del self.gridCellList self.setupGrid()
def test_least_squares_err(self): x_train = TEST_DATA['ls']['x_train'] y_train = TEST_DATA['ls']['y_train'] M = TEST_DATA['ls']['M'] err_expected = TEST_DATA['ls']['err'] _, err = least_squares(x_train, y_train, M) self.assertEqual(np.size(err), 1) self.assertAlmostEqual(err, err_expected) zzz(1)
def confirmStatus( id ): # this is used to monitor the status of the computer via the database hosted on digitalocean control_variable = 300 isSent = False mailOnFail.mailOnFail(id, ' is UP!') while True: current_system_time = udpServer.getCurrentTime() last_ping_time = dbh.checkTime(id) result = int(current_system_time) - int(last_ping_time) control_variable = last_ping_time programstatus = dbh.checkProgramStatus(id) if (programstatus == False and isSent == False): mailOnFail.mailOnFail( id, ' is not recording! Timecode - ' + dbh.getTimeOfDeath(id)) isSent = True if (programstatus == True and isSent == True): mailOnFail.mailOnFail(id, ' is now recording again!') isSent = False print('Time scince last ping from ' + id + ' is ' + str(result) + ' second(s)') if ( result >= 10 ): ## Denne skal oppdateres til 15 min i ferdig versjon etter testing hos kunde break if (result < 0 and (last_ping_time == control_variable) ): #handles the situation where result is stuck at >0 zzz(4) if ((dbh.checkTime(id)) == control_variable): break zzz(5) print('CLIENT WITH ID: ' + id + ' IS DOWN!') dbh.updateComputerStatus(id, '0') dbh.updateProgramStatus(id, '0') dbh.setTimeOfDeath(id, setTimeOfDeath()) mailOnFail.mailOnFail(id, ' is DOWN! Timecode - ' + dbh.getTimeOfDeath(id)) return
def sendInfoToServer( ): ## sends all needed info to server, as well as recieving and saving the assigned id first_itteration = testIp() ip_host_of_client = getLocalIp() port_to_try = 5000 #will be auto assigned if occupied by another system server = (server_ip, server_port) #ip of server s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((ip_host_of_client, port_to_try)) if (first_itteration): location_id = giveId() put_in_db = '0' if not (first_itteration): location_id = pickle.load(open('id.p', 'rb')) put_in_db = '1' while True: program_is_running = testForProcess() if (program_is_running): isRunning = '1' if not (program_is_running): isRunning = '0' message = str.encode(location_id + ',' + put_in_db + ',' + isRunning) s.sendto(message, server) print('*ping*') if (first_itteration): put_in_db = '1' #Tells server not to ubdate db first_itteration = False #we are no longer on first itteration location_id, addr = s.recvfrom(1024) location_id = bytes.decode(location_id) pickle.dump(location_id, open('id.p', 'wb')) print('server svarte med id: ' + location_id) zzz(3) ## skal oppdateres til 7.5 min eller 8 ganger i timen s.close()
def randFill(self): l = [] from random import randrange n = self.ui.randFillInput.value() while len(l) < n: rnum, cnum = randrange(len(self.gridCellList)), randrange(len(self.gridCellList[0])) if tuple((rnum, cnum)) in l: continue l.append((rnum, cnum)) self.clearBoard() zzz(0.05) for rnum, cnum in l: self.gridCellList[rnum][cnum].setLiveVal(1)
def run(self): while True: try: if len(self.path) > 1: if sys.platform != 'win32': #if we're not on windows, try the linux (& os x) opener self.linuxOpener(self.path) else: QtGui.QDesktopServices.openUrl(self.path) self.openedList.append(self.path) self.path = None self.hasEverHadPath_debug = 'yes' else: pass except (ValueError, TypeError): pass zzz(.1)
def tweetimage(): photo = nsplshr.getImages(cr.UNSPLASH_CLIENT_ID).body[0] user = '******' + photo['user']['username'] link = photo['links']['html'] download_link = photo['links']['download'] img_dir = f"./imgs/{photo['id']}.jpg" tweet = f"{user}\n{link}\n{download_link}" urllib.request.urlretrieve(download_link, img_dir) with open(img_dir, "rb") as imagefile: imagedata = imagefile.read() t_upload = Twitter(domain='upload.twitter.com', auth=OAuth(cr.TT_ACCESS_TOKEN, cr.TT_ACCESS_TOKEN_SECRET, cr.TT_API_KEY, cr.TT_API_SECRET_KEY)) try: id_img1 = t_upload.media.upload(media=imagedata)["media_id_string"] except Exception: tweetimage() t.statuses.update(status=tweet, media_ids=",".join([id_img1])) unlink(img_dir) zzz(3600) tweetimage()
try: from time import sleep as zzz print("Haz ejecutado el módulo como si pudiera mantenerse él solo") print("No debiste hacer eso...") for i in range(10, 0, -1): zzz(0.75) print("%d" % i) for _ in range(100): print('\a') zzz(0.1) except: print(">:( no lo vuelvas a hacer, por fa")
def animate_method_2(speed): # hide command line cursor ... hide() # infinite repetition until forced exit ... while True: # move stars from left to right for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # stars variable ... stars = ' ' * space + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\033[D \033[D' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars])) # move stars from right to left for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # stars variable ... stars = ' ' * (command_line_size_method_2 - space) + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars]))
def animate_method_1(speed): # hide command line cursor ... hide() # infinite repetition until forced exit ... while True: # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | bgy r | stdout.write(' ' * half_command_line_size_method_1 + star.BLUE + star.GREEN + star.YELLOW + ' ' * space + star.RED) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | r bgy | stdout.write(' ' * space + star.RED + ' ' * reverse + star.BLUE + star.GREEN + star.YELLOW) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | rbg y | stdout.write(' ' * half_command_line_size_method_1 + star.RED + star.BLUE + star.GREEN + ' ' * space + star.YELLOW) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | y rgbg | stdout.write(' ' * space + star.YELLOW + ' ' * reverse + star.RED + star.BLUE + star.GREEN) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | yrb g | stdout.write(' ' * half_command_line_size_method_1 + star.YELLOW + star.RED + star.BLUE + ' ' * space + star.GREEN) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable ... reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | g yrb | stdout.write(' ' * space + star.GREEN + ' ' * reverse + star.YELLOW + star.RED + star.BLUE) # show loading ... for space in range(half_command_line_size_method_1): # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | gyr b | stdout.write(' ' * half_command_line_size_method_1 + star.GREEN + star.YELLOW + star.RED + ' ' * space + star.BLUE) # show loading ... for space in range(half_command_line_size_method_1): # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | b gyr | stdout.write(' ' * space + star.BLUE + ' ' * reverse + star.GREEN + star.YELLOW + star.RED)
def loading(sleep=None, function=None, speed=None, method=None, argument=None, output=None): # show error function ... def error(problem): print('tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : ' + problem) # colored stars animate functions ... class star: BLUE = '{blue}*'.format(blue='\033[94m') GREEN = '{green}*'.format(green='\033[92m') RED = '{red}*'.format(red='\033[91m') YELLOW = '{yellow}*'.format(yellow='\033[33m') # find (filename or line) python file ... x = stack()[1] x = x[0] get_python_file_name_or_line = getframeinfo(x) # set valur for find line in python file ... line_python_file = str(get_python_file_name_or_line.lineno) # set value for find python file name ... python_file_name = str(get_python_file_name_or_line.filename) # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # all argument is None ... list_argument = [sleep, function, speed, method, argument, output] if list_argument == [None, None, None, None, None, None]: error('please use arguments ...') return # function has value ... if function is not None: # set method , default 1 ... if method is None: method = 1 elif type(method) is not int: error('\'method\' argument must be number range of 1 to 2 ...') return elif method == 0: error('\'method\' argument must be number range of 1 to 2 ...') return elif method > 2: error('\'method\' argument must be number range of 1 to 2 ...') return # set value for speed ... if speed is None: speed = 0.040 elif speed is not None: if type(speed) is not int: error('\'speed\' argument must be number range of 1 to 10 ...') return elif speed == 1: speed = 0.020 elif speed == 2: speed = 0.030 elif speed == 3: speed = 0.040 elif speed == 4: speed = 0.050 elif speed == 5: speed = 0.060 elif speed == 6: speed = 0.070 elif speed == 7: speed = 0.080 elif speed == 8: speed = 0.090 elif speed == 9: speed = 0.200 elif speed == 10: speed = 0.350 elif speed > 10: error('\'speed\' argument must be number range of 1 to 10 ...') return # cannot use simultaneously 'sleep' and 'function' argument ... if sleep is not None: error( 'if use \'sleep\' argument , cannot use \'function\' argument and vice versa ...' ) return # argument has value ... if argument is not None: if type(argument) is not list: error('argument \'argument\' must be a list type ...') return # output no value ... if output is None: output = True # output has value ... elif output is not None: if type(output) is not bool: error('argument \'output\' must be boolean type ...') return # function no value ... elif function is None: # sleep no value ... if sleep is None: # sleep has value ... if speed is not None: error( 'need \'sleep\' or \'function\' argument to use the \'speed\' argument ...' ) return # method has value ... elif method is not None: error( 'need \'sleep\' or \'function\' argument to use the \'method\' argument ...' ) return # argument has value ... if argument is not None: error( 'need \'function\' argument to use the \'argument\' argument ...' ) return # output has value ... if output is not None: error( 'need \'function\' argument to use the \'output\' argument ...' ) return # output has value ... if output is not None: error( 'need \'function\' argument to use the \'output\' argument ...' ) return # sleep has value ... if sleep is not None: if type(sleep) is not int: error('argument \'sleep\' must be a int type ...') return # set method , default 1 ... if method is None: method = 1 elif type(method) is not int: error('\'method\' argument must be number range of 1 to 2 ...') return elif method == 0: error('\'method\' argument must be number range of 1 to 2 ...') elif method > 2: error('\'method\' argument must be number range of 1 to 2 ...') return # set value for speed ... if speed is None: speed = 0.040 elif speed is not None: if type(speed) is not int: error('\'speed\' argument must be number range of 1 to 10 ...') return elif speed == 1: speed = 0.020 elif speed == 2: speed = 0.030 elif speed == 3: speed = 0.040 elif speed == 4: speed = 0.050 elif speed == 5: speed = 0.060 elif speed == 6: speed = 0.070 elif speed == 7: speed = 0.080 elif speed == 8: speed = 0.090 elif speed == 9: speed = 0.200 elif speed == 10: speed = 0.350 elif speed > 10: error('\'speed\' argument must be number range of 1 to 10 ...') return # ----------------------------------------------------------------------------------------------------------------------------------------------------------- # fix show text color ... system('') # if finished is True break animate function ... finished = False # check command prompet columns size if ostype().upper() == 'WINDOWS': resize = str(check_output("mode con:", shell=True)) resize = resize.split('\\r\\n K', 1)[0] a = resize[-3] b = resize[-2] c = resize[-1] resize = a + b + c resize = resize.replace(' ', '') elif ostype().upper() == 'LINUX': resize = str(check_output("resize", shell=True)) resize = resize[10], resize[11], resize[12] resize = str(resize) resize = resize.replace(' ', '') resize = resize.replace(',', '') resize = resize.replace('\'', '') resize = resize.replace(')', '') resize = resize.replace('(', '') resize = resize.replace(';', '') # command prompet size method 1 ... command_line_size_method_1 = int(resize) # command prompet half size method 2 ... half_command_line_size_method_1 = (command_line_size_method_1 - 3) // 2 # command prompet size method 2 ... command_line_size_method_2 = int(resize) - 4 # -------------------------------------------------------------------------------------------------------------------------------------------------------------------- # b is blue , g is green , r is red , y is yellow in animate method 1 comment ... # animate method 1 function ... def animate_method_1(speed): # hide command line cursor ... hide() # infinite repetition until forced exit ... while True: # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | bgy r | stdout.write(' ' * half_command_line_size_method_1 + star.BLUE + star.GREEN + star.YELLOW + ' ' * space + star.RED) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | r bgy | stdout.write(' ' * space + star.RED + ' ' * reverse + star.BLUE + star.GREEN + star.YELLOW) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | rbg y | stdout.write(' ' * half_command_line_size_method_1 + star.RED + star.BLUE + star.GREEN + ' ' * space + star.YELLOW) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | y rgbg | stdout.write(' ' * space + star.YELLOW + ' ' * reverse + star.RED + star.BLUE + star.GREEN) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | yrb g | stdout.write(' ' * half_command_line_size_method_1 + star.YELLOW + star.RED + star.BLUE + ' ' * space + star.GREEN) # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # add star to 3 stars from left varable ... reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | g yrb | stdout.write(' ' * space + star.GREEN + ' ' * reverse + star.YELLOW + star.RED + star.BLUE) # show loading ... for space in range(half_command_line_size_method_1): # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | gyr b | stdout.write(' ' * half_command_line_size_method_1 + star.GREEN + star.YELLOW + star.RED + ' ' * space + star.BLUE) # show loading ... for space in range(half_command_line_size_method_1): # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | b gyr | stdout.write(' ' * space + star.BLUE + ' ' * reverse + star.GREEN + star.YELLOW + star.RED) # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # animate method 2 function ... def animate_method_2(speed): # hide command line cursor ... hide() # infinite repetition until forced exit ... while True: # move stars from left to right for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # stars variable ... stars = ' ' * space + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\033[D \033[D' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars])) # move stars from right to left for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\r') return # stars variable ... stars = ' ' * (command_line_size_method_2 - space) + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\b \b' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars])) # ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # create loading by sleep ... if sleep is not None: # animate method function selection ... if method == 1: # show animate function method 1 ... thread = Thread(target=animate_method_1, args=[speed]) thread.start() # if sleep time ended break animate function ... zzz(sleep) # delete line ... stdout.write('\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\033[0m\r') # if finished is True breaked animate method 1 function ... finished = True elif method == 2: # show animate function method 2 ... thread = Thread(target=animate_method_2, args=[speed]) # start thread ... thread.start() # if sleep time ended break animate function ... zzz(sleep) # delete line ... stdout.write('\b \b' * int(resize)) stdout.write(' ' * int(resize) + '\033[0m\r') # if finished is True breaked animate method 2 function ... finished = True # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # create loading by function ... elif function is not None: # check function return value ... return_value = Queue() def storeInQueue(function): def returned(*args): try: return_value.put(function(*args)) except TypeError: error( 'content of the \'argument\' argument does not match the arguments for \'function\' ...' ) return returned # redirect function stdout ... def redirect(f): def wrapper(*args, **kwargs): default_stdout = sys.stdout if ostype().upper() == 'LINUX': sys.stdout = open('/dev/null', 'w') elif ostype().upper() == 'WINDOWS': sys.stdout = open('file', 'w') try: return f(*args, **kwargs) except TypeError: error( 'content of the \'argument\' argument does not match the arguments for \'function\' ...' ) return finally: sys.stdout.close() sys.stdout = default_stdout return wrapper # output is False , redirect function output ... if output is False: # if is arguments ... if argument is not None: # if type 'argument' is not list show error ... if type(argument) is not list: error('argument \'argument\' must be a list type ...') return # create thread ... thread = Thread(target=storeInQueue(redirect(function)), args=argument) # if is not arguments ... elif argument is None: # create thread ... thread = Thread(target=storeInQueue(redirect(function))) # output is True , can't redirect function output ... elif output is True: # if is argument ... if argument is not None: # create thread ... thread = Thread(target=storeInQueue(function), args=argument) # if is not arguments ... elif argument is None: # create thread ... thread = Thread(target=storeInQueue(function)) # start thread and show loading ... thread.start() # if function is running ... while thread.isAlive(): # selection method to show animate ... if method == 1: animate_method_1(speed) elif method == 2: animate_method_2(speed) # return function value ... return return_value.get()
def loading(speed=None, sleep=None, function=None, args=None, method=None): threads = [] # find (filename or line) python file ... x = stack()[1] x = x[0] get_python_file_name_or_line = getframeinfo(x) # set valur for find line in python file ... line_python_file = str(get_python_file_name_or_line.lineno) # set value for find python file name ... python_file_name = str(get_python_file_name_or_line.filename) # set speed for animates function , default is 5 ... if speed == None: speed = 0.040 elif type(speed) != int: print( 'tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : speed argument must be number range of 1 to 10 ...') return elif speed == 1: speed = 0.020 elif speed == 2: speed = 0.030 elif speed == 3: speed = 0.040 elif speed == 4: speed = 0.050 elif speed == 5: speed = 0.060 elif speed == 6: speed = 0.070 elif speed == 7: speed = 0.080 elif speed == 8: speed = 0.090 elif speed == 9: speed = 0.200 elif speed == 10: speed = 0.350 else: print( 'tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : speed argument must be number range of 1 to 10 ...') return # set method for animates function , default 1 ... if method == None: method = 1 elif type(method) != int: print( 'tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : method argument must be number range of 1 to 2 ...') return elif method == 1: method = 1 elif method == 2: method = 2 else: print( 'tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : method argument must be number range of 1 to 2 ...') return # hide command line cursor ... hide() # fix show text color ... system('') # if finished == True break animate function ... finished = False # check command prompet columns size if os_type().upper() == 'WINDOWS': resize = str(check_output("mode con:", shell=True)) resize = resize.split('\\r\\n K', 1)[0] a = resize[-3] b = resize[-2] c = resize[-1] resize = a + b + c resize = resize.replace(' ', '') elif os_type().upper() == 'LINUX': resize = str(check_output("resize", shell=True)) resize = resize[10], resize[11], resize[12] resize = str(resize) resize = resize.replace(' ', '') resize = resize.replace(',', '') resize = resize.replace('\'', '') resize = resize.replace(')', '') resize = resize.replace('(', '') resize = resize.replace(';', '') # command prompet size method 1 ... command_line_size_method_1 = int(resize) # command prompet half size method 2 ... half_command_line_size_method_1 = (command_line_size_method_1 - 3) // 2 # command prompet size method 2 ... command_line_size_method_2 = int(resize) - 4 # colored stars animate functions ... if os_release == '7': class star: blue = '*' green = '*' red = '*' yellow = '*' else: class star: blue = '\033[94m' + '*' green = '\033[92m' + '*' red = '\033[91m' + '*' yellow = '\033[33m' + '*' # b == blue , g == green , r == red , y == yellow in animate method 1 comment ... # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # animate method 1 function ... def animate_method_1(speed): # infinite repetition until forced exit ... while True: # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | bgy r | stdout.write(' ' * half_command_line_size_method_1 + star.blue + star.green + star.yellow + ' ' * space + star.red) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | r bgy | stdout.write(' ' * space + star.red + ' ' * reverse + star.blue + star.green + star.yellow) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | rbg y | stdout.write(' ' * half_command_line_size_method_1 + star.red + star.blue + star.green + ' ' * space + star.yellow) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | y rgbg | stdout.write(' ' * space + star.yellow + ' ' * reverse + star.red + star.blue + star.green) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | yrb g | stdout.write(' ' * half_command_line_size_method_1 + star.yellow + star.red + star.blue + ' ' * space + star.green) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable ... reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | g yrb | stdout.write(' ' * space + star.green + ' ' * reverse + star.yellow + star.red + star.blue) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | gyr b | stdout.write(' ' * half_command_line_size_method_1 + star.green + star.yellow + star.red + ' ' * space + star.blue) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | b gyr | stdout.write(' ' * space + star.blue + ' ' * reverse + star.green + star.yellow + star.red) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # animate method 2 function ... def animate_method_2(speed): # infinite repetition until forced exit ... while True: # move stars from left to right for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # stars variable ... stars = ' ' * space + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\033[D \033[D' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars])) # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate method 2 function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # move stars from right to left for space in range(command_line_size_method_2): # end color ... stdout.write('\033[0m') # stars variable ... stars = ' ' * (command_line_size_method_2 - space) + "***" # set stars random color ... colors = [ '\x1b[34m', '\x1b[36m', '\x1b[32m', '\x1b[90m', '\x1b[94m', '\x1b[96m', '\x1b[92m', '\x1b[95m', '\x1b[91m', '\x1b[97m', '\x1b[93m', '\x1b[35m', '\x1b[31m', '\x1b[39m', '\x1b[37m', '\x1b[33m' ] # delete line ... stdout.flush() stdout.write('\033[D \033[D' * int(resize)) zzz(speed) stdout.write(' ' * int(resize) + '\r') # show stars random color ... stdout.write(''.join([choice(colors) + char for char in stars])) # exit from animate function method 2 , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # create loading by sleep ... if sleep != None: # if type sleep is not int or float , break ... if (type(sleep) == int) or (type(sleep) == float): # if use 'sleep' argument , cannot use 'function' and 'args' arguments ... if (function != None) or (args != None): print( 'tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : if use \'sleep\' argument , cannot use \'function\' and \'args\' arguments ...' ) return # animate method function selection ... if method == 1: # show animate function method 1 ... thread = Thread(target=animate_method_1, args=[speed]) thread.start() # if sleep time ended break animate function ... zzz(sleep) # delete line ... stdout.write('\033[D \033[D' * int(resize)) stdout.write(' ' * int(resize) + '\033[0m\r') # if finished == True breaked animate method 1 function ... finished = True elif method == 2: # show animate function method 2 ... thread = Thread(target=animate_method_2, args=[speed]) # start thread ... thread.start() # if sleep time ended break animate function ... zzz(sleep) # delete line ... stdout.write('\033[D \033[D' * int(resize)) stdout.write(' ' * int(resize) + '\033[0m\r') # if finished == True breaked animate method 2 function ... finished = True # if type sleep is not int or float show error ... else: print('tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : sleep argument must be int type ...') return # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # create loading by function ... elif function != None: # check function return value ... return_value = Queue() def storeInQueue(function): def returned(*args): return_value.put(function(*args)) return returned # if is arguments ... if args != None: # if type args is not list show error ... if type(args) != list: print('tekrar module - error | python file : ' + python_file_name + ' | line : ' + line_python_file + ' | problem : argument \'args\' must be a list type ...') return # create thread ... thread = Thread(target=storeInQueue(function), args=args) # if is not arguments ... if args == None: # create thread ... t = Thread(target=storeInQueue(function)) threads.append(t) # redirect print ... with redirect_stdout(None): # start thread and show loading ... for thread in threads: thread.start() # if function is running ... while thread.isAlive(): # selection method to show animate ... if method == 1: animate_method_1(speed) elif method == 2: animate_method_2(speed) for thread in threads: thread.join() # return function value ... return return_value.get()
def animate_method_1(speed): # infinite repetition until forced exit ... while True: # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | bgy r | stdout.write(' ' * half_command_line_size_method_1 + star.blue + star.green + star.yellow + ' ' * space + star.red) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | r bgy | stdout.write(' ' * space + star.red + ' ' * reverse + star.blue + star.green + star.yellow) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | rbg y | stdout.write(' ' * half_command_line_size_method_1 + star.red + star.blue + star.green + ' ' * space + star.yellow) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | y rgbg | stdout.write(' ' * space + star.yellow + ' ' * reverse + star.red + star.blue + star.green) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | yrb g | stdout.write(' ' * half_command_line_size_method_1 + star.yellow + star.red + star.blue + ' ' * space + star.green) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable ... reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | g yrb | stdout.write(' ' * space + star.green + ' ' * reverse + star.yellow + star.red + star.blue) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | gyr b | stdout.write(' ' * half_command_line_size_method_1 + star.green + star.yellow + star.red + ' ' * space + star.blue) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return # show loading ... for space in range(half_command_line_size_method_1): # end color ... stdout.write('\033[0m') # add star to 3 stars from left varable reverse = (half_command_line_size_method_1 - 1) - space # delete line ... stdout.flush() stdout.write('\033[D \033[D' * command_line_size_method_1) zzz(speed) stdout.write(' ' * command_line_size_method_1 + '\r') # show loading , | b gyr | stdout.write(' ' * space + star.blue + ' ' * reverse + star.green + star.yellow + star.red) # exit from animate function , if runtime ended ... if (not thread.isAlive()) or (finished): # show command line cursor ... show() # delete line and close animate function ... stdout.write('\r\033[D \033[D' * command_line_size_method_1) stdout.write(' ' * command_line_size_method_1 + '\033[0m\r') return
def processMoves(self): while self.running: self.oneMove() for _ in range(20): QtCore.QCoreApplication.processEvents() zzz(self.tickTime / 20.0)
def giveId( ): ## returns the name of the location so that server can assign an id while True: location = input('Where is this recorder located? ') confirmation = input('Retype location ' + location + ' to confirm: ') if (str.upper(location) == str.upper(confirmation)): if (str.upper( input('is the location ' + str.upper(location) + ' correct? Y/N ')) == 'Y'): break else: print('\nRestarting input procedure\n') zzz(0.3) print('.') zzz(0.3) print('.') zzz(0.3) print('.\n') continue print( '\n************Please make sure your first and second input matches************\n' ) zzz(0.3) print('.') zzz(0.3) print('.') zzz(0.3) print('.\n') return location