Exemplo n.º 1
0
    def perform(self, objects, *args, **kwargs):
        if self.check_objects_size(objects) is False:
            return

        input_function = get_input_function()

        while True:
            try:
                filename = input_function('Input filename to save data: ')
                filename = SAVE_PATH + "/" + filename + SAVE_EXTENSION

                if not os.path.exists(SAVE_PATH):
                    os.makedirs(SAVE_PATH)

                if os.path.isfile(filename):
                    while True:
                        print('File ', filename, 'already exist!')
                        answer = input_function('Rewrite (y/n)?')
                        if answer == "y":
                            break
                        if answer == "n":
                            return

                with open(filename, 'w') as outfile:
                    pickle.dump(objects, outfile, pickle.HIGHEST_PROTOCOL)
                break
            except IOError:
                print('Can\'t create such file!')

        print('All information was successfull dumped into', filename)
Exemplo n.º 2
0
    def perform(self, objects, *args, **kwargs):
        classes = self._load_item_classes()

        print('Select item type:')
        for index, name in enumerate(classes.keys()):
            print('{}: {}'.format(index, name))

        input_function = get_input_function()
        selection = None
        selected_key = None

        def give_me_num():
            selection = int(input_function('Input number: '))
            selected_key = list(classes.keys())[selection]
            return selected_key

        selected_key = self.user_input_secure_wrap(give_me_num)

        selected_class = classes[selected_key]
        print('Selected: {}'.format(selected_class.__name__))
        print()

        new_object = selected_class.construct()

        objects.append(new_object)
        print('Added {}'.format(str(new_object)))
        print()
        return new_object
Exemplo n.º 3
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()
        selection = None
        selected_key = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_key = list(objects)[selection]

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_key.done = '+'

        #print(selected_class = objects[selected_key])
        #print('Selected: {}'.format(selected_class.__name__))
        print()
Exemplo n.º 4
0
    def perform(self, objects, *args, **kwargs):
        classes = self._load_item_classes()

        print('Select item type:')
        for index, name in enumerate(classes.keys()):
            print('{}: {}'.format(index, name))

        input_function = get_input_function()
        selection = None
        selected_key = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_key = list(classes.keys())[selection]

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_class = classes[selected_key]
        print('Selected: {}'.format(selected_class.__name__))
        print()

        new_object = selected_class.construct()

        objects.append(new_object)
        print('Added {}'.format(str(new_object)))
        print()
        return new_object
Exemplo n.º 5
0
    def construct(cls):
        input_function = get_input_function()
        heading = input_function('Input heading: ')
        due_date = input_function('Input Due_date: ')
        url = input_function('Input url: ')

        return ToReadItem(heading, due_date, url)
Exemplo n.º 6
0
    def perform(self, objects, *args, **kwargs):
        classes = self._load_item_classes()

        print('Select item type:')
        for index, name in enumerate(classes.keys()):
            print('{}: {}'.format(index, name))

        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                break
            except ValueError:
                print('Bad input, try again.')

        selected_key = list(classes.keys())[selection]
        selected_class = classes[selected_key]
        print('Selected: {}'.format(selected_class.__name__))
        print()

        new_object = selected_class.construct()

        objects.append(new_object)
        print('Added {}'.format(str(new_object)))
        print()
        return new_object
Exemplo n.º 7
0
    def perform(self, objects, *args, **kwargs):
        classes = self._load_item_classes()

        print('Select item:')
        for index, name in enumerate(objects):
            print('{}: {}'.format(index, name))

        input_function = get_input_function()
        selection = None
        selected_key = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_key = objects[selection]
                print(selected_key)
                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_key.done = False
        print('Undone {}'.format(str(selected_key)))
        print()
        return selected_key
Exemplo n.º 8
0
 def perform(self, objects, *args, **kwargs):
     ListCommand().perform(objects)
     input_func = get_input_function()
     select = input_func('select item id ')
     objects[int(select)].status = False
     # select.status = 'done'
     print('done')
Exemplo n.º 9
0
    def perform(self, objects, *args, **kwargs):
        done = kwargs['done']
        label = kwargs['label']

        valid_items = [item for item in objects if item.done is not done]

        if len(valid_items) == 0:
            print('Nothing to {}!'.format(label))
        else:
            print('Select item to {}:'.format(label))

        for index, item in enumerate(valid_items):
            print('{}: {}'.format(index, item))

        input_function = get_input_function()
        selection = None
        selected_object = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_object = valid_items[selection]
                break
            except (ValueError, IndexError):
                print('Bad input, try again.')

        selected_object.done = done

        print('You {} {}'.format(label, str(selected_object)))
        print()
Exemplo n.º 10
0
    def perform(self, objects, *args, **kwargs):

        objects_list = [obj for obj in objects if obj.done == True]

        if len(objects_list) == 0:
            print('There are no done items.')
            return
        else:
            for index, obj in enumerate(objects_list):
                if obj.done == True:
                    print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(
                    input_function('Input number to mark undone: '))
                selected_key = objects_list[selection]
                selected_key.done = False
                print(selected_key)
                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Are you a blind?')
Exemplo n.º 11
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return
        tasks = {}
        for index, obj in enumerate(objects):
            tasks[index] = obj
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_key = list(tasks.keys())[selection]

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_task = tasks[selected_key]
        self.change_status(selected_task)
        self.print_result(selected_task)
Exemplo n.º 12
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        print('Select type of sorting:')
        print('0 - by task type')
        print('1 - by execution status')
        
        input_function = get_input_function()
        selection = None
        while True:
            try:
                selection = int(input_function('Input sort type: '))
                if selection not in [0,1]:
                    raise ValueError
                break
            except ValueError:
                print('Bad input, try again.')

        if selection == 0:
            objects.sort(key = lambda x: type(x))
        elif selection == 1:
            objects.sort(key = lambda x: x.done)

        
        print('List is sorted')
        print()
Exemplo n.º 13
0
    def perform(self, objects, *args, **kwargs):
        sortD = {'first unfinished then finished':0, 'sort by type':1}

        if len(objects) == 0:
            print('There are no items in storage.')
            return
        else:
            print('Select sort type:')
        for index, name in enumerate(sortD.keys()):
            print('{}: {}'.format(index, name))

        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                break
            except ValueError:
                print('Bad input, try again.')

        if selection == 0:
            objects.sort(key=lambda z: z.done)
            for index, obj in enumerate(objects):
                print('{}: {}'.format(index, str(obj)))
        elif selection == 1:
            objects.sort(key=lambda z: z.__class__.__name__)
            for index, obj in enumerate(objects):
                print('{}: {}'.format(index, str(obj)))
        else:
            print('Bad input, try again.')
Exemplo n.º 14
0
    def perform(self, objects, doundo, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        print('Select task for mark:')
        input_function = get_input_function()
        selection = None
        selected_key = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                storage_item = objects[selection]
                storage_item.done = bool(doundo)
                a = ListCommand()
                a.perform(objects)
                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')
Exemplo n.º 15
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('- | {}: {}'.format(index, str(obj)))

        input_function = get_input_function()
        selection = None
        selected_key = None
        classes = self._load_item_classes()

        while True:
            try:
                selection = int(input_function('Input item # to finish it: '))
                selected_key = objects[selection]

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_class = classes[selected_key]
        print('Finished: {}'.format(str(selected_class.__name__)))
        print()

        new_object = selected_class.construct()

        objects.append(new_object)
        print('Finished {}'.format(str(new_object)))
        print()
        return new_object
Exemplo n.º 16
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        input_function = get_input_function()
        sorting = None

        while True:
            try:
                sorting = int(
                    input_function('Select criteria of sorting:\n\
1 - by status\n\
2 - by type\n'))
                break
            except ValueError:
                print('Bad input, try again.')

        if sorting == 1:
            objects.sort(key=lambda x: x.status)
        elif sorting == 2:
            objects.sort()

        print('Result of sorting:')
        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))
Exemplo n.º 17
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        print('Select item:')
        
        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input item number: '))
                break
            except ValueError:
                print('Bad input, try again.')

        if objects[selection].done == ' ':
           objects[selection].done = ' + '
           print('Item #{} is checked as done'.format(selection))
        else:
            objects[selection].done = ' '
            print('Item #{} is checked as undone'.format(selection))
       
            
        print()
Exemplo n.º 18
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        input_function = get_input_function()
        sorting = None

        while True:
            try:
                sorting = int(input_function('Select criteria of sorting:\n\
1 - by status\n\
2 - by type\n'))
                break
            except ValueError:
                print('Bad input, try again.')

        if sorting == 1:
            objects.sort(key=lambda x: x.status)
        elif sorting == 2:
            objects.sort()

        print('Result of sorting:')
        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))
Exemplo n.º 19
0
    def construct(cls):
        input_function = get_input_function()
        input_function_num = get_input_function_num()

        def get_heading():
            while True:
                try:
                    heading = input_function('Item name: ')
                    break
                except UserInputTextException:
                    print('Error. Enter correct name!')
            return heading

        def get_price():
            while True:
                try:
                    price = input_function_num('Item price: ')
                    break
                except UserInputNumException:
                    print('Error. Enter number!')
            return price

        heading = get_heading()
        price = get_price()

        return ToBuyItem(heading, price)
Exemplo n.º 20
0
    def perform(self, objects, *args, **kwargs):
        obj_done = [obj for obj in objects if obj.done is True]
        if len(obj_done) == 0:
            print('No items in undone list.')
            return
        i = []
        print('Select number do set Done:\n')
        for index, obj in enumerate(obj_done):
            print('{}: {}'.format(index, str(obj)))
            i += [index]

        input_function = get_input_function()
        selector = None

        # while True:
        try:
            selector = int(input_function('number:'))
            if selector in i:
                # selector = int(input_function('number:'))
                obj_done[selector].done = False
                # break
            else:
                print('not in list')
        except ValueError:
            print('Wrong value!')
Exemplo n.º 21
0
    def perform(self, objects, *args, **kwargs):

        ListCommand().perform(objects)

        if len(objects) == 0:
            return

        input_function = get_input_function()
        self.user_input_secure_wrap(self.remove_task, input_function, objects)
Exemplo n.º 22
0
def main():
    global input_function
    input_function = get_input_function()
    game = Game()

    while True:
        game.make_move()

    print("\n\n\nYou win!\n\n\n")
Exemplo n.º 23
0
         def perform(self, objects, *args, **kwargs):
             classes = self._load_user_classes()

             print('Select UserName:'******'{}'.format(name))

             input_function = get_input_function()
             selection = None
             return new_user
Exemplo n.º 24
0
 def perform(self, objects, *args, **kwargs):
     input_function = get_input_function()
     sort_methods = ['By complete', 'By title']
     for i, method in enumerate(sort_methods):
         print('{}: {}'.format(i, method))
     sort_method = input_function('Select Sorting method: ')
     if sort_method == '1':
         objects.sort(key=lambda x: str(x))
     elif sort_method == '0':
         objects.sort(key=lambda x: x.status)
Exemplo n.º 25
0
def parse_user_input():
    """
    Gets the user input.
    :return: `str` with the user input.
    """

    input_function = get_input_function()

    message = 'Input your command: (%s): ' % '|'.join(get_routes().keys())
    return input_function(message)
Exemplo n.º 26
0
 def choose_index():
     input_function = get_input_function()
     selection = None
     while True:
         try:
             selection = int(input_function('Input number: '))
             break
         except ValueError:
             print('Bad input, try again.')
     return selection
Exemplo n.º 27
0
    def perform(self, objects, *args, **kwargs):
        input_function = get_input_function()

        try:
            index = input_function('Input index to %s: ' %
                                   self.__class__.message)
            objects[int(index)].done = self.__class__.status_to_set
            print('%sed!' % self.__class__.message)
        except ValueError:
            print('Bad value!')
        except IndexError:
            print('Bad index!')
Exemplo n.º 28
0
    def perform(self, objects, *args, **kwargs):
        input_function = get_input_function()

        try:
            index = input_function('Input index to %s: ' %
                                   self.__class__.message)
            objects[int(index)].done = self.__class__.status_to_set
            print('%sed!' % self.__class__.message)
        except ValueError:
            print('Bad value!')
        except IndexError:
            print('Bad index!')
Exemplo n.º 29
0
        def perform(self, objects, *args, **kwargs):
            classes = self._load_field_classes()

            print('Select length:')
            for index, name in enumerate(classes.keys()):
                print('{}'.format(lengt))
            print('Select high:')
            for index, name in enumerate(classes.keys()):
                print('{}'.format(high))

            input_function = get_input_function()
            selection = None
            return new_field
Exemplo n.º 30
0
    def perform(self, objects, *args, **kwargs):
        classes = self._load_shot_classes()

        print('Select x:')
        for index, name in enumerate(classes.keys()):
            print('{}'.format(x))
        print('Select y:')
        for index, name in enumerate(classes.keys()):
            print('{}'.format(y))

        input_function = get_input_function()
        selection = None
        return new_shot
Exemplo n.º 31
0
    def loop_input(self, list_=False):
        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                if list_:
                    list_[selection]
                break
            except (ValueError, IndexError):
                print('Bad input, try again.')

        return selection
Exemplo n.º 32
0
    def perform(self, objects, *args, **kwargs):
        input_function = get_input_function()
        selection = None
        aaa = ListCommand("list")
        aaa.perform(objects)

        while True:
            try:
                selection = int(input_function('Input number: '))
                obj = objects[selection]
                sort_obj = obj.sort
                return sort_obj
            except ValueError:
                print('Bad input, try again.')
Exemplo n.º 33
0
    def construct(cls):
        input_function = get_input_function()

        def get_info(string):
            while True:
                try:
                    heading = input_function(string)
                    break
                except UserInputTextException:
                    print('Error. Enter correct info!')
            return heading

        heading = get_info('Item: ')
        return ToDoItem(heading)
Exemplo n.º 34
0
    def input_while_correct(self, message, type="ship"):
        input_function = get_input_function()

        while True:
            try:
                _input = input_function(message)
                self.check_coordinate_ethics(_input)
                _input = self.mutate_coordinates_to_digits(_input)
                if type == "ship":
                    self._check_coordinate_for_emptiness(_input)
                break
            except SyntaxError as msg:
                print(msg)

        return _input
Exemplo n.º 35
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        input_function = get_input_function()
        try:
            s = int(input_function('Sort by: \n1: Done\n2: Type\n'))
            if s in [1, 2]:
                objects.sort(key=lambda x: x.done if s == 1 else x.heading)
                print('Sorted!')
            else:
                raise IndexError
        except ValueError:
            print('Bad value')
        except IndexError:
            print('Bad index')
Exemplo n.º 36
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('Nothing to undone.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()
        while True:
            try:
                selection = int(input_function('input number: '))
                objects[selection].done = False
                break
            except IndexError:
                print('Bad input, try again.')
            except ValueError:
                print('Bad input, try again.')
Exemplo n.º 37
0
    def perform(self, objects, *args, **kwargs):
        super().perform(objects, *args, **kwargs)

        input_function = get_input_function()

        def give_me_num():
            index = int(input_function('Input number: '))
            item = objects[index]
            return item

        item = self.user_input_secure_wrap(give_me_num)

        if item.done != self.action:
            item.done = self.action
            print('"{}" is {}'.format(item.heading,
                                      'done' if self.action else 'undone'))
        else:
            print('"{}" {} done before'.format(item.heading,
                                               'was' if action else 'was not'))
Exemplo n.º 38
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('Nothing to be marked as done')
            return

        print('Select object to be marked as done')
        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                objects[selection].done = True
                break
            except ValueError:
                print('Bad input, try again.')
Exemplo n.º 39
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in the list to be undone!')
            return

        print('Select object to be marked as undone')
        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()

        while True:
            try:
                selection = int(input_function('Input number: '))
                objects[selection].done = False
                print ('Undone (--)')
                break
            except ValueError:
                print('Bad input, try again.')
Exemplo n.º 40
0
def main():
    """
    Main method, works infinitelly until exit command.
    Or hits `Ctrl+C` in the console.
    """

    try:
        clear_screen()

        school_log = SchoolLog()

        commands = {
            'show': show_marks,
            'add': add_mark,
            'exit': exit,
        }

        command_pattern = r'^(?P<command>\w+)\s(all|(?P<name>.*)\sfrom\s(?P<class_name>\w+))\s(marks|got\s(?P<mark>\w)\son\s(?P<lesson>.*)\slesson)$'

        while True:
            try:
                cmd = get_input_function()(
                    "Type command or 'exit' to close application: ")

                if cmd == 'exit':
                    commands[cmd]()

                match = re.match(command_pattern, cmd)
                command_values = match.groupdict()

                if not match or command_values['command'] not in commands:
                    print('Bad command!')
                    continue

                commands[command_values['command']](school_log,
                                                    **command_values)

            except (ValueError, IndexError):
                print('Bad input, try again.')

    except KeyboardInterrupt:
        school_log.save()
        print('\nGood bye!')
Exemplo n.º 41
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        input_function = get_input_function()
        selection = None
        print()
        print('Input task number to mark it as undone: ')
        print()
        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))
        while True:
            try:
                selection = int(input_function('Input task number: '))
                objects[selection].done = False
                break
            except IndexError:
                print('Bad item number, try again.')

        print(str(objects[selection]) + ': Task marked as undone')
Exemplo n.º 42
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        print('Select item')
        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                break
            except ValueError:
                print('Bad input, try again.')

        objects[selection].status = True
        return selection
Exemplo n.º 43
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        print('Select item:')
        for index, obj in enumerate(objects):
            print('{}: {} '.format(index, str(obj)))

        input_function = get_input_function()
        selection = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        objects[selection].done = False
Exemplo n.º 44
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()

        selection = None

        while True:
            try:
                selection = int(input_function('\nSelect Item to complete: '))
                break
            except ValueError:
                print('Bad input, try again.')

        objects[selection].status = self.com_status

        print('Change status {} to {} \n\
         '.format(str(objects[selection]), str(objects[selection].status)))
Exemplo n.º 45
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        input_function = get_input_function()

        selection = None

        while True:
            try:
                selection = int(input_function('\nSelect Item to complete: '))
                break
            except ValueError:
                print('Bad input, try again.')

        objects[selection].status = self.com_status

        print('Change status {} to {} \n\
         '.format(str(objects[selection]), str(objects[selection].status)))
Exemplo n.º 46
0
    def perform(self, objects, *args, **kwargs):
        input_function = get_input_function()

        if not os.path.exists(SAVE_PATH):
            print('There is load path!')
            return

        working_directory = os.getcwd()
        os.chdir(SAVE_PATH)

        saved_files = glob.glob("*" + SAVE_EXTENSION)
        print(saved_files)

        if len(saved_files) < 1:
            print('There is no files to load!')
            return

        while True:
            try:
                filename = input_function('Input filename to load data: ')
                if not os.path.isfile(filename):
                    raise SyntaxError
                with open(filename, 'rb') as infile:
                    loaded_objects = pickle.load(infile)
                break
            except SyntaxError:
                print('There is no such file!')

        for obj in loaded_objects:
            objects.append(obj)

        print('\nAll information was successfull loaded:')
        list_ = ListCommand("abc")
        list_.perform(objects)
        print()

        os.chdir(working_directory)
Exemplo n.º 47
0
    def perform(self, objects, *args, **kwargs):


        global index
        print('Select item type:')
        for index, obj in enumerate(objects):
            print('{}: {}  '.format(index, str(obj)) )

        input_function = get_input_function()
        selection = None
        selected_key = None

        while True:
            try:
                selection = int(input_function('Input number: '))
                selected_key = list(objects)[selection]

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')

        selected_class = objects[index]
        #print('Selected: {}'.format(selected_key))
        print()

        new_object = selected_key.construct()

        new_object1 = str(new_object) + " + "
        objects.clear()
        objects.append(new_object1)

        print('Added {}'.format(str(new_object1)))
        print()
        return new_object1
Exemplo n.º 48
0
    def perform(self, objects, *args, **kwargs):
        if len(objects) == 0:
            print('There are no items in storage.')
            return

        for index, obj in enumerate(objects):
            print('{}: {}'.format(index, str(obj)))

        while True:
            try:
                selection = int(get_input_function()('Input number: '))
                selection_record = objects[selection]
                if selection_record.done:
                    selection_record.done = False
                else:
                    print('This deal is undone!!!')
                    break
                print('{} is done!'.format(str(selection_record)))

                break
            except ValueError:
                print('Bad input, try again.')
            except IndexError:
                print('Wrong index, try again.')
Exemplo n.º 49
0
    def perform(self, objects, *args, **kwargs):

        ListCommand().perform(objects)

        input_function = get_input_function()
        self.user_input_secure_wrap(self.change_state, input_function, objects)
Exemplo n.º 50
0
 def construct(cls):
     input_function = get_input_function()
     heading = input_function('Input heading: ')
     url = input_function('Input URL: ')
     return ToReadItem(heading, url)
Exemplo n.º 51
0
 def construct(cls):
     input_function = get_input_function()
     heading = input_function('Input heading: ')
     return ToDoItem(heading)
Exemplo n.º 52
0
 def construct(cls):
     input_function = get_input_function()
     heading = input_function('Input heading: ')
     price = input_function('Input price: ')
     return ToBuyItem(heading, price)
Exemplo n.º 53
0
 def construct(cls):
     input_function = get_input_function()
     heading = input_function('Input heading: ')
     link = input_function('Input link: ')
     due_date = input_function('Due date: ')
     return ToReadItem(heading, link, due_date)