Beispiel #1
0
    def add_to_ex_grid(self):

        set_number = self.number_sets.text

        # Sets all of the data to what the user inputted
        reps_label = Label(
            text=self.completed_reps.text +
            ' Reps')  # Creates label with newest number of reps inputted
        weight_label = Label(
            text=self.completed_weight.text +
            ' Pounds')  # Creates label with newest amount of weight inputted
        set_label = Label(text='Set ' + set_number)
        # Checks to make sure there is a name and numbers of sets as input
        if self.completed_reps.text and self.completed_weight.text != "":

            # Adds the input to the grid
            self.display_ex_grid.add_widget(set_label)
            self.display_ex_grid.add_widget(
                reps_label)  # Adds the reps to the grid
            self.display_ex_grid.add_widget(
                weight_label)  # Adds the weight to the grid

            # Creates variables to store routine data
            name_text = self.display_ex_name.text
            sets_text = set_number  # Stores the amount of sets
            reps_text = self.completed_reps.text  # Stores the amount of reps
            weight_text = self.completed_weight.text  # Stores the amount of weight

            newest_line_check = 0
            file_name = self.display_name.text + '.csv'
            newest_line = self.get_newest_line(file_name)

            with open('routines/' +
                      file_name) as csv_file:  # Opens the file to read
                csv_reader = csv.reader(csv_file,
                                        delimiter=',')  # Starts the csv reader
                for row in csv_reader:  # Loops through the rows in the file
                    newest_line_check += 1  # Increments once for each new row it loops through
                    if newest_line_check != newest_line:  # Checks to see if you are not on the newest like
                        pass  # If your not, do nothing
                    else:

                        # TODO, if user doesnt do an exercise, exercise name still needed in the row being created
                        for element in range(len(row)):
                            element_name = ""
                            if row[element][0] == '[':

                                element_name = ast.literal_eval(
                                    row[element]
                                )  # To convert the 'string' in csv file to a list
                                element_name = element_name[
                                    0]  # To get the first element in the list

                            if row[element] == name_text or element_name == name_text:
                                # Appends all the exercise info to the list (order important)
                                update_workout_list[element].append(name_text)
                                update_workout_list[element + 1].append(
                                    sets_text
                                )  # Adds the number of sets to the list
                                update_workout_list[element + 2].append(
                                    reps_text
                                )  # Adds the number of reps to the list
                                update_workout_list[element + 3].append(
                                    weight_text
                                )  # Adds the amount of weight to the list
                                print(update_workout_list)

            self.number_sets.text = str(int(self.number_sets.text) + 1)

            # Calls the next step
            ScreenManager.reset_set_input(self)

            # Changes previous set
            ScreenManager.display_next_set(self)