Esempio n. 1
0
    def set_sellable(self, sellable):
        self.sellable = sellable
        if not self.sellable or not self.sellable.image:
            self.image.set_from_stock(Gtk.STOCK_MISSING_IMAGE,
                                      Gtk.IconSize.DIALOG)
            return

        if self._use_thumbnail:
            size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)

            if not sellable.image.thumbnail:
                # If image came without a thumbnail, generate one for it
                # This should happen only once for each image
                sellable.image.thumbnail = get_thumbnail(
                    sellable.image.image, size)

            pixbuf = get_pixbuf(sellable.image.thumbnail, size)
        else:
            pixbuf = _pixbuf_converter.from_string(sellable.image.image)
            iw, ih = pixbuf.get_width(), pixbuf.get_height()
            image_aspect = float(iw) / ih

            width, height = self._size
            window_aspect = float(width) / height

            if image_aspect < window_aspect:
                width = int(height * image_aspect)
            else:
                height = int(width / image_aspect)

            pixbuf = pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)

        self.image.set_from_pixbuf(pixbuf)
Esempio n. 2
0
    def _setup_thumbnail(self):
        if not self.image_model:
            self._thumbnail = None
            return

        size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        if not self.image_model.thumbnail:
            # If image came without a thumbnail, generate one for it
            # This should happen only once for each image
            self.image_model.thumbnail = get_thumbnail(
                self.image_model.image, size)

        self._thumbnail = get_pixbuf(self.image_model.thumbnail, fill_image=size)
Esempio n. 3
0
    def _update_widgets(self):
        branch = api.get_current_branch(self.store)

        is_main_branch = self.branch_filter.get_state().value is branch
        item = self.results.get_selected()

        sellable = item and item.product.sellable
        if sellable:
            if item.has_image:
                # XXX:Workaround for a bug caused by the image domain refactoring
                # which left some existent thumbnail as None
                thumbnail = sellable.image.thumbnail
                if thumbnail is None:
                    # Create new store to create the thumbnail
                    with api.new_store() as new_store:
                        image = sellable.image
                        image = new_store.fetch(image)
                        size = (Image.THUMBNAIL_SIZE_WIDTH,
                                Image.THUMBNAIL_SIZE_HEIGHT)
                        image.thumbnail = get_thumbnail(image.image, size)
                        thumbnail = image.thumbnail
                pixbuf = self.pixbuf_converter.from_string(thumbnail)
            else:
                pixbuf = None

            self._update_edit_image(pixbuf)
            if self.image_viewer:
                self.image_viewer.set_sellable(sellable)
        else:
            self._update_edit_image()

        # Always let the user choose the manage stock option and do a proper
        # check there (showing a warning if he can't)
        self.set_sensitive([self.ManageStock], bool(item))
        self.set_sensitive([self.EditProduct, self.PrintLabels], bool(item))
        self.set_sensitive([self.ProductStockHistory],
                           bool(item) and is_main_branch)
        # We need more than one branch to be able to do transfers
        # Note that 'all branches' is not a real branch
        has_branches = len(self.branch_filter.combo) > 2

        transfer_active = self.NewTransfer.get_enabled()
        self.set_sensitive([self.NewTransfer], transfer_active
                           and has_branches)
        # Building a list of searches that we must disable if there is no
        # branches other than the main company
        searches = [
            self.SearchTransfer, self.SearchTransferItems,
            self.SearchPendingReturnedSales
        ]
        self.set_sensitive(searches, has_branches)
Esempio n. 4
0
    def _setup_thumbnail(self):
        if not self.image_model:
            self._thumbnail = None
            return

        size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        if not self.image_model.thumbnail:
            # If image came without a thumbnail, generate one for it
            # This should happen only once for each image
            self.image_model.thumbnail = get_thumbnail(self.image_model.image,
                                                       size)

        self._thumbnail = get_pixbuf(self.image_model.thumbnail,
                                     fill_image=size)
Esempio n. 5
0
    def _update_widgets(self):
        branch = api.get_current_branch(self.store)

        is_main_branch = self.branch_filter.get_state().value is branch
        item = self.results.get_selected()

        sellable = item and item.product.sellable
        if sellable:
            if item.has_image:
                # XXX:Workaround for a bug caused by the image domain refactoring
                # which left some existent thumbnail as None
                thumbnail = sellable.image.thumbnail
                if thumbnail is None:
                    # Create new store to create the thumbnail
                    with api.new_store() as new_store:
                        image = sellable.image
                        image = new_store.fetch(image)
                        size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
                        image.thumbnail = get_thumbnail(image.image, size)
                        thumbnail = image.thumbnail
                pixbuf = self.pixbuf_converter.from_string(thumbnail)
            else:
                pixbuf = None

            self._update_edit_image(pixbuf)
            if self.image_viewer:
                self.image_viewer.set_sellable(sellable)
        else:
            self._update_edit_image()

        # Always let the user choose the manage stock option and do a proper
        # check there (showing a warning if he can't)
        self.set_sensitive([self.ManageStock], bool(item))
        self.set_sensitive([self.EditProduct, self.PrintLabels], bool(item))
        self.set_sensitive([self.ProductStockHistory],
                           bool(item) and is_main_branch)
        # We need more than one branch to be able to do transfers
        # Note that 'all branches' is not a real branch
        has_branches = len(self.branch_filter.combo) > 2

        transfer_active = self.NewTransfer.get_enabled()
        self.set_sensitive([self.NewTransfer],
                           transfer_active and has_branches)
        # Building a list of searches that we must disable if there is no
        # branches other than the main company
        searches = [self.SearchTransfer, self.SearchTransferItems,
                    self.SearchPendingReturnedSales]
        self.set_sensitive(searches, has_branches)