Beispiel #1
0
    def select_source(self, text):
        """
            Method used when cb_source is activated
            Attributes :receive the Actual text in the combobox

            This method retrieves the category depending of the source
            selected by the user.
            Load the category's name in cb_category Combobox
        """
        if text == "API":
            self.categories = Cat.select_from_api(self.message)
        else:
            self.categories = Cat.select_from_db(self.sql, self.message)
            if len(self.categories) == 0:
                self.categories = Cat.select_from_api(self.message)

        if len(self.categories) > 0:
            self.ui.cb_product.clear()
            self.ui.cb_substitute.clear()
            widgets.empty_table_column(self.ui.tab_product, 1)
            widgets.empty_table_column(self.ui.tab_substitute, 1)
            categories_name = [
                str(category)
                for category in self.categories[:CST.NB_OF_CATEGORY_TO_SHOW]
            ]
            widgets.add_list_items_to_combobox(self.ui.cb_category,
                                               categories_name)
            Message.select(self.message, "category")