Example #1
0
def main():
    """
    user can create a collection of Thing objects
    """
    things = []
    label_pile = [str(thing) for thing in things]
    enum = Enumeration(label_pile, 'Inventory')

    # Start Screen
    SHELL.welcome(
        'Things',
        'This is a test/demonstration of my cjh.shell module and Thing class.')
    print('')  # pylint: disable=C0325
    selection = SHELL.list_menu(MAIN_MENU)

    while True:
        if selection == 1:
            name = form(
                enum, selection, lambda: SHELL.input('\nName of thing: '))
            something = Thing()
            something.label = name
            things.append(something)
        elif selection == 2:
            form(enum, selection, Cli.wait)
        elif selection == 3:
            discard_menu = ListPrompt(label_pile)
            if len(things) > 0:
                print('Choose a <Thing> to Discard.')  # pylint: disable=C0325
                discard = form(
                    enum, selection, lambda: discard_menu.input(hidden=True))
                things.remove(things[discard - 1])
        elif selection == 4:
            print('\n')  # pylint: disable=C0325
            sys.exit('Good bye.')

        label_pile = [str(thing) for thing in things]
        enum = Enumeration(label_pile, 'Inventory')
        selection = Cli.make_page(
            header='Main Menu', obj=str(enum) + Cli.hrule(
            width=.333, string=True),
            func=lambda: SHELL.list_menu(MAIN_MENU))
Example #2
0
else: ARGS = None

# If ARGS.width is an integer, convert it to be of type int.
# An int for this value means width in columns.
# A decimal < 1 means a percentage of the width of the terminal.
if ARGS is not None and ARGS.width is not None and\
    (ARGS.width == int(ARGS.width)):
    ARGS.width = int(ARGS.width)

# possible to this automatically?
def populate_args():
    """
    Convert args namespace to a dictionary, for use in the Cli.hrule()
    method.
    """
    kw_dict = {}
    if ARGS is not None:
        if ARGS.width is not None:
            kw_dict.update({'width': ARGS.width})
        if ARGS.pattern is not None:
            kw_dict.update({'symbols': ARGS.pattern})
        if ARGS.center is True:
            kw_dict.update({'centered': ARGS.center})
    return kw_dict

# print arg_dic
ARG_DICT = populate_args()

if __name__ == '__main__':
    Cli.hrule(**ARG_DICT)
Example #3
0
    def __repr__(self):
        string = ''
        try:
            if self.header_dict['GM'] == '1': 
                string += 'Game: Go\n'
            elif self.header_dict['GM'] == '2':
                string += 'Game: Reversi\n'
        except:pass

        try:
            string += "Size: {} x {}\n".format(self.header_dict['SZ'])
        except:pass

        try:
            string += "{} vs. {}\n".format(self.header_dict['PW'], self.header_dict['PB'])
        except:pass

        try:
            string += "Komi: {}\n".format(self.header_dict['KM'])
        except: pass

        try:
            for game, index in enumerate(self.game_list):
                self.game_list[index].header = str(game[1]) + "\n"
        except: # type?
            pass



        ### This block doesn't work ###
        bullet_items = []
        try:
            bullet_items.append("SGF generated by {}.".format(self.header['AP']))
        except:pass
        if 'DT' in self.header:
            bullet_items.append(self.header['DT'])
        #if "GM" in self.header:
        #    game = ''
        #    if self.header['GM'] == '1':
        #        game = 'go'
        #    else: game = 'unknown'
        #    s += ["The game is {}.".format(game)]
        if 'RU' in self.header:
            bullet_items += ["{} rules.".format(self.header['RU'])]
        if 'SZ' in self.header:
            bullet_items += ["The board size is {0} × {0}.".format(self.header['SZ'])]
        if 'KM' in self.header:
            bullet_items += ["Komi is {}.".format(self.header['KM'])]
        if 'PB' in self.header:
            bullet_items += ["Black Player: {}".format(self.header['PB'])]
        if 'PW' in self.header:
            bullet_items += ["White Player: {}".format(self.header['PW'])]
        self.bullets = ItemList(bullet_items)
        ###############################


        moves_enum = Enumeration(self.moves)
        return ('\n' + Cli.term_fx('u', self.label.title()) + #self.ul_label() + 
                string + #'\n\nself.bullets: ' + str(self.bullets) + 
                '\nmoves_enum: ' + str(moves_enum) +
                '\n' + Cli.hrule(string=True, width=40))