Пример #1
0
            win.label_status.config(text=str(err), foreground="red")
        else:
            win.label_status.config(text="Success")
        win.progress_bar.stop()
        win.update()
        win.is_searching = False
    else:
        print("Searching is running")


win = Gui()
win.is_searching = False
win.show_img = True
#We init the task manager
task_manager = Task()
task_manager.run()

##############################################################################
#this code is to review, because can be x-x
#We pass the task who represent the command of search associate to task manager
win.cmd1 = lambda text: task_manager.add(lambda: search(win, text))
win.cmd2 = lambda: win.__setattr__('show_img', False if win.show_img else True)
##############################################################################

win.label_status.config(text="What do you search?", foreground='green')
win.create_tag('title', underline=1, justify=CENTER, font=('Arial', 16))
win.create_tag('url', justify=LEFT, font=('Arial', 12), foreground='green')
win.create_tag('error', justify=LEFT, font=('Arial', 12), foreground='red')
win.mainloop()
#We stop the task manager
task_manager.stop()
Пример #2
0
def task_menu(user, logger):
    continuation = True
    while continuation is True:
        print(f'\33[97m{"-" * 100}\33[m')
        print('''\33[34m
        1.add a task
        2.show my tasks
        3.edit a task
        4.share a task
        5.back\33[m''')
        choice = None
        while choice is None:
            try:
                choice = int(
                    input(
                        '\33[35m\t\t>> Please select one of the above items: \33[m'
                    ))
                assert choice in range(1, 6)
            except ValueError:
                print('\33[34m\t\tInvalid input. Please try again.\33[m')
            except AssertionError:
                print('\33[34m\t\tEnter a number between 1 and 5.\33[m')
                choice = None

        if choice == 1:  # add a task
            Task.add(user)
            logger.info('a new task added')
            write_to_file(User.user_list)

        elif choice == 2:  # show my tasks
            print(f'\33[97m{"-" * 100}\33[m')
            print('''\33[34m
        1.show all of the tasks
        2.daily report
        3.weekly report
        4.monthly report
        5.back\33[m''')
            item = None
            while item is None:
                try:
                    item = int(
                        input(
                            '\33[35m\t\t>> Please select one of the above items: \33[m'
                        ))
                    assert item in range(1, 6)
                except ValueError:
                    print('\33[35m\t\tInvalid input. Please try again.\33[m')
                except AssertionError:
                    print('\33[35m\t\tEnter a number between 1 and 5.\33[m')
                    item = None

            if item == 1:
                user.show_tasks()
            elif item == 2:
                Task.daily_report(user)
            elif item == 3:
                Task.weekly_report(user)
            elif item == 4:
                Task.monthly_report(user)
            elif item == 5:
                continue

        elif choice == 3:  # edit a task
            if not user.tasks:
                print('\33[35m\t\tNo task defined yet...\33[m')
                input("\n\t\tPress Enter to Continue...")
                continue

            user.show_tasks()
            code = None
            while code is None:
                try:
                    code = int(
                        input(
                            '\33[35m\t\tPlease enter the task code which you wanna edit: \33[m'
                        ))
                    assert code in range(
                        1,
                        len(user.tasks) +
                        1) and user.tasks[code - 1].activation is True
                except ValueError:
                    print('\33[35m\t\tInvalid input. Please try again.\33[m')
                except AssertionError:
                    print('\33[35m\t\tInvalid number. Please try again.\33[m')
                    code = None

            print('''\33[34m
        1.done              2.postpone
        3.category          4.description
        5.location          6.link
        7.importance        8.urgency
                   9.delete\33[m''')
            item = None
            while item is None:
                try:
                    item = int(
                        input(
                            '\33[35m\t\t>> Which item do you wanna edit? \33[m'
                        ))
                    assert item in range(1, 10)
                except ValueError:
                    print('\33[35\t\tmInvalid input. Please try again.\33[m')
                except AssertionError:
                    print('\33[35m\t\tEnter a number between 1 and 9.\33[m')
                    item = None
            edit_task(user.tasks[code - 1], user, item, logger)
            write_to_file(User.user_list)

        elif choice == 4:  # share a task
            try:
                assert user.show_tasks()
                code = None
                while code is None:
                    try:
                        code = int(
                            input(
                                '\33[35m\t\tPlease enter the task code which you wanna share: \33[m'
                            ))
                        assert code in range(
                            1,
                            len(user.tasks) +
                            1) and user.tasks[code - 1].activation is True
                    except ValueError:
                        print(
                            '\33[35m\t\tInvalid input. Please try again.\33[m')
                    except AssertionError:
                        print(
                            '\33[35m\t\tInvalid number. Please try again.\33[m'
                        )
                        code = None

                usernames = None
                while usernames is None:
                    usernames = input(
                        '\33[35m\t\tEnter the usernames of the users you wanna share with.\n\t\t'
                        ' (separated with comma) : \33[m').split(',')
                    usernames = [username.strip() for username in usernames]
                    for username in usernames:
                        try:
                            assert username in [
                                user.username for user in User.user_list
                            ]
                        except AssertionError:
                            print(
                                f'\33[35m\t\t{username} does not exist.\33[m')
                            usernames = None
                            break
                user.tasks[code - 1].share(usernames)
                input("\n\t\tDone.\n\t\tPress Enter to Continue...")
            except AssertionError:
                print(
                    '\33[35m\t\tDefine a task first, then try to share it.\33[m'
                )
                input("\t\tPress Enter to Continue...")

        elif choice == 5:  # back
            continuation = False
Пример #3
0
class Main:
    def __init__(self):
        self.model = Model()
        self.task = Task()
        self.tag = Tag()
        self.config = Config()
        self.params = Params()
        self.screen = Screen()

        self.fzf = FzfPrompt()

        self.parser = argparse.ArgumentParser('ztm')
        self.parser.add_argument('-c', '--current', dest='active', action='store_true')
        self.parser.set_defaults(active=False)

    def run(self):
        n = self.parser.parse_args()
        if n.active:
            self.params.update('active', True)
        self.menu()

    def menu(self):
        about = '''
Short instruction
-----------------
? - help (this dialog)
+ - add
/ - search
t - tag manager
c - configuration
q - exit
            '''
        self.screen.change_path('~', '?+/tcq', about)
        menu = self.screen.print()

        if menu == '?':
            self.screen.activate_about()
            self.menu()

        elif menu == '+':
            self.task.add()
            self.menu()

        elif menu == '/':
            self.task.search()
            self.menu()

        elif menu == 't':
            self.tag.manage_tag()
            self.menu()

        elif menu == 'c':
            self.config.manage()
            self.menu()

        elif menu == 'q':
            self.screen.bye()

        else:
            self.screen.add_fail('This is not implemented...')
            self.menu()