コード例 #1
0
def handle_add_total_calories_and_protein_for_week(window, values, db_path):
    try:
        week = int(values['-WEEK-'])
    except ValueError:
        sg.popup_error('You must provide a number for the week!',
                       title='Error')
    else:
        try:
            calories = int(values['-KCAL-'])
        except ValueError:
            sg.popup_error('You must provide a number for the calories!',
                           title='Error')
        else:
            try:
                protein = int(values['-PROTEIN-'])
            except ValueError:
                sg.popup_error(
                    'You must provide a number for the grams of protein!',
                    title='Error')
            else:
                confirmation = sg.popup_yes_no(
                    f"Are you sure you want to add week {week}, with {calories} "
                    f"total calories and {protein} total grams of protein?",
                    title='Confirmation')

                if calories > 0 and protein > 0 and confirmation == 'Yes':
                    sg.popup(add_total_calories_and_protein_for_week(
                        db_path, week, calories, protein),
                             title='Message')
                    window['-WEEK-'].update('')
                    window['-KCAL-'].update('')
                    window['-PROTEIN-'].update('')
                    window['-WEEK-'].update(
                        values=get_sorted_tuple(db_path, 'id', 'week'))
コード例 #2
0
def handle_add_food(window, values, db_path):
    food = values['-FOOD-'].strip()

    try:
        calories = int(values['-KCAL-'])
    except ValueError:
        sg.popup_error('You must provide a number for the calories!',
                       title='Error')
    else:
        try:
            protein = int(values['-PROTEIN-'])
        except ValueError:
            sg.popup_error(
                'You must provide a number for the grams of protein!',
                title='Error')
        else:
            if food and calories > 0 and protein >= 0:
                confirmation = sg.popup_yes_no(
                    f"Are you sure you want to add the food '{food}' to the database, "
                    f"with {calories} calories and {protein} grams of protein?",
                    title='Confirmation')

                if confirmation == 'Yes':
                    sg.popup(add_food(db_path, food, calories, protein),
                             title='Message')
                    window['-FOOD-'].update('')
                    window['-KCAL-'].update('')
                    window['-PROTEIN-'].update('')
                    window['-FOOD-'].update(
                        values=get_sorted_tuple(db_path, 'id', 'food'))
コード例 #3
0
def handle_delete_week(window, values, db_path):
    try:
        week = int(values['-WEEK-'])
    except ValueError:
        sg.popup_error('You must provide a number for the week!',
                       title='Error')
    else:
        confirmation = sg.popup_yes_no(
            f"Are you sure you want to delete week {week} from the database?",
            title='Confirmation')

        if confirmation == 'Yes':
            sg.popup(delete_week(db_path, week), title='Message')
            window['-WEEK-'].update('')
            window['-WEEK-'].update(
                values=get_sorted_tuple(db_path, 'id', 'week'))
コード例 #4
0
def handle_delete_food(window, values, db_path):
    food = values['-FOOD-'].strip()

    if food:
        confirmation = sg.popup_yes_no(
            f"Are you sure you want to delete the food '{food}' from the database?",
            title='Confirmation')

        if confirmation == 'Yes':
            sg.popup(delete_food(db_path, food), title='Message')
            window['-FOOD-'].update('')
            window['-FOOD-'].update(
                values=get_sorted_tuple(db_path, 'id', 'food'))

    else:
        sg.popup_error('You must enter a food!', title='Error')
コード例 #5
0
def handle_add_equipment(window, values, db_path):
    equipment = values['-EQUIPMENT-'].strip()

    if equipment:
        confirmation = sg.popup_yes_no(
            f"Are you sure you want to add the '{equipment}' equipment to the database?",
            title='Confirmation')

        if confirmation == 'Yes':
            sg.popup(add_equipment(db_path, equipment), title='Message')
            window['-EQUIPMENT-'].update('')
            window['-EQUIPMENT-'].update(
                values=get_sorted_tuple(db_path, 'id', 'equipment'))

    else:
        sg.popup_error('You must provide some equipment!', title='Error')
コード例 #6
0
def handle_delete_exercise(window, values, db_path):
    exercise = values['-EXERCISE-'].strip()

    if exercise:
        confirmation = sg.popup_yes_no(
            f"Are you sure you want to delete the '{exercise}' exercise from the database?",
            title='Confirmation')

        if confirmation == 'Yes':
            sg.popup(delete_exercise(db_path, exercise), title='Message')
            window['-EXERCISE-'].update('')
            window['-EXERCISE-'].update(
                values=get_sorted_tuple(db_path, 'id', 'exercise'))

    else:
        sg.popup_error('You must enter an exercise!', title='Error')
コード例 #7
0
def handle_add_exercise(window, values, db_path):
    exercise = values['-EXERCISE-'].strip()
    equipment = values['-EQUIPMENT-'].strip()

    if exercise and equipment:
        confirmation = sg.popup_yes_no(
            f"Are you sure you want to add the '{exercise}' exercise to the database, with the '{equipment}' equipment?",
            title='Confirmation')

        if confirmation == 'Yes':
            sg.popup(add_exercise(db_path, exercise, equipment),
                     title='Message')
            window['-EXERCISE-'].update('')
            window['-EQUIPMENT-'].update('')
            window['-EXERCISE-'].update(
                values=get_sorted_tuple(db_path, 'id', 'exercise'))

    else:
        sg.popup_error('You must provide an exercise and its equipment!',
                       title='Error')