예제 #1
0
    def return_to_course(self) -> None:
        """returns to the course screen"""
        def yes_func():
            self.clear_fields()
            utils.switch_screen(self, 'course_view_screen', 'right')

        if self._assignment is not None:
            str_pts_rec = '' if self._assignment.pts_rec is None else str(
                self._assignment.pts_rec)
            if self._name != self._assignment.name or self.ids.checkbox_graded.active != self._assignment.is_graded(
            ) or self._pts_rec != str_pts_rec or self._pts_total != str(
                    self._assignment.pts_total
            ) or self.ids.cat_spinner.text != self._course.get_cateogry_from_assign(
                    self._assignment).name:
                utils.yesno_popup(
                    'Are you sure you want to go back?  This assignment will not be updated.',
                    yes_func)
            else:
                yes_func()

        elif self._name == '' and self._pts_rec == '' and self._pts_total == '' and self.ids.checkbox_graded.active:
            utils.switch_screen(self, 'course_view_screen', 'right')
        else:
            utils.yesno_popup(
                'Are you sure you want to go back?  This assignment will not be added.',
                yes_func)
예제 #2
0
 def save_categories(self) -> None:
     """saves all of the changes made to the categories"""
     cats = []
     for cat, fl, n, w in self._category_layouts.values():
         name = n.text.strip()
         if name.replace(
                 ' ', '') != '':  # if all categories have a name, continue
             try:
                 weight_f = float(w.text)  # if all weights are valid
             except ValueError:
                 utils.default_popup(
                     f'The weight of {name} must be a number.')
                 break
             else:
                 cats.append((name, weight_f))
         else:
             utils.default_popup('All categories must have a name.')
             break
     else:
         s = sum([i[1] for i in cats])
         if s == 100:
             for i in range(len(self._course.categories)):
                 self._course.categories[i].name = cats[i][0]
                 self._course.categories[i].weight = cats[i][1]
             utils.SCREENS['course_view_screen'].init(self._course)
             utils.SCREENS['schedule_screen']._schedule.save()
             utils.switch_screen(self, 'course_view_screen', 'right')
             self.clear_fields()
         else:
             utils.default_popup(
                 f'The sum of all weights must be 100%, it is currently {s}%'
             )
예제 #3
0
 def submit_genres(self, genres):
     Logger.info('GENRES: %s', genres)
     if len(genres) >= 1:
         self.genres_dialog.genres_dialog.dismiss()
         self.app.genres = genres
         switch_screen(ArtistsPage(), 'artists_page')
     else:
         toast('You must at least choose one genre.')
예제 #4
0
 def yes_func():
     try:
         schedule_loader.delete_schedule(self._schedule.name)
     except utils.ScheduleDeleteError as e:
         utils.default_popup(f'{e.message}\nTry reloading the schedule and then deleting it.')
     else:
         utils.SCREENS['home_screen'].remove_schedule(self._schedule.name)
         self._schedule = None
         utils.switch_screen(self, 'home_screen', 'right')
예제 #5
0
 def get_and_save_genres(*args):
     self.loading.active = False
     if req.status_code == 200:
         self.app.genres = req.response['genres']
         Logger.debug(self.app.genres)
         self.age_dialog.dismiss()
         switch_screen(ArtistsPage(), 'artists_page')
     else:
         msg = "Failed to get genrs. Retrying in 3 seconds."
         self.snackbar = create_snackbar(msg, retry)
         self.retry_event = Clock.schedule_once(retry, 3)
         self.snackbar.open()
예제 #6
0
    def return_to_course(self) -> None:
        """returns to the course screen"""
        def yes_func():
            self.clear_fields()
            utils.switch_screen(self, 'course_view_screen', 'right')

        if self._name == '':
            utils.switch_screen(self, 'course_view_screen', 'right')
        else:
            utils.yesno_popup(
                'Are you sure you want to go back?  This category will not be added to the course.',
                yes_func)
예제 #7
0
 def add_category(self) -> None:
     """adds the category to the course"""
     name = self._name.strip()
     if name.replace(' ',
                     '') != '':  # if the name is blank space, show an error
         if name not in [c.name for c in self._course.categories]:
             self._course.add_category(course.Category(name, 0))
             utils.SCREENS['schedule_screen']._schedule.save()
             utils.SCREENS['course_view_screen'].init(self._course)
             self.clear_fields()
             utils.switch_screen(self, 'course_view_screen', 'right')
         else:
             utils.default_popup(
                 f'A category with name {name} already exists.')
     else:
         utils.default_popup('Category name cannot be left blank.')
예제 #8
0
 def add_assignment(self) -> None:
     """adds the assignment to the course"""
     name = self._name.strip()
     if name.replace(' ',
                     '') != '':  # if the name is empty space, show an error
         pts_rec_f = None
         if self.ids.checkbox_graded.active:
             try:
                 pts_rec_f = float(self._pts_rec)
                 if pts_rec_f < 0:
                     utils.default_popup(
                         'Points recieved must be greater than 0.')
                     return
             except ValueError:
                 utils.default_popup('Points recieved must be a number.')
                 return
         try:
             pts_total_f = float(self._pts_total)
             if pts_total_f < 0:
                 utils.default_popup('Poins total must be greater than 0.')
                 return
         except ValueError:
             utils.default_popup('Points total must be a number.')
         else:
             if self.ids.cat_spinner.text in self.ids.cat_spinner.values:  # if the category has not been chosen, show an error
                 if self._assignment is not None:  # if you are editing an assignment, first remove the old one, then
                     self._course.del_assignment(
                         self._assignment
                     )  # add in the new one, otherwise just add the new one
                 self._course.add_assignment(
                     self._course.get_category(self.ids.cat_spinner.text),
                     course.Assignment(name, pts_rec_f, pts_total_f))
                 utils.SCREENS['course_view_screen'].init(self._course)
                 utils.SCREENS['schedule_screen'].update_gpa()
                 utils.SCREENS['schedule_screen']._schedule.save()
                 utils.switch_screen(self, 'course_view_screen', 'right')
                 self.clear_fields()
             else:
                 utils.default_popup(
                     'You must chose a category for the assignment to be in.'
                 )
     else:
         utils.default_popup('Assignment name cannot be blank.')
예제 #9
0
    def get_preferences(self, code, platform):
        page = OAuthInfoPage()
        page_name = 'oauth_page'
        switch_screen(page, page_name)

        def retry(*args):
            self.snackbar.dismiss()
            self.retry_event.cancel()
            self.get_preferences(code, platform)
            return

        def get_and_save_preferences(*args):
            if req.status_code == 200:
                self.app.genres = req.response['genres']
                self.app.artists = req.response['artists']
                Logger.debug(self.app.genres)
                if self.app.genres:
                    OAuthCompletePage(self.app.genres, self.app.artists)
                else:
                    msg = (f"Sorry, couldn't guess "
                           f"preferences from {platform.capitalize()}")
                    for button in self.ids.choices_layout.children[0].children:
                        if platform in button.text.lower():
                            button.disabled = True
                            break
                    self.snackbar = create_snackbar(msg, callback=None)
                    self.app.screen_manager.switch_to(self.parent)
                    self.snackbar.open()
            else:
                msg = "Failed to get preferences. Retrying in 3 seconds."
                self.snackbar = create_snackbar(msg, retry)
                self.retry_event = Clock.schedule_once(retry, 3)
                self.snackbar.open()

        if self.get_preferences_trigger is None:
            self.get_preferences_trigger = Clock.create_trigger(
                get_and_save_preferences
            )
        req = self.app.api.get_preferences(
            code=code,
            platform=platform,
            trigger=self.get_preferences_trigger
        )
예제 #10
0
    def back(self) -> None:
        if (self._schedule is not None and self._name == self._schedule.name
                and self._gpa == str(self._schedule.current_gpa)
                and self._units == str(self._schedule.current_units)):
            self._clear_text_fields()
            utils.switch_screen(self, 'schedule_screen', 'right')
            return

        elif (self._name == '' and self._gpa == '' and self._units == ''):
            utils.switch_screen(
                self, 'home_screen',
                'right')  # if no changes have been made, then slide back
        else:

            def yes_func():
                self._clear_text_fields()
                utils.switch_screen(
                    self, 'home_screen', 'right'
                )  # if changes have been made make sure they meant to go back

            utils.yesno_popup(
                'Are you sure you want to go back?  This schedule will not be saved.',
                yes_func)
예제 #11
0
    def create(self) -> None:
        name = self._name.strip()
        if name != '':  # if the name is not empty space or just spaces
            if self._schedule is not None or name not in utils.SCREENS[
                    'home_screen'].sch_names:  # it a schedule of that name does not already exist
                gpa_f = 0
                try:  # make sure the GPA is a number
                    gpa_f = float(self._gpa)
                except ValueError:
                    utils.default_popup('G.P.A. must be a number.')
                else:
                    if gpa_f < 0:  # make sure the GPA is >= 0
                        utils.default_popup(
                            'G.P.A. must be greater than zero.')
                    else:
                        try:
                            units_f = float(self._units.strip(
                            ))  # make sure the units is a number
                        except ValueError:
                            utils.default_popup(
                                'Previous units taken must be a number.')
                        else:
                            units_i = int(units_f)
                            if (units_f < 0):  # make sure the units is >= 0
                                utils.default_popup(
                                    'Previous units taken must be greater than zero.'
                                )
                            elif (units_i != units_f
                                  ):  # make sure the units is a whole number
                                utils.default_popup(
                                    'Previous units taken must be a whole number'
                                )
                            else:
                                if self._schedule is None:  # if there is no schedule, it is a new schedule
                                    self._schedule = schedule.Schedule(
                                        name, gpa_f, units_i, [])
                                else:  # otherwise update the current one and save it
                                    schedule_loader.delete_schedule(
                                        self._schedule.name)
                                    utils.SCREENS[
                                        'home_screen'].remove_schedule(
                                            self._schedule.name)
                                    self._schedule.name = name
                                    self._schedule.current_gpa = gpa_f
                                    self._schedule.current_units = units_i
                                    self._schedule.save()

                                self._schedule.save()
                                utils.SCREENS['schedule_screen'].init(
                                    self._schedule)
                                self._schedule = None
                                utils.switch_screen(self, 'schedule_screen',
                                                    'left')

                                utils.SCREENS['home_screen'].add_sch_button(
                                    name)
                                utils.SCREENS[
                                    'home_screen'].check_view_no_sch_lbl()
                                self._clear_text_fields()
            else:
                utils.default_popup(
                    f'A schedule with that name "{name}" already exists.')
        else:
            utils.default_popup('Schedule name cannot be left blank.')
예제 #12
0
 def yes_func():
     self._clear_text_fields()
     utils.switch_screen(
         self, 'home_screen', 'right'
     )  # if changes have been made make sure they meant to go back
예제 #13
0
 def launch_create_schedule(self) -> None:
     """switches over to the create schedule screen"""
     utils.switch_screen(self, 'create_schedule', 'left')
예제 #14
0
 def yes_func():
     self._course.categories = self._org_categories
     utils.SCREENS['course_view_screen'].init(self._course)
     utils.SCREENS['schedule_screen']._schedule.save()
     utils.switch_screen(self, 'course_view_screen', 'right')
     self.clear_fields()
예제 #15
0
 def launch_edit_schedule(self) -> None:
     """opens up the schedule editor with all of the info in the schedule already displayed"""
     utils.SCREENS['create_screen'].init(self._schedule)
     utils.switch_screen(self, 'create_schedule', 'left')
예제 #16
0
 def load_course(c: course.Course):
     utils.switch_screen(self, 'course_view_screen', 'left')
     utils.SCREENS['course_view_screen'].init(c)
예제 #17
0
 def launch_add_course(self) -> None:
     """switches the screen to add course"""
     utils.switch_screen(self, 'course_screen', 'right')
예제 #18
0
 def return_to_homescreen(self) -> None:
     """sets the screen to the homescreen"""
     self._schedule.save()
     utils.switch_screen(self, 'home_screen', 'right')
예제 #19
0
 def yes_func():
     self.clear_fields()
     utils.switch_screen(self, 'course_view_screen', 'right')
예제 #20
0
 def load_screen(
         *args):  # function that is custom to each button schedule
     utils.switch_screen(self, 'schedule_screen', 'left')
     utils.SCREENS['schedule_screen'].init(
         schedule_loader.load_schedule(name))