def save_and_create(self): # Checks to make sure the routine name is not empty if self.workout_name.text != "": if workout_list: # Gets the name of the routine to be used as the button routine_name = self.workout_name.text # Creates list containing entire routine routine_name_list.append( routine_name) # First entry is always the routine name routine_name_list.append( 'Not Used') # Second entry is always the last used date routine_name_list.extend( workout_list ) # The rest is each exercise, set, rep, weight file_name = routine_name + '.csv' # Creates the file name (as .csv file) my_file = open("routines/" + file_name, 'w') # Creates the file to store the routine # Dict headers to point to the data in the dict fieldnames = [ 'routine', 'last_used', 'name', 'sets', 'reps', 'weight' ] # Uses dictWriter to create a csv file with the data in its correct column writer = DictWriter(my_file, fieldnames=fieldnames, extrasaction='ignore', delimiter=',', lineterminator='\n') # Creates all of the titles for the .csv file csv_titles = ['Routine Name', 'Last Used' ] # The first two titles will always be this number_exercises = int( len(workout_list) / 4 ) # Gets number of exercise names (not everything in list /4) for i in range( number_exercises ): # Loops through each one and adds titles for each csv_titles.append('Exercise Name') # Exercise Name title csv_titles.append('Sets') # Sets title csv_titles.append('Reps') # Reps title csv_titles.append('Weight') # Weight title # Dict writer writes to the file writer.writer.writerow( csv_titles ) # Writes the titles across the top row of csv file writer.writer.writerow( routine_name_list ) # Writes the routine underneath the titles my_file.close() # Closes file # Updates the Routines page and adds the new routine button to the page ScreenManager.update_routines(self) self.save_button.text = str( 'Saved') # Change button to 'saved' # Resets the add_routine page so its ready for a new entry self.add_routine_grid.clear_widgets( ) # Clears out the grid layout self.add_routine_grid.rows = 0 # Resets the rows in the add_routine grid # Changes screen to Routines self.transition.direction = 'right' # Sets the transition direction self.current = "Routines" # Which screen to change to