def __init__(self, parent):
        self.parent = parent
        self.frame = ttk.Frame(parent.frame)

        self.current_subject = None
        self.current_section = None

        self.labels = {
            'subject code': {
                'text': 'Código:'
            },
            'section': {
                'text': 'Paralelo:'
            }
        }
        self.comboboxes = {
            'subject code': {
                'items': callbacks.get_subject_list(),
                'textvariable': tk.StringVar(self.frame)
            },
            'section': {
                'items': callbacks.get_section_list(self.current_subject), 
                'textvariable': tk.StringVar(self.frame)
            }
        }
        self.buttons = {
            'submit schedule': {
                'text': 'Ingresar',
                'command': self.new_schedule_option
            },
            'delete schedule': {
                'text': 'Borrar',
                'command': self.delete_schedule_option
            }
        }    
    def subject_selected_callback(self, ve):
        self.current_subject = self.comboboxes['subject code']['textvariable'].get()
        self.comboboxes['section']['widget']['values']=callbacks.get_section_list(self.current_subject)
        self.comboboxes['section']['textvariable'].set(self.comboboxes['section']['widget']['values'][0])
        self.current_section = self.comboboxes['section']['widget']['values'][0]
        self.parent.children['schedule_child'].clear_schedule()

        if (self.current_subject is not None) and (self.current_section is not None):
            self.parent.children['schedule_child'].load_schedule(
                self.current_subject, self.current_section)
 def section_write_callback(self, ve):
     #print('Escribiste algo en el paralelo')
     section = self.comboboxes['section']['textvariable'].get().strip()
     if section.isdigit() or section == '':
         subject_list = callbacks.get_subject_list()
         if self.comboboxes['subject code']['textvariable'].get() in subject_list:   
             self.current_section = section
             self.parent.children['schedule_child'].clear_schedule()
             section_list = callbacks.get_section_list(self.current_subject)
             if (self.current_subject is not None) and (self.current_section is not None) and (self.current_section in section_list):
                 self.parent.children['schedule_child'].load_schedule(
                     self.current_subject, self.current_section)
     else:
         
         messagebox.showinfo(
                 title='Paralelo',
                 message='El paralelo debe ser un número entero'
             )
         while (not section.isdigit()) and (not section==''):
             section = section[slice(len(section)-1)]
         self.comboboxes['section']['textvariable'].set(section)
    def subject_write_callback(self, ve):
        #print('Escribiste algo en el ramo')
        subject_list = callbacks.get_subject_list()
        if self.comboboxes['subject code']['textvariable'].get() in subject_list:
            self.current_subject = self.comboboxes['subject code']['textvariable'].get()

            section_list = callbacks.get_section_list(self.current_subject)
            self.comboboxes['section']['widget']['values'] = section_list
            self.current_section = self.comboboxes['section']['widget']['values'][0]
            self.comboboxes['section']['textvariable'].set(
                    self.current_section
                )
        else:
            self.current_subject = None
            self.current_section = None
            self.comboboxes['section']['textvariable'].set('')
        if (self.current_subject is not None) and (self.current_section is not None):
            self.parent.children['schedule_child'].load_schedule(
                self.current_subject, self.current_section)
        else:
            self.parent.children['schedule_child'].clear_schedule()
    def delete_schedule_option(self):
        subject_code = self.comboboxes['subject code']['textvariable'].get()
        section = self.comboboxes['section']['textvariable'].get()
        if not subject_code:
            if not section:
                error_message = 'No hay ramo ni paralelo para eliminar'
            else:
                error_message = 'No hay ramo para eliminar'
            messagebox.showinfo(
                    title='Eliminar opción de horario',
                    message=error_message
                )
        elif not section:
            error_message = 'No hay paralelo para eliminar'
            messagebox.showinfo(
                    title='Eliminar opción de horario',
                    message=error_message
                )
        else:
            anwser = messagebox.askyesno(
                message='¿Estas segur@ de que quieres eliminar el paralelo {} del ramo {}?'.format(section, subject_code),
                title='Eliminar opción de horario'
            )
            if anwser:
                delete_result = callbacks.delete_schedule_option(subject_code, section)
                if type(delete_result)==str:
                    messagebox.showinfo(
                        title='Eliminar opción de horario',
                        message=delete_result
                    )
                self.comboboxes['subject code']['textvariable'].set('')
                self.comboboxes['section']['textvariable'].set('')
                self.current_subject = None
                self.current_section = None

                self.comboboxes['subject code']['widget']['values']=callbacks.get_subject_list()
                self.comboboxes['section']['widget']['values']=callbacks.get_section_list(self.current_subject)
                
            else:
                pass
    def new_schedule_option(self):
        schedule_dictionary = self.get_schedule_dict()
        subject_code = self.comboboxes['subject code']['textvariable'].get()
        section = self.comboboxes['section']['textvariable'].get()

        validate_result = callbacks.validate_new_schedule_option(subject_code, section)

        if validate_result[0]==subject_code:
            if validate_result[1]==section:
                callbacks.new_schedule_option(subject_code, section, schedule_dictionary)

                self.comboboxes['subject code']['textvariable'].set('')
                self.comboboxes['section']['textvariable'].set('')
                self.current_subject = None
                self.current_section = None
                self.comboboxes['subject code']['widget']['values']=callbacks.get_subject_list()
                self.comboboxes['section']['widget']['values']=callbacks.get_section_list(self.current_subject)

                messagebox.showinfo(
                    title='Agregar opción de horario',
                    message='Horario agragado correctamente'
                )
                self.parent.children['schedule_child'].clear_schedule()
            else:
                messagebox.showinfo(
                    title='Agregar opción de horario',
                    message=validate_result[1]
                )
        elif validate_result[1]==section:
            messagebox.showinfo(
                title='Agregar opción de horario',
                message=validate_result[0]
            )
        else:
            messagebox.showinfo(
                title='Agregar opción de horario',
                message=validate_result[0]+'\n'+validate_result[1]
            )