def spin(): try: while True: cli.write('/') time.sleep(.25) cli.write('\b|') time.sleep(.25) cli.write('\b\\') time.sleep(.25) cli.write('\b-') time.sleep(.25) cli.write('\b') except KeyboardInterrupt: return
def main(): """ Gets two pairs of magnitude and angle from command line or interactive prompt and perform vector addition. """ # If no args, greet first-time user if len(sys.argv[1:]) == 0: SHELL.welcome(description=""" Find the sum of two 2D vectors (reads from command line and standard input) VectorSum.py [mag1] [ang1] [mag2] [ang2] """) loop_flag = True #else: # loop_flag = False while loop_flag is True: if SHELL.interface == 'Tk' or len(sys.argv[1:]) != 0: loop_flag = False if loop_flag is True: cli.Cli.output('') mag1 = decimal.Decimal(SHELL.arg(*PROMPTS)) cli.write(' ' * 2)#temporary fix theta1 = decimal.Decimal(SHELL.arg(*PROMPTS)) if loop_flag is True: cli.Cli.output('') mag2 = decimal.Decimal(SHELL.arg(*PROMPTS)) cli.write(' ' * 2)#temporary fix theta2 = decimal.Decimal(SHELL.arg(*PROMPTS)) cli.Cli.output('') angle1 = Angle(theta1, 'deg') vector1 = Vector(mag1, angle1) angle2 = Angle(theta2, 'deg') vector2 = Vector(mag2, angle2) vector_sum = vector1 + vector2 vector_sum.theta = vector_sum.theta.deg() SHELL.output('{}\n'.format(vector_sum)) if SHELL.interface not in ['bash', 'sh']: SHELL.main_window.mainloop()
def histogram(self): print('') #pylint: disable=C0325 cli.write('%3s:' % self.items[0]) for i in range(len(self)): cli.write('[*]') #try: if self[i] != self[i + 1]: cli.write('\n%3s:' % self[i + 1]) #except: # pass print('\n') #pylint: disable=C0325
def print_points(self): """ Print the graph as a table of ordered pairs. Used for debugging or non- Euclidean space. """ for y_val in range(self.size): for x_val in range(self.size): if self.pt_at_cursor() and self.plane[x_val][y_val] ==\ self.pt_at_cursor(): cli.write('{:>9}'.format('>{}<'.format( self.plane[x_val][y_val]))) elif self.pt_at_cursor() and self.plane[x_val][y_val] ==\ self.pt_at_cursor(): cli.write('{:>9}'.format(self.plane[x_val][y_val])) else: cli.write('{:>8} '.format(self.plane[x_val][y_val])) print('') #pylint: disable=C0325
def main(): """ Starts the countdown timer, continually double-checking against clock time to maintain accuracy. """ cli.Cli() remaining = SECONDS string = (subprocess.check_output('./mmss.py {}'.format( int(remaining)), shell=True)).decode('utf-8') cli.write('\033[?25l') cli.write('{} remaining'.format(string.rstrip())) while remaining >= 0: time.sleep(.5) remaining = SECONDS - time.time() + _SINCE string = (subprocess.check_output('./mmss.py {}'.format( int(remaining)), shell=True)).decode('utf-8') cli.write('\r{}'.format(string.strip())) alert()
# MAIN # ########## def main(): """ Starts the countdown timer, continually double-checking against clock time to maintain accuracy. """ cli.Cli() remaining = SECONDS string = (subprocess.check_output('./mmss.py {}'.format( int(remaining)), shell=True)).decode('utf-8') cli.write('\033[?25l') cli.write('{} remaining'.format(string.rstrip())) while remaining >= 0: time.sleep(.5) remaining = SECONDS - time.time() + _SINCE string = (subprocess.check_output('./mmss.py {}'.format( int(remaining)), shell=True)).decode('utf-8') cli.write('\r{}'.format(string.strip())) alert() if __name__ == '__main__': try: main() finally: cli.write('\033[?25h')
def main(): """ Preprocessor "include" statements are the only thing the interpreter remembers from previously-input commands. ^C will discard all data, erase all data files, and end the program. """ if ARGS.f90: if ARGS.cpp: sys.exit('Please choose one language.\n') else: includes = '' elif ARGS.cpp: includes = '#include <iostream>\n' else: includes = '#include <stdio.h>\n' cli.Cli() try: while True: if ARGS.f90: block = 'PROGRAM Interactive\nIMPLICIT NONE\n' else: if ARGS.cpp: block = 'using namespace std;' else: block = '' block += 'int main(int argc, char* argv[])\n{\n' if ARGS.f90: prompt = '+' elif ARGS.cpp: prompt = '%%' else: prompt = '%' cli.write(prompt) while True: try: line = cli.Cli.input('') if line.startswith('#include'): includes += line + '\n' else: block += ('\t' + line + '\n') except EOFError: if ARGS.f90: block += 'END PROGRAM Interactive' else: block += '\n\treturn 0;\n}' break if ARGS.cpp: filename = './tmp.cpp' elif ARGS.f90: filename = './tmp.f90' else: filename = './tmp.c' try: file_ptr = open(filename, 'w') file_ptr.write(includes + '\n' + block) finally: file_ptr.close() if ARGS.f90: command = 'gfortran ./tmp.f90' elif ARGS.cpp: command = 'g++ ./tmp.cpp' else: if "math.h" in includes: command = 'gcc -lm ./tmp.c' else: command = 'tcc ./tmp.c' return_val = subprocess.check_call(command, shell=True) if return_val == 0: # There is probably a better way # than having to run the code twice.... proc = subprocess.Popen('./a.out', shell=True) proc.wait() #output = subprocess.check_output('./a.out', shell=True) #if not output.endswith('\n'): #print('\033[7m\033[1m%\033[0m') except KeyboardInterrupt: sys.stdout.write('\b\b\b') sys.stdout.flush() try: os.remove('./tmp.c') except OSError: pass try: os.remove('./a.out') except OSError: pass
#!/usr/bin/env python import os, time import cjh.cli as cli __author__ = 'Chris Horn <*****@*****.**>' if __name__ == '__main__': cli.write('\033[?25l') try: while True: cli.write('/') time.sleep(.075) cli.write('\b|') time.sleep(.075) cli.write('\b\\') time.sleep(.075) cli.write('\b-') time.sleep(.075) cli.write('\b') finally: cli.write('\033[?25h')
import math, sys, time from cjh import cli cli.Cli() cli.Cli.clear() print(' ' * 30 + 'SINE WAVE') print(' ' * 15 + 'CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n') cli.Cli.wait() print('\n' * 4) toggle = 0 iter_count = 0 try: cli.write('\033[?25l') while True: s = iter_count / 4.0 width = cli.Cli.width() indent = int((width - 10) * math.sin(s) + width - 8) // 2 cli.write(' ' * indent) if(toggle == 1): print('CREATIVE') toggle = 0 else: print('COMPUTING') toggle = 1 time.sleep(.025) iter_count += 1 except KeyboardInterrupt: pass