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


Python cli.Cli类代码示例

本文整理汇总了Python中cjh.cli.Cli的典型用法代码示例。如果您正苦于以下问题:Python Cli类的具体用法?Python Cli怎么用?Python Cli使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: main

def main():
    """
    Main function
    """
    record = GameRecord(ARGS.filename)

    game_list = record[:]
    game_label_list = [game.label for game in game_list]

    while True:
        int_response = Cli.list_menu(Enumeration(game_label_list))
        move_list = game_list[int_response - 1][:]
        print Enumeration(move_list)

        goban = Goban(game_list[int_response - 1].header_dict['SZ'])

        color = 'black'
        for move in move_list:
            Cli.wait()
            Cli.clear()
            print goban
            goban.place_stone(move.address[0], move.address[1], color)

            if color == 'black':
                color = 'white'
            elif color == 'white':
                color = 'black'
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:27,代码来源:sgf_read.py

示例2: main

def main():
    """
    This particular file shows a point oscillating left and right along
    the x-axis.
    """
    goban = Goban(size=SIZE_, sh_obj=Cli(), adjust_ssize=-8)
    current_frame_no = 0

    while True:
        for i in range(-(goban.max_domain), goban.max_domain + 1,
            int(round(D_INTERVAL))):
            goban.fill('empty')
            goban.plot_point(i, 0, 'white')
            current_frame_no += 1
            Cli.print_header('+f{}'.format(current_frame_no))
            print((str(goban).rstrip()))  # pylint: disable=C0325
            time.sleep(T_INTERVAL)

        for i in range(-(goban.max_domain - 1), (goban.max_domain),
            int(round(D_INTERVAL))):
            goban.fill('empty')
            goban.plot_point(-i, 0, 'black')
            current_frame_no += 1
            Cli.print_header('+f{}'.format(current_frame_no))
            print((str(goban).rstrip()))  # pylint: disable=C0325
            time.sleep(T_INTERVAL)
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:26,代码来源:bounce_demo.py

示例3: main

def main():
    """
    Reads in a specified file, removes trailing whitespace, and re-saves.
    """
    # Open file and store lines as str list
    try:
        file_handler = open(ARGS.filename, 'r+')
    except IOError:
        print(traceback.format_exc())  # pylint: disable=C0325
        sys.exit()

    lines_of_text = file_handler.readlines()
    file_handler.seek(0)

    # Preview and write text back to file and close file
    print(lines_of_text)  # pylint: disable=C0325
    Cli.wait()
    string = ''
    preview_string = ''
    for index, _ in enumerate(lines_of_text):
        string += lines_of_text[index].rstrip() + '\n'
        preview_string = string.strip() + Cli.term_fx('b', 'EOL')
    pydoc.pipepager(preview_string, cmd='less -R')
    try:
        char = Cli.get_keypress('Write to file?')
        assert char == 'y'
        file_handler.write(string)
    except AssertionError:
        print('File not saved.  Good bye.')  # pylint: disable=C0325
    finally:
        file_handler.close()
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:31,代码来源:trimline.py

示例4: work_with_p_files

def work_with_p_files(cartesian):
    """
    Writes instance to pickle file or loads instance from pickle file.
    """
    #global file_list, pickle_list

    if ARGS and ARGS.infile:
        infile = ARGS.infile
    else:
        infile = 'save.p'

    current_dir = os.getcwd()
    file_list = os.listdir(current_dir)
    filemenu_list = ['..', 'save as pickle', 'open a pickle file']

    if infile in file_list:
        filemenu_list.append("reopen '" + infile + "'")
    menu1 = PlainList(filemenu_list)
    #pickle_list = []
    sel1 = Cli.make_page('pickle', cartesian, lambda: SHELL.list_menu(menu1))
    if sel1 == 2:
        cartesian.save_p_file(BASENAME)
    elif sel1 != 1:
        cartesian = Cli.open_p_file()
    return cartesian
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:25,代码来源:gocalc.py

示例5: main

def main():
    """
    Takes  a space-delimited int list (e.g., '1 2 3 4 5 6 7 8 9 10 11
    12') as input; generates and ouputs an ASCII diagram.

    * It might be good to define more functions.
    """
#    SHELL.welcome('Draw Tonerow', 'draw a diagram of a 12-tone row')
    in_str = Cli().input(prompt='')
    str_list = in_str.split()
    int_list = [int(s) for s in str_list]
    out_str = '\n'
    out_str += '\n ' + str(int_list)
    out_str += '\n' + '=' * 41 + '\n'
    out_str += '\n'

    for row in range(12):
        str_row = ' {:>2} '.format(12 - row)

        for index in range(12):
            if int_list[index] == 12 - row:
                str_row += '[X]'
            else:
                str_row += '. .'

        out_str += str_row + '\n'

    out_str += '\n'
    SHELL.output(out_str)
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:29,代码来源:draw_row.py

示例6: play_thru

 def play_thru(self, autoplay=False):
     goban = Goban(int(self.header_dict['SZ'])) #, skinfile=self.skin)
     color = 'black'
     for _, turn in enumerate(self.moves):
         goban.place_stone(turn[0], int(turn[1:]), color)
         if autoplay:
             func = lambda: time.sleep(.25)
         else: func = Cli.wait
         Cli.make_page(self.label, str(goban), func)
         if color == 'white':
             color = 'black'
         elif color == 'black':
             color = 'white'
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:13,代码来源:igo.py

示例7: main

def main():
    """
    Print welcome message then get pizza size and price and output area
    and unit price.
    """
    Cli.print_header()
    print_welcome()

    while True:
        diameter = set_diameter(ABBREV)
        pizza = make_circle(diameter)
        pizza = _set_area_units(pizza)
        price = set_price()
        output_results(pizza, price)
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:14,代码来源:pizza.py

示例8: main

def main():
    """
    Produce output and print to pager.
    """
    dummy = TextGen()
    print('')  # pylint: disable=C0325
    text_str = ''
    for _ in range(PARAS):
        pgraph = Paragraph(dummy.chunk(), int(Cli.width() * 0.6), True)
        pgraph.set_lmargin(Cli.width() // 5)
        text_str += str(pgraph)
    if PAGER is True:
        Cli.less(text_str)
    else:
        print(text_str)  # pylint: disable=C0325
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:15,代码来源:spit.py

示例9: main

def main():
    """
    In a text environment, roll one die with or without animation,
    according to command-line flags.  In Tk, run the main loop.
    """
    if SHELL.interface == 'Tk':
        SHELL.main_window.mainloop()
    else:
        while True:
            if SHELL_NAME in ['bash', 'sh']:
                if ARGS is not None and ARGS.anim:
                    die.animate()
                else: roll_and_output()
            Cli.wait()
            Cli.clear(9)
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:15,代码来源:dice.py

示例10: __init__

    def __init__(self, sgf_str='', skin='unicode1.json'):

        # Parent constructor
        super(GoGame, self).__init__()

        # Declare a new dictionary
        self.header_dict = {}

        # If an sgf string is given...
        if len(sgf_str) > 0:

            # Split it up into units
            self.units = sgf_str.split(';')

            # Get the header string
            self.units = self.units[1:]
            self.header_str = self.units[0]

            # Get the list of moves and 
            self.moves = self.units[1:]

            # Strip off any whitespace
            self.moves = [move.strip() for move in self.moves]

            # Convert the header information to a dictionary
            self.head_list = self.header_str.split(']')[:-1]
            for unit in self.head_list:
                l = unit.split('[')
                l = [i.strip() for i in l]
                self.header_dict.update({l[0]:l[1]})

            self.size = eval(self.header_dict['SZ']) #there is a better way i think

            # Convert the sgf representations to Turn objects
            for i, v in enumerate(self.moves):
                if self.moves[i][0] == 'B': colour = 'black'
                elif self.moves[i][0] == 'W': colour = 'white'
                address = (self.moves[i][2].upper(), self.size - (ord(self.moves[i][3]) - 97))
                self.moves[i] = Turn(colour, address, self.moves[i][5:])



        else:

            # If this is a new game, there will be no header.  So let's make one.
            black_player = Cli.input("Black player's name: ")
            white_player = Cli.input("White player's name: ")
            self.header_dict.update({'SZ': 19, 'PW': white_player, 'PB': black_player, 'KM': 6.5, 'GM':1})
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:48,代码来源:igo.py

示例11: main

def main():
    """Launch an interface, i.e., main loop."""
    if SHELL.interface == 'Tk':
        SHELL.main_window.mainloop()
    else:
        while True:
            f = lambda: SHELL.list_menu(MENU_OPTS)
            action = Cli.make_page(func=f)
            if action == 1:
                scriptname = choose_file(SCRIPT_LIST)
                MENU_OPTS.items[0] = scriptname
            elif action == 2:
                shell_name = select_shell(SHELL_LIST)
                MENU_OPTS.items[1] = shell_name
            elif action == 3:
                pass
            elif action == 4:
                try:
                    run_script(scriptname, shell_name)
                except KeyboardInterrupt:
                    continue
            elif action == 5:
                open_in_editor(scriptname)
            elif action == 6:
                sys.exit(0)
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:25,代码来源:run2.py

示例12: access_gnugo_functs

    def access_gnugo_functs(self, basename):
        """
        Scoring/estimating tools from gnugo; this should take filename instead.
        """
        Cli.make_page(
            'WRITE FILE: {}.sgf'.format(basename), self, lambda: self.write_sgf(
            basename))

        menu1 = ListPrompt(['..', 'fast', 'medium', 'slow'])
        sel1 = Cli.make_page('MENU: GNUGO Scoring Tools', self, menu1.input)
        gnugo_dict = {'fast':'estimate', 'medium':'finish', 'slow':'aftermath'}
        print('') #pylint: disable=C0325
        if sel1 != 1:
            os.system('gnugo --score ' + gnugo_dict[menu1.items[sel1 - 1]] +\
                      ' --quiet -l {}.sgf'.format(basename))
            Cli.wait()
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:16,代码来源:igo.py

示例13: fill

def fill():
    """
    Call the graphs fill() method and refresh the text of the message
    widget.
    """
    graph.fill(graph.color_chooser())
    SHELL.msgtxt.set(Cli.ul(graph.label.title(), width=SIZE*2+6) + str(graph))
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:7,代码来源:gocalc_tk.py

示例14: load_p_file

 def load_p_file():
     """load pickle file with Tk"""
     global graph
     graph = SHELL.open_p_file()
     SHELL.msgtxt.set(
         Cli.ul(graph.label.title(), width=SIZE*2+6) + str(graph))
     graph.sh_obj = SHELL
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:7,代码来源:gocalc_tk.py

示例15: file_actions

def file_actions(cartesian):
    """
    work with files: open or save
    """
    sel1 = Cli.make_page(
        'MENU: File Actions', cartesian, lambda: SHELL.list_menu(FILE_OPTS))
    if sel1 == 2:
        cartesian.write_txt(BASENAME)
    elif sel1 == 3:
        cartesian.write_sgf(BASENAME)
    elif sel1 == 4:
        cartesian.save_p_file(BASENAME)
    elif sel1 == 5:
        cartesian = Cli.open_p_file()  # A = A.__class__.open_p_file()
    elif sel1 == 6:
        cartesian = work_with_p_files(cartesian)
    return cartesian
开发者ID:hammerhorn,项目名称:hammerhorn-jive,代码行数:17,代码来源:gocalc.py


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