コード例 #1
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)
コード例 #2
0
ファイル: home_screen.py プロジェクト: CMS-APP/Sportzone
    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)
コード例 #3
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)
コード例 #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)
コード例 #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)
コード例 #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))
コード例 #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")
コード例 #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)
コード例 #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)
コード例 #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
コード例 #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")
コード例 #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)
コード例 #13
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)