def backspace_f(n=1): puts( Cursor.BACK(n) + self.line[self.cursor_pos:] + ' ' * n + Cursor.BACK(len(self.line) - self.cursor_pos + n)) self.line = self.line[:self.cursor_pos - 1] + self.line[self.cursor_pos:] self.cursor_pos -= n if self.cursor_pos < 0: self.cursor_pos = 0
def menu_principal(opciones, titulo): os.system('cls') print( '-' * 40, Cursor.DOWN(1) + Cursor.BACK(41) + '{:15}{:29}{}'.format('|', Fore.BLUE + titulo, Style.RESET_ALL + '|'), Cursor.DOWN(1) + Cursor.BACK(41) + '-' * 40) for x in range(len(opciones)): print("{:3} {:5} {:29}|".format('|', str(x + 1) + ')', opciones[x])) print('-' * 40) mn = 3 while mn != '1' and mn != '2' and mn != '3': mn = input('Elija Opcion [1/{}] '.format(len(opciones))) return mn
def Consultar(busca='', ban=0): result = ctr.consultar(busca) print('-' * 34, Cursor.DOWN(1) + Cursor.BACK(35) + '{:3}'.format('|'), Style.BRIGHT + Fore.BLUE + '{:15} {:12}'.format('ID', 'Grupo'), Style.RESET_ALL + '|', Cursor.DOWN(1) + Cursor.BACK(35) + ('-' * 34)) for x in result: print('{:3} {:15} {:12} |'.format('|', str(x[0]), x[1]), Cursor.DOWN(1) + Cursor.BACK(35) + '-' * 34) if ban == 1: input(Cursor.DOWN(3) + 'Presione una tecla para continuar....: ') ban = 0 else: ban = 0
def MenuGrupo(opcion, titulo): os.system('cls') print( '-' * 41, Cursor.DOWN(1) + Cursor.BACK(42) + "{:14} {:33}".format('|', Style.BRIGHT + Fore.BLUE + titulo), Style.RESET_ALL + "|", Cursor.DOWN(1) + Cursor.BACK(42) + '-' * 41) for x in range(len(opcion)): print("{:3} {:5} {:30}|".format('|', str(x + 1) + ')', opcion[x])) print('-' * 41) while True: opc = int(input('ingrese opcion [1...{}]: '.format(len(opcion)))) if 1 <= opc <= int(len(opcion)): break return opc
def preload( files: Iterable[MultimediaFile], func: callable, workers: int = 8, verbose: bool = True, ) -> Dict: """ load metadata in parallel and yield element when done """ def load(item: MultimediaFile): if verbose: print_temp_message(f"Analyze {item.file.name}") return func(item) with ThreadPoolExecutor(max_workers=workers) as executor: jobs = {executor.submit(load, f): f for f in files} for future in concurrent.futures.as_completed(jobs): item, result = jobs[future], None if verbose: message = f"Analyze {item.file.name}" print(message, Cursor.BACK(len(message)), sep="", end="", flush=True) try: result = future.result() except BaseException: # pylint: disable=broad-except pass yield item, result
def up_screen(fix_count=1): for i in range(width * fix_count): print(cursor.BACK()) for i in range(height * fix_count): print(cursor.UP())
def back(n): return Cursor.BACK(n)
from colorama import Cursor up = lambda n=1: print(Cursor.UP(n), end="") down = lambda n=1: print(Cursor.DOWN(n), end="") left = lambda n=1: print(Cursor.BACK(n), end="") right = lambda n=1: print(Cursor.FORWARD(n), end="") pos = lambda x, y: print(Cursor.POS(x, y), end="") class cursor: def __init__(self): pos(0, 0) self.x = 0 self.y = 0 self.saved_positions = {} def down(self, n=1): self.y += n pos(self.x, self.y) def up(self, n=1): self.y -= n pos(self.x, self.y) def right(self, n=1): self.x += n pos(self.x, self.y) def left(self, n=1): self.x -= n
def input(self): """ Non blocking input listener """ ret = [ord(b'\r')] if os.name == "nt" else [10, 13] backspace = [ord(b'\x08')] if os.name == "nt" else [127] mod = [0, ord(b'\xe0')] if os.name == "nt" else [27] puts = lambda x: self.log(x, end='') def backspace_f(n=1): puts( Cursor.BACK(n) + self.line[self.cursor_pos:] + ' ' * n + Cursor.BACK(len(self.line) - self.cursor_pos + n)) self.line = self.line[:self.cursor_pos - 1] + self.line[self.cursor_pos:] self.cursor_pos -= n if self.cursor_pos < 0: self.cursor_pos = 0 if kbhit(): c = getch() if c == None: return if c in ret: self.hist_up.append(self.line) self.line = '' self.cursor_pos = 0 puts('\n') return self.hist_up[-1] elif c in backspace: backspace_f() elif c in mod: if not os.name == 'nt': getch() c = getch() K = ord(b'K') if os.name == 'nt' else 68 M = ord(b'M') if os.name == 'nt' else 67 H = ord(b'H') if os.name == 'nt' else 65 P = ord(b'P') if os.name == 'nt' else 66 S = ord(b'S') if os.name == 'nt' else 51 if c == K and self.cursor_pos > 0: # left arrow self.cursor_pos -= 1 puts(Cursor.BACK()) elif c == M and self.cursor_pos < len( self.line): # right arrow self.cursor_pos += 1 puts(Cursor.FORWARD()) elif c == H and len(self.hist_up) > 0: # up arrow puts( Cursor.BACK(len(self.line[:self.cursor_pos])) + ' ' * len(self.line) + Cursor.BACK(len(self.line))) self.hist_down.append(self.line) self.line = self.hist_up.pop() self.log(self.line, end='') self.cursor_pos = len(self.line) elif c == P and len(self.hist_down) > 0: # down arrow puts( Cursor.BACK(len(self.line[:self.cursor_pos])) + ' ' * len(self.line) + Cursor.BACK(len(self.line))) self.hist_up.append(self.line) self.line = self.hist_down.pop() self.log(self.line, end='') self.cursor_pos = len(self.line) elif c == S and self.cursor_pos < len(self.line): #suppr if os.name != 'nt': getch() self.cursor_pos += 1 puts(Cursor.FORWARD()) backspace_f() else: c = chr(c) self.line = self.line[:self.cursor_pos] + c + self.line[ self.cursor_pos:] puts(self.line[self.cursor_pos:] + Cursor.BACK(len(self.line[self.cursor_pos:])) + Cursor.FORWARD()) self.cursor_pos += 1 return None
def print_temp_message(msg: str): """ print a message and reset the cursor to the begining of the line """ print(clear_line(), msg, Cursor.BACK(len(msg)), sep="", end="", flush=True)
out = cv2.VideoWriter(out_path, codec, fps, (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))) last_frame = [] last_frame = cap.read()[1] print('\033[2J', Pointer.UP() * 20, end='') started_at = get_ticks() while True: frame = cap.read()[1] frames_read += 1 for_test = frame == last_frame if type(for_test) == bool: break if not (for_test).all(): last_frame = frame out.write(frame) frames_wrote += 1 print(Pointer.UP() * 5, Pointer.BACK() * (get_size()[0] + 1), end='') need_str = f'Frames read: {frames_read}\nFrames wrote: {frames_wrote}' print(need_str, ' ' * int(len(need_str) - 1), end='') end_at = get_ticks() all_ = end_at - started_at all_min = int(all_ / 60) all_sec = int() out.release()