Exemplo n.º 1
0
    def last_substitute(self):
        """
            Method called when last Substitute Button is pressed
            Get the index in (list) substitutes of the first Item in the combobox
            If the index > 0 --> Fill the combox with the last items
            using range Tuple
            Amount of items showed can be configured in the settings
        """
        if self.ui.cb_substitute.count() > 0:
            first_item = self.ui.cb_substitute.itemText(0)
            index_in_list = next(
                (index for index, item in enumerate(self.substitutes)
                 if item.name == first_item),
                -1,
            )

            if index_in_list > 0:
                range = self.get_last_range(index_in_list,
                                            CST.NB_OF_SUBSTITUTE_TO_SHOW)
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                substitutes_name = [
                    str(substitute)
                    for substitute in self.substitutes[range[0]:range[1]]
                ]
                widgets.add_list_items_to_combobox(self.ui.cb_substitute,
                                                   substitutes_name)
Exemplo n.º 2
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")
Exemplo n.º 3
0
    def next_substitute(self):
        """
            Method called when next Substitute Button is pressed
            Get the index in (list) substitutes of the last Item in the combobox
            If the index < len(substitutes) --> Fill the combox with the next items
            using range Tuple.
            Amount of items showed can be configured in the settings
        """
        if (self.ui.cb_category.count() > 0
                and self.ui.cb_category.count() == CST.NB_OF_CATEGORY_TO_SHOW):
            last_item = self.ui.cb_substitute.itemText(
                self.ui.cb_substitute.count() - 1)
            index_in_list = next(
                (index for index, item in enumerate(self.substitutes)
                 if item.name == last_item),
                -1,
            )

            if index_in_list < len(self.substitutes) - 1:
                range = self.get_next_range(len(self.substitutes),
                                            index_in_list,
                                            CST.NB_OF_SUBSTITUTE_TO_SHOW)
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                substitutes_name = [
                    str(substitute)
                    for substitute in self.substitutes[range[0]:range[1]]
                ]
                widgets.add_list_items_to_combobox(self.ui.cb_substitute,
                                                   substitutes_name)
Exemplo n.º 4
0
    def last_product(self):
        """
            Method called when last products Button is pressed
            Get the index in (list) productss of the first Item in the combobox
            If the index > 0 --> Fill the combox with the last items
            using range Tuple
            Amount of items showed can be configured in the settings
        """
        if self.ui.cb_product.count() > 0:
            first_item = self.ui.cb_product.itemText(0)
            index_in_list = next(
                (index for index, item in enumerate(self.products)
                 if item.name == first_item),
                -1,
            )

            if index_in_list > 0:
                range = self.get_last_range(index_in_list,
                                            CST.NB_OF_PRODUCT_TO_SHOW)
                self.ui.cb_substitute.clear()
                widgets.empty_table_column(self.ui.tab_product, 1)
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                products_name = [
                    str(product)
                    for product in self.products[range[0]:range[1]]
                ]
                widgets.add_list_items_to_combobox(self.ui.cb_product,
                                                   products_name)
Exemplo n.º 5
0
    def next_product(self):
        """
            Method called when next product Button is pressed
            Get the index in (list) products of the last Item in the combobox
            If the index < len(products) --> Fill the combox with the next items
            using range Tuple.
            Amount of items showed can be configured in the settings
        """
        if self.ui.cb_product.count() > 0:
            last_item = self.ui.cb_product.itemText(
                self.ui.cb_product.count() - 1)
            index_in_list = next(
                (index for index, item in enumerate(self.products)
                 if item.name == last_item),
                -1,
            )

            if (index_in_list < len(self.products) - 1 and
                    self.ui.cb_category.count() == CST.NB_OF_CATEGORY_TO_SHOW):
                range = self.get_next_range(len(self.products), index_in_list,
                                            CST.NB_OF_PRODUCT_TO_SHOW)
                self.ui.cb_substitute.clear()
                widgets.empty_table_column(self.ui.tab_product, 1)
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                products_name = [
                    str(product)
                    for product in self.products[range[0]:range[1]]
                ]
                widgets.add_list_items_to_combobox(self.ui.cb_product,
                                                   products_name)
Exemplo n.º 6
0
    def select_product(self, text):
        """
        Method used when cb_product is activated
        Attributes :receive the Actual text in the combobox
        Show the product's attribut in tab_product.
        This method retrieves the substitutes depending of the source
        selected by the user.
        Load the substitute's name in cb_substitute Combobox
        """
        if self.ui.cb_product.count() > 0:
            product = next(
                (prod for prod in self.products if prod.name == text), None)
            widgets.populate_tab_column(self.ui.tab_product,
                                        product.list_attributes_to_show(), 1)

            self.substitutes = product.find_substitutes(
                self.sql,
                self.ui.cb_source.currentText(),
                self.ui.cb_category.currentText(),
            )
            if len(self.substitutes) > 0:
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                substitutes_name = [
                    str(substitute) for substitute in
                    self.substitutes[:CST.NB_OF_SUBSTITUTE_TO_SHOW]
                ]
                widgets.add_list_items_to_combobox(self.ui.cb_substitute,
                                                   substitutes_name)
                Message.select(self.message, "substitute")
Exemplo n.º 7
0
    def select_category(self):
        """
            Method used when cb_category is activated

            This method retrieves the product depending of the source
            selected by the user.
            Load the product's name in cb_producty Combobox
        """
        if self.ui.cb_category.count() > 0:
            category = self.ui.cb_category.currentText()
            if self.ui.cb_source.currentText() == "API":
                self.products = Prod.select_from_api(self.message, self.sql,
                                                     category)
            else:
                self.products = Prod.select_from_db(self.sql, self.message,
                                                    category)
                if len(self.products) == 0:
                    self.products = Prod.select_from_api(
                        self.message, self.sql, category)

            if len(self.products) > 0:
                self.ui.cb_substitute.clear()
                widgets.empty_table_column(self.ui.tab_product, 1)
                widgets.empty_table_column(self.ui.tab_substitute, 1)
                products_name = [
                    str(product)
                    for product in self.products[:CST.NB_OF_PRODUCT_TO_SHOW]
                ]
                widgets.add_list_items_to_combobox(
                    self.ui.cb_product,
                    products_name,
                )
                Message.select(self.message, "product")