Esempio n. 1
0
    def change_weight_action(self, exercise_button, *args):
        if not self.change_weight:
            self.ids.main_scroll.do_scroll_y = False
            self.change_weight = True
            self.weight_canvas = InstructionGroup()
            self.weight_canvas.add(Color(0, 0, 0, 0.4))
            self.background = Rectangle(rectangle=(0, 0, 0, 0))
            self.weight_canvas.add(self.background)
            self.weight_canvas.add(Color(1, 1, 1, 1))
            self.weight_rect = Rectangle(rectangle=(0, 0, 0, 0))
            self.weight_canvas.add(self.weight_rect)
            self.canvas.add(self.weight_canvas)
            self.weight_input = IntegerInput(self, "Weight(kg)", 0, 500, True, exercise_button.exercise.weight, None,
                                             size_hint=[1 / 3, None], height=100,
                                             pos_hint={"x": 1 / 3, "center_y": 4 / 9})
            label_text = ""
            if exercise_button.exercise.base_exercise.equipment == "Dumbbell":
                label_text = "The weight for each dumbbell. "
            elif exercise_button.exercise.base_exercise.equipment == "Barbell":
                label_text = "The total weight of the barbell (usually 20kg/45lb) and the plates on either side"

            self.info_label = KivyLabel(grid=self, font_size=20, halign="center", size_hint=[3 / 4, 1 / 3],
                                        pos_hint={"center_x": 1 / 2, "top": 3 / 4}, color=(0, 0, 0, 1), text=label_text)

            self.save_button = KivyButton(grid=self, md_bg_color=L_GREEN, font_size=25, on_release_action=None,
                                          size_hint=[9 / 20, 1 / 10],
                                          pos_hint={"x": 11 / 40, "y": 11 / 40}, text="Save Weight")
            self.save_button.bind(on_release=lambda _: self.save_weight(self.weight_input.text, exercise_button))
            self.update_bg()
            self.bind(size=self.update_bg, pos=self.update_bg)
            self.bind(on_touch_up=self.weight_touch_up)
Esempio n. 2
0
    def __init__(self,
                 selected_exercise,
                 routine_grid,
                 exercise_data=None,
                 **kwargs):
        super(ExerciseGrid, self).__init__(**kwargs)
        self.selected_exercise = selected_exercise
        self.routine_grid = routine_grid
        self.height = 265

        # Grid for the exercise name and 'Delete' buttons
        name_grid = GridLayout(cols=2,
                               size_hint_x=1,
                               spacing=[10, 0],
                               padding=[10, 0])
        KivyButton(grid=name_grid,
                   md_bg_color=L_GREEN,
                   on_release_action=self.exercise_info,
                   font_size=15,
                   size_hint=[1 / 2, None],
                   text=selected_exercise.name,
                   height=50)

        KivyButton(grid=name_grid,
                   md_bg_color=L_GREEN,
                   on_release_action=self.delete_exercise,
                   font_size=15,
                   size_hint=[1 / 2, None],
                   text="Delete",
                   height=50)
        self.add_widget(name_grid)

        start_numbers = [8, 1, 20, 4, 0, 90]
        if exercise_data is not None:
            start_numbers = exercise_data

        self.all_text_inputs = []
        # Using the 'IntegerInput' class to represent the text inputs for the different parameters
        text_inputs = [[
            "Reps", "Min Reps", "Max Reps", "Sets", "Weight (kg)",
            "Rest Time (s)"
        ], [1, 1, 1, 1, 0, 1], [21, 21, 21, 7, 500, 500],
                       [False, False, False, False, True, False],
                       start_numbers]

        input_grid = GridLayout(cols=3,
                                size_hint_x=1,
                                spacing=[25, 0],
                                padding=[10, 0])
        for i in range(len(text_inputs[0])):
            text_input = IntegerInput(input_grid, text_inputs[0][i],
                                      text_inputs[1][i], text_inputs[2][i],
                                      text_inputs[3][i], text_inputs[4][i],
                                      self.routine_grid)
            self.all_text_inputs.append(text_input)
        self.add_widget(input_grid)
Esempio n. 3
0
    def start(self):
        self.update_event = Clock.schedule_interval(self.update, 0)
        self.ids.action_grid.clear_widgets()
        KivyButton(grid=self.ids.action_grid, md_bg_color=ORANGE, font_size=15, on_release_action=self.gym_action,
                   size_hint=[1 / 2, None], height=50, text="Gym")

        KivyLabel(grid=self.ids.action_grid, font_size=25, size_hint=[1 / 2, None], height=50)
Esempio n. 4
0
    def __init__(self, routine_grid, **kwargs):
        super(SuperSetGrid, self).__init__(**kwargs)
        self.routine_grid = routine_grid
        self.height = 70
        self.main_grid = GridLayout(cols=1,
                                    size_hint_x=1,
                                    padding=[10, 10],
                                    spacing=[0, 10])
        self.all_text_inputs, self.all_exercises = [], []

        name_grid = GridLayout(cols=2, size_hint_x=1, spacing=[10, 0])
        KivyLabel(grid=name_grid,
                  font_size=30,
                  size_hint=[1 / 2, None],
                  text="Super-Set",
                  height=50)
        KivyButton(grid=name_grid,
                   md_bg_color=L_GREEN,
                   font_size=15,
                   on_release_action=self.delete_super_set,
                   size_hint=[1 / 2, None],
                   text="Delete Super Set")

        self.main_grid.add_widget(name_grid)
        self.insert_add_exercise_button()
        self.add_widget(self.main_grid)
Esempio n. 5
0
    def __init__(self,
                 selected_exercise,
                 super_set_grid,
                 exercise_data=None,
                 **kwargs):
        super(SuperSetExerciseGrid, self).__init__(**kwargs)
        self.selected_exercise = selected_exercise
        self.super_set_grid = super_set_grid
        self.cols, self.size_hint_x = 1, 1
        self.spacing, self.all_text_inputs = [25, 0], []
        self.exercise_grid = GridLayout(cols=2, size_hint_x=1, spacing=[10, 0])
        KivyButton(grid=self.exercise_grid,
                   md_bg_color=L_GREEN,
                   font_size=15,
                   on_release_action=self.exercise_info,
                   size_hint=[1 / 2, None],
                   text=selected_exercise.name)
        KivyButton(grid=self.exercise_grid,
                   md_bg_color=L_GREEN,
                   font_size=15,
                   on_release_action=self.delete_exercise,
                   size_hint=[1 / 2, None],
                   text="Delete Exercise")
        self.add_widget(self.exercise_grid)
        if exercise_data is not None:
            exercise_numbers = exercise_data
        else:
            exercise_numbers = [8, 1, 20, 0]

        # Add the non initial parameters to the exercise grid
        text_inputs_data = [["Reps", "Min Reps", "Max Reps", "Weight (kg)"],
                            [1, 1, 1, 0], [21, 21, 21, 500],
                            [False, False, False, True], exercise_numbers]
        self.text_input_grid = GridLayout(cols=2,
                                          size_hint_x=1,
                                          spacing=[10, 5],
                                          padding=[10, 5])
        for i in range(4):
            text_input = IntegerInput(
                self.text_input_grid, text_inputs_data[0][i],
                text_inputs_data[1][i], text_inputs_data[2][i],
                text_inputs_data[3][i], text_inputs_data[4][i],
                self.super_set_grid)
            self.all_text_inputs.append(text_input)
        self.add_widget(self.text_input_grid)
Esempio n. 6
0
    def __init__(self, app, **kwargs):
        super(CreateScreen, self).__init__(**kwargs)
        self.app = app

        for muscle in self.muscles:
            KivyButton(self.ids.muscle_pick_grid,
                       L_GREEN,
                       25,
                       None, [1 / 2, 1 / 3],
                       text=muscle).bind(on_release=lambda button: self.
                                         insert_exercise_pick(button))
Esempio n. 7
0
 def insert_add_exercise_button(self):
     # Function to add the 'Add Exercise' button to the super set grid
     if len(self.all_exercises) < 3 and self.add_exercise_button is None:
         self.height += 60
         self.add_exercise_button = KivyButton(
             grid=self.main_grid,
             md_bg_color=L_GREEN,
             font_size=15,
             on_release_action=self.insert_muscle_pick,
             size_hint=[1 / 2, None],
             text="Add Exercise")
Esempio n. 8
0
    def __init__(self, active_exercise, screen, **kwargs):
        super(ExerciseGrid, self).__init__(**kwargs)
        self.active_exercise = active_exercise
        self.base_exercise = active_exercise.base_exercise
        self.reps = active_exercise.reps
        self.sets = active_exercise.sets
        self.weight = active_exercise.weight
        self.rest_time = active_exercise.rest_time
        self.main_grid = GridLayout(cols=1)
        self.screen = screen
        self.height = 190
        grid = GridLayout(cols=1, padding=[10, 10], spacing=[0, 10], size_hint=[1, None])

        title_grid = GridLayout(cols=2, size_hint=[1, None], height=40)
        grid.add_widget(title_grid)
        KivyButton(grid=title_grid, md_bg_color=L_GREEN, font_size=15, on_release_action=None, size_hint=[1 / 2, None],
                   height=40, text=f"{self.base_exercise.name}")
        self.rest_title = KivyLabel(title_grid, font_size=25, halign="right", size_hint=[1 / 2, None], height=40)

        exercise_info_grid = GridLayout(cols=2, size_hint=[1, None], height=40)

        rep_text = f"{self.sets} sets of {self.reps} reps"

        if self.base_exercise.each_side:
            rep_text += " each side"

        weight_button = KivyButton(grid=exercise_info_grid, md_bg_color=L_GREEN, font_size=15, on_release_action=None,
                                   size_hint=[1 / 2, None], height=40, text=f"{self.weight} kg")
        weight_button.bind(on_release=lambda weight_button: screen.change_weight_action(weight_button))

        KivyLabel(grid=exercise_info_grid, font_size=30, halign="center", size_hint=[1 / 2, None], height=40,
                  text=rep_text)

        grid.add_widget(exercise_info_grid)

        self.exercise_row = ExerciseRow(self.sets, self.reps, self.rest_time, self, self.screen)
        grid.add_widget(self.exercise_row)

        self.add_widget(grid)
Esempio n. 9
0
    def add_exercise_info(self, exercise, show_add_button):
        self.clear_widgets()
        self.add = True
        self.exercise = exercise
        self.padding, self.spacing = [10, 10], [0, 5]

        KivyLabel(self,
                  30,
                  "center",
                  text=f"{exercise.name} info",
                  size_hint=[1, 1 / 10])
        self.add_widget(MDSeparator(height=2))
        KivyLabel(self,
                  25,
                  "center",
                  text=f"{exercise.name} info coming soon!",
                  size_hint=[1, 8 / 10])

        button_hint = [1, None]
        if show_add_button:
            button_hint = [1 / 2, None]

        grid = GridLayout(cols=2, size_hint=[1, None], spacing=[10, 0])
        KivyButton(grid,
                   L_GREEN,
                   25,
                   self.remove_card,
                   size_hint=button_hint,
                   text="Cancel")
        if show_add_button:
            KivyButton(grid,
                       L_GREEN,
                       25,
                       self.add_exercise,
                       button_hint,
                       text="Add Exercise")
        self.add_widget(grid)
Esempio n. 10
0
 def insert_add_buttons(self):
     if self.add_button_grid is None and len(self.all_sets) < 10:
         button_info = [["Add Exercise", "Add Superset"],
                        [self.screen.insert_muscle_pick, self.add_superset]]
         self.add_button_grid = GridLayout(cols=2,
                                           size_hint=[1, None],
                                           height=50,
                                           spacing=[10, 0])
         self.add_widget(self.add_button_grid)
         for text, action in zip(button_info[0], button_info[1]):
             KivyButton(self.add_button_grid,
                        L_GREEN,
                        15,
                        action, [1 / 2, None],
                        text=text)
     if self.finish_button is None and len(self.all_sets) > 0:
         self.finish_button = KivyButton(self,
                                         L_GREEN,
                                         15,
                                         self.finish_routine, [1, None],
                                         text="Finish Routine")
     elif self.finish_button is not None and len(self.all_sets) == 0:
         self.remove_widget(self.finish_button)
         self.finish_button = None
Esempio n. 11
0
    def start_routine(self, routine):
        self.ids.active_routine_grid.clear_widgets()
        self.ids.title.text = routine.name
        self.all_grids = []
        self.routine = routine

        if self.weight_canvas is not None:
            self.canvas.remove(self.weight_canvas)

        for set in self.routine.exercises:
            if isinstance(set, SuperSet):
                grid = SuperSetGrid(set, self)
                self.all_grids.append(grid)
                self.ids.active_routine_grid.add_widget(grid)
            elif isinstance(set, Exercise):
                grid = ExerciseGrid(set, self)
                self.all_grids.append(grid)
                self.ids.active_routine_grid.add_widget(grid)

        KivyButton(grid=self.ids.active_routine_grid, md_bg_color=L_GREEN, font_size=15,
                   on_release_action=self.finish_routine, size_hint=[1, None], height=100, text="Finish Routine")
Esempio n. 12
0
    def show_routine(self, routine):
        self.ids.routine_display_grid.clear_widgets()
        self.selected_routine = routine

        spare_height = Window.size[1] - 330

        title_grid = GridLayout(cols=2)
        self.ids.routine_display_grid.add_widget(title_grid)
        KivyLabel(grid=title_grid,
                  font_size=(45 - len(routine.name)),
                  halign="left",
                  text=routine.name,
                  size_hint=[1 / 2, None],
                  height=50)
        KivyLabel(grid=title_grid,
                  font_size=(45 - len(routine.name)),
                  halign="left",
                  text=routine.name,
                  size_hint=[1 / 2, None],
                  height=50)
        KivyButton(grid=title_grid,
                   md_bg_color=L_GREEN,
                   font_size=15,
                   on_release_action=self.hide_routine,
                   size_hint=[1 / 2, None],
                   text="Back",
                   height=50)

        set_number, exercise_number = 0, 0

        for exercise_set in routine.exercises:
            if isinstance(exercise_set, SuperSet):
                set_number += 1
            elif isinstance(exercise_set, Exercise):
                exercise_number += 1

        for exercise_set in routine.exercises:

            spare_height -= 11
            if spare_height < 80:
                break
            self.ids.routine_display_grid.add_widget(
                MDSeparator(height=1, size_hint=[1, None]))
            if isinstance(exercise_set, SuperSet):
                set_text = "set"
                if exercise_set.sets != 1:
                    set_text += "s"
                KivyLabel(
                    grid=self.ids.routine_display_grid,
                    font_size=20,
                    halign="left",
                    text=
                    f"Super Set - {exercise_set.sets} {set_text} for each exercise:",
                    height=20,
                    size_hint=[1, None])
                spare_height -= 40
                set_number -= 1
                for exercise in exercise_set.super_set_exercises:
                    if spare_height < 40:
                        break
                    rep_text = "rep"
                    if exercise.reps != 1:
                        rep_text += "s"
                    KivyLabel(
                        grid=self.ids.routine_display_grid,
                        font_size=20,
                        halign="left",
                        size_hint=[1, None],
                        text=
                        f"    {exercise.base_exercise.name} - {exercise.reps} {rep_text}",
                        height=20)
                    spare_height -= 30
            elif isinstance(exercise_set, Exercise):
                set_text = "set"
                if exercise_set.sets != 1:
                    set_text += "s"
                rep_text = "rep"
                if exercise_set.reps != 1:
                    rep_text += "s"
                KivyLabel(
                    grid=self.ids.routine_display_grid,
                    font_size=20,
                    halign="left",
                    height=20,
                    size_hint=[1, None],
                    text=
                    f"{exercise_set.base_exercise.name} - {exercise_set.sets} {set_text} of {exercise_set.reps} {rep_text}"
                )
                spare_height -= 30
                exercise_number -= 1

        if set_number != 0:
            self.ids.routine_display_grid.add_widget(
                MDSeparator(height=1, size_hint=[1, None]))
            KivyLabel(grid=self.ids.routine_display_grid,
                      font_size=20,
                      halign="left",
                      height=20,
                      text=f"+{set_number} more super-set")

        if exercise_number != 0:
            self.ids.routine_display_grid.add_widget(
                MDSeparator(height=1, size_hint=[1, None]))
            exercise_remain_text = "more exercise"
            if exercise_number > 1:
                exercise_remain_text += "s"
            KivyLabel(grid=self.ids.routine_display_grid,
                      font_size=20,
                      halign="left",
                      height=20,
                      size_hint=[1, None],
                      text=f"+{exercise_number} {exercise_remain_text}")

        self.ids.routine_display_grid.add_widget(MDSeparator(height=1))

        action_grid = GridLayout(cols=3,
                                 size_hint=[1, None],
                                 spacing=[10, 0],
                                 height=50)
        self.ids.routine_display_grid.add_widget(action_grid)
        action_button_dict = {
            "Start Routine": self.start_routine,
            "Edit Routine": self.edit_routine,
            "Delete Routine": self.delete_routine
        }

        for button_text, action in action_button_dict.items():
            KivyButton(grid=action_grid,
                       md_bg_color=L_GREEN,
                       font_size=15,
                       on_release_action=action,
                       size_hint=[1 / 3, None],
                       text=button_text)

        KivyLabel(self.ids.routine_display_grid)

        Animation(x=0, duration=0.2).start(self.ids.routine_display)
Esempio n. 13
0
class ActiveGymScreen(Screen):
    change_weight = False
    weight_canvas = None
    selected_exercise = None
    weight_input = None
    info_label = None
    save_button = None
    routine_changed = False
    previous_routine = None

    def __init__(self, app, **kwargs):
        super(ActiveGymScreen, self).__init__(**kwargs)
        self.app = app

    def start_routine(self, routine):
        self.ids.active_routine_grid.clear_widgets()
        self.ids.title.text = routine.name
        self.all_grids = []
        self.routine = routine

        if self.weight_canvas is not None:
            self.canvas.remove(self.weight_canvas)

        for set in self.routine.exercises:
            if isinstance(set, SuperSet):
                grid = SuperSetGrid(set, self)
                self.all_grids.append(grid)
                self.ids.active_routine_grid.add_widget(grid)
            elif isinstance(set, Exercise):
                grid = ExerciseGrid(set, self)
                self.all_grids.append(grid)
                self.ids.active_routine_grid.add_widget(grid)

        KivyButton(grid=self.ids.active_routine_grid, md_bg_color=L_GREEN, font_size=15,
                   on_release_action=self.finish_routine, size_hint=[1, None], height=100, text="Finish Routine")

    def change_weight_action(self, exercise_button, *args):
        if not self.change_weight:
            self.ids.main_scroll.do_scroll_y = False
            self.change_weight = True
            self.weight_canvas = InstructionGroup()
            self.weight_canvas.add(Color(0, 0, 0, 0.4))
            self.background = Rectangle(rectangle=(0, 0, 0, 0))
            self.weight_canvas.add(self.background)
            self.weight_canvas.add(Color(1, 1, 1, 1))
            self.weight_rect = Rectangle(rectangle=(0, 0, 0, 0))
            self.weight_canvas.add(self.weight_rect)
            self.canvas.add(self.weight_canvas)
            self.weight_input = IntegerInput(self, "Weight(kg)", 0, 500, True, exercise_button.exercise.weight, None,
                                             size_hint=[1 / 3, None], height=100,
                                             pos_hint={"x": 1 / 3, "center_y": 4 / 9})
            label_text = ""
            if exercise_button.exercise.base_exercise.equipment == "Dumbbell":
                label_text = "The weight for each dumbbell. "
            elif exercise_button.exercise.base_exercise.equipment == "Barbell":
                label_text = "The total weight of the barbell (usually 20kg/45lb) and the plates on either side"

            self.info_label = KivyLabel(grid=self, font_size=20, halign="center", size_hint=[3 / 4, 1 / 3],
                                        pos_hint={"center_x": 1 / 2, "top": 3 / 4}, color=(0, 0, 0, 1), text=label_text)

            self.save_button = KivyButton(grid=self, md_bg_color=L_GREEN, font_size=25, on_release_action=None,
                                          size_hint=[9 / 20, 1 / 10],
                                          pos_hint={"x": 11 / 40, "y": 11 / 40}, text="Save Weight")
            self.save_button.bind(on_release=lambda _: self.save_weight(self.weight_input.text, exercise_button))
            self.update_bg()
            self.bind(size=self.update_bg, pos=self.update_bg)
            self.bind(on_touch_up=self.weight_touch_up)

    def update_bg(self, *args):
        self.background.size, self.background.pos = [self.width, self.height], [0, 0]
        self.weight_rect.size, self.weight_rect.pos = [self.width * 3 / 4, self.height / 2], [self.width / 8,
                                                                                              self.height / 4]

    def weight_touch_up(self, *args):
        if not self.width / 4 < args[1].x < self.width * (3 / 4) or not self.height / 4 < args[1].y < self.height * (
                3 / 4):
            self.unbind(on_touch_up=self.weight_touch_up)

    def change_weight_bool(self, *args):
        self.ids.main_scroll.do_scroll_y = True
        self.change_weight = False

    def save_weight(self, exercise_text, exercise_button):
        self.hide_weight_change()
        try:
            float(exercise_text)
        except ValueError:
            return
        exercise_button.text = f"{float(exercise_text)} kg"

        self.previous_routine = self.routine

        for exercise_set in self.routine.exercises:
            if isinstance(exercise_set, SuperSet):
                for exercise in exercise_set.super_set_exercises:
                    if exercise.base_exercise.number == exercise_button.exercise.base_exercise.number:
                        pass
                        exercise.weight = float(exercise_text)
            elif isinstance(exercise_set, Exercise):
                if exercise_set.base_exercise.number == exercise_button.exercise.base_exercise.number:
                    pass
                    exercise_set.weight = float(exercise_text)

        save_new_routine("files/gym_files/saved_routines.pkl", [self.routine.name, self.routine.exercises],
                         self.previous_routine)
        self.routine_changed = True

    def finish_routine(self):
        self.previous_routine = self.routine
        all_data = []
        for set_of_exercises in self.all_grids:
            if isinstance(set_of_exercises, SuperSetGrid):
                superset_data = ["Superset", [set_of_exercises.sets, set_of_exercises.rest_time], []]
                for active_exercise in set_of_exercises.active_exercises:
                    superset_data[2].append([active_exercise, []])
                for row in set_of_exercises.all_rows:
                    for i in range(len(row.all_buttons)):
                        superset_data[2][i][1].append(row.all_buttons[i].reps)
                all_data.append(superset_data)
            elif isinstance(set_of_exercises, ExerciseGrid):
                exercise_data = ["Exercise", set_of_exercises.active_exercise, []]
                for button in set_of_exercises.exercise_row.all_buttons:
                    exercise_data[2].append(button.reps)
                all_data.append(exercise_data)

        def progression_calculator(exercise, reps_completed, total_reps):
            def weight_calculator(weight, progression):
                if 0.0 <= float(weight) < 10.0:
                    weight = round(weight) + progression * 1
                    if weight < 0.0:
                        weight = 0.0
                    elif weight > 10.0:
                        weight = 10.0

                elif 10.0 <= float(weight) < 20.0:
                    weight = round(weight) + progression * 2
                    if weight < 10.0:
                        weight = 10.0
                    elif weight > 20.0:
                        weight = 20.0

                elif float(weight) >= 20.0:
                    if exercise.base_exercise.equipment == "Dumbbell":
                        weight += 2.0
                    elif exercise.base_exercise.equipment == "Barbell" or "Body-weight":
                        weight += 2.5
                return float(weight)

            progress = 0

            if (reps_completed / total_reps) * 100 == 100.0:
                progress = 1
            elif 75.0 <= (reps_completed / total_reps) * 100 < 100.0:
                progress = 0
            elif 0.0 <= (reps_completed / total_reps) * 100 < 75.0:
                progress = -1

            exercise.reps = exercise.reps + progress

            if exercise.reps > exercise.max_reps:
                exercise.weight = weight_calculator(exercise.weight, 1)
                exercise.reps = exercise.min_reps
            elif exercise.reps < exercise.min_reps:
                exercise.weight = weight_calculator(exercise.weight, -1)
                exercise.reps = exercise.max_reps
            return exercise

        new_routine_exercises = []
        for data in all_data:
            if data[0] == "Superset":
                new_exercises = []
                for exercise in data[2]:
                    reps_completed = 0
                    for active_reps in exercise[1]:
                        if active_reps is None:
                            active_reps = 0
                        reps_completed += active_reps
                    new_exercises.append(
                        progression_calculator(exercise[0], reps_completed, exercise[0].reps * data[1][0]))
                new_routine_exercises.append(SuperSet(new_exercises, [data[1][0], data[1][1]]))

            elif data[0] == "Exercise":
                reps_completed = 0
                for active_reps in data[2]:
                    if active_reps is None:
                        active_reps = 0
                    reps_completed += active_reps
                new_routine_exercises.append(
                    progression_calculator(data[1], reps_completed, data[1].reps * data[1].sets))
        save_new_routine("files/gym_files/saved_routines.pkl", [self.routine.name, new_routine_exercises],
                         self.previous_routine)

        screen = self.app.screen_action("gym_screen", "down", "R/T")
        screen.start()

    def hide_weight_change(self):
        self.unbind(size=self.update_bg, pos=self.update_bg)
        if self.weight_canvas is not None:
            self.canvas.remove(self.weight_canvas)
            self.weight_canvas = None
        self.change_weight = False
        if self.weight_input is not None:
            self.remove_widget(self.weight_input)
        if self.info_label is not None:
            self.remove_widget(self.info_label)
        if self.save_button is not None:
            self.remove_widget(self.save_button)
        Clock.schedule_once(self.change_weight_bool, 0.5)

    def gym_screen(self):
        if not self.change_weight:
            screen = self.app.screen_action("gym_screen", "down", "R/T")
            screen.start()

    def home_screen(self):
        if not self.change_weight:
            self.app.screen_action(selected_screen_name="home_screen", direction="down", action="R/T").start()

    def open_nav_drawer(self):
        if not self.change_weight:
            self.ids.nav_drawer.set_state()
Esempio n. 14
0
    def __init__(self, active_super_set, screen, **kwargs):
        super(SuperSetGrid, self).__init__(**kwargs)
        self.active_exercises = active_super_set.super_set_exercises
        self.sets = active_super_set.sets
        self.rest_time = active_super_set.rest_time
        self.screen = screen
        self.height = 225 + 60 * self.sets
        self.all_rows = []
        grid = GridLayout(cols=1, size_hint=[1, None], height=250 + 60 * self.sets, spacing=[0, 10], padding=[10, 10])

        title_grid = GridLayout(cols=2, size_hint=[1, None], height=40)

        KivyLabel(grid=title_grid, font_size=30, halign="center", size_hint=[1 / 2, None], text="Super-Set", height=40)
        self.rest_title = KivyLabel(grid=title_grid, font_size=30, halign="right", size_hint=[1 / 2, None], height=40)
        grid.add_widget(title_grid)

        exercise_button_grid = GridLayout(rows=1, cols=len(self.active_exercises), size_hint=[1, None],
                                          height=50, spacing=[10, 0])

        exercise_weight = GridLayout(rows=1, cols=len(self.active_exercises), size_hint=[1, None],
                                     height=30, spacing=[10, 0])

        exercise_reps = GridLayout(rows=1, cols=len(self.active_exercises), size_hint=[1, None],
                                   height=30, spacing=[10, 0])

        rep_data = []
        weight_data = []

        for exercise in self.active_exercises:
            rep_data.append(exercise.reps)
            weight_data.append(exercise.weight)

            new_name = []
            for word in exercise.base_exercise.name.split(" "):
                new_name.append(word.capitalize())

            button = KivyButton(grid=exercise_button_grid, md_bg_color=L_GREEN, font_size=15,
                                size_hint=[1 / len(self.active_exercises), None], text="\n".join(new_name), height=30)
            button.bind(on_release=lambda exercise_button: self.exercise_info(exercise_button.exercise))

            button = KivyButton(grid=exercise_weight, md_bg_color=L_GREEN, font_size=15,
                                size_hint=[1 / len(self.active_exercises), None], text=f"{exercise.weight} kg",
                                height=30)
            button.exercise = exercise
            button.bind(on_release=lambda weight_button: screen.change_weight_action(weight_button))

            rep_text = f"{exercise.reps} reps"
            if exercise.base_exercise.each_side:
                rep_text += " each side"

            KivyLabel(grid=exercise_reps, font_size=20, halign="center",
                      size_hint=[1 / len(self.active_exercises), None], height=30, text=rep_text)

        grid.add_widget(exercise_button_grid)
        grid.add_widget(exercise_weight)
        grid.add_widget(exercise_reps)
        self.add_widget(grid)
        active_set_grid = GridLayout(rows=self.sets * 2, size_hint=[1, None], padding=[0, 0])
        grid.add_widget(active_set_grid)

        for i in range(self.sets):
            KivyLabel(grid=active_set_grid, halign="center", size_hint=[1, None], height=10)
            row = SuperSetRow(active_set_grid, rep_data, self.rest_time, self, i)
            self.all_rows.append(row)