def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,
            font=const.SD_TITLE_FONT,
            text=const.SD_TITLE_TEXT,
            padx=const.SD_TITLE_PADX,
            pady=const.SD_TITLE_PADY,
        )

        self._f_subtitle = tk.Frame(self,
                                    relief=const.SD_SUBFRAME_RELIEF,
                                    padx=const.SD_SUBFRAME_PADX,
                                    pady=const.SD_SUBFRAME_PADY,
                                    bd=const.SD_SUBFRAME_BD)

        self._slo_name = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            font=const.SD_FONT,
            description=const.SD_NAME_TEXT,
            output_text=const.SD_INITIAL_NAME_TEXT)

        self._mo_description = MultilineOutputF(
            parent=self._f_subtitle,
            user_instruction=const.SD_DESCRIPTION_TEXT,
        )
    def _create_widgets(self):

        super()._create_widgets()

        self._lbl_title.config(text=const.TSSD_TITLE_TEXT)

        self._slo_neural_network = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_NN_MODEL_TEXT,
            output_text=const.TSSD_NN_MODEL_INITIAL_TEXT)

        self._slo_examples_per_batch = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_BATCH_SIZE_TEXT,
            output_text=const.TSSD_BATCH_SIZE_INITIAL_TEXT)

        self._slo_number_of_epochs = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_EPOCHS_NBR_TEXT,
            output_text=const.TSSD_EPOCHS_NBR_INITIAL_TEXT)

        self._slo_image_size = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_IMAGE_SIZE_TEXT,
            output_text=const.TSSD_IMAGE_SIZE_INITIAL_TEXT)
Esempio n. 3
0
    def _create_widgets(self):

        super()._create_widgets()

        title_text = const.USDO_TITLE_TEXT + str(self._data_set_index)

        self._lbl_title.config(text=title_text)

        self._slo_image_size = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.USDO_IMAGE_SIZE_TEXT,
            output_text=const.USDO_IMAGE_SIZE_INITIAL_TEXT)

        self._slo_number_of_files = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.USDO_NUMBER_OF_FILES_TEXT,
            output_text=const.USDO_NUMBER_OF_FILES_INITIAL_TEXT)

        self._slo_number_of_examples = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.USDO_NUMBER_OF_EXAMPLES_TEXT,
            output_text=const.USDO_NUMBER_OF_EXAMPLES_INITIAL_TEXT)
    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,
            font=const.TSOR_TITLE_FONT,
            text=const.TSOR_TITLE_TEXT,
            padx=const.TSOR_TITLE_PADX,
            pady=const.TSOR_TITLE_PADY,
        )

        self._f_results = tk.Frame(self,
                                   relief=const.TSOR_SUBFRAME_RELIEF,
                                   padx=const.TSOR_SUBFRAME_PADX,
                                   pady=const.TSOR_SUBFRAME_PADY,
                                   bd=const.TSOR_SUBFRAME_BD)

        self._slo_subtitle = SingleLineOutputF(
            parent=self,
            description_width=28,
            font=const.TSOR_SUBTITLE_FONT,
            description=const.TSOR_SUBTITLE_EVAL_METHOD_TEXT,
            output_text=const.TSOR_SUBTITLE_RESULT_TEXT)

        self._slo_precision = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_PRECISION_TEXT,
            output_text=const.TSOR_PRECISION_INITIAL_TEXT)

        self._slo_recall = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_RECALL_TEXT,
            output_text=const.TSOR_RECALL_INITIAL_TEXT)

        self._slo_f_measure = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_F_MEASURE_TEXT,
            output_text=const.TSOR_F_MEASURE_INITIAL_TEXT)
    def _create_widgets(self):

        super()._create_widgets()

        self._lbl_title.config(text=const.DSDO_TITLE_TEXT)

        self._slo_examples = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_EXAMPLES_NBR_TEXT,
            output_text=const.DSDO_EXAMPLES_NBR_INITIAL_TEXT
        )

        self._slo_classes_nbr = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_CLASSES_NBR_TEXT,
            output_text=const.DSDO_CLASSES_NBR_INITIAL_TEXT
        )

        self._slo_image_size = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_IMAGE_SIZE_TEXT,
            output_text=const.DSDO_IMAGE_SIZE_INITIAL_TEXT
        )

        self._classes_output = ClassesOutputF(
            parent=self._f_subtitle,
        )

        self._classes_output.config(relief='flat')
class TrainSessSaveDetailsOutputF(SaveDetailsOutputF):
    def __init__(self, parent, disabled=False):
        """
        :param parent: Parent.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.
        """

        SaveDetailsOutputF.__init__(self, parent, disabled)

        self._create_widgets()
        self._place_widgets()

        if disabled:
            self.disable()

    #########################################################################
    # Widget handling

    def _create_widgets(self):

        super()._create_widgets()

        self._lbl_title.config(text=const.TSSD_TITLE_TEXT)

        self._slo_neural_network = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_NN_MODEL_TEXT,
            output_text=const.TSSD_NN_MODEL_INITIAL_TEXT)

        self._slo_examples_per_batch = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_BATCH_SIZE_TEXT,
            output_text=const.TSSD_BATCH_SIZE_INITIAL_TEXT)

        self._slo_number_of_epochs = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_EPOCHS_NBR_TEXT,
            output_text=const.TSSD_EPOCHS_NBR_INITIAL_TEXT)

        self._slo_image_size = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            description=const.TSSD_IMAGE_SIZE_TEXT,
            output_text=const.TSSD_IMAGE_SIZE_INITIAL_TEXT)

    def _place_widgets(self):

        super()._place_widgets()

        self._slo_neural_network.pack(side='top', fill='both', expand=True)

        self._slo_examples_per_batch.pack(side='top', fill='both', expand=True)

        self._slo_number_of_epochs.pack(side='top', fill='both', expand=True)

        self._slo_image_size.pack(side='top', fill='both', expand=True)

    @staticmethod
    def _kill():
        """
        - In case something goes wrong this method displays a message and 
        exits the application.        
        """

        messagebox.showerror(title=const.TSSD_ERROR_TITLE,
                             message=const.TSSD_ERROR_MSG)

        sys.exit(3)

    #########################################################################
    # Public methods

    def update_save_details(self, train_sess_details: SessionDetails):
        """
        - Updates the session details

        :param train_sess_details: TrainSessionSaveDetails with the 
                                   session's details.
        """

        if not isinstance(train_sess_details, SessionDetails) \
                or not train_sess_details.is_valid():
            self._kill()

        self.update_output_text(name=train_sess_details.name,
                                description=train_sess_details.description)

        self._slo_neural_network.update_output(
            output_text=train_sess_details.neural_network)
        self._slo_examples_per_batch.update_output(
            output_text=train_sess_details.examples_per_batch)
        self._slo_number_of_epochs.update_output(
            output_text=train_sess_details.number_of_epochs)
        self._slo_image_size.update_output(
            output_text=train_sess_details.image_size)

    def enable(self):
        """ Enables all the widgets."""

        self._slo_examples_per_batch.enable()
        self._slo_number_of_epochs.enable()
        self._slo_neural_network.enable()
        self._slo_image_size.enable()
        super().enable()

    def disable(self):
        """ Disables all the widgets."""

        super().disable()
        self._slo_image_size.disable()
        self._slo_neural_network.disable()
        self._slo_number_of_epochs.disable()
        self._slo_examples_per_batch.disable()
class DataSetSaveDetailsOutputF(SaveDetailsOutputF):

    def __init__(self,

                 parent,

                 disabled=False):
        """
        :param parent: Parent.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.
        """

        SaveDetailsOutputF.__init__(self,
                                    parent,
                                    disabled)

        self._create_widgets()
        self._place_widgets()

        if disabled:
            self.disable()

    #########################################################################
    # Widget handling

    def _create_widgets(self):

        super()._create_widgets()

        self._lbl_title.config(text=const.DSDO_TITLE_TEXT)

        self._slo_examples = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_EXAMPLES_NBR_TEXT,
            output_text=const.DSDO_EXAMPLES_NBR_INITIAL_TEXT
        )

        self._slo_classes_nbr = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_CLASSES_NBR_TEXT,
            output_text=const.DSDO_CLASSES_NBR_INITIAL_TEXT
        )

        self._slo_image_size = SingleLineOutputF(
            parent=self._f_subtitle,

            description_width=const.SD_DESCRIPTION_WIDTH,

            description=const.DSDO_IMAGE_SIZE_TEXT,
            output_text=const.DSDO_IMAGE_SIZE_INITIAL_TEXT
        )

        self._classes_output = ClassesOutputF(
            parent=self._f_subtitle,
        )

        self._classes_output.config(relief='flat')

    def _place_widgets(self):

        super()._place_widgets()

        self._slo_examples.pack(side='top',
                                fill='both',
                                expand=True)

        self._slo_classes_nbr.pack(side='top',
                                   fill='both',
                                   expand=True)

        self._slo_image_size.pack(side='top',
                                  fill='both',
                                  expand=True)

        self._classes_output.pack(side='top',
                                  fill='both',
                                  expand=True)

    @staticmethod
    def _kill():
        """
        - In case something goes wrong this method displays a message and 
        exits the application.        
        """

        messagebox.showerror(
            title=const.DSDO_ERROR_TITLE,
            message=const.DSDO_ERROR_MSG
        )

        sys.exit(4)

    #########################################################################
    # Public methods

    def update_save_details(
            self,

            data_set_details: DataSetDetails):
        """
        - Updates the data set details

        :param data_set_details: DataSetSaveDetails with the data set's 
                                 details.
        """

        if not isinstance(data_set_details, DataSetDetails) \
                or not data_set_details.is_valid():
            self._kill()

        self.update_output_text(
            name=data_set_details.name,
            description=data_set_details.description
        )

        classes = data_set_details.classes

        number_of_classes = len(classes.get_data_set_classes())

        self._slo_examples.update_output(
            output_text=data_set_details.number_of_examples)
        self._slo_classes_nbr.update_output(
            output_text=str(number_of_classes))
        self._slo_image_size.update_output(
            output_text=data_set_details.image_size)

        self._classes_output.update_classes(data_set_details.classes)

    def enable(self):
        """ Enables all the widgets."""

        self._slo_examples.enable()
        self._slo_classes_nbr.enable()
        super().enable()

    def disable(self):
        """ Disables all the widgets."""

        super().disable()
        self._slo_classes_nbr.disable()
        self._slo_examples.disable()
class SaveDetailsOutputF(tk.Frame):
    """
    - Use to display save details (name and description).
    """
    def __init__(self, parent, disabled=False):
        """
        :param parent: Parent.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.
        """

        tk.Frame.__init__(self,
                          parent,
                          relief=const.SD_FRAME_RELIEF,
                          padx=const.SD_FRAME_PADX,
                          pady=const.SD_FRAME_PADY,
                          bd=const.SD_FRAME_BD)

        if disabled:
            self.disable()

    #########################################################################
    # Widget handling

    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,
            font=const.SD_TITLE_FONT,
            text=const.SD_TITLE_TEXT,
            padx=const.SD_TITLE_PADX,
            pady=const.SD_TITLE_PADY,
        )

        self._f_subtitle = tk.Frame(self,
                                    relief=const.SD_SUBFRAME_RELIEF,
                                    padx=const.SD_SUBFRAME_PADX,
                                    pady=const.SD_SUBFRAME_PADY,
                                    bd=const.SD_SUBFRAME_BD)

        self._slo_name = SingleLineOutputF(
            parent=self._f_subtitle,
            description_width=const.SD_DESCRIPTION_WIDTH,
            font=const.SD_FONT,
            description=const.SD_NAME_TEXT,
            output_text=const.SD_INITIAL_NAME_TEXT)

        self._mo_description = MultilineOutputF(
            parent=self._f_subtitle,
            user_instruction=const.SD_DESCRIPTION_TEXT,
        )

    def _place_widgets(self):

        self._lbl_title.pack(side='top', fill='both', expand=True)

        self._f_subtitle.pack(side='top', fill='both', expand=True)

        self._slo_name.pack(side='top', fill='both', expand=True)

        self._mo_description.pack(side='top', fill='both', expand=True)

    #########################################################################
    # Public methods

    def create_and_place_elements(self):
        """
        - Creates and places the widgets.
        """

        self._create_widgets()
        self._place_widgets()

    def update_output_text(self, name: str, description: str):
        """
        - Updates the name and the description.

        :param name: Name. 
        :param description: Description text.
        """

        self._slo_name.update_output(name)

        self._mo_description.set_output_text(output_text=description)

    def enable(self):
        """ Enables all the widgets."""

        self._lbl_title.config(state='normal')
        self._mo_description.enable()
        self._slo_name.enable()

    def disable(self):
        """ Disables all the widgets."""

        self._slo_name.disable()
        self._mo_description.disable()
        self._lbl_title.config(state='disabled')
class TestSessOverallResultsOutputF(tk.Frame):
    """
    - Use to display overall results for a test session.
    """
    def __init__(self, parent, disabled=False):
        """
        :param parent: Parent.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.
        """

        tk.Frame.__init__(self,
                          parent,
                          relief=const.TSOR_FRAME_RELIEF,
                          padx=const.TSOR_FRAME_PADX,
                          pady=const.TSOR_FRAME_PADY,
                          bd=const.TSOR_FRAME_BD)

        self._slo_identifiers_classes = []

        self._create_widgets()
        self._place_widgets()

        if disabled:
            self.disable()

    #########################################################################
    # Widget handling

    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,
            font=const.TSOR_TITLE_FONT,
            text=const.TSOR_TITLE_TEXT,
            padx=const.TSOR_TITLE_PADX,
            pady=const.TSOR_TITLE_PADY,
        )

        self._f_results = tk.Frame(self,
                                   relief=const.TSOR_SUBFRAME_RELIEF,
                                   padx=const.TSOR_SUBFRAME_PADX,
                                   pady=const.TSOR_SUBFRAME_PADY,
                                   bd=const.TSOR_SUBFRAME_BD)

        self._slo_subtitle = SingleLineOutputF(
            parent=self,
            description_width=28,
            font=const.TSOR_SUBTITLE_FONT,
            description=const.TSOR_SUBTITLE_EVAL_METHOD_TEXT,
            output_text=const.TSOR_SUBTITLE_RESULT_TEXT)

        self._slo_precision = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_PRECISION_TEXT,
            output_text=const.TSOR_PRECISION_INITIAL_TEXT)

        self._slo_recall = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_RECALL_TEXT,
            output_text=const.TSOR_RECALL_INITIAL_TEXT)

        self._slo_f_measure = SingleLineOutputF(
            parent=self._f_results,
            description_width=26,
            font=const.TSOR_FONT,
            description=const.TSOR_F_MEASURE_TEXT,
            output_text=const.TSOR_F_MEASURE_INITIAL_TEXT)

    def _place_widgets(self):

        self._lbl_title.pack(side='top', fill='both', expand=True)

        self._slo_subtitle.pack(side='top', fill='both', expand=True)

        self._slo_precision.pack(side='top', fill='both', expand=True)
        self._slo_recall.pack(side='top', fill='both', expand=True)
        self._slo_f_measure.pack(side='top', fill='both', expand=True)

        self._f_results.pack(side='top', fill='both', expand=True)

    #########################################################################
    # Public methods

    def update_results(self, overall_results: TestSessOverallResults):
        """
        - Updates the results.
        
        :param overall_results: Overall test session results. 
        """

        if overall_results.is_valid():
            self._slo_precision.update_output(output_text='%.2f' %
                                              overall_results.precision)

            self._slo_recall.update_output(output_text='%.2f' %
                                           overall_results.recall)

            self._slo_f_measure.update_output(output_text='%.2f' %
                                              overall_results.f_measure)
        else:
            raise ValueError('Overall results are not valid:\n\n' +
                             str(overall_results))

    def enable(self):
        """ Enables all the widgets."""

        self._lbl_title.config(state='normal')
        self._slo_precision.enable()
        self._slo_f_measure.enable()
        self._slo_subtitle.enable()
        self._slo_recall.enable()

        for item in self._slo_identifiers_classes:
            item.enable()

    def disable(self):
        """ Disables all the widgets."""

        self._slo_recall.disable()
        self._slo_subtitle.disable()
        self._slo_f_measure.disable()
        self._slo_precision.disable()
        self._lbl_title.config(state='disabled')