def on_create(self) -> None: con.clear() con.box_print("Project Malcolm") print("Local IP Address:", network.get_local_ip()) print("Public IP Address:", network.get_public_ip()) print("Server IP Address:", self.address) print() print("Press any key to continue") con.getch()
def init(args: argparse.Namespace): con.clear() con.box_print("Project Malcolm") print("Local IP Address:", network.get_local_ip()) print("Public IP Address:", network.get_public_ip()) print("File size:", file.get_size(args.file), "Bytes") print("Checksum:", file.gen_checksum(args.file)) print() print("Press any key to start servers") con.getch()
def run(self): try: self.begin() more_sentences = True while True: key = console.getch() # print('Key code:', repr(key)) if key in Presenter.KEY_PREV: more_sentences = self.prev() elif key in Presenter.KEY_NEXT: if more_sentences: more_sentences = self.next() else: break elif key in Presenter.KEY_AGAIN: more_sentences = self.again() elif key in Presenter.KEY_GOTO: if self.state != Presenter.READY_TO_TYPE: self.next() try: self.write('\n\n') if self.colors: self.write(colorama.Fore.GREEN, colorama.Style.BRIGHT) self.write('Go to: ') sentence = input() finally: if self.colors: self.write(colorama.Style.RESET_ALL) self.write('\n') self.prompt() try: more_sentences = self.go_to(int(sentence)) except ValueError: pass elif key in Presenter.KEY_SHELL: self.interact() elif key in Presenter.KEY_EXIT: break self.end() finally: if self.colors: self.write(colorama.Style.RESET_ALL)
def game_start(): quit = False sleep_time = 1 / 60 map1.updata() map1.draw_need_camera(camera) player1.draw_need_camera(camera) game_draw_information(0) while quit == False: ch = ord(console.getch()) # game_clear(); console.clear_buffer() if ch == 27: # ESC quit = True if ch == ord('a') or ch == 75 or ch == 260: player1.walk(PersonWay.LEFT, map1) elif ch == ord('d') or ch == 77 or ch == 261: player1.walk(PersonWay.RIGHT, map1) elif ch == ord('w') or ch == 72 or ch == 259: player1.walk(PersonWay.UP, map1) elif ch == ord('s') or ch == 80 or ch == 258: player1.walk(PersonWay.DOWN, map1) camera.look_x = player1.x camera.look_y = player1.y map1.draw_in_buffer_need_camera(camera) player1.draw_in_buffer_need_camera(camera) game_draw_information(ch) map1.draw_tile_information(player1.x, player1.y) console.refresh() time.sleep(sleep_time) pass game_exit()
sock.connect((address, port)) print('connected to ', address) sendPWM(sock, PWMlow) #except: # print('error on ', address) sockets.append(sock) on.append(False) # 'on' list contains the opposite of the bool we send to SocketThread, so call SocketThread first and then flip def toggleFade(index): SocketThread(sockets[index], addresses[index], on[index]) on[index] = not on[index] print('Type 1, 2, or 3 to fade a light up or down:') while True: c = getch() print(c) if c == '\x1b': sys.exit() if c == '1': toggleFade(0) if c == '2': toggleFade(1) if c == '3': toggleFade(2) #while not gShouldExit: # time.sleep(.2) # i = random.randint(0, len(sockets)-1) # #for i in range(0, len(sockets)): # try: # sockets[i].send('r' + str(i)) # except socket.error: # print 'error writing to socket' # and recreate connection periodically
kwargs={ "id": process_id, "interval": args.interval, "port": int(port), "queue": queue, }, ) process.start() procs.append((process_id, process, queue)) status = ["Server {}: Status Alive".format(i) for i, _, _ in procs] display = mp.Process(target=display_info) display.start() while True: try: x = int(getch()) for index, (process_id, process, queue) in enumerate(procs): if process_id == x: _has = True queue.put_nowait( "Server {}: Status DEAD".format(process_id)) process.terminate() process.join() procs.remove(procs[index]) if len(procs) == 0: display.terminate() display.join() quit() except ValueError as e: con.error("Invalid value provided\nDescription: {}".format(e))
shouldStop = False try: print(line) readings = literal_eval(line) print(readings) if outOfRangeFloor(readings[0]) or outOfRangeFloor(readings[1]): shouldStop = True if outOfRangeFront(readings[2]) or outOfRangeFront(readings[3]): shouldStop = True except SyntaxError: print('error interpreting sensor output as a dict') if shouldStop: print('STOP!') ucMotor.write(b' ') ucSensors = UltrasonicSensor('/dev/ttyACM0', 38400) ucMotor = SerialThread('/dev/ttyACM1', 38400) while True: c = getch() if c == 'q' or c == 'Q': ucSensors.exit() ucMotor.exit() break elif c == '=' or c == '+': ucMotor.write(b'LR') elif c == '-': ucMotor.write(b'lr') elif c == ' ': ucMotor.write(b' ') # immediate stop