Python click.getchar() Examples
The following are 9
code examples of click.getchar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click
, or try the search function
.
Example #1
Source File: player_agent_blocking.py From playground with Apache License 2.0 | 6 votes |
def act(self, obs, action_space): key = click.getchar() if self.agent_control == 'arrows': if key == K_RT + K_PREFIX: return constants.Action.Right.value if key == K_LF + K_PREFIX: return constants.Action.Left.value if key == K_UP + K_PREFIX: return constants.Action.Up.value if key == K_DN + K_PREFIX: return constants.Action.Down.value if key == ' ': return constants.Action.Bomb.value return constants.Action.Stop.value if self.agent_control == 'wasd': if key == 'd': return constants.Action.Right.value if key == 'a': return constants.Action.Left.value if key == 'w': return constants.Action.Up.value if key == 's': return constants.Action.Down.value if key == 'e': return constants.Action.Bomb.value if key == 'q': return constants.Action.Stop.value return constants.Action.Stop.value
Example #2
Source File: cli.py From csvtotable with MIT License | 6 votes |
def prompt_overwrite(file_name): # Skip if file doesn't exist if not os.path.exists(file_name): return True # Prompt for file overwrite if outfile already exists fmt = "File ({}) already exists. Do you want to overwrite? (y/n): " message = fmt.format(file_name) click.secho(message, nl=False, fg="red") choice = click.getchar() click.echo() if choice not in ("y", "Y"): return False return True
Example #3
Source File: simulation_maneuver.py From flappy with MIT License | 5 votes |
def run(self): print("Key listening thread started") # print('Starting ' + self.name) while True: self.last_key_press = click.getchar() if self.last_key_press == 'q': print("Key listening thread terminated") break
Example #4
Source File: simulation.py From flappy with MIT License | 5 votes |
def draw_with_ri(self, ri): ri.set_color(0, 0, 0) ri.draw_text([20, 40], "time = %.4fs" % self.t) ri.set_color(0, 0, 0) ri.draw_text([20, 80], "frame = %d" % self.frame) R = self.skeletons[0].bodynode('torso').world_transform() ri.draw_text([20, 100], "roll = %.4f" % (np.arctan2(R[2,1],R[2,2])/np.pi*180)) ri.draw_text([20, 120], "pitch = %.4f" % (np.arcsin(-R[2,0])/np.pi*180)) ri.draw_text([20, 140], "yaw = %.4f" % (np.arctan2(R[1,0],R[0,0])/np.pi*180)) ri.draw_text([20, 160], "p = %.4f" % (self.skeletons[0].bodynode('torso').com_spatial_velocity()[0]/np.pi*180)) ri.draw_text([20, 180], "q = %.4f" % (self.skeletons[0].bodynode('torso').com_spatial_velocity()[1]/np.pi*180)) ri.draw_text([20, 200], "r = %.4f" % (self.skeletons[0].bodynode('torso').com_spatial_velocity()[2]/np.pi*180)) ri.draw_text([20, 220], "x = %.4f" % self.skeletons[0].positions()[self.skeletons[0].dof('torso_to_world_pos_x').id]) ri.draw_text([20, 240], "y = %.4f" % self.skeletons[0].positions()[self.skeletons[0].dof('torso_to_world_pos_y').id]) ri.draw_text([20, 260], "z = %.4f" % self.skeletons[0].positions()[self.skeletons[0].dof('torso_to_world_pos_z').id]) # visulize force not working # pl0 = self.skeletons[1].bodynode('left_wing').C # pl1 = pl0 + 0.01 * np.array([1,0,0]) # ri.set_color(1.0, 0.0, 0.0) # ri.render_arrow(pl0, pl1, r_base=0.05, head_width=0.1, head_len=0.1) # keyboard input thread # class KeyListener(threading.Thread): # def __init__(self,threadID,name,counter): # threading.Thread.__init__(self) # self.threadID = threadID # self.name = name # self.counter = counter # self.last_key_press = None # self.new_key_pressed = False # def run(self): # print("Key listening thread started") # # print('Starting ' + self.name) # while True: # self.last_key_press = click.getchar() # if self.last_key_press == 'q': # print("Key listening thread terminated") # break
Example #5
Source File: simulation_maneuver.py From flappy with MIT License | 5 votes |
def run(self): print("Key listening thread started") # print('Starting ' + self.name) while True: self.last_key_press = click.getchar() if self.last_key_press == 'q': print("Key listening thread terminated") break
Example #6
Source File: simulation.py From flappy with MIT License | 5 votes |
def run(self): print("Key listening thread started") # print('Starting ' + self.name) while True: self.last_key_press = click.getchar() if self.last_key_press == 'q': print("Key listening thread terminated") break
Example #7
Source File: _cli.py From cider with MIT License | 5 votes |
def main(): try: cli.main(standalone_mode=False) except CalledProcessError as e: tty.puterr("`{0}` failed with code {1}".format( " ".join(e.cmd), e.returncode )) except ParserError as e: tty.puterr("Error reading {0} at {1}: {2}".format( e.filetype, e.filepath, e )) except BrewMissingError as e: print("Next, install Homebrew (press any key to redirect)") click.getchar() urlopen(e.url) sys.exit(1) except (CiderException, click.ClickException) as e: tty.puterr(e, prefix="Error:") sys.exit(e.exit_code) except click.Abort: sys.stderr.write("Aborted!\n") sys.exit(1)
Example #8
Source File: confirm.py From alchemydumps with MIT License | 5 votes |
def ask(self): if self.assume_yes: return True click.echo('\n==> Press "Y" to confirm, or anything else to abort: ') return click.getchar().lower() == "y"
Example #9
Source File: tools.py From q2cli with BSD 3-Clause "New" or "Revised" License | 4 votes |
def view(visualization_path, index_extension): # Guard headless envs from having to import anything large import sys from q2cli.core.config import CONFIG if not os.getenv("DISPLAY") and sys.platform != "darwin": raise click.UsageError( 'Visualization viewing is currently not supported in headless ' 'environments. You can view Visualizations (and Artifacts) at ' 'https://view.qiime2.org, or move the Visualization to an ' 'environment with a display and view it with `qiime tools view`.') import zipfile import qiime2.sdk if index_extension.startswith('.'): index_extension = index_extension[1:] try: visualization = qiime2.sdk.Visualization.load(visualization_path) # TODO: currently a KeyError is raised if a zipped file that is not a # QIIME 2 result is passed. This should be handled better by the framework. except (zipfile.BadZipFile, KeyError, TypeError): raise click.BadParameter( '%s is not a QIIME 2 Visualization. Only QIIME 2 Visualizations ' 'can be viewed.' % visualization_path) index_paths = visualization.get_index_paths(relative=False) if index_extension not in index_paths: raise click.BadParameter( 'No index %s file is present in the archive. Available index ' 'extensions are: %s' % (index_extension, ', '.join(index_paths.keys()))) else: index_path = index_paths[index_extension] launch_status = click.launch(index_path) if launch_status != 0: click.echo(CONFIG.cfg_style('error', 'Viewing visualization ' 'failed while attempting to open ' f'{index_path}'), err=True) else: while True: click.echo( "Press the 'q' key, Control-C, or Control-D to quit. This " "view may no longer be accessible or work correctly after " "quitting.", nl=False) # There is currently a bug in click.getchar where translation # of Control-C and Control-D into KeyboardInterrupt and # EOFError (respectively) does not work on Python 3. The code # here should continue to work as expected when the bug is # fixed in Click. # # https://github.com/pallets/click/issues/583 try: char = click.getchar() click.echo() if char in {'q', '\x03', '\x04'}: break except (KeyboardInterrupt, EOFError): break