当前位置: 首页>>代码示例>>Python>>正文


Python click.getchar方法代码示例

本文整理汇总了Python中click.getchar方法的典型用法代码示例。如果您正苦于以下问题:Python click.getchar方法的具体用法?Python click.getchar怎么用?Python click.getchar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在click的用法示例。


在下文中一共展示了click.getchar方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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) 
开发者ID:msanders,项目名称:cider,代码行数:27,代码来源:_cli.py

示例2: act

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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 
开发者ID:MultiAgentLearning,项目名称:playground,代码行数:20,代码来源:player_agent_blocking.py

示例3: prompt_overwrite

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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 
开发者ID:vividvilla,项目名称:csvtotable,代码行数:19,代码来源:cli.py

示例4: run

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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 
开发者ID:purdue-biorobotics,项目名称:flappy,代码行数:10,代码来源:simulation_maneuver.py

示例5: draw_with_ri

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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 
开发者ID:purdue-biorobotics,项目名称:flappy,代码行数:42,代码来源:simulation.py

示例6: ask

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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" 
开发者ID:cuducos,项目名称:alchemydumps,代码行数:8,代码来源:confirm.py

示例7: view

# 需要导入模块: import click [as 别名]
# 或者: from click import getchar [as 别名]
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 
开发者ID:qiime2,项目名称:q2cli,代码行数:61,代码来源:tools.py


注:本文中的click.getchar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。